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); }
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(); }
string GetRelativeSyncActionDirectoryPath(SyncAction action) => GetRelativeSyncActionDirectoryPath(action.State, action.Path);
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; }
bool IsPendingSyncAction(SyncAction action) => action.State.IsPendingState();
/// <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; }
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); }
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); }
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); }