Пример #1
0
 private void DetectChanges(Guid syncId, string path, FileSyncScopeFilter filter)
 {
     using (FileSyncProvider provider = new FileSyncProvider(syncId, path, filter, this.syncOptions))
     {
         provider.DetectChanges();
     }
 }
Пример #2
0
        public static void synchronize()
        {
            string s2 = str[1];
            string st = folderA + "\\" + s2;

            try
            {
                FileSyncProvider providerA = new FileSyncProvider(Guid.NewGuid(), st);
                FileSyncProvider providerB = new FileSyncProvider(Guid.NewGuid(), s);

                // Ask providers to detect changes
                providerA.DetectChanges();
                providerB.DetectChanges();

                // Sync changes
                SyncOrchestrator agent = new SyncOrchestrator();
                agent.LocalProvider  = providerA;
                agent.RemoteProvider = providerB;
                agent.Direction      = SyncDirectionOrder.UploadAndDownload;
                agent.Synchronize();
                Console.WriteLine("Files are  synchronized");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        //Creates/updates metadata file in root folders for synchronization
        public void DetectChangesInAllRootFolders()
        {
            FileSyncProvider provider = null;

            try
            {
                if (RootPathsList != null && RootPathsList.Count > 1)
                {
                    for (int i = 0; i < RootPathsList.Count; i++)
                    {
                        provider = new FileSyncProvider(RootPathsList[i], Filter, FileSyncOptions.None);
                        provider.DetectChanges();
                    }
                }
                else
                {
                    throw new Exception("Exception: List of paths is null or contain less than 2 pathes");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (provider != null)
                {
                    provider.Dispose();
                }
            }
        }
Пример #4
0
        private static void Main(string[] args)
        {
            const string replica1RootPath = "_R0";
            const string replica2RootPath = "_R1";

            if (Directory.Exists(replica1RootPath))
            {
                Directory.Delete(replica1RootPath, true);
            }
            Directory.CreateDirectory(replica1RootPath);

            if (Directory.Exists(replica2RootPath))
            {
                Directory.Delete(replica2RootPath, true);
            }
            Directory.CreateDirectory(replica2RootPath);

            try
            {
                // Set options for the synchronization operation
                const FileSyncOptions options =
                    FileSyncOptions.ExplicitDetectChanges |
                    FileSyncOptions.RecycleDeletedFiles |
                    FileSyncOptions.RecyclePreviousFileOnUpdates |
                    FileSyncOptions.RecycleConflictLoserFiles;

                var filter = new FileSyncScopeFilter();
                //filter.FileNameExcludes.Add("*.lnk"); // Exclude all *.lnk files

                Guid replica1Guid = Guid.Parse("181517DE-B950-4e62-9582-56F01884288D");
                Guid replica2Guid = Guid.Parse("86C9D79E-679D-4d33-A051-AA4EEFF17E55");

                using (var provider0 = new FileSyncProvider(replica1Guid, replica1RootPath, filter, options))
                {
                    using (var provider1 = new FileSyncProvider(replica2Guid, replica2RootPath, filter, options))
                    //using (var provider1 = new TestProvider(replica2Guid, Path.Combine(replica2RootPath, "_replica.sdf")))
                    {
                        var agent = CreateAgent(
                            provider0,
                            provider1
                            );

                        while (true)
                        {
                            provider0.DetectChanges();
                            provider1.DetectChanges();

                            agent.Synchronize();

                            Thread.Sleep(25);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("\nException from File Synchronization Provider:\n" + e);
            }
        }
Пример #5
0
        private static void DetectChangesOnFileSystemReplica(string replicaPath, FileSyncScopeFilter filter, FileSyncOptions options)
        {
            FileSyncProvider provider = null;

            try
            {
                provider = new FileSyncProvider(replicaPath, filter, options);
                provider.DetectChanges();
            }
            finally
            {
                if (provider != null)
                {
                    provider.Dispose();
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Detect the changes done to the folder
        /// <para>Updates the metadata</para>
        /// </summary>
        /// <param name="replicaRootPath">This parameter is the folder path to be checked</param>
        /// <param name="filter">This parameter is the filter which will be used during synchronization</param>
        /// <param name="options">This parameter holds the synchronization options</param>
        private static void DetectChangesonFileSystemReplica(string replicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options)
        {
            FileSyncProvider provider = null;

            try
            {
                provider = new FileSyncProvider(replicaRootPath, filter, options);
                provider.DetectChanges();
            }
            finally
            {
                // Release resources or memory
                if (provider != null)
                {
                    provider.Dispose();
                }
            }
        }
Пример #7
0
    public static void DetectChangesOnFileSystemReplica(
            string replicaRootPath,
            FileSyncScopeFilter filter, FileSyncOptions options)
    {
        FileSyncProvider provider = null;

        try
        {
            provider = new FileSyncProvider(replicaRootPath, filter, options);
            provider.DetectChanges();
        }
        finally
        {
            // Release resources
            if (provider != null)
                provider.Dispose();
        }
    }
Пример #8
0
        public static void DetectChangesOnFileSystemReplica(string replicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options, string metadataPath, string metadataFile, string tempDir, string trashDir)
        {
            FileSyncProvider provider = null;

            try
            {
                provider = new FileSyncProvider(replicaRootPath, filter, options, metadataPath, metadataFile, tempDir, trashDir);
                provider.DetectChanges();
            }
            finally
            {
                // Release resources
                if (provider != null)
                {
                    provider.Dispose();
                }
            }
        }
Пример #9
0
        public static void GravarMetadados(string pasta, FileSyncScopeFilter filtro)
        {
            FileSyncProvider provider = null;

            const FileSyncOptions opcoes = FileSyncOptions.ExplicitDetectChanges |
                                           FileSyncOptions.RecycleDeletedFiles |
                                           FileSyncOptions.RecyclePreviousFileOnUpdates |
                                           FileSyncOptions.RecycleConflictLoserFiles;

            try
            {
                provider = new FileSyncProvider(pasta, filtro, opcoes);
                provider.DetectChanges();
            }
            finally
            {
                if (provider != null) provider.Dispose();
            }
        }
Пример #10
0
        public void DetectChangesOnFileSystemReplica(
            Guid replicaId, string replicaRootPath,
            FileSyncScopeFilter filter, FileSyncOptions options)
        {
            FileSyncProvider provider = null;

            try
            {
                provider = new FileSyncProvider(replicaId, replicaRootPath, filter, options);
                provider.DetectChanges();
            }
            finally
            {
                // Release resources
                if (provider != null)
                {
                    provider.Dispose();
                }
            }
        }
Пример #11
0
        public static void DetectChangesOnFileSystemReplica(
            SyncId syncid, string replicaRootPath,
            FileSyncScopeFilter filter, FileSyncOptions options,
            DirectoryInfo syncDir,
            string metadataName)
        {
            FileSyncProvider provider = null;

            try
            {
                provider = new FileSyncProvider(
                    syncid.GetGuidId(), replicaRootPath, filter, options, syncDir.FullName, metadataName, syncDir.FullName, null);
                provider.DetectChanges();
            }
            finally
            {
                // Release resources
                if (provider != null)
                    provider.Dispose();
            }
        }
Пример #12
0
        // Create a provider, and detect changes on the replica that the provider
        // represents.
        public static void DetectChangesOnFileSystemReplica(
            string replicaRootPath,
            FileSyncScopeFilter filter, FileSyncOptions options)
        {
            FileSyncProvider provider = null;

            //FileSyncProvider provider;

            try
            {
                //3provider = new FileSyncProvider("C:\\inetpub\\wwwroot\\MAKRO\\Repository");
                provider = new FileSyncProvider(replicaRootPath, filter, options);
                //1provider = new FileSyncProvider(replicaRootPath);
                provider.DetectChanges();
            }
            finally
            {
                // Release resources.
                if (provider != null)
                {
                    provider.Dispose();
                }
            }
        }
Пример #13
0
        //public static void DetectChangesOnFileSystemReplica(
        //string replicaRootPath,
        //FileSyncScopeFilter filter, FileSyncOptions options)
        //{
        //    FileSyncProvider provider = null;

        //    try
        //    {
        //        provider = new FileSyncProvider(replicaRootPath, filter, options);
        //        provider.DetectChanges();

        //    }
        //    finally
        //    {
        //        // Release resources
        //        if (provider != null)
        //            provider.Dispose();
        //    }
        //}

        public static void SyncFileSystemReplicasOneWay(
            string sourceReplicaRootPath, string destinationReplicaRootPath,
            FileSyncScopeFilter filter, FileSyncOptions options)
        {
            FileSyncProvider sourceProvider      = null;
            FileSyncProvider destinationProvider = null;

            try
            {
                sourceProvider = new FileSyncProvider(
                    sourceReplicaRootPath, filter, options);

                //filter.SubdirectoryExcludes.Add(@".\");

                destinationProvider = new FileSyncProvider(
                    destinationReplicaRootPath, filter, options);

                sourceProvider.AppliedChange +=
                    new EventHandler <AppliedChangeEventArgs>(OnAppliedChange);
                sourceProvider.SkippedChange +=
                    new EventHandler <SkippedChangeEventArgs>(OnSkippedChange);


                sourceProvider.DetectChanges();

                sourceProvider.CopyingFile += (s, a) =>
                {
                    string file    = a.FilePath;
                    int    percent = a.PercentCopied;
                };
                sourceProvider.AppliedChange += (s, a) =>
                {
                    string file   = a.NewFilePath;
                    var    change = a.ChangeType;
                };
                sourceProvider.DetectedChanges += (s, a) =>
                {
                    //a.TotalDirectoriesFound
                };

                destinationProvider.CopyingFile += (s, a) =>
                {
                    string file    = a.FilePath;
                    int    percent = a.PercentCopied;
                    FileIO.FileTransferProgress(null, new FileTransferProgressEventArgs(percent, Path.GetFileName(file)));
                };
                destinationProvider.AppliedChange += (s, a) =>
                {
                    string file = a.NewFilePath;
                };
                destinationProvider.AppliedChange += (s, a) =>
                {
                    if (a.ChangeType == ChangeType.Delete)
                    {
                        return;
                    }

                    string file       = a.NewFilePath;
                    string serverPath = FileIO.GetPath(destinationReplicaRootPath) + file;
                    if (FileIO.IsDirectory(serverPath))
                    {
                        return;
                    }
                    FileIO.FinshedFileTransfer(null, new FinshedFileTransferEventArgs(Path.GetFileName(serverPath)));
                    string localDirectory = FileIO.GetPath(FileIO.GetPath(sourceReplicaRootPath) + file);
                    string localFile      = localDirectory + Path.GetFileName(file);
                    string topLevelDir    = FileIO.GetPath(sourceReplicaRootPath) + FileIO.GetTopLevelFolder(file);
                    try
                    {
                        File.Delete(localFile);
                    }
                    catch (Exception ex) { Logging.Log(ex.Message); }

                    if (topLevelDir == FileIO.GetPath(sourceReplicaRootPath))
                    {
                        return;
                    }
                    //bool isMoreTransfers = filter.FileNameIncludes.Any(x => Directory.GetFiles(localDirectory, x) != null);
                    foreach (string filterVal in filter.FileNameIncludes)
                    {
                        if (Directory.EnumerateFiles(topLevelDir, filterVal, SearchOption.AllDirectories).Count() > 0)
                        {
                            return;
                        }
                    }

                    //if (isMoreTransfers) return;

                    try
                    {
                        FileIO.ForceDeleteDirectory(topLevelDir);
                    }
                    catch (Exception ex) { Logging.Log(ex.Message); }
                };

                //SyncOrchestrator agent = new SyncOrchestrator();
                _agent.LocalProvider  = sourceProvider;
                _agent.RemoteProvider = destinationProvider;
                _agent.Direction      = SyncDirectionOrder.Upload;

                Logging.Log("Synchronizing changes to replica: " +
                            destinationProvider.RootDirectoryPath);

                _agent.StateChanged += (s, a) =>
                {
                    if (a.OldState == SyncOrchestratorState.Uploading && a.NewState == SyncOrchestratorState.Ready)
                    {
                        string path         = FileIO.GetPath(destinationReplicaRootPath);
                        string metadataFile = path + _metadataFile;

                        try
                        {
                            Logging.Log("Syncronization complete, cleanning up...");
                            File.Delete(metadataFile);
                            foreach (string tmpFile in Directory.EnumerateFiles(path, "*.tmp"))
                            {
                                File.Delete(tmpFile);
                            }
                            //FileSync.WatchFileSystem(sourceReplicaRootPath, destinationReplicaRootPath);
                        }
                        catch (Exception ex)
                        {
                            Logging.LogError(ex.Message);
                        }
                    }
                };
                _agent.SessionProgress += (s, a) =>
                {
                    uint p = a.CompletedWork;
                };
                _agent.Synchronize();
                //keep background worker alive
                //while (true) { };
            }
            catch (Exception ex)
            {
                Logging.Log(ex.Message);
            }
            finally
            {
                // Release resources
                if (sourceProvider != null)
                {
                    sourceProvider.Dispose();
                }
                if (destinationProvider != null)
                {
                    destinationProvider.Dispose();
                }
                //if (_agent != null) _agent.Cancel(); _agent = null;
            }
        }
Пример #14
0
        public static void DetectChanges(string root, FileSyncScopeFilter filter, FileSyncOptions options)
        {
            FileSyncProvider provider = null;
            try
            {

                provider = new FileSyncProvider(root, filter, options);
                provider.DetectChanges();
            }
            finally
            {
                if (provider != null)
                    provider.Dispose();
            }
        }
Пример #15
0
 public void DetectChanges()
 {
     localPro.DetectChanges();
     remotePro.DetectChanges();
 }
Пример #16
0
        //public static void DetectChangesOnFileSystemReplica(
        //string replicaRootPath,
        //FileSyncScopeFilter filter, FileSyncOptions options)
        //{
        //    FileSyncProvider provider = null;
        //    try
        //    {
        //        provider = new FileSyncProvider(replicaRootPath, filter, options);
        //        provider.DetectChanges();
        //    }
        //    finally
        //    {
        //        // Release resources
        //        if (provider != null)
        //            provider.Dispose();
        //    }
        //}
        public static void SyncFileSystemReplicasOneWay(
                string sourceReplicaRootPath, string destinationReplicaRootPath,
                FileSyncScopeFilter filter, FileSyncOptions options)
        {
            FileSyncProvider sourceProvider = null;
            FileSyncProvider destinationProvider = null;

            try
            {
                sourceProvider = new FileSyncProvider(
                    sourceReplicaRootPath, filter, options);

                //filter.SubdirectoryExcludes.Add(@".\");

                destinationProvider = new FileSyncProvider(
                    destinationReplicaRootPath, filter, options);

                sourceProvider.AppliedChange +=
                    new EventHandler<AppliedChangeEventArgs>(OnAppliedChange);
                sourceProvider.SkippedChange +=
                    new EventHandler<SkippedChangeEventArgs>(OnSkippedChange);

                sourceProvider.DetectChanges();

                sourceProvider.CopyingFile += (s, a) =>
                {
                    string file = a.FilePath;
                    int percent = a.PercentCopied;
                };
                sourceProvider.AppliedChange += (s, a) =>
                {
                    string file = a.NewFilePath;
                    var change = a.ChangeType;
                };
                sourceProvider.DetectedChanges += (s, a) =>
                {
                    //a.TotalDirectoriesFound
                };

                destinationProvider.CopyingFile += (s, a) =>
                {
                    string file = a.FilePath;
                    int percent = a.PercentCopied;
                    FileIO.FileTransferProgress(null, new FileTransferProgressEventArgs(percent, Path.GetFileName(file)));
                };
                destinationProvider.AppliedChange += (s, a) =>
                {
                    string file = a.NewFilePath;
                };
                destinationProvider.AppliedChange += (s, a) =>
                {
                    if (a.ChangeType == ChangeType.Delete) return;

                    string file = a.NewFilePath;
                    string serverPath = FileIO.GetPath(destinationReplicaRootPath) + file;
                    if (FileIO.IsDirectory(serverPath)) return;
                    FileIO.FinshedFileTransfer(null, new FinshedFileTransferEventArgs(Path.GetFileName(serverPath)));
                    string localDirectory = FileIO.GetPath(FileIO.GetPath(sourceReplicaRootPath) + file);
                    string localFile = localDirectory + Path.GetFileName(file);
                    string topLevelDir = FileIO.GetPath(sourceReplicaRootPath) + FileIO.GetTopLevelFolder(file);
                    try
                    {
                        File.Delete(localFile);
                    }
                    catch (Exception ex) { Logging.Log(ex.Message); }

                    if (topLevelDir == FileIO.GetPath(sourceReplicaRootPath)) return;
                   //bool isMoreTransfers = filter.FileNameIncludes.Any(x => Directory.GetFiles(localDirectory, x) != null);
                    foreach(string filterVal in filter.FileNameIncludes)
                    {
                        if (Directory.EnumerateFiles(topLevelDir, filterVal, SearchOption.AllDirectories).Count() > 0) return;
                    }

                    //if (isMoreTransfers) return;

                    try
                    {
                        FileIO.ForceDeleteDirectory(topLevelDir);
                    }
                    catch (Exception ex) { Logging.Log(ex.Message); }
                };

                //SyncOrchestrator agent = new SyncOrchestrator();
                _agent.LocalProvider = sourceProvider;
                _agent.RemoteProvider = destinationProvider;
                _agent.Direction = SyncDirectionOrder.Upload;

                Logging.Log("Synchronizing changes to replica: " +
                    destinationProvider.RootDirectoryPath);

                _agent.StateChanged += (s, a) =>
                {
                    if (a.OldState == SyncOrchestratorState.Uploading && a.NewState == SyncOrchestratorState.Ready)
                    {
                        string path = FileIO.GetPath(destinationReplicaRootPath);
                        string metadataFile = path + _metadataFile;

                        try
                        {
                            Logging.Log("Syncronization complete, cleanning up...");
                            File.Delete(metadataFile);
                            foreach (string tmpFile in Directory.EnumerateFiles(path, "*.tmp"))
                            {
                                File.Delete(tmpFile);
                            }
                            //FileSync.WatchFileSystem(sourceReplicaRootPath, destinationReplicaRootPath);
                        }
                        catch (Exception ex)
                        {
                            Logging.LogError(ex.Message);
                        }

                    }
                };
                _agent.SessionProgress += (s, a) =>
                {
                    uint p = a.CompletedWork;
                };
                _agent.Synchronize();
                //keep background worker alive
                //while (true) { };
            }
            catch (Exception ex)
            {
                Logging.Log(ex.Message);
            }
            finally
            {
                // Release resources
                if (sourceProvider != null) sourceProvider.Dispose();
                if (destinationProvider != null) destinationProvider.Dispose();
                //if (_agent != null) _agent.Cancel(); _agent = null;
            }
        }
Пример #17
0
        public bool DetectChanges(FileSyncProvider provider)
        {
            //throw new NotImplementedException();
            try
            {
                provider = AttachDetectedChangeEventHandler(provider);
                provider.DetectChanges();
            }
            finally
            {
                // Release resources
                DisposeProvider(provider);

            }
            return true;
        }
Пример #18
0
 private void DetectChanges(Guid syncId, string path, FileSyncScopeFilter filter)
 {
     using (FileSyncProvider provider = new FileSyncProvider(syncId, path, filter, this.syncOptions))
     {
         provider.DetectChanges();
     }
 }