예제 #1
0
        public static Delta SyncReadOnly(List <QueueProcessor> qlist, string clientmachine, string sharename, string token, State clientstate)
        {
            var cs = Global.ConnectionList.Find(x => x.Name == sharename && x.MachineName == clientmachine && x.Token == token);

            if (cs != null)
            {
                var q = qlist.Find(x => x.cs == cs);
                if (q != null)
                {
                    _log.Info("Sync RO : " + sharename);
                    var state = DeltaProcessor.GetCurrentState(cs.Path, cs);
                    q.SetInfo(state);
                    return(DeltaProcessor.ComputeDelta(state, clientstate));
                }
            }
            _log.Debug($"{clientmachine}/{sharename} and token not found");
            return(new Delta());
        }
예제 #2
0
        public static Delta SyncReadWrite(List <QueueProcessor> qlist, string clientmachine, string sharename, string token, State clientstate, Delta clientdelta)
        {
            var cs = Global.ConnectionList.Find(x => x.Name == sharename && x.MachineName == clientmachine && x.Token == token);

            if (cs != null)
            {
                var q = qlist.Find(x => x.cs == cs);
                if (q != null)
                {
                    _log.Info("Sync RW : " + sharename);
                    return(DeltaProcessor.SynchronizeSendRecieve(q, cs, clientstate, clientdelta));
                }
                else
                {
                    _log.Debug("Queue for share not found : " + cs);
                    return(new Delta());
                }
            }
            _log.Debug($"{clientmachine}/{sharename} and token not found");
            return(new Delta());
        }
예제 #3
0
        private void NewSync()
        {
            lock (_lock)
            {
                if (ClientCommands.isConnected(_conn.MachineName) == false)
                {
                    return;
                }
                if (_conn.isConfirmed == false)
                {
                    _conn.isConfirmed = ClientCommands.isConfirmed(_conn);
                    _conn.isPaused    = false;
                    ServerCommands.SaveConnection(_conn);
                }
                if (_que.Count > 0)
                {
                    return;
                }

                if (_conn.ReadyForSync())
                {
                    if (_conn.ReadOnly)
                    {
                        if (ClientCommands.isChanged(_conn) || _conn.isChanged)
                        {
                            _log.Info("syncing readonly : " + _conn.Name);
                            var state = DeltaProcessor.GetCurrentState(_conn.Path, _conn);
                            _connInfo.TotalFileCount = state.Files.Count;
                            var d = ClientCommands.SyncMeReadonly(state, _conn);
                            if (d != null)
                            {
                                QueueDelta(d);
                                _conn.isChanged = false;
                            }
                        }
                    }
                    else
                    {
                        if (ClientCommands.isChanged(_conn) || _conn.isChanged)
                        {
                            _log.Info("syncing read write : " + _conn.Name);
                            var laststate = DeltaProcessor.GetLastState(_conn);
                            // sync read write
                            var state = DeltaProcessor.GetCurrentState(_conn.Path, _conn);
                            _connInfo.TotalFileCount = state.Files.Count;
                            var delta = DeltaProcessor.ComputeDelta(state, laststate);
                            if (laststate.Files.Count > 0 || laststate.Folders.Count > 0)
                            {
                                delta.FilesChanged = new List <SyncFile>();
                                delta.FilesAdded   = new List <SyncFile>();
                            }

                            var d = ClientCommands.SyncMeReadWrite(state, delta, _conn);
                            if (d != null)
                            {
                                QueueDelta(d);
                                _conn.isChanged = false;
                                DeltaProcessor.SaveState(_conn, state);
                            }
                        }
                    }
                }

                SaveQueue();
            }
        }