コード例 #1
0
 public string Serialize(SyncAction action)
 {
     if (action == null)
     {
         throw new ArgumentNullException(nameof(action));
     }
     var dto = new SyncActionDto(action);
     return JsonConvert.SerializeObject(dto, Formatting.Indented, s_SerializerSettings);
 }
コード例 #2
0
        public void Serialize(SyncAction action, System.IO.Stream writeTo)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }
            if (writeTo == null)
            {
                throw new ArgumentNullException(nameof(writeTo));
            }

            var json = Serialize(action);
            var writer = new StreamWriter(writeTo);
            writer.Write(json);
            writer.Flush();
        }
コード例 #3
0
 string GetRelativeSyncActionDirectoryPath(SyncAction action) => GetRelativeSyncActionDirectoryPath(action.State, action.Path);
コード例 #4
0
 public SyncActionDto(SyncAction action)
 {
     Target = action.Target;
     Id = action.Id;
     State = action.State;
     SyncPointId = action.SyncPointId;
     Type = action.Type;
     FromVersion = action.FromVersion != null ? new FileReferenceDto(action.FromVersion) : null;
     ToVersion = action.ToVersion != null ? new FileReferenceDto(action.ToVersion) : null;
 }
コード例 #5
0
ファイル: Synchronizer.cs プロジェクト: ap0llo/SyncTool
 bool IsPendingSyncAction(SyncAction action) => action.State.IsPendingState();
コード例 #6
0
ファイル: Synchronizer.cs プロジェクト: ap0llo/SyncTool
 /// <summary>
 /// Tries to apply the specified sync action to the change grpah
 /// </summary>
 /// <returns>Retruns true if the action could be added to the graph, otherwise return false</returns>
 bool TryApplySyncAction(Graph<IFileReference> changeGraph, SyncAction action)
 {
     if (changeGraph.Contains(action.FromVersion) && changeGraph.Contains(action.ToVersion))
     {
         changeGraph.AddEdge(action.FromVersion, action.ToVersion);
         return true;
     }
     return false;
 }
コード例 #7
0
        public void SyncAction_Roundtrip_Modified()
        {
            var lastWriteTime = DateTime.Now;

            var oldVersion = new FileReference("/file1", lastWriteTime, 23);
            var newVersion = new FileReference("/file1", lastWriteTime.AddDays(1), 23 * 2);            
            
            var expected = new SyncAction(ChangeType.Modified, oldVersion, newVersion, Guid.NewGuid(), Guid.NewGuid().ToString(), SyncActionState.Completed, 42);
            var actual = m_Instance.Deserialize(m_Instance.Serialize(expected));

            Assert.NotNull(actual);
            Assert.Equal(expected.Id, actual.Id);
            Assert.Equal(expected.Target, actual.Target);
            Assert.Equal(expected.FromVersion, actual.FromVersion);
            Assert.Equal(expected.ToVersion, actual.ToVersion);
            Assert.Equal(expected.State, actual.State);
            Assert.Equal(expected.SyncPointId, actual.SyncPointId);
        }
コード例 #8
0
        public void SyncAction_Roundtrip_Deleted()
        {
            var fileReference = new FileReference("/file1", DateTime.Now, 23);

            var expected = new SyncAction(ChangeType.Deleted, fileReference, null, Guid.NewGuid(), "targetName", SyncActionState.Active,23);
            var actual = m_Instance.Deserialize(m_Instance.Serialize(expected));

            Assert.NotNull(actual);
            Assert.Equal(expected.Id, actual.Id);
            Assert.Equal(expected.Target, actual.Target);
            Assert.Equal(expected.ToVersion, actual.ToVersion);
            Assert.Equal(expected.FromVersion, actual.FromVersion);
            Assert.Equal(expected.State, actual.State);
            Assert.Equal(expected.SyncPointId, actual.SyncPointId);
        }
コード例 #9
0
        public void SyncAction_Roundtrip_Added()
        {
            var fileReference = new FileReference("/file1", DateTime.Now, 23);
            
            var expected = new SyncAction(ChangeType.Added, null, fileReference, Guid.Parse("A7226A4D-4BE8-4B10-B378-BEF72A29FD24"), "targetName", SyncActionState.Queued, 42);
            var actual = m_Instance.Deserialize(m_Instance.Serialize(expected));

            Assert.NotNull(actual);
            Assert.Equal(expected.Id, actual.Id);
            Assert.Equal(expected.Target, actual.Target);
            Assert.Equal(expected.FromVersion, actual.FromVersion);
            Assert.Equal(expected.ToVersion, actual.ToVersion);
            Assert.Equal(expected.State, actual.State);
            Assert.Equal(expected.SyncPointId, actual.SyncPointId);
        }