Пример #1
0
 public void EndSession()
 {
     try
     {
         KnowledgeSyncProvider provider = GetSessionProvider();
         provider.EndSession(null);
     }
     catch
     {
     }
     //catch(SyncException e)
     //{
     //    throw SoapErrorCreator.RaiseException(HttpContext.Current.Request.Url.ToString(),
     //                                      new SyncronizationServiceError(SyncronizationServiceError.eServiceErrorType.SyncFramework, e),
     //                                      true);
     //}
     //catch (Exception e)
     //{
     //    throw SoapErrorCreator.RaiseException(HttpContext.Current.Request.Url.ToString(),
     //                                      new SyncronizationServiceError(SyncronizationServiceError.eServiceErrorType.SyncProvider, e),
     //                                      true);
     //}
 }
Пример #2
0
        /// <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;
            }
        }