private void getDefaultCalendar(NameSpace oNS, ref MAPIFolder defaultCalendar) { log.Debug("Finding default Mailbox calendar folders"); try { MainForm.Instance.rbOutlookDefaultMB.CheckedChanged -= MainForm.Instance.rbOutlookDefaultMB_CheckedChanged; MainForm.Instance.rbOutlookDefaultMB.Checked = true; Settings.Instance.OutlookService = OutlookOgcs.Calendar.Service.DefaultMailbox; MainForm.Instance.rbOutlookDefaultMB.CheckedChanged += MainForm.Instance.rbOutlookDefaultMB_CheckedChanged; defaultCalendar = oNS.GetDefaultFolder(OlDefaultFolders.olFolderCalendar); calendarFolders.Add("Default " + defaultCalendar.Name, defaultCalendar); string excludeDeletedFolder = folders.Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderDeletedItems).EntryID; MainForm.Instance.lOutlookCalendar.BackColor = System.Drawing.Color.Yellow; MainForm.Instance.lOutlookCalendar.Text = "Getting calendars"; findCalendars(oNS.DefaultStore.GetRootFolder().Folders, calendarFolders, excludeDeletedFolder, defaultCalendar); MainForm.Instance.lOutlookCalendar.BackColor = System.Drawing.Color.White; MainForm.Instance.lOutlookCalendar.Text = "Select calendar"; } catch (System.Exception ex) { OGCSexception.Analyse(ex, true); throw ex; } }
private Dictionary <OutlookOgcs.CustomProperty.MetadataId, object> cleanIDs(ref AppointmentItem copiedAi) { log.Info("Temporarily removing OGCS properties from copied Outlook appointment item."); Dictionary <OutlookOgcs.CustomProperty.MetadataId, object> propertyBackup = new Dictionary <OutlookOgcs.CustomProperty.MetadataId, object>(); try { object backupValue = null; foreach (OutlookOgcs.CustomProperty.MetadataId metaDataId in Enum.GetValues(typeof(OutlookOgcs.CustomProperty.MetadataId))) { log.Fine("Backing up " + metaDataId.ToString()); if (metaDataId == OutlookOgcs.CustomProperty.MetadataId.ogcsModified) { backupValue = OutlookOgcs.CustomProperty.GetOGCSlastModified(copiedAi); } else { backupValue = OutlookOgcs.CustomProperty.Get(copiedAi, metaDataId); } propertyBackup.Add(metaDataId, backupValue); } OutlookOgcs.CustomProperty.RemoveAll(ref copiedAi); OutlookOgcs.CustomProperty.Add(ref copiedAi, OutlookOgcs.CustomProperty.MetadataId.locallyCopied, true.ToString()); copiedAi.Save(); } catch (System.Exception ex) { log.Warn("Failed to clean OGCS properties from copied item."); OGCSexception.Analyse(ex); } return(propertyBackup); }
private void btOK_Click(object sender, EventArgs e) { log.Fine("Checking no duplicate mappings exist."); SettingsStore.Calendar profile = Forms.Main.Instance.ActiveCalendarProfile; try { List <String> oColValues = new List <String>(); List <String> gColValues = new List <String>(); foreach (DataGridViewRow row in colourGridView.Rows) { oColValues.Add(row.Cells["OutlookColour"].Value.ToString()); gColValues.Add(row.Cells["GoogleColour"].Value.ToString()); } String oDuplicates = string.Join("\r\n", oColValues.GroupBy(v => v).Where(g => g.Count() > 1).Select(s => "- " + s.Key).ToList()); String gDuplicates = string.Join("\r\n", gColValues.GroupBy(v => v).Where(g => g.Count() > 1).Select(s => "- " + s.Key).ToList()); if (!string.IsNullOrEmpty(oDuplicates) && (profile.SyncDirection.Id == Sync.Direction.OutlookToGoogle.Id || profile.SyncDirection.Id == Sync.Direction.Bidirectional.Id)) { OgcsMessageBox.Show("The following Outlook categories cannot be mapped more than once:-\r\n\r\n" + oDuplicates, "Duplicate Outlook Mappings", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } else if (!string.IsNullOrEmpty(gDuplicates) && (profile.SyncDirection.Id == Sync.Direction.GoogleToOutlook.Id || profile.SyncDirection.Id == Sync.Direction.Bidirectional.Id)) { OgcsMessageBox.Show("The following Google colours cannot be mapped more than once:-\r\n\r\n" + gDuplicates, "Duplicate Google Mappings", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } catch (System.Exception ex) { OGCSexception.Analyse("Failed looking for duplicating mappings before storing in Settings.", ex); OgcsMessageBox.Show("An error was encountered storing your custom mappings.", "Cannot save mappings", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { log.Fine("Storing colour mappings in Settings."); profile.ColourMaps.Clear(); foreach (DataGridViewRow row in colourGridView.Rows) { if (row.Cells["OutlookColour"].Value == null || row.Cells["OutlookColour"].Value.ToString().Trim() == "") { continue; } try { profile.ColourMaps.Add(row.Cells["OutlookColour"].Value.ToString(), GoogleOgcs.EventColour.Palette.GetColourId(row.Cells["GoogleColour"].Value.ToString())); } catch (System.ArgumentException ex) { if (OGCSexception.GetErrorCode(ex) == "0x80070057") { //An item with the same key has already been added } else { throw; } } } } catch (System.Exception ex) { OGCSexception.Analyse("Could not save colour/category mappings to Settings.", ex); } finally { this.Close(); } }
private void ogcsPushTimer_Tick(object sender, EventArgs e) { if (Forms.ErrorReporting.Instance.Visible) { return; } log.Fine("Push sync triggered."); try { System.Collections.Generic.List <Microsoft.Office.Interop.Outlook.AppointmentItem> items = OutlookOgcs.Calendar.Instance.GetCalendarEntriesInRange(true); if (items.Count < this.lastRunItemCount || items.FindAll(x => x.LastModificationTime > this.lastRunTime).Count > 0) { log.Debug("Changes found for Push sync."); Forms.Main.Instance.NotificationTray.ShowBubbleInfo("Autosyncing calendars: " + Settings.Instance.SyncDirection.Name + "..."); if (!Sync.Engine.Instance.SyncingNow) { Forms.Main.Instance.Sync_Click(sender, null); } else { log.Debug("Busy syncing already. No need to push."); } } else { log.Fine("No changes found."); } failures = 0; } catch (System.Exception ex) { failures++; log.Warn("Push Sync failed " + failures + " times to check for changed items."); String hResult = OGCSexception.GetErrorCode(ex); if ((ex is System.InvalidCastException && hResult == "0x80004002" && ex.Message.Contains("0x800706BA")) || //The RPC server is unavailable (ex is System.Runtime.InteropServices.COMException && ( ex.Message.Contains("0x80010108(RPC_E_DISCONNECTED)") || //The object invoked has disconnected from its clients hResult == "0x800706BE" || //The remote procedure call failed hResult == "0x800706BA")) //The RPC server is unavailable ) { OGCSexception.Analyse(OGCSexception.LogAsFail(ex)); try { OutlookOgcs.Calendar.Instance.Reset(); } catch (System.Exception ex2) { OGCSexception.Analyse("Failed resetting Outlook connection.", ex2); } } else { OGCSexception.Analyse(ex); } if (failures == 10) { Forms.Main.Instance.Console.UpdateWithError("Push Sync is failing.", ex, notifyBubble: true); } } }
/// <summary> /// Detects paste events in order to remove OGCS properties from pasted item. /// /// However, the clipboard is a reference to the copied item /// and the pasted object is not available yet until AFTER this function! /// We can't short-circuit the paste event by setting "Cancel = true" and performing the Copy() /// because it pastes to the same DateTime as the copied item. /// In Outlook2010 the (Explorer.View as CalendarView).SelectedStartTime exists, but not in 2007, /// so there's no way of knowing the time to paste the item in to. /// /// So the workaround is to temporarily doctor the original copied item (ie remove OGCS properties), /// which the pasted item inherits. A delayed background thread then post-processes the original item /// to revert any changes and repopulate values. /// </summary> private void beforeItemPaste(ref object ClipboardContent, MAPIFolder Target, ref bool Cancel) { log.Info("Item paste event caught."); try { Selection selection = ClipboardContent as Selection; if (selection == null) { log.Warn("Clipboard selection returned nothing."); return; } log.Debug("We've got " + selection.Count + " items selected for copy."); foreach (Object item in selection) { AppointmentItem copiedAi = null; try { if (item is AppointmentItem) { copiedAi = item as AppointmentItem; } else { throw new ApplicationException("The item is not an appointment item."); } log.Debug(OutlookOgcs.Calendar.GetEventSummary(copiedAi)); String entryID = copiedAi.EntryID; if (OutlookOgcs.CustomProperty.Exists(copiedAi, OutlookOgcs.CustomProperty.MetadataId.gEventID)) { Dictionary <String, object> propertyBackup = cleanIDs(ref copiedAi); OutlookOgcs.CustomProperty.Add(ref copiedAi, CustomProperty.MetadataId.originalStartDate, copiedAi.Start); copiedAi.Save(); System.Threading.Thread repopIDsThrd = new System.Threading.Thread(() => repopulateIDs(entryID, propertyBackup)); repopIDsThrd.Start(); } else { log.Debug("This item isn't managed by OGCS."); //But we still need to tag the pasted item as a "copied" item to avoid bad matches on Google events. OutlookOgcs.CustomProperty.Add(ref copiedAi, OutlookOgcs.CustomProperty.MetadataId.locallyCopied, true.ToString()); copiedAi.Save(); //Untag the original copied item System.Threading.Thread untagAsCopiedThrd = new System.Threading.Thread(() => untagAsCopied(entryID)); untagAsCopiedThrd.Start(); } } catch (System.ApplicationException ex) { log.Debug(ex.Message); } catch (System.Exception ex) { log.Warn("Not able to process copy and pasted event."); OGCSexception.Analyse(ex); } finally { copiedAi = (AppointmentItem)OutlookOgcs.Calendar.ReleaseObject(copiedAi); } } } catch (System.Exception ex) { OGCSexception.Analyse(ex); } }
private void ProfileManage_FormClosing(object sender, FormClosingEventArgs e) { if ((sender as Form).DialogResult == DialogResult.Cancel) { return; } if (this.btOK.Text == "Add") { SettingsStore.Calendar newCalendar = null; try { String profileName = this.txtProfileName.Text; if (string.IsNullOrEmpty(profileName)) { return; } newCalendar = new SettingsStore.Calendar(); newCalendar._ProfileName = profileName; Settings.Instance.Calendars.Add(newCalendar); log.Info("Added new calendar settings '" + profileName + "'."); int addedIdx = ddProfile.Items.Add(profileName); ddProfile.SelectedIndex = addedIdx; Forms.Main.Instance.NotificationTray.AddProfileItem(profileName); newCalendar.InitialiseTimer(); newCalendar.RegisterForPushSync(); } catch (System.Exception ex) { OGCSexception.Analyse("Failed to add new profile.", ex); throw; } } else if (this.btOK.Text == "Rename") { String currentProfileName = ddProfile.Text; String newProfileName = ""; try { newProfileName = this.txtProfileName.Text; if (newProfileName == "") { return; } Forms.Main.Instance.ActiveCalendarProfile._ProfileName = newProfileName; int idx = ddProfile.SelectedIndex; ddProfile.Items.RemoveAt(idx); ddProfile.Items.Insert(idx, newProfileName); ddProfile.SelectedIndex = idx; log.Info("Renamed calendar settings from '" + currentProfileName + "' to '" + newProfileName + "'."); } catch (System.Exception ex) { OGCSexception.Analyse("Failed to rename profile from '" + currentProfileName + "' to '" + newProfileName + "'.", ex); throw; } Forms.Main.Instance.NotificationTray.RenameProfileItem(currentProfileName, newProfileName); } }
public void ResetLastRun() { this.lastRunTime = DateTime.Now; try { log.Fine("Updating calendar item count following Push Sync."); this.lastRunItemCount = OutlookOgcs.Calendar.Instance.GetCalendarEntriesInRange(true).Count; } catch (System.Exception ex) { OGCSexception.Analyse("Failed to update item count following a Push Sync.", ex); } }
public Categories() { try { Delimiter = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator + " "; } catch (System.Exception ex) { log.Error("Failed to get system ListSeparator value."); OGCSexception.Analyse(ex); Delimiter = ", "; } }
private void findCalendars(Folders folders, Dictionary <string, MAPIFolder> calendarFolders, String excludeDeletedFolder, MAPIFolder defaultCalendar = null) { //Initiate progress bar (red line underneath "Getting calendars" text) System.Drawing.Graphics g = Forms.Main.Instance.tabOutlook.CreateGraphics(); System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.Red, 3); System.Drawing.Point startPoint = new System.Drawing.Point(Forms.Main.Instance.lOutlookCalendar.Location.X, Forms.Main.Instance.lOutlookCalendar.Location.Y + Forms.Main.Instance.lOutlookCalendar.Size.Height + 3); double stepSize = Forms.Main.Instance.lOutlookCalendar.Size.Width / folders.Count; int fldCnt = 0; foreach (MAPIFolder folder in folders) { fldCnt++; System.Drawing.Point endPoint = new System.Drawing.Point(Forms.Main.Instance.lOutlookCalendar.Location.X + Convert.ToInt16(fldCnt * stepSize), Forms.Main.Instance.lOutlookCalendar.Location.Y + Forms.Main.Instance.lOutlookCalendar.Size.Height + 3); try { g.DrawLine(p, startPoint, endPoint); } catch { /*May get GDI+ error if g has been repainted*/ } System.Windows.Forms.Application.DoEvents(); try { OlItemType defaultItemType = folder.DefaultItemType; if (defaultItemType == OlItemType.olAppointmentItem) { if (defaultCalendar == null || (folder.EntryID != defaultCalendar.EntryID)) { calendarFolderAdd(folder.Name, folder); } } if (folder.EntryID != excludeDeletedFolder && folder.Folders.Count > 0) { findCalendars(folder.Folders, calendarFolders, excludeDeletedFolder, defaultCalendar); } } catch (System.Exception ex) { OGCSexception.Analyse(ex); if (oApp.Session.ExchangeConnectionMode.ToString().Contains("Disconnected") || ex.Message.StartsWith("Network problems are preventing connection to Microsoft Exchange.") || OGCSexception.GetErrorCode(ex, 0x000FFFFF) == "0x00040115") { log.Info("Currently disconnected from Exchange - unable to retrieve MAPI folders."); Forms.Main.Instance.ToolTips.SetToolTip(Forms.Main.Instance.cbOutlookCalendars, "The Outlook calendar to synchonize with.\nSome may not be listed as you are currently disconnected."); } else { log.Error("Failed to recurse MAPI folders."); log.Error(ex.Message); MessageBox.Show("A problem was encountered when searching for Outlook calendar folders.", "Calendar Folders", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } p.Dispose(); try { g.Clear(System.Drawing.Color.White); } catch { } g.Dispose(); System.Windows.Forms.Application.DoEvents(); }
private void ColourPicker_Enter(object sender, EventArgs e) { if (Forms.Main.Instance.ActiveCalendarProfile.UseGoogleCalendar == null || string.IsNullOrEmpty(Forms.Main.Instance.ActiveCalendarProfile.UseGoogleCalendar.Id)) { OgcsMessageBox.Show("You need to select a Google Calendar first on the 'Settings' tab.", "Configuration Required", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } ToolTip loading = new ToolTip(); try { GoogleOgcs.EventColour.Palette currentSelection = null; if (GoogleOgcs.Calendar.IsInstanceNull || !GoogleOgcs.Calendar.Instance.ColourPalette.IsCached()) { loading.SetToolTip(this, "Retrieving colours from Google..."); loading.ShowAlways = true; loading.InitialDelay = 0; loading.Show("Retrieving colours from Google...", this, this.FindForm().PointToClient(this.Parent.PointToScreen(this.Location))); GoogleOgcs.Calendar.Instance.ColourPalette.Get(); currentSelection = (GoogleOgcs.EventColour.Palette)SelectedItem; loading.Hide(this); } if (Items.Count != GoogleOgcs.Calendar.Instance.ColourPalette.ActivePalette.Count) { while (Items.Count > 0) { Items.RemoveAt(0); } AddPaletteColours(true); } foreach (GoogleOgcs.EventColour.Palette pInfo in Items) { if (pInfo.Id == currentSelection?.Id) { SelectedItem = pInfo; break; } } } catch (System.Exception ex) { OGCSexception.Analyse("ColourPicker_Enter()", ex); } finally { loading.Hide(this); loading.RemoveAll(); } if (Items.Count > 1 && SelectedIndex == -1) { SelectedIndex = 0; } }
/// <summary> /// Get colour ID from the name /// </summary> /// <param name="name">The name of the colour</param> /// <returns>The ID number</returns> public static String GetColourId(String name) { String id = null; try { id = eventColourNames.First(n => (n.Value as Metadata).Name == name).Key.ToString(); } catch (System.Exception ex) { OGCSexception.Analyse("Could not find colour ID for '" + name + "'.", ex); } return(id); }
/// <summary> /// Convert from HTML hex string to Color /// </summary> public static Color RgbColour(String hexColour) { Color colour = new Color(); try { colour = ColorTranslator.FromHtml(hexColour); log.Fine("Converted " + hexColour + " to " + colour.ToString()); } catch (System.Exception ex) { OGCSexception.Analyse("Could not convert hex '" + hexColour + "' to RGB colour.", ex); } return(colour); }
public void AbortSync() { try { bwSync.Abort(); bwSync.Dispose(); bwSync = null; } catch (System.Exception ex) { OGCSexception.Analyse(ex); } finally { log.Warn("Sync thread forcefully aborted!"); } }
public static Outlook.OlCategoryColor GetClosestCategory(GoogleOgcs.EventColour.Palette basePalette) { try { var colourDistance = Colours.Select(x => new { Value = x, Diff = GoogleOgcs.EventColour.GetDiff(x.Value, basePalette.RgbValue) }).ToList(); var minDistance = colourDistance.Min(x => x.Diff); return(colourDistance.Find(x => x.Diff == minDistance).Value.Key); } catch (System.Exception ex) { log.Warn("Failed to get closest Outlook category for " + basePalette.ToString()); OGCSexception.Analyse(ex); return(Outlook.OlCategoryColor.olCategoryColorNone); } }
/// <summary> /// Find the closest colour palette offered by Google. /// </summary> /// <param name="colour">The colour to search with.</param> public Palette GetClosestColour(Color baseColour) { try { var colourDistance = ActivePalette.Select(x => new { Value = x, Diff = GetDiff(x.RgbValue, baseColour) }).ToList(); var minDistance = colourDistance.Min(x => x.Diff); return(colourDistance.Find(x => x.Diff == minDistance).Value); } catch (System.Exception ex) { log.Warn("Failed to get closest Event colour for " + baseColour.Name); OGCSexception.Analyse(ex); return(Palette.NullPalette); } }
public EventAttendee(Google.Apis.Calendar.v3.Data.EventAttendee baseAttendee) { parent = baseAttendee; foreach (PropertyInfo prop in parent.GetType().GetProperties()) { try { prop.SetValue(this, prop.GetValue(baseAttendee)); } catch (System.Exception ex) { log.Warn("Failed to set property " + prop.Name); OGCSexception.Analyse(ex); } } }
private void spawnOauth() { ClientSecrets cs = getCalendarClientSecrets(); //Calling an async function from a static constructor needs to be called like this, else it deadlocks:- var task = System.Threading.Tasks.Task.Run(async() => { await getAuthenticated(cs); }); try { task.Wait(CancelTokenSource.Token); } catch (System.OperationCanceledException) { Forms.Main.Instance.Console.Update("Authorisation to allow OGCS to manage your Google calendar was cancelled.", Console.Markup.warning); } catch (System.Exception ex) { OGCSexception.Analyse(ex); } }
private static void add(ref AppointmentItem ai, MetadataId key, OlUserPropertyType keyType, object keyValue) { String addkeyName = metadataIdKeyName(key); UserProperties ups = null; try { int maxSet; int? keySet = null; String currentKeyName = null; if (!Exists(ai, key, out currentKeyName)) { keySet = getKeySet(ai, out maxSet); if (key == MetadataId.gCalendarId && (keySet ?? 0) == 0) //Couldn't find key set for calendar { keySet = maxSet + 1; //So start a new one } else if (key != MetadataId.gCalendarId && keySet == null) //Couldn't find non-calendar key in the current set { keySet = 0; //Add them in to the default key set } if (keySet.HasValue && keySet.Value != 0) { addkeyName += "-" + keySet.Value.ToString("D2"); } try { ups = ai.UserProperties; ups.Add(addkeyName, keyType); } catch (System.Exception ex) { OGCSexception.Analyse(ex); ups.Add(addkeyName, keyType, false); } finally { ups = (UserProperties)Calendar.ReleaseObject(ups); } } else { addkeyName = currentKeyName; //Might be suffixed with "-01" } ups = ai.UserProperties; ups[addkeyName].Value = keyValue; OutlookOgcs.Calendar.Instance.EphemeralProperties.Add(ai, new EphemeralProperty(EphemeralProperty.PropertyName.KeySet, keySet)); OutlookOgcs.Calendar.Instance.EphemeralProperties.Add(ai, new EphemeralProperty(EphemeralProperty.PropertyName.MaxSet, keySet)); log.Fine("Set userproperty " + addkeyName + "=" + keyValue.ToString()); } finally { ups = (UserProperties)Calendar.ReleaseObject(ups); } }
private void loadConfig() { try { tzGridView.AllowUserToAddRows = true; if (Settings.Instance.TimezoneMaps.Count > 0) { tzGridView.Rows.Clear(); } foreach (KeyValuePair <String, String> tzMap in Settings.Instance.TimezoneMaps) { addRow(tzMap.Key, tzMap.Value); } } catch (System.Exception ex) { OGCSexception.Analyse("Populating gridview cells from Settings.", ex); } }
/// <summary> /// Get the categories as configured in Outlook and store in class /// </summary> /// <param name="oApp"></param> /// <param name="store"></param> public void Get(Outlook.Application oApp, Outlook.Store store) { if (Settings.Instance.OutlookService == OutlookOgcs.Calendar.Service.DefaultMailbox) { this.categories = oApp.Session.Categories; } else { try { this.categories = store.GetType().GetProperty("Categories").GetValue(store, null) as Outlook.Categories; } catch (System.Exception ex) { OGCSexception.Analyse(ex, true); this.categories = oApp.Session.Categories; } } }
private void CloudLogging_Shown(object sender, EventArgs e) { try { //Highlight the ERROR text and scroll so it's in view int lastError = tbLog.Text.LastIndexOf(" ERROR ") + 1; int highlightLength = tbLog.Text.Substring(lastError).IndexOf("\n"); tbLog.Select(lastError, highlightLength); tbLog.SelectionBackColor = System.Drawing.Color.Yellow; int previousLineBreak = tbLog.Text.Substring(0, lastError).LastIndexOf("\n"); tbLog.SelectionStart = previousLineBreak; tbLog.ScrollToCaret(); btYes.Focus(); } catch (System.Exception ex) { OGCSexception.Analyse(ex); } }
private void getGaccountEmail(String accessToken) { String jsonString = ""; log.Debug("Retrieving email address associated with Google account."); try { System.Net.WebClient wc = new System.Net.WebClient(); wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"); jsonString = wc.DownloadString("https://www.googleapis.com/plus/v1/people/me?fields=emails&access_token=" + accessToken); JObject jo = Newtonsoft.Json.Linq.JObject.Parse(jsonString); JToken jtEmail = jo["emails"].Where(e => e.Value <String>("type") == "account").First(); String email = jtEmail.Value <String>("value"); if (Settings.Instance.GaccountEmail != email) { if (!String.IsNullOrEmpty(Settings.Instance.GaccountEmail)) { log.Debug("Looks like the Google account username value has been tampering with? :-O"); } Settings.Instance.GaccountEmail = email; log.Debug("Updating Google account username: "******"The remote server returned an error: (403) Forbidden.") || ex.Message == "Insufficient Permission") { log.Warn(ex.Message); String msg = ApiKeyring.ChangeKeys(); throw new System.ApplicationException(msg); } OGCSexception.Analyse(ex); if (ex.Message.ToLower().Contains("access denied")) { MainForm.Instance.Logboxout("Failed to obtain Calendar access from Google - it's possible your access has been revoked." + "\r\nTry disconnecting your Google account and reauthenticating."); } throw ex; } catch (System.Exception ex) { log.Debug("JSON: " + jsonString); log.Error("Failed to retrieve Google account username."); OGCSexception.Analyse(ex); log.Debug("Using previously retrieved username: " + Settings.Instance.GaccountEmail_masked()); } }
private void colourGridView_SelectionChanged(object sender, EventArgs e) { //Protect against the last row being selected for deletion try { if (colourGridView.SelectedRows.Count == 0) { return; } int selectedRow = colourGridView.SelectedRows[colourGridView.SelectedRows.Count - 1].Index; if (selectedRow == colourGridView.Rows.Count - 1) { log.Debug("Last row"); colourGridView.Rows[selectedRow].Selected = false; } } catch (System.Exception ex) { OGCSexception.Analyse(ex); } }
public object GetCategories() { if (Settings.Instance.OutlookService == OutlookOgcs.Calendar.Service.DefaultMailbox) { return(oApp.Session.Categories); } Store store = null; try { store = useOutlookCalendar.Store; return(store.GetType().GetProperty("Categories").GetValue(store, null)); } catch (System.Exception ex) { OGCSexception.Analyse(ex, true); return(oApp.Session.Categories); } finally { store = (Store)OutlookOgcs.Calendar.ReleaseObject(store); } }
private void repopulateIDs(String entryID, Dictionary <OutlookOgcs.Calendar.MetadataId, object> propertyValues) { //Allow time for pasted item to complete System.Threading.Thread.Sleep(2000); log.Debug("Repopulating IDs to original copied Outlook item"); AppointmentItem copiedAi = null; try { OutlookOgcs.Calendar.Instance.IOutlook.GetAppointmentByID(entryID, out copiedAi); if (copiedAi == null) { throw new System.Exception("Could not find Outlook item with entryID " + entryID + " for post-processing."); } log.Debug(OutlookOgcs.Calendar.GetEventSummary(copiedAi)); foreach (KeyValuePair <OutlookOgcs.Calendar.MetadataId, object> property in propertyValues) { if (property.Value == null) { OutlookOgcs.Calendar.RemoveOGCSproperty(ref copiedAi, property.Key); } else { if (property.Value is DateTime) { OutlookOgcs.Calendar.AddOGCSproperty(ref copiedAi, property.Key, (DateTime)property.Value); } else { OutlookOgcs.Calendar.AddOGCSproperty(ref copiedAi, property.Key, property.Value.ToString()); } } } copiedAi.Save(); } catch (System.Exception ex) { log.Warn("Failed to repopulate OGCS properties back to copied item."); OGCSexception.Analyse(ex); } finally { copiedAi = (AppointmentItem)OutlookOgcs.Calendar.ReleaseObject(copiedAi); } }
/// <summary> /// Log the various User Properties. /// </summary> /// <param name="ev">The Event.</param> /// <param name="thresholdLevel">Only log if logging configured at this level or higher.</param> public static void LogProperties(Event ev, log4net.Core.Level thresholdLevel) { if (((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level.Value > thresholdLevel.Value) { return; } try { if (ev.ExtendedProperties != null && ev.ExtendedProperties.Private__ != null) { log.Debug(GoogleOgcs.Calendar.GetEventSummary(ev)); foreach (KeyValuePair <String, String> prop in ev.ExtendedProperties.Private__.OrderBy(k => k.Key)) { log.Debug(prop.Key + "=" + prop.Value); } } } catch (System.Exception ex) { OGCSexception.Analyse("Failed to log Event ExtendedProperties", ex); } }
public static void DrawComboboxItemColour(Boolean comboEnabled, Brush boxColour, Brush textColour, String itemDescription, Graphics graphics, Rectangle cellBounds) { try { // Draw colour box Rectangle colourbox = new Rectangle(); colourbox.X = cellBounds.X + 2; colourbox.Y = cellBounds.Y + 2; colourbox.Height = cellBounds.Height - 5; colourbox.Width = 18; graphics.FillRectangle(boxColour, colourbox); graphics.DrawRectangle(comboEnabled ? SystemPens.WindowText : SystemPens.InactiveBorder, colourbox); int textX = cellBounds.X + colourbox.X + colourbox.Width + 2; graphics.DrawString(itemDescription, Control.DefaultFont, textColour, /*cellBounds.X*/ +colourbox.X + colourbox.Width + 2, cellBounds.Y + ((cellBounds.Height - Control.DefaultFont.Height) / 2)); } catch (System.Exception ex) { OGCSexception.Analyse(ex); } }
private void tzGridView_DataError(object sender, DataGridViewDataErrorEventArgs e) { log.Error(e.Context.ToString()); if (e.Exception.HResult == -2147024809) //DataGridViewComboBoxCell value is not valid. { DataGridViewCell cell = tzGridView.Rows[e.RowIndex].Cells[e.ColumnIndex]; log.Warn("Cell[" + cell.RowIndex + "][" + cell.ColumnIndex + "] has invalid value of '" + cell.Value + "'. Removing."); cell.OwningRow.Cells[0].Value = null; cell.OwningRow.Cells[1].Value = null; } else { try { DataGridViewCell cell = tzGridView.Rows[e.RowIndex].Cells[e.ColumnIndex]; log.Debug("Cell[" + cell.RowIndex + "][" + cell.ColumnIndex + "] caused error."); } catch { } finally { OGCSexception.Analyse("Bad cell value in timezone data grid.", e.Exception); } } }
private static String getMd5(String input) { log.Debug("Getting MD5 hash for '" + EmailAddress.MaskAddress(input) + "'"); System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); try { byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input); byte[] hash = md5.ComputeHash(inputBytes); //Convert byte array to hex string for (int i = 0; i < hash.Length; i++) { sb.Append(hash[i].ToString("x2")); } } catch (System.Exception ex) { log.Error("Failed to create MD5 for '" + EmailAddress.MaskAddress(input) + "'"); OGCSexception.Analyse(ex); } return(sb.ToString()); }
private void addRow(String organiserTz, String systemTz) { int lastRow = 0; try { lastRow = tzGridView.Rows.GetLastRow(DataGridViewElementStates.None); Object currentValue = tzGridView.Rows[lastRow].Cells["OrganiserTz"].Value; if (currentValue != null && currentValue.ToString() != "") { lastRow++; tzGridView.Rows.Insert(lastRow); } tzGridView.Rows[lastRow].Cells["OrganiserTz"].Value = organiserTz; tzGridView.Rows[lastRow].Cells["SystemTz"].Value = systemTz; tzGridView.CurrentCell = tzGridView.Rows[lastRow].Cells[1]; tzGridView.NotifyCurrentCellDirty(true); tzGridView.NotifyCurrentCellDirty(false); } catch (System.Exception ex) { OGCSexception.Analyse("Adding timezone map row #" + lastRow, ex); } }