Skip to content

Commit

Permalink
Small amount of cleanup:
Browse files Browse the repository at this point in the history
Downgraded many log messages from WARN to INFO;
Generally replaced leading spaces in log messages with tabs;
Generally replaced "" with String.Empty.
  • Loading branch information
simon-brooke committed Feb 23, 2017
1 parent d600f8f commit 48e8de2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 47 deletions.
42 changes: 20 additions & 22 deletions SuiteCRMAddIn/BusinessLogic/AppointmentSyncing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public string GetID(string sEmailID, string sModule)
{
string str5 = "(" + sModule.ToLower() + ".id in (select eabr.bean_id from email_addr_bean_rel eabr INNER JOIN email_addresses ea on eabr.email_address_id = ea.id where eabr.bean_module = '" + sModule + "' and ea.email_address LIKE '%" + SuiteCRMAddIn.clsGlobals.MySqlEscape(sEmailID) + "%'))";

Log.Warn("-------------------GetID-----Start---------------");
Log.Info("-------------------GetID-----Start---------------");

Log.Warn(" str5=" + str5);
Log.Info("\tstr5=" + str5);

Log.Warn("-------------------GetID-----End---------------");
Log.Info("-------------------GetID-----End---------------");

string[] fields = new string[1];
fields[0] = "id";
Expand All @@ -60,7 +60,7 @@ public string GetID(string sEmailID, string sModule)
{
return clsSuiteCRMHelper.GetValueByKey(_result.entry_list[0], "id");
}
return "";
return String.Empty;
}

override public Outlook.MAPIFolder GetDefaultFolder()
Expand Down Expand Up @@ -105,24 +105,22 @@ override protected void OutlookItemChanged(Outlook.AppointmentItem olItem)
var utcNow = DateTime.UtcNow;
if (Math.Abs((utcNow - syncStateForItem.OModifiedDate).TotalSeconds) > 5.0)
{
Log.Warn("2 callitem.IsUpdate = " + syncStateForItem.IsUpdate);
Log.Info("2 callitem.IsUpdate = " + syncStateForItem.IsUpdate);
syncStateForItem.IsUpdate = 0;
}

Log.Warn("Before UtcNow - callitem.OModifiedDate= " + (int)(utcNow - syncStateForItem.OModifiedDate).TotalSeconds);
Log.Info("Before UtcNow - callitem.OModifiedDate= " + (int)(utcNow - syncStateForItem.OModifiedDate).TotalSeconds);

if (Math.Abs((utcNow - syncStateForItem.OModifiedDate).TotalSeconds) > 2.0 && syncStateForItem.IsUpdate == 0)
{
syncStateForItem.OModifiedDate = DateTime.UtcNow;
Log.Warn("1 callitem.IsUpdate = " + syncStateForItem.IsUpdate);
Log.Info("1 callitem.IsUpdate = " + syncStateForItem.IsUpdate);
syncStateForItem.IsUpdate++;
}

Log.Warn("callitem = " + syncStateForItem.OutlookItem.Subject);
Log.Warn("callitem.SEntryID = " + syncStateForItem.CrmEntryId);
Log.Warn("callitem mod_date= " + syncStateForItem.OModifiedDate.ToString());
Log.Warn("utcNow= " + DateTime.UtcNow.ToString());
Log.Warn("UtcNow - callitem.OModifiedDate= " + (int)(DateTime.UtcNow - syncStateForItem.OModifiedDate).TotalSeconds);
this.LogItemAction(syncStateForItem.OutlookItem, "AppointmentSyncState.OutlookItemChanged, syncing");
Log.Info("utcNow= " + DateTime.UtcNow.ToString());
Log.Info("UtcNow - callitem.OModifiedDate= " + (int)(DateTime.UtcNow - syncStateForItem.OModifiedDate).TotalSeconds);

if (IsCurrentView && syncStateForItem.IsUpdate == 1)
{
Expand Down Expand Up @@ -193,8 +191,8 @@ private void AddMeetingRecipientsFromOutlookToCrm(Outlook.AppointmentItem aItem,
{
try
{
Log.Warn("objRecepientName= " + objRecepient.Name.ToString());
Log.Warn("objRecepient= " + objRecepient.Address.ToString());
Log.Info("objRecepientName= " + objRecepient.Name.ToString());
Log.Info("objRecepient= " + objRecepient.Address.ToString());
}
catch
{
Expand All @@ -203,11 +201,11 @@ private void AddMeetingRecipientsFromOutlookToCrm(Outlook.AppointmentItem aItem,
}

string sCID = SetCrmRelationshipFromOutlook(meetingId, objRecepient, "Contacts");
if (sCID != "")
if (sCID != String.Empty)
{
string AccountID = clsSuiteCRMHelper.getRelationship("Contacts", sCID, "accounts");

if (AccountID != "")
if (AccountID != String.Empty)
{
eSetRelationshipValue info = new eSetRelationshipValue
{
Expand Down Expand Up @@ -266,7 +264,7 @@ private void AddMeetingRecipientsFromOutlookToCrm(Outlook.AppointmentItem aItem,
if (iMin > 0)
olItem.End.AddMinutes(iMin);
}
Log.Warn(" default SetRecepients");
Log.Info("\tdefault SetRecepients");
SetRecipients(olItem, crmItem.id.value.ToString(), crmType);

try
Expand Down Expand Up @@ -686,7 +684,7 @@ private static void RemoveSynchronisationPropertyFromOutlookItem(Outlook.Appoint
private string SetCrmRelationshipFromOutlook(string _result, Outlook.Recipient objRecepient, string relnName)
{
string sCID = GetID(objRecepient.Address, relnName);
if (sCID != "")
if (sCID != String.Empty)
{
eSetRelationshipValue info = new eSetRelationshipValue
{
Expand Down Expand Up @@ -721,9 +719,9 @@ private void SetRecipients(Outlook.AppointmentItem olAppointment, string sMeetin
{
dynamic dResult1 = JsonConvert.DeserializeObject(oResult1.name_value_object.ToString());

Log.Warn("-------------------SetRecepients-----Start-----dResult1---2-------");
Log.Warn((string)Convert.ToString(dResult1));
Log.Warn("-------------------SetRecepients-----End---------------");
Log.Info("-------------------SetRecepients-----Start-----dResult1---2-------");
Log.Info((string)Convert.ToString(dResult1));
Log.Info("-------------------SetRecepients-----End---------------");

string phone_work = dResult1.phone_work.value.ToString();
string sTemp =
Expand Down Expand Up @@ -940,7 +938,7 @@ private void UpdateOutlookStartAndDuration(string crmType, dynamic crmItem, Date
olAppointment.End.AddHours(hours);
if (minutes > 0)
olAppointment.End.AddMinutes(minutes);
Log.Warn(" SetRecepients");
Log.Info("\tSetRecepients");
SetRecipients(olAppointment, crmItem.id.value.ToString(), crmType);
}
olAppointment.Duration = minutes + hours * 60;
Expand Down
4 changes: 2 additions & 2 deletions SuiteCRMAddIn/BusinessLogic/ContactSyncing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private bool ShouldSyncContact(dynamic crmContact)
if (crmItem.primary_address_street.value != null)
cItem.BusinessAddressStreet = crmItem.primary_address_street.value.ToString();
cItem.Body = crmItem.description.value.ToString();
cItem.Account = cItem.CompanyName = "";
cItem.Account = cItem.CompanyName = String.Empty;
if (crmItem.account_name != null && crmItem.account_name.value != null)
{
cItem.Account = crmItem.account_name.value.ToString();
Expand Down Expand Up @@ -532,7 +532,7 @@ private void AddOrUpdateItemFromOutlookToCrm(Outlook.ContactItem oItem, string s
if (oItem == null) return;
try
{
string _result = "";
string _result = String.Empty;
eNameValue[] data = new eNameValue[19];

data[0] = clsSuiteCRMHelper.SetNameValuePair("email1", oItem.Email1Address);
Expand Down
42 changes: 21 additions & 21 deletions SuiteCRMAddIn/BusinessLogic/TaskSyncing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void SyncFolder(Outlook.MAPIFolder tasksFolder)
int iOffset = 0;
while (true)
{
eGetEntryListResult _result2 = clsSuiteCRMHelper.GetEntryList("Tasks", "",
eGetEntryListResult _result2 = clsSuiteCRMHelper.GetEntryList("Tasks", String.Empty,
0, "date_start DESC", iOffset, false, clsSuiteCRMHelper.GetSugarFields("Tasks"));
var nextOffset = _result2.next_offset;
if (iOffset == nextOffset)
Expand Down Expand Up @@ -147,7 +147,7 @@ private void SyncFolder(Outlook.MAPIFolder tasksFolder)
if (!string.IsNullOrWhiteSpace(dResult.date_start.value.ToString()) &&
!string.IsNullOrEmpty(dResult.date_start.value.ToString()))
{
Log.Warn(" SET date_start = dResult.date_start");
Log.Warn("\tSET date_start = dResult.date_start");
date_start = DateTime.ParseExact(dResult.date_start.value.ToString(), "yyyy-MM-dd HH:mm:ss", null);

date_start = date_start.Value.Add(new DateTimeOffset(DateTime.Now).Offset);
Expand All @@ -159,7 +159,7 @@ private void SyncFolder(Outlook.MAPIFolder tasksFolder)

if (date_start != null && date_start < GetStartDate())
{
Log.Warn(" date_start=" + date_start.ToString() + ", GetStartDate= " + GetStartDate().ToString());
Log.Warn("\tdate_start=" + date_start.ToString() + ", GetStartDate= " + GetStartDate().ToString());
return null;
}

Expand All @@ -174,14 +174,14 @@ private void SyncFolder(Outlook.MAPIFolder tasksFolder)

foreach (var lt in ItemsSyncState)
{
Log.Warn(" Task= " + lt.CrmEntryId);
Log.Warn("\tTask= " + lt.CrmEntryId);
}

var oItem = ItemsSyncState.FirstOrDefault(a => a.CrmEntryId == dResult.id.value.ToString());

if (oItem == null)
{
Log.Warn(" if default");
Log.Warn("\tif default");
Outlook.TaskItem tItem = tasksFolder.Items.Add(Outlook.OlItemType.olTaskItem);
tItem.Subject = dResult.name.value.ToString();

Expand Down Expand Up @@ -210,26 +210,26 @@ private void SyncFolder(Outlook.MAPIFolder tasksFolder)
CrmEntryId = dResult.id.value.ToString(),
};
ItemsSyncState.Add(newState);
Log.Warn(" save 0");
Log.Warn("\tsave 0");
tItem.Save();
return newState;
}
else
{
Log.Warn(" else not default");
Log.Warn("\telse not default");
Outlook.TaskItem tItem = oItem.OutlookItem;
Outlook.UserProperty oProp = tItem.UserProperties["SOModifiedDate"];

Log.Warn(
(string)
(" oProp.Value= " + oProp.Value + ", dResult.date_modified=" + dResult.date_modified.value.ToString()));
("\toProp.Value= " + oProp.Value + ", dResult.date_modified=" + dResult.date_modified.value.ToString()));
if (oProp.Value != dResult.date_modified.value.ToString())
{
tItem.Subject = dResult.name.value.ToString();

if (!string.IsNullOrWhiteSpace(dResult.date_start.value.ToString()))
{
Log.Warn(" tItem.StartDate= " + tItem.StartDate + ", date_start=" + date_start);
Log.Warn("\ttItem.StartDate= " + tItem.StartDate + ", date_start=" + date_start);
tItem.StartDate = date_start.Value;
}
if (!string.IsNullOrWhiteSpace(dResult.date_due.value.ToString()))
Expand All @@ -248,7 +248,7 @@ private void SyncFolder(Outlook.MAPIFolder tasksFolder)
if (oProp2 == null)
oProp2 = tItem.UserProperties.Add("SEntryID", Outlook.OlUserPropertyType.olText);
oProp2.Value = dResult.id.value.ToString();
Log.Warn(" save 1");
Log.Warn("\tsave 1");
tItem.Save();
}
oItem.OModifiedDate = DateTime.ParseExact(dResult.date_modified.value.ToString(), "yyyy-MM-dd HH:mm:ss", null);
Expand Down Expand Up @@ -301,7 +301,7 @@ override protected void OutlookItemChanged(Outlook.TaskItem oItem)
{
Log.Debug("Outlook Tasks ItemChange");
string entryId = oItem.EntryID;
Log.Warn(" oItem.EntryID= " + entryId);
Log.Warn("\toItem.EntryID= " + entryId);

var taskitem = ItemsSyncState.FirstOrDefault(a => a.OutlookItem.EntryID == entryId);
if (taskitem != null)
Expand Down Expand Up @@ -341,7 +341,7 @@ override protected void OutlookItemChanged(Outlook.TaskItem oItem)
Outlook.UserProperty oProp1 = oItem.UserProperties["SEntryID"];
if (oProp1 != null)
{
Log.Warn(" go to AddTaskToS");
Log.Warn("\tgo to AddTaskToS");
taskitem.IsUpdate++;
AddToCrm(oItem, oProp1.Value.ToString());
}
Expand Down Expand Up @@ -372,10 +372,10 @@ private void AddToCrm(Outlook.TaskItem oItem, string sID = "")
if (oItem == null) return;
try
{
string _result = "";
string _result = String.Empty;
eNameValue[] data = new eNameValue[7];
string strStatus = "";
string strImportance = "";
string strStatus = String.Empty;
string strImportance = String.Empty;
switch (oItem.Status)
{
case Outlook.OlTaskStatus.olTaskNotStarted:
Expand Down Expand Up @@ -412,9 +412,9 @@ private void AddToCrm(Outlook.TaskItem oItem, string sID = "")
if (oItem.DueDate != null)
time2 = oItem.DueDate.ToUniversalTime();

string body = "";
string body = String.Empty;
string str, str2;
str = str2 = "";
str = str2 = String.Empty;
if (oItem.Body != null)
{
body = oItem.Body.ToString();
Expand Down Expand Up @@ -447,7 +447,7 @@ private void AddToCrm(Outlook.TaskItem oItem, string sID = "")
//str2 = "2016-11-19 11:34:01";


string description = "";
string description = String.Empty;

if (!string.IsNullOrEmpty(body))
{
Expand All @@ -459,7 +459,7 @@ private void AddToCrm(Outlook.TaskItem oItem, string sID = "")
description = body;
}
}
Log.Warn(" description= " + description);
Log.Warn("\tdescription= " + description);

data[0] = clsSuiteCRMHelper.SetNameValuePair("name", oItem.Subject);
data[1] = clsSuiteCRMHelper.SetNameValuePair("description", description);
Expand All @@ -468,7 +468,7 @@ private void AddToCrm(Outlook.TaskItem oItem, string sID = "")
data[4] = clsSuiteCRMHelper.SetNameValuePair("date_start", str);
data[5] = clsSuiteCRMHelper.SetNameValuePair("priority", strImportance);

if (sID == "")
if (sID == String.Empty)
data[6] = clsSuiteCRMHelper.SetNameValuePair("assigned_user_id", clsSuiteCRMHelper.GetUserId());
else
data[6] = clsSuiteCRMHelper.SetNameValuePair("id", sID);
Expand All @@ -495,7 +495,7 @@ private void AddToCrm(Outlook.TaskItem oItem, string sID = "")
else
ItemsSyncState.Add(new TaskSyncState { CrmEntryId = _result, OModifiedDate = DateTime.UtcNow, OutlookItem = oItem });

Log.Warn(" date_start= " + str + ", date_due=" + str2);
Log.Warn("\tdate_start= " + str + ", date_due=" + str2);
}
catch (Exception ex)
{
Expand Down
10 changes: 8 additions & 2 deletions SuiteCRMAddIn/ThisAddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public void Authenticate()
{
try
{
if (settings.host != "")
if (settings.host != String.Empty)
{
SuiteCRMUserSession =
new SuiteCRMClient.UserSession(
Expand Down Expand Up @@ -539,7 +539,13 @@ public void Authenticate()
{
// We don't have a URL to connect to, dummy the connection.
SuiteCRMUserSession =
new SuiteCRMClient.UserSession("", "", "", "", log, Settings.RestTimeout);
new SuiteCRMClient.UserSession(
String.Empty,
String.Empty,
String.Empty,
String.Empty,
log,
Settings.RestTimeout);
}

SuiteCRMUserSession.AwaitingAuthentication = false;
Expand Down

0 comments on commit 48e8de2

Please sign in to comment.