public void Remove([NotNull] ProjectBase project, [NotNull] FolderSynchronizer folder)
        {
            Assert.ArgumentNotNull(project, nameof(project));
            Assert.ArgumentNotNull(folder, nameof(folder));

            lock (syncObject)
            {
                Folders.Remove(folder);
            }

            SaveProject(project);
        }
        public void Add([NotNull] Projects.Project project, [NotNull] string sourceFolder, [NotNull] string destinationFolder, FolderSynchronizationMode mode, string pattern)
        {
            Assert.ArgumentNotNull(project, nameof(project));
            Assert.ArgumentNotNull(sourceFolder, nameof(sourceFolder));
            Assert.ArgumentNotNull(destinationFolder, nameof(destinationFolder));
            Assert.ArgumentNotNull(pattern, nameof(pattern));

            var folder = new FolderSynchronizer(project, sourceFolder, destinationFolder, mode, pattern);

            lock (syncObject)
            {
                Folders.Add(folder);
            }

            SaveProject(project);
        }
        private void LoadProject([NotNull] Projects.Project project, [NotNull] string projectFileName)
        {
            Debug.ArgumentNotNull(project, nameof(project));
            Debug.ArgumentNotNull(projectFileName, nameof(projectFileName));

            var fileName = GetConfigFileName(project);

            if (!System.IO.File.Exists(fileName))
            {
                return;
            }

            var root = System.IO.File.ReadAllText(fileName).ToXElement();

            if (root == null)
            {
                AppHost.Output.Log("Folder Sync: Project is not well-formed: " + fileName);
                LogMessage(string.Format("Error: Load Project: {0} is not wellformed", fileName));
                return;
            }

            var folderSyncElement = root.Element("FolderSync");

            if (folderSyncElement == null)
            {
                AppHost.Output.Log("Folder Sync: Project root element is missing: " + fileName);
                LogMessage("Error: Load Project: FolderSync element is missing");
                return;
            }

            project.SynchronizeOutputFolderOnBuild = folderSyncElement.GetAttributeValue("SynchronizeProjectOutputFolderOnBuild") == "True";
            foreach (var element in folderSyncElement.Elements("Folder"))
            {
                var sourceFolder      = element.GetAttributeValue("SourceFolder");
                var destinationFolder = element.GetAttributeValue("DestinationFolder");
                var pattern           = element.GetAttributeValue("Pattern");
                var folder            = new FolderSynchronizer(project, sourceFolder, destinationFolder, element.GetAttributeValue("Mode") == "Mirror" ? FolderSynchronizationMode.Mirror : FolderSynchronizationMode.Copy, pattern);

                lock (syncObject)
                {
                    Folders.Add(folder);
                }

                AppHost.Output.Log("Folder Sync: Monitoring : " + folder.AbsoluteSourceFolder + " => " + folder.AbsoluteDestinationFolder);
                LogMessage(string.Format("Load Project: Monitoring {0}", folder.AbsoluteSourceFolder));
            }
        }
        private bool MatchesPattern(string sourceFile, FolderSynchronizer folderDescriptor)
        {
            if (string.IsNullOrEmpty(folderDescriptor.Pattern))
            {
                return(true);
            }

            var fileName = Path.GetFileName(sourceFile);

            var patterns = folderDescriptor.GetPatterns();

            foreach (var p in patterns)
            {
                var regex = "^" + Regex.Escape(p).Replace(@"\*", ".*").Replace(@"\?", ".") + "$";
                if (Regex.IsMatch(fileName, regex))
                {
                    return(true);
                }
            }

            return(false);
        }