예제 #1
0
파일: FooSync.cs 프로젝트: wfraser/FooSync
        public static void UpdateRepoState(RepositoryStateCollection state, FooChangeSet changeset, FooTree repo, FooTree source)
        {
            if (state == null)
                throw new ArgumentNullException("state");
            if (changeset == null)
                throw new ArgumentNullException("changeset");
            if (repo == null)
                throw new ArgumentNullException("repo");
            if (source == null)
                throw new ArgumentNullException("source");

            /*
            foreach (var filename in changeset.Where(e => e.FileOperation != FileOperation.NoOp))
            {
                ChangeStatus cstatus = changeset[filename].ChangeStatus;
                FileOperation operation = changeset[filename].FileOperation;

                if (cstatus == ChangeStatus.SourceDeleted
                        && operation != FileOperation.UseRepo)
                {
                    state.Source.MTimes.Remove(filename);
                }

                if (cstatus == ChangeStatus.RepoDeleted
                        && operation != FileOperation.UseSource)
                {
                    state.Repository.MTimes.Remove(filename);
                }

                if (operation == FileOperation.UseSource)
                {
                    state.Repository.MTimes[filename] = source.Files[filename].MTime;
                    state.Source.MTimes[filename] = source.Files[filename].MTime;
                    state.Origin[filename] = state.Source.ID;
                }
                else if (operation == FileOperation.UseRepo)
                {
                    state.Repository.MTimes[filename] = repo.Files[filename].MTime;
                    state.Source.MTimes[filename] = repo.Files[filename].MTime;
                }
                else if (operation == FileOperation.DeleteSource)
                {
                    state.Source.MTimes.Remove(filename);
                }
                else if (operation == FileOperation.DeleteRepo)
                {
                    state.Repository.MTimes.Remove(filename);
                }
            }
            */
        }
예제 #2
0
파일: FooSync.cs 프로젝트: wfraser/FooSync
        public FooChangeSet Inspect(RepositoryStateCollection state, Dictionary<Guid, FooTree> trees, Progress callback = null)
        {
            if (state == null)
                throw new ArgumentNullException("state");
            if (trees == null)
                throw new ArgumentNullException("trees");

            FooChangeSet changeset = new FooChangeSet(trees.Keys);

            long total = (from tree in trees.Values
                          select tree.Files.Count)
                            .Aggregate((a, b) => (a + b));
            long current = 0;

            foreach (Guid repoId in trees.Keys)
            {
                foreach (string filename in trees[repoId].Files.Keys)
                {
                    if (callback != null)
                    {
                        callback(current++, total, trees[repoId].Base.IsLocal ? Path.Combine(trees[repoId].Base.LocalPath, filename)
                                                                              : trees[repoId].Base.ToString() + filename);
                    }

                    if (state.Repositories[repoId].MTimes.ContainsKey(filename))
                    {
                        foreach (Guid otherId in trees.Keys)
                        {
                            if (repoId == otherId)
                            {
                                continue;
                            }
                            if (trees[otherId].Files.ContainsKey(filename))
                            {
                                DateTime repoTime = trees[repoId].Files[filename].MTime;
                                DateTime otherTime = trees[otherId].Files[filename].MTime;

                                changeset.Add(
                                    filename,
                                    (state.Repositories[repoId].MTimes[filename] == repoTime)
                                        ? ChangeStatus.Identical
                                        : ChangeStatus.Changed,
                                    repoId);

                                changeset.Add(
                                    filename,
                                    (state.Repositories[otherId].MTimes[filename] == otherTime)
                                        ? ChangeStatus.Identical
                                        : ChangeStatus.Changed,
                                    otherId);
                            }
                            else
                            {
                                //
                                // Don't check if the file exists in the state for the other repo;
                                // just display it as missing.
                                //

                                changeset.Add(filename, ChangeStatus.Missing, otherId);

                                //
                                // Also add an 'Identical' entry for the existing one.
                                //

                                changeset.Add(filename, ChangeStatus.Identical, repoId);
                            }
                        }
                    }
                    else
                    {
                        changeset.Add(filename, ChangeStatus.New, repoId);
                    }
                }
            }

            foreach (string filename in changeset.Filenames)
            {
                FooChangeSetElem change = changeset[filename];

                foreach (Guid repoId in trees.Keys)
                {
                    if (change.ChangeStatus[repoId] == ChangeStatus.Undetermined)
                    {
                        changeset[filename].ChangeStatus[repoId] =
                            (state.Repositories.ContainsKey(repoId) && state.Repositories[repoId].MTimes.ContainsKey(filename))
                                ? ChangeStatus.Deleted
                                : ChangeStatus.Missing;
                    }
                }
            }

            return changeset;
        }
예제 #3
0
파일: Program.cs 프로젝트: wfraser/FooSync
        private Dictionary<SyncGroupConfigMember, RepositoryStateCollection> GetStates(SyncGroupConfig syncGroup, Dictionary<SyncGroupConfigMember, FooTree> trees)
        {
            Dictionary<SyncGroupConfigMember, RepositoryStateCollection> states = new Dictionary<SyncGroupConfigMember, RepositoryStateCollection>();

            foreach (SyncGroupConfigMember member in syncGroup.Members)
            {
                RepositoryStateCollection state = null;

                if (member.Url.IsLocal)
                {
                    try
                    {
                        state = new RepositoryStateCollection(Path.Combine(member.Url.LocalPath, FooSyncEngine.RepoStateFileName));
                    }
                    catch (FileNotFoundException)
                    {
                        state = new RepositoryStateCollection();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Unexpected {0} trying to read repository state: {1}",
                            ex.GetType().Name,
                            ex.Message);
                        continue;
                    }
                }
                else
                {
                    NetClient nc = new NetClient(
                        Foo,
                        member.Url.Host,
                        member.Url.Port,
                        member.Auth == null ? string.Empty : member.Auth.User,
                        member.Auth == null ? string.Empty : member.Auth.Password,
                        member.Url.AbsolutePath.Substring(1)
                        );

                    state = nc.GetState();
                }

                if (state.Repository == null)
                {
                    state.AddRepository(trees[member], state.RepositoryID);
                }

                foreach (var otherPair in states)
                {
                    SyncGroupConfigMember otherMember = otherPair.Key;
                    RepositoryStateCollection otherState = otherPair.Value;

                    if (!state.Repositories.ContainsKey(otherState.RepositoryID))
                    {
                        state.AddRepository(trees[otherMember], otherState.RepositoryID);
                    }

                    if (!otherState.Repositories.ContainsKey(state.RepositoryID))
                    {
                        otherState.AddRepository(trees[member], state.RepositoryID);
                    }
                }

                states.Add(member, state);
            }

            foreach (var pair in states)
            {
                SyncGroupConfigMember member = pair.Key;
                RepositoryStateCollection state = pair.Value;

                if (member.Url.IsLocal)
                {
                    state.Write(Path.Combine(member.Url.LocalPath, FooSyncEngine.RepoStateFileName));
                }
                else
                {
                    //TODO
                }
            }

            return states;
        }