Exemplo n.º 1
0
        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);
                }
            }
            */
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        public static bool PerformActions(FooChangeSet changeSet, Dictionary<Guid, FooSyncUrl> basePaths, Progress copyCallback = null, Progress deleteCallback = null)
        {
            List<FooSyncUrl> copyFrom = new List<FooSyncUrl>();
            List<FooSyncUrl> copyTo = new List<FooSyncUrl>();
            List<FooSyncUrl> delete = new List<FooSyncUrl>();

            foreach (string filename in changeSet.Filenames)
            {
                FooSyncUrl copySourceUrl = null;
                List<FooSyncUrl> copyDestUrls = new List<FooSyncUrl>();
                List<FooSyncUrl> deleteUrls = new List<FooSyncUrl>();

                foreach (Guid repoId in changeSet.RepositoryIDs)
                {
                    FooSyncUrl fullUrl = new FooSyncUrl(basePaths[repoId], filename);

                    switch (changeSet[filename].FileOperation[repoId])
                    {
                        case FileOperation.Source:
                            copySourceUrl = fullUrl;
                            break;

                        case FileOperation.Destination:
                            copyDestUrls.Add(fullUrl);
                            break;

                        case FileOperation.Delete:
                            deleteUrls.Add(fullUrl);
                            break;
                    }
                }

                if (copySourceUrl == null && copyDestUrls.Count > 0)
                {
                    throw new InvalidOperationException(
                        string.Format("No copy source given for {0}", filename));
                }

                foreach (FooSyncUrl destUrl in copyDestUrls)
                {
                    copyFrom.Add(copySourceUrl);
                    copyTo.Add(destUrl);
                }

                delete.AddRange(deleteUrls);
            }

            bool result = Copy(copyFrom, copyTo, copyCallback);

            if (!result)
            {
                return result;
            }

            result = Delete(delete, deleteCallback);

            return result;
        }