/// <summary>
        /// Syncs the specified module.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="reportingDelegate">The reporting delegate.</param>
        /// <param name="syncedLearningModulePath">The synced learning module path (necessary when Startpage isn't initialized).</param>
        /// <remarks>Documented by Dev03, 2009-02-12</remarks>
        public static void Sync(LearningModulesIndexEntry module, SyncStatusReportingDelegate reportingDelegate, string syncedLearningModulePath)
        {
            if (module.Connection == null) //no user is required for syncing
                throw new SynchronizationFailedException(new ServerOfflineException());

            try
            {
                string serverUri = module.Connection is WebConnectionStringBuilder ? (module.Connection as WebConnectionStringBuilder).SyncURI : (module.Connection as PostgreSqlConnectionStringBuilder).SyncURI;
                bool createNew = (module.SyncedPath == string.Empty);
                string path = Tools.GetFullSyncPath(module.SyncedPath, syncedLearningModulePath, module.ConnectionName, module.UserName);

                Sync(serverUri, module.ConnectionString.LmId, module.UserId, ref path, module.ConnectionString.ProtectedLm, module.ConnectionString.Password, createNew, false, reportingDelegate);

                module.SyncedPath = Tools.GetSyncedPath(path, syncedLearningModulePath, module.ConnectionName, module.UserName);
            }
            catch (SynchronizationFailedException) { throw; }
            catch { throw new SynchronizationFailedException(new ServerOfflineException()); }
        }
        /// <summary>
        /// Syncs the specified server URI.
        /// </summary>
        /// <param name="serverUri">The server URI.</param>
        /// <param name="learningModuleId">The learning module id.</param>
        /// <param name="userId">The user id.</param>
        /// <param name="path">The path.</param>
        /// <param name="createNew">if set to <c>true</c> [create new].</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        /// <param name="reportingDelegate">The reporting delegate.</param>
        /// <remarks>Documented by Dev03, 2009-02-12</remarks>
        private static void Sync(string serverUri, int learningModuleId, int userId, ref string path, bool contentProtected, string password, bool createNew, bool overwrite, SyncStatusReportingDelegate reportingDelegate)
        {
            syncStatusDelegate = reportingDelegate;
            SyncAgent syncAgent = SyncClient.GetAgent(serverUri, learningModuleId, userId, ref path, contentProtected, password, createNew, overwrite);
            syncAgent.SessionProgress += new EventHandler<SessionProgressEventArgs>(syncAgent_SessionProgress);
            (syncAgent.LocalProvider as SqlCeClientSyncProvider).ApplyChangeFailed += new EventHandler<ApplyChangeFailedEventArgs>(syncAgent_ApplyChangeFailed);
            try
            {
                SyncStatistics stats = syncAgent.Synchronize();
                if (SyncClient.IsNewDb(syncAgent))
                    SyncClient.ApplyIndicesToDatabase(path, contentProtected, password);

                string text = string.Empty;
                foreach (PropertyInfo info in stats.GetType().GetProperties())
                    text += info.Name + ": " + info.GetValue(stats, null).ToString() + Environment.NewLine;
                Trace.WriteLine(text);

                //If IDENTITY Problem apears again --> uncomment this lines
                //syncStatusDelegate.Invoke(-1, Resources.SyncStateCheckingDataIntegrity);
                //SyncClient.VerifyDataBase(path, contentProtected, password);
                //syncStatusDelegate.Invoke(100, string.Empty);
            }
            catch (Exception ex)
            {
                syncStatusDelegate.Invoke(100, "Sync failed!");
                Trace.WriteLine("LearningModulesPage.Sync - " + ex.Message);

                DriveInfo info = new DriveInfo(path[0].ToString());
                if (info.TotalFreeSpace < 1000000)   //FreeSpace <1MB
                    throw new NotEnoughtDiskSpaceException();

                throw new SynchronizationFailedException(ex);
            }
        }
 /// <summary>
 /// Syncs the specified module.
 /// </summary>
 /// <param name="module">The module.</param>
 /// <param name="reportingDelegate">The reporting delegate.</param>
 /// <remarks>Documented by Dev08, 2009-04-30</remarks>
 public static void Sync(LearningModulesIndexEntry module, SyncStatusReportingDelegate reportingDelegate)
 {
     Sync(module, reportingDelegate, SyncedLearningModulePath);
 }