Ejemplo n.º 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public RepoBase(RepoInfo repoInfo, IActivityListener activityListener)
        {
            EventManager = new SyncEventManager();
            EventManager.AddEventHandler(new DebugLoggingHandler());
            EventManager.AddEventHandler(new GenericSyncEventHandler<RepoConfigChangedEvent>(0, RepoInfoChanged));
            Queue = new SyncEventQueue(EventManager);
            RepoInfo = repoInfo;
            LocalPath = repoInfo.TargetDirectory;
            Name = repoInfo.Name;
            RemoteUrl = repoInfo.Address;

            this.activityListener = activityListener;

            if (repoInfo.IsSuspended) Status = SyncStatus.Suspend;

            // Folder lock.
            // Disabled for now. Can be an interesting feature, but should be made opt-in, as
            // most users would be surprised to see this file appear.
            // folderLock = new FolderLock(LocalPath);

            Watcher = new Watcher(LocalPath);
            Watcher.EnableRaisingEvents = true;


            // Main loop syncing every X seconds.
            remote_timer.Elapsed += delegate
            {
                // Synchronize.
                SyncInBackground();
            };
            remote_timer.AutoReset = true;
            Logger.Info("Repo " + repoInfo.Name + " - Set poll interval to " + repoInfo.PollInterval + "ms");
            remote_timer.Interval = repoInfo.PollInterval;

            //Partial sync interval..
            local_timer.Elapsed += delegate
            {
                // Run partial sync.
                SyncInBackground(false);
            };
            local_timer.AutoReset = false;
            local_timer.Interval = delay_interval;
        }
Ejemplo n.º 2
0
            /// <summary>
            ///  Constructor for Repo (at every launch of CmisSync)
            /// </summary>
            public SynchronizedFolder(RepoInfo repoInfo, RepoBase repoCmis, IActivityListener activityListener)
            {
                this.activityListener = activityListener;

                if (null == repoInfo || null == repoCmis)
                {
                    throw new ArgumentNullException("repoInfo");
                }

                this.repo = repoCmis;
                this.repoinfo = repoInfo;

                suspended = this.repoinfo.IsSuspended;

				Queue = repoCmis.Queue;

                // Database is the user's AppData/Roaming
                database = new Database(repoinfo.CmisDatabase);

                // Get path on remote repository.
                remoteFolderPath = repoInfo.RemotePath;

                cmisParameters = new Dictionary<string, string>();
                UpdateCmisParameters();
                if (Logger.IsInfoEnabled)
                {
                    foreach (string ignoredFolder in repoInfo.getIgnoredPaths())
                    {
                        Logger.Info("The folder \"" + ignoredFolder + "\" will be ignored");
                    }
                }
                repoCmis.EventManager.AddEventHandler(new GenericSyncEventHandler<RepoConfigChangedEvent>(10, RepoInfoChanged));

                syncWorker = new BackgroundWorker();
                syncWorker.WorkerSupportsCancellation = true;
                syncWorker.DoWork += new DoWorkEventHandler(
                    delegate(Object o, DoWorkEventArgs args)
                    {
                        bool syncFull = (bool)args.Argument;
                        try
                        {
                            Sync(syncFull);
                        }
                        catch (OperationCanceledException e)
                        {
                            Logger.Info(e.Message);
                        }
                        catch (CmisPermissionDeniedException e)
                        {
                            repo.OnSyncError(new PermissionDeniedException("Authentication failed.", e));
                        }
                        catch (Exception e)
                        {
                            repo.OnSyncError(new BaseException(e));
                        }
                        finally
                        {
                            SyncComplete(syncFull);
                        }
                    }
                );
            }