Ejemplo n.º 1
0
        /// <summary>
        /// C'tor, using a base URL and a relative path.
        /// </summary>
        /// <param name="baseUrl">file:/// or fs:// URL</param>
        /// <param name="relativePath">Relative path to add to baseUrl</param>
        public FooSyncUrl(FooSyncUrl baseUrl, string relativePath)
            : base(baseUrl, relativePath)
        {
            _isLocal = (Scheme == Uri.UriSchemeFile);

            if (!_isLocal && Scheme != UriSchemeFooSync)
            {
                throw new FormatException("Invalid URI schema; must be " + UriSchemeFooSync + " or " + Uri.UriSchemeFile + ", not " + Scheme);
            }

            if (UserInfo != string.Empty)
            {
                throw new FormatException("Don't use a username/password with a fs:// URL");
            }

            if (!_isLocal && string.IsNullOrEmpty(Host))
            {
                throw new FormatException("Hostname is required for fs:// URL");
            }
        }
Ejemplo n.º 2
0
        FooSyncUrl NormalizePath(string given)
        {
            if (!given.StartsWith("fs://"))
            {
                given = Path.GetFullPath(given);
            }

            if (given.StartsWith("/"))
            {
                given = "file://" + given;
            }

            FooSyncUrl url;
            try
            {
                url = new FooSyncUrl(given);
            }
            catch (FormatException)
            {
                return null;
            }

            return url;
        }
Ejemplo 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;
        }