示例#1
0
文件: core.cs 项目: ovg1985/sync
        public void Run()
        {
            ILogger logger = new CompoundLogger()
            {
                Logs = new ILogger[] {
                    new EventLogger(),
                    new ConsoleLogger()
                    {
                        Verbosity = Verbosity
                    }
                }
            };

            ChangesMonitor monitor = new ChangesMonitor(logger)
            {
                SourcePath = SourcePath,
                Excludes   = Excludes
            };

            ChangesTransmitter transmitter = new ChangesTransmitter(logger)
            {
                Host            = Host,
                User            = User,
                PrivateKey      = PrivateKey,
                Passphrase      = Passphrase,
                DestinationPath = DestinationPath,
                DryRun          = DryRun,
                Excludes        = Excludes,
            };

            monitor.TurnOn();
            transmitter.WaitChanges(monitor, () => false);
        }
示例#2
0
文件: core.cs 项目: ovg1985/sync
        private EventPool RetrieveChanges(ChangesMonitor source)
        {
            if (LostLifeChanges.Count == 0)
            {
                return(source.Wait(IsCancel));
            }

            // we failed last time and there are unprocessed changes
            var changes = new EventPool(LostLifeChanges);

            LostLifeChanges.Clear();
            return(changes);
        }
示例#3
0
文件: core.cs 项目: ovg1985/sync
        public void WaitChanges(ChangesMonitor source, Predicate cancelPoller)
        {
            SourcePath     = source.SourcePath;
            BashSourcePath = Utils.ToBashPath(SourcePath);
            BashExePath    = Utils.TryBashExePath();
            var sessionOptions  = CreateSessionOptions();
            var transferOptions = CreateTransferOptions();

            Session.Timeout = Timeout;
            IsCancel        = cancelPoller;

            while (!IsCancel())
            {
                try {
                    OpenSession(sessionOptions);
                    while (!IsCancel())
                    {
                        var changes = RetrieveChanges(source);
                        OnChangesStart();
                        if (changes == null)
                        {
                            return;
                        }

                        TransferAll(changes, transferOptions);
                        OnChangesFinish();
                    }
                } catch (SessionRemoteException err) {
                    Log.Error("Remote failure: {0}", err);
                } catch (TimeoutException) {
                    Log.Error("Session timeout. Retryng to connect...");
                } catch (InvalidOperationException err) {
                    Log.Error("Remote failure: {0}", err);
                } catch (SessionLocalException err) {
                    Log.Error("Local failure: {0}", err);
                } catch (Exception err) {
                    Log.Error("UNKNOWN EXCEPTION: {0}. Yury, you MUST fix it!", err);

                    if (LostLifeChanges.Count > 0)
                    {
                        var first = LostLifeChanges[0];
                        Log.Debug("Skip problem change: {0} {1}", first.ChangeType, first.FullPath);
                        LostLifeChanges.RemoveAt(0);
                    }

                    Thread.Sleep(1000);
                } finally {
                    CloseSession();
                }
            }
        }
示例#4
0
文件: core.cs 项目: ovg1985/sync
        public void Start(Predicate cancelPoller)
        {
            OnChangesWait();
            ILogger logger = new EventLogger();

            /// add delegates
            ChangesMonitor monitor = new ChangesMonitor(logger)
            {
                SourcePath = SourcePath,
                Excludes   = Excludes,
            };

            ChangesTransmitter transmitter = new ChangesTransmitter(logger)
            {
                Host            = Host,
                User            = User,
                PrivateKey      = PrivateKey,
                Passphrase      = Passphrase,
                DestinationPath = DestinationPath,
                Excludes        = Excludes,
            };

            monitor.OnChangesCollect += OnChangesProcessed;
            monitor.OnWait           += OnChangesWait;

            monitor.TurnOn();

            var cancelListen = new Task(new Action(() => {
                while (!cancelPoller())
                {
                    Thread.Sleep(1000);
                }

                //monitor.TurnOff();
                transmitter.Stop();
            }));

            cancelListen.Start();

            transmitter.WaitChanges(monitor, cancelPoller);
            OnStop();
            logger.Info("Stopping...");
        }