/// <summary> /// Converts the type. /// </summary> /// <returns></returns> public static object ConvertType2Type(Type mcType, object obj) { object retVal = null; Dictionary <Type, ConversionDelegate> TypeConv; if ((obj == null) || (obj == DBNull.Value)) { return(retVal); } if (_conversionTable.TryGetValue(obj.GetType(), out TypeConv)) { ConversionDelegate convDelegate; if (TypeConv.TryGetValue(mcType, out convDelegate)) { retVal = convDelegate(obj); } } else { String errMsg = String.Format("conversion from [{0}] to [{1}] not found", obj.GetType().ToString(), mcType.ToString()); DebugAssistant.Log(errMsg); } return(retVal); }
public void SaveActiveProfile() { DebugAssistant.Log("ProfileSetting: Save active profile"); RegistryController regConn = new RegistryController(ProfileSettingRoot); if (SyncAppSettingLink != null) { SyncAppSettingLink.SaveLink(); regConn.WriteRegKey(SYNC_APPLICATION_REGKEY, SyncAppSettingLink.LinkId.ToString()); } if (SyncAppointmentSettingLink != null) { SyncAppointmentSettingLink.SaveLink(); regConn.WriteRegKey(SYNC_APPOINTMENT_REGKEY, SyncAppointmentSettingLink.LinkId.ToString()); } if (SyncContactSettingLink != null) { SyncContactSettingLink.SaveLink(); regConn.WriteRegKey(SYNC_CONTACT_REGKEY, SyncContactSettingLink.LinkId.ToString()); } if (SyncTaskSettingLink != null) { SyncTaskSettingLink.SaveLink(); regConn.WriteRegKey(SYNC_TASK_REGKEY, SyncTaskSettingLink.LinkId.ToString()); } }
protected override void ReadDataStore() { DebugAssistant.Log("Entering ReadDataStore()"); _localItems.Clear(); foreach (OutlookItem outlookItem in OutlookMapiFolder.Items) { OutlookAppointment appItem = outlookItem as OutlookAppointment; if (appItem != null) { try { SyncTransferData transferData = Appointment2TransferData(appItem); _localItems.Add(transferData); } catch (Exception e) { DebugAssistant.Log(DebugSeverity.Error | DebugSeverity.MessageBox, e.Message); throw; } } } DebugAssistant.Log("Leaving ReadDataStore(), localLastModificationTimesUtc.Count = " + _localItems.Count); }
private void WorkerProcess() { while (true) { DebugAssistant.Log("ThreadedWorkManager: Worker process begin main loop"); if (NeedTerminate) //Завершаем поток если установлен флаг завершения { break; } if (_tasks.Count > 0) { T task = _tasks.Dequeue(); DebugAssistant.Log("ThreadedWorkManager: Worker process processed job task " + task); if (_workProc != null) { _workProc(task); } } else { DebugAssistant.Log("ThreadedWorkManager: Worker process sleeping...."); _wh.WaitOne(); // Больше задач нет, ждем сигнала... } } DebugAssistant.Log("ThreadedWorkManager: Worker process finished"); }
public override void SaveLink() { DebugAssistant.Log("RegistrySettingLinkFile: Save setting in file " + FilePath); //XmlSerializer xmlsz = new XmlSerializer(typeof(T)); //using (Stream writer = new FileStream(FilePath, FileMode.Create)) //{ // xmlsz.Serialize(writer, base.ReferencedSetting); //} base.SaveLink(); }
/// <summary> /// Transitions to. /// </summary> /// <param name="state">The state.</param> /// <returns></returns> public State <T> TransitionTo(State <T> state, string debugPrefix) { State <T> nextState = AvailTransitions.Find(x => state.stateName.Equals(x.stateName)); if (nextState != null) { DebugAssistant.Log("SM " + debugPrefix + ": transition " + stateName.ToString() + "-> " + nextState.stateName.ToString()); return(nextState); } throw new Exception("SM" + debugPrefix + ": Unable to transition from state " + stateName.ToString() + "to state " + state.stateName.ToString()); }
/// <summary> /// Called when [sync session stage process change]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="Microsoft.Synchronization.SyncOrchestratorStateChangedEventArgs"/> instance containing the event data.</param> protected virtual void OnSyncSessionStageProcessChange(object sender, SyncOrchestratorStateChangedEventArgs args) { if (_syncApp.CurrentProcessedSyncType == null) { throw new NullReferenceException("CurrentProcessedSyncType"); } _syncItemForm.CurrentSyncSessionStage = args; string debugStr = string.Format("Session stage changed: {0} -> {1}", args.OldState.ToString(), args.NewState.ToString()); DebugAssistant.Log(DebugSeverity.Debug, debugStr); _syncItemForm.ThrUpdateSyncItemStatus(_syncApp.CurrentProcessedSyncType.Value); }
/// <summary> /// Called when [sync process change]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="Microsoft.Synchronization.SyncStagedProgressEventArgs"/> instance containing the event data.</param> protected virtual void OnSyncProcessChange(object sender, SyncStagedProgressEventArgs args) { if (_syncApp.CurrentProcessedSyncType == null) { throw new NullReferenceException("CurrentProcessedSyncType"); } _syncItemForm.CurrentSyncStagedProgress = args; string debugStr = string.Format("Progress changed: provider - {0}, stage - {1}, work - {2} of {3}", args.ReportingProvider.ToString(), args.Stage.ToString(), args.CompletedWork, args.TotalWork); DebugAssistant.Log(DebugSeverity.Debug, debugStr); _syncItemForm.ThrUpdateSyncItemStatus(_syncApp.CurrentProcessedSyncType.Value); }
/// <summary> /// Called when [sync item conflicting]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="Microsoft.Synchronization.ItemConflictingEventArgs"/> instance containing the event data.</param> protected virtual void OnSyncItemConflicting(object sender, ItemConflictingEventArgs e) { if (_syncApp.CurrentProcessedSyncType == null) { throw new NullReferenceException("CurrentProcessedSyncType"); } string debugStr = string.Format("Item conflict detected: source data - {0}, destination data - {1}", e.SourceChangeData != null ? e.SourceChangeData.ToString() : "unknow", e.DestinationChangeData != null ? e.DestinationChangeData.ToString() : "unknow"); DebugAssistant.Log(debugStr); ConflictResolutionAction resolution = GetConflictResolutionAction(e); e.SetResolutionAction(resolution); }
/// <summary> /// Called when [sync item change skiped]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="Microsoft.Synchronization.ItemChangeSkippedEventArgs"/> instance containing the event data.</param> protected virtual void OnSyncItemChangeSkiped(object sender, ItemChangeSkippedEventArgs args) { if (_syncApp.CurrentProcessedSyncType == null) { throw new NullReferenceException("CurrentProcessedSyncType"); } SaveChangeAction changeAction = (SaveChangeAction)Enum.Parse(typeof(SaveChangeAction), args.ItemRecoverableErrorData.ItemDisplayName); string debugStr = string.Format("Item change skiped: {0} in stage - {1} provider position - {2} for action {3} error detail {4}", args.ItemRecoverableErrorData.ItemDisplayName, args.Stage.ToString(), args.ReportingProvider.ToString(), changeAction.ToString(), args.ItemRecoverableErrorData.ErrorDescription); DebugAssistant.Log(debugStr); }
protected override T LoadSetting() { if (!File.Exists(FilePath)) { throw new FileNotFoundException(FilePath + "not found"); } DebugAssistant.Log("RegistrySettingLinkFile: Load setting from file " + FilePath); T retVal = null; string xmlDoc = File.ReadAllText(FilePath); XmlSerializer xmlsz = new XmlSerializer(typeof(T)); using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(xmlDoc))) { retVal = (T)xmlsz.Deserialize(ms); } return(retVal); }
/// <summary> /// Gets the outlook prop val. /// </summary> /// <param name="oItem">The o item.</param> /// <param name="propName">Name of the prop.</param> /// <returns></returns> public object GetOutlookPropVal(object oItem, string propName) { object retVal = null; if (oItem == null) { throw new ArgumentNullException("oItem"); } if (this.InvokeRequired) { Func <object, string, object> func = this.GetOutlookPropVal; retVal = this.Invoke(func, oItem, propName); } else { DebugAssistant.Log(DebugSeverity.Debug, "OutlookListener: get property " + propName); Type outlookType = GetOutlookTypeForComObject(oItem); if (outlookType == null) { throw new ArgumentException("oItem invalid outlook type"); } PropertyInfo propInfo = outlookType.GetProperty(propName); if (propInfo == null) { throw new NullReferenceException("prop with name " + propName + " not found"); } retVal = propInfo.GetValue(oItem, null); //Пытаемся преобразовать выходной тип outlook в тип заместитель if (retVal != null) { OutlookItem outlookItem = _factory.Create <OutlookItem>(retVal); if (outlookItem != null) { retVal = outlookItem; } } } return(retVal); }
public virtual void SaveLink() { DebugAssistant.Log("RegistrySettingLinkBase: save link setting"); RegistryController regConn = new RegistryController(Id2RegKey(LinkId)); LinkDataType linkType = RegistrySettingLinkBase <T> .LinkDataType.File; RegistrySettingLinkFile <T> selfType = this as RegistrySettingLinkFile <T>; if (selfType != null) { regConn.WriteRegKey("filePath", selfType.FilePath); } else { linkType = LinkDataType.Registry; } //Save link type regConn.WriteRegKey("linkType", ((int)linkType).ToString()); }
/// <summary> /// Shows the sync form. /// </summary> /// <param name="show">if set to <c>true</c> [show].</param> public void ShowSyncForm(bool show) { try { if (_syncItemForm != null) { Func formMethod = _syncItemForm.Hide; if (show) { formMethod = _syncItemForm.Show; } _syncItemForm.Invoke(formMethod); } } catch (Exception exception) { DebugAssistant.Log(exception.Message); throw; } }
protected virtual void OnSettingApply(object sender, EventArgs args) { object syncAccountSetting = (object)_syncApp.CurrentSettings.CurrentSyncAppSetting; object syncAppointmentSetting = (object)_syncApp.CurrentSettings.CurrentSyncAppointentSetting; object syncContactSetting = (object)_syncApp.CurrentSettings.CurrentContactSetting; object syncTaskSetting = (object)_syncApp.CurrentSettings.CurrentTaskSetting; try { this._syncOptionsForm.HarvestSetting(ref syncAccountSetting); this._syncOptionsForm.HarvestSetting(ref syncAppointmentSetting); this._syncOptionsForm.HarvestSetting(ref syncContactSetting); this._syncOptionsForm.HarvestSetting(ref syncTaskSetting); } catch (System.Exception exception) { DebugAssistant.Log(DebugSeverity.MessageBox | DebugSeverity.Error, exception.Message); return; } _syncApp.CurrentSettings.SaveActiveProfile(); }
/// <summary> /// Picks the outlook folder path. /// </summary> /// <param name="oApp">The o app.</param> /// <param name="oItemType">Type of the o item.</param> /// <returns></returns> public static string PickOutlookFolderPath(Outlook._Application oApp, Outlook.OlItemType oItemType) { string retVal = null; bool correctFolderSelected = false; try { while (!correctFolderSelected) { Outlook.NameSpace oNameSpace = oApp.GetNamespace("MAPI"); Outlook.MAPIFolder oMapiFolder = oNameSpace.PickFolder(); if (oMapiFolder.DefaultItemType != oItemType) { DebugAssistant.Log(DebugSeverity.Error | DebugSeverity.MessageBox, Resources.ERR_OUTLOOK_BAD_FOLDER_TYPE, oItemType); continue; } correctFolderSelected = true; retVal = oMapiFolder.Name; while (oMapiFolder.Parent is Outlook.MAPIFolder) { oMapiFolder = (Outlook.MAPIFolder)oMapiFolder.Parent; retVal = string.Format("{0}/", oMapiFolder.Name) + retVal; } retVal = "//" + retVal; } } catch (Exception e) { DebugAssistant.Log(DebugSeverity.Debug, e.Message); DebugAssistant.Log(DebugSeverity.Debug | DebugSeverity.MessageBox, Resources.DBG_OUTLOOK_FOLDER_NOT_SELECTED); } return(retVal); }
/// <summary> /// Saves the setting. /// </summary> /// <param name="setting">The setting.</param> public override void SaveLink() { DebugAssistant.Log("RegistrySettingLinkreg: Save setting in registry"); SettingPropertyAction <T>(base.ReferencedSetting, SavePropertyRegAction); base.SaveLink(); }
/// <summary> /// Loads the setting. /// </summary> /// <returns></returns> protected override T LoadSetting() { DebugAssistant.Log("RegistrySettingLinkreg: Load setting from registry"); return(SettingPropertyAction <T>(ReferencedSetting, LoadPropertyRegAction)); }
public static UserProfileSetting LoadActiveProfile() { UserProfileSetting retVal = new UserProfileSetting(); RegistryController regConn = new RegistryController(ProfileSettingRoot); string activeSyncAppSettingLink = (string)regConn.ReadRegKey(SYNC_APPLICATION_REGKEY, null); string activeAppointmentSettingLink = (string)regConn.ReadRegKey(SYNC_APPOINTMENT_REGKEY, null); string activeContactSettingLink = (string)regConn.ReadRegKey(SYNC_CONTACT_REGKEY, null); string activeTaskSettingLink = (string)regConn.ReadRegKey(SYNC_TASK_REGKEY, null); //Application if (!string.IsNullOrEmpty(activeSyncAppSettingLink)) { DebugAssistant.Log("ProfileSetting: Load sync application setting."); retVal.SyncAppSettingLink = RegistrySettingLinkBase <syncAppSetting> .CreateInstance(new Guid(activeSyncAppSettingLink)); } else { DebugAssistant.Log("ProfileSetting: Sync application setting not found. Create default.."); retVal.SyncAppSettingLink = RegistrySettingLinkBase <syncAppSetting> .CreateInstance(); retVal.SyncAppSettingLink.SaveLink(); } //Appointment if (!string.IsNullOrEmpty(activeAppointmentSettingLink)) { DebugAssistant.Log("ProfileSetting: Load sync appointment setting."); retVal.SyncAppointmentSettingLink = RegistrySettingLinkBase <syncAppointmentSetting> .CreateInstance(new Guid(activeAppointmentSettingLink)); } else { DebugAssistant.Log("ProfileSetting: Sync appointment setting not found. Create default.."); retVal.SyncAppointmentSettingLink = RegistrySettingLinkBase <syncAppointmentSetting> .CreateInstance(); retVal.SyncAppointmentSettingLink.SaveLink(); } //Contact if (!string.IsNullOrEmpty(activeContactSettingLink)) { retVal.SyncContactSettingLink = RegistrySettingLinkBase <syncContactSetting> .CreateInstance(new Guid(activeContactSettingLink)); } else { retVal.SyncContactSettingLink = RegistrySettingLinkBase <syncContactSetting> .CreateInstance(); retVal.SyncContactSettingLink.SaveLink(); } //Task if (!string.IsNullOrEmpty(activeTaskSettingLink)) { retVal.SyncTaskSettingLink = RegistrySettingLinkBase <syncTaskSetting> .CreateInstance(new Guid(activeTaskSettingLink)); } else { retVal.SyncTaskSettingLink = RegistrySettingLinkBase <syncTaskSetting> .CreateInstance(); retVal.SyncTaskSettingLink.SaveLink(); } retVal.SaveActiveProfile(); return(retVal); }
/// <summary> /// Does the sync. Выполняется в другом потоке отличном от AddinModule /// </summary> /// <param name="oItemType">Type of the o item.</param> private void DoSync(Outlook.OlItemType oItemType) { //reset last error LastSyncErrorDescr = string.Empty; LastSyncErrorOccur = false; //reset skipped items _skippedItems.Clear(); KnowledgeSyncProvider localProvider = null; KnowledgeSyncProvider remoteProvider = null; CurrentProcessedSyncType = oItemType; try { remoteProvider = GetRemoteSyncProvidersBySyncType(oItemType); localProvider = GetLocalSyncProviderBySyncType(oItemType); if (localProvider != null) { //Create sync session if (_syncAgent == null) { _syncAgent = new SyncOrchestrator(); //Subscribe sync framework events SubscribeEvents(_syncAgent); } //ISyncProviderSetting providerSetting = localProvider.ProviderSetting; ISyncProviderSetting providerSetting = localProvider as ISyncProviderSetting; if (providerSetting != null) { SyncDirectionOrder direction = providerSetting.SyncDirectionOrderSetting; ConflictResolutionPolicy conflictResolution = providerSetting.ConflictResolutionPolicySetting; remoteProvider.Configuration.ConflictResolutionPolicy = conflictResolution; localProvider.Configuration.ConflictResolutionPolicy = conflictResolution; _syncAgent.Direction = direction; _syncAgent.LocalProvider = localProvider; _syncAgent.RemoteProvider = remoteProvider; //Subscribe to knowledege provider events SubscribeEvents(localProvider); SubscribeEvents(remoteProvider); //raise sync process begin event OnSyncProcessBegin(new SyncProcessEventArgs()); SyncOperationStatistics syncStats = _syncAgent.Synchronize(); CollectStatistics(syncStats); } } } catch (UriFormatException e) { DebugAssistant.Log(DebugSeverity.Error, e.Message); LastSyncErrorOccur = true; LastSyncErrorDescr = OutlookAddin.Resources.ERR_SYNC_SERVICE_INVALID_URL; //DebugAssistant.Log(DebugSeverity.Error | DebugSeverity.MessageBox, // OutlookAddin.Resources.ERR_SYNC_SERVICE_INVALID_URL); } catch (SoapException e) { LastSyncErrorOccur = true; SyncronizationServiceError syncError = SoapErrorHandler.HandleError(e); string msg = OutlookAddin.Resources.ERR_SYNC_SERVICE_UKNOW; if (syncError != null) { DebugAssistant.Log(DebugSeverity.Error, syncError.errorType.ToString() + " " + syncError.message + " " + syncError.stackTrace); switch (syncError.errorType) { case SyncronizationServiceError.eServiceErrorType.AuthFailed: msg = Resources.ERR_SYNC_SERVICE_AUTH_FAILED; break; case SyncronizationServiceError.eServiceErrorType.NotAuthRequest: msg = Resources.ERR_SYNC_SERVICE_NOT_AUTH; break; case SyncronizationServiceError.eServiceErrorType.ProviderNotSpecified: msg = Resources.ERR_SYNC_SERVICE_INVALID_PROVIDER; break; case SyncronizationServiceError.eServiceErrorType.SyncFramework: msg = Resources.ERR_SYNC_SERVICE_FRAMEWORK; break; case SyncronizationServiceError.eServiceErrorType.SyncProvider: msg = Resources.ERR_SYNC_SERVICE_PROVIDER; break; case SyncronizationServiceError.eServiceErrorType.ServerError: msg = Resources.ERR_SYNC_SERVICE_SERVER; break; case SyncronizationServiceError.eServiceErrorType.Undef: msg = Resources.ERR_SYNC_SERVICE_UKNOW; break; } } LastSyncErrorDescr = msg; //DebugAssistant.Log(DebugSeverity.Error | DebugSeverity.MessageBox, msg); } catch (System.Net.WebException e) { LastSyncErrorOccur = true; LastSyncErrorDescr = Resources.ERR_SYNC_CONNECTION; DebugAssistant.Log(DebugSeverity.Error, e.Message); } catch (Exception e) { LastSyncErrorOccur = true; LastSyncErrorDescr = OutlookAddin.Resources.ERR_ADDIN_UNKNOW; DebugAssistant.Log(DebugSeverity.Error, e.Message); //DebugAssistant.Log(DebugSeverity.Error | DebugSeverity.MessageBox, OutlookAddin.Resources.ERR_ADDIN_UNKNOW); } finally { if (localProvider != null) { localProvider.EndSession(null); } if (remoteProvider != null) { remoteProvider.EndSession(null); } OnSyncProcessEnd(new SyncProcessEventArgs()); CurrentProcessedSyncType = null; } }