public void LoadStateFrom(string path = "multisync_state.msync") { /* check file */ if (!File.Exists(path)) { return; } StreamReader stream = new StreamReader(path); string line; while ((line = stream.ReadLine()) != null) { string[] args = line.Split(" "); string id = args[0]; int state = int.Parse(args[1]); SynchronizingItem.SyncState convertedState = ((SynchronizingItem.SyncState)state); int task = int.Parse(args[2]); SynchronizingItem.TaskState convertedTask = ((SynchronizingItem.TaskState)task); SynchronizingItem item = new SynchronizingItem(id, drive, convertedTask); localStack.Add(item); } stream.Close(); }
public void UpdateState(SynchronizingItem item) { int index = -1; int i = 0; foreach (var localItem in localStack) { if (item.ID == localItem.ID) { index = i; break; } i++; } if (item.State == SynchronizingItem.SyncState.DeletingAll && item.Task == SynchronizingItem.TaskState.Done) { if (index >= 0) { localStack.Remove(item); } // Else, just don't add } else { if (index < 0) { localStack.Add(item); } else { localStack[index] = item; } } }
public void SyncWithState(ItemInterface item, SynchronizingItem.SyncState state) { while (tempSyncItems_locked) /* wait */; { } var localItem = localStack.GetItem(item.ID); if (localItem != null && (localItem.State == state && localItem.Task != SynchronizingItem.TaskState.Done)) { return; } var syncItem = new SynchronizingItem(item, SynchronizingItem.TaskState.NotStarted, state); int index = 0; bool shouldBeUpdatedAtIndex = false; foreach (var sItem in tempSyncItems) { if (sItem.ID == syncItem.ID) { shouldBeUpdatedAtIndex = true; break; } index++; } tempSyncItems_locked = true; if (shouldBeUpdatedAtIndex) { tempSyncItems[index] = syncItem; } else { tempSyncItems.Add(syncItem); } tempSyncItems_locked = false; }