private void HandleAddRemoveFiles(FileChangeType changeType, int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments, FileChangedEventHandler csFileEvent, FileChangedEventHandler templateEvent)
        {
            if (csFileEvent == null && templateEvent == null)
            {
                return;
            }

            var paths     = ExtractPath(cProjects, cFiles, rgpProjects, rgFirstIndices, rgpszMkDocuments);
            var templates = ImmutableArray.CreateBuilder <string>();
            var csFiles   = ImmutableArray.CreateBuilder <string>(cFiles);

            foreach (var path in paths)
            {
                if (path.EndsWith(Constants.CsExtension, StringComparison.InvariantCultureIgnoreCase))
                {
                    csFiles.Add(path);
                }
                else if (path.EndsWith(Constants.TemplateExtension, StringComparison.InvariantCultureIgnoreCase))
                {
                    templates.Add(path);
                }
            }

            if (csFileEvent != null && csFiles.Count > 0)
            {
                csFileEvent(this, new FileChangedEventArgs(changeType, csFiles.ToArray()));
            }
            if (templateEvent != null && templates.Count > 0)
            {
                templateEvent(this, new FileChangedEventArgs(changeType, templates.ToArray()));
            }
        }
Exemple #2
0
        public FileChangeEventArgs(FileChangeType type, int num)
        {
            changeTable = new List <int>();
            switch (type)
            {
            case FileChangeType.None:
                deviation = 0;
                break;

            case FileChangeType.Add:
                for (int i = 0; i < num; i++)
                {
                    changeTable.Add(i);
                }
                deviation = 1;
                break;

            case FileChangeType.Delete:
                for (int i = 0; i < num; i++)
                {
                    changeTable.Add(i);
                }
                changeTable.Add(-1);
                deviation = -1;
                break;
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates a new <see cref="ChangedFile"/> object which has been added, changed or removed.<para></para>
        ///
        /// If a file has been renamed, use ChangedFile(<see cref="string"/> name, <see cref="string"/> oldName) instead!
        /// </summary>
        /// <param name="name">The name of the changed file</param>
        /// <param name="changeType">The type of change which has been made to the file (see <see cref="FileChangeType"/>)</param>
        public ChangedFile(string name, FileChangeType changeType)
        {
            this.name       = name;
            this.changeType = changeType;

            switch (changeType)
            {
            case FileChangeType.Added:
                icon = PackIconKind.Plus;
                break;

            case FileChangeType.Changed:
                icon = PackIconKind.Pencil;
                break;

            case FileChangeType.Deleted:
                icon      = PackIconKind.Minus;
                isDeleted = true;
                break;

            case FileChangeType.Renamed:
                icon = PackIconKind.CursorText;
                break;

            default:
                icon = PackIconKind.Help;
                break;
            }
        }
        //static void FileWatcher_Created(object sender, FileSystemEventArgs e)
        //{
        //    // Do nothing...
        //}

        private static void FireFileChangedEvent(string filePath, FileChangeType changeType)
        {
            filePath = filePath.ToLowerInvariant();

            ReadOnlyCollection<Pair<MethodInfo, WeakReference>> weakInvocationList;

            if (!_subscribers.TryGetValue(filePath.ToLowerInvariant(), out weakInvocationList))
            {
                return;
            }

            var parameters = new object[] { filePath, changeType };

            foreach (var callInfo in weakInvocationList)
            {
                if (callInfo.Second == null) // Call to a static method
                {
                    callInfo.First.Invoke(null, parameters);
                }
                else
                {
                    object target = callInfo.Second.Target;
                    if (target != null) // Checking if object is alive
                    {
                        callInfo.First.Invoke(target, parameters);
                    }
                }
            }
        }
        //static void FileWatcher_Created(object sender, FileSystemEventArgs e)
        //{
        //    // Do nothing...
        //}

        private static void FireFileChangedEvent(string filePath, FileChangeType changeType)
        {
            filePath = filePath.ToLowerInvariant();

            ReadOnlyCollection <Pair <MethodInfo, WeakReference> > weakInvocationList;

            if (!_subscribers.TryGetValue(filePath.ToLowerInvariant(), out weakInvocationList))
            {
                return;
            }

            var parameters = new object[] { filePath, changeType };

            foreach (var callInfo in weakInvocationList)
            {
                if (callInfo.Second == null) // Call to a static method
                {
                    callInfo.First.Invoke(null, parameters);
                }
                else
                {
                    object target = callInfo.Second.Target;
                    if (target != null) // Checking if object is alive
                    {
                        callInfo.First.Invoke(target, parameters);
                    }
                }
            }
        }
 private void OnFileChanged(string filePath, FileChangeType changeType)
 {
     if (changeType == FileChangeType.Unspecified && !File.Exists(filePath) || changeType == FileChangeType.Delete)
     {
         _workspace.TryRemoveMiscellaneousDocument(filePath);
     }
 }
 private void ClearCachedData(string filePath, FileChangeType changeType)
 {
     lock (_lock)
     {
         _xslTransformations.Clear();
     }
 }
Exemple #8
0
        public static FileChangeModel Parse(string fileName, FileChangeType fileChangeType = FileChangeType.Add)
        {
            var fileChangeModel = new FileChangeModel {
                FileName = fileName, FileChangeType = fileChangeType
            };

            if (!fileName.Contains("__"))
            {
                return(fileChangeModel);
            }

            var fileParts = fileName.Split("__");

            if (fileParts.Length < 3 || !fileParts[2].Contains(Convert.ToChar(".")))
            {
                return(fileChangeModel);
            }

            var priority = fileParts[2].Split(Convert.ToChar("."))[0]
                           .Replace("F", "", StringComparison.InvariantCultureIgnoreCase);

            if (int.TryParse(priority, out var priorityInt))
            {
                fileChangeModel.Priority = priorityInt;
            }

            return(fileChangeModel);
        }
 public void Invoke(string filePath, FileChangeType changeType)
 {
     foreach (var callback in _callbacks)
     {
         callback(filePath, changeType);
     }
 }
Exemple #10
0
        public void Notify(string filePath, FileChangeType changeType = FileChangeType.Unspecified)
        {
            lock (_gate)
            {
                if (changeType == FileChangeType.DirectoryDelete)
                {
                    _folderCallbacks.Invoke(filePath, FileChangeType.DirectoryDelete);
                }

                if (_callbacksMap.TryGetValue(filePath, out var fileCallbacks))
                {
                    fileCallbacks.Invoke(filePath, changeType);
                }

                var directoryPath = Path.GetDirectoryName(filePath);
                if (_callbacksMap.TryGetValue(directoryPath, out var directoryCallbacks))
                {
                    directoryCallbacks.Invoke(filePath, changeType);
                }

                var extension = Path.GetExtension(filePath);
                if (!string.IsNullOrEmpty(extension) &&
                    _callbacksMap.TryGetValue(extension, out var extensionCallbacks))
                {
                    extensionCallbacks.Invoke(filePath, changeType);
                }
            }
        }
 void HandleFileChangedEvent(FileChangeType eventType, string path)
 {
     // Event from the monitor usually comes from non-UI threads.
     App.Current.GUIToolkit.Invoke((s, e) => {
         if (eventType == FileChangeType.Created)
         {
             string ext = Path.GetExtension(path);
             try {
                 if (ImportTeams && ext == Constants.TEAMS_TEMPLATE_EXT)
                 {
                     LMTeam team = App.Current.DependencyRegistry.
                                   Retrieve <IFileStorage> (InstanceType.Default, null).RetrieveFrom <LMTeam> (path);
                     App.Current.TeamTemplatesProvider.Add(team);
                     File.Delete(path);
                 }
                 else if (ImportDashboards && ext == Constants.CAT_TEMPLATE_EXT)
                 {
                     Dashboard team = App.Current.DependencyRegistry.
                                      Retrieve <IFileStorage> (InstanceType.Default, null).RetrieveFrom <Dashboard> (path);
                     App.Current.CategoriesTemplatesProvider.Add(team as LMDashboard);
                     File.Delete(path);
                 }
                 else if (ImportProjects && ext == Constants.PROJECT_EXT)
                 {
                     LMProject project = App.Current.DependencyRegistry.
                                         Retrieve <IFileStorage> (InstanceType.Default, null).RetrieveFrom <LMProject> (path);
                     App.Current.DatabaseManager.ActiveDB.Store <LMProject> (project, true);
                     File.Delete(path);
                 }
             } catch (Exception ex) {
                 Log.Exception(ex);
             }
         }
     });
 }
 public FileChangeEvent(FileChangeType type, string path, string oldPath = null)
 {
     Type         = type;
     LocalPath    = path;
     CloudPath    = Util.Utils.LocalPathtoCloudPath(path);
     OldLocalPath = oldPath;
     OldCloudPath = Util.Utils.LocalPathtoCloudPath(oldPath);
 }
        static void FileWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            FileChangeType changeType = e.ChangeType == WatcherChangeTypes.Renamed
                                            ? FileChangeType.Renamed
                                            : FileChangeType.Modified;

            FireFileChangedEvent(e.FullPath, changeType);
        }
        private void OnFileChanged(IVsProject project, string filePath, FileChangeType changeType)
        {
            var localEvent = FileChanged;

            if (localEvent != null)
            {
                localEvent(this, new ProjectFileChangedEventArgs(project, filePath, changeType));
            }
        }
Exemple #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DummyFileInfo"/> class.
 /// </summary>
 /// <param name="newFileName">New name of the file.</param>
 /// <param name="newFilePath">The new file path.</param>
 /// <param name="fileOperation">The file operation.</param>
 /// <param name="oldFileName">Old name of the file.</param>
 /// <param name="oldFilePath">The old file path.</param>
 /// <param name="packageName">Name of the package.</param>
 public DummyFileInfo(string newFileName, string newFilePath, FileChangeType fileOperation, string oldFileName = "", string oldFilePath = "", string packageName = "")
 {
     this.NewFileName   = newFileName;
     this.OldFileName   = oldFileName;
     this.NewFilePath   = newFilePath;
     this.OldFilePath   = oldFilePath;
     this.PackageName   = packageName;
     this.FileOperation = fileOperation;
 }
Exemple #16
0
        void EmitChange(FileChangeType changeType, string path)
        {
            if (FileChangedEvent == null)
            {
                return;
            }

            FileChangedEvent(changeType, path);
        }
Exemple #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DummyFileInfo"/> class.
 /// </summary>
 /// <param name="newFileName">New name of the file.</param>
 /// <param name="newFilePath">The new file path.</param>
 /// <param name="fileOperation">The file operation.</param>
 /// <param name="oldFileName">Old name of the file.</param>
 /// <param name="oldFilePath">The old file path.</param>
 /// <param name="packageName">Name of the package.</param>
 public DummyFileInfo(string newFileName, string newFilePath, FileChangeType fileOperation, string oldFileName = "", string oldFilePath = "", string packageName = "")
 {
     this.NewFileName = newFileName;
     this.OldFileName = oldFileName;
     this.NewFilePath = newFilePath;
     this.OldFilePath = oldFilePath;
     this.PackageName = packageName;
     this.FileOperation = fileOperation;
 }
Exemple #18
0
        public FolderOrFileItem(string name, FileChangeType changeType)
        {
            this.Name           = name;
            this.FileChangeType = changeType;

            //We do not need to allocate memory for deleted directories, as we will not traverse subtree
            //if(initializeChildItems)
            //    ChildItems = new List<FolderOrFileItem>();
        }
Exemple #19
0
        public void ProcessLine(string line)
        {
            if (line.StartsWith("diff "))
            {
                _currentChangeType = FileChangeType.Unknown;
                return;
            }

            if (line.StartsWith("index "))
            {
                return;
            }

            if (line.StartsWith("deleted file"))
            {
                _currentChangeType = FileChangeType.Deleted;
                return;
            }

            if (line.StartsWith("new file"))
            {
                _currentChangeType = FileChangeType.Created;
                return;
            }

            if (line.StartsWith("---") || line.StartsWith("+++"))
            {
                // see we have a filename to show
                if (line.Substring(4) != "/dev/null")
                {
                    AddFile(line.Substring(6), _currentChangeType);
                }

                return;
            }

            if (line.StartsWith("@@"))
            {
                AddFileSection(line);
                return;
            }

            if (line.StartsWith("-"))
            {
                CurrentFileSection.AddLine(new DiffLine(line.Substring(1), LineChangeType.Delete));
                return;
            }

            if (line.StartsWith("+"))
            {
                CurrentFileSection.AddLine(new DiffLine(line.Substring(1), LineChangeType.Add));
                return;
            }

            CurrentFileSection.AddLine(new DiffLine(line.Substring(1), LineChangeType.None));
        }
Exemple #20
0
        public void ProcessLine(string line)
        {
            if (line.StartsWith("diff "))
            {
                _currentChangeType = FileChangeType.Unknown;
                return;
            }

            if (line.StartsWith("index "))
            {
                return;
            }

            if (line.StartsWith("deleted file"))
            {
                _currentChangeType = FileChangeType.Deleted;
                return;
            }

            if (line.StartsWith("new file"))
            {
                _currentChangeType = FileChangeType.Created;
                return;
            }

            if (line.StartsWith("---") || line.StartsWith("+++"))
            {
                // see we have a filename to show
                if (line.Substring(4) != "/dev/null")
                {
                    AddFile(line.Substring(6), _currentChangeType);
                }

                return;
            }

            if (line.StartsWith("@@"))
            {
                AddFileSection(line);
                return;
            }

            if (line.StartsWith("-"))
            {
                CurrentFileSection.AddLine(new DiffLine(line.Substring(1), LineChangeType.Delete));
                return;
            }

            if (line.StartsWith("+"))
            {
                CurrentFileSection.AddLine(new DiffLine(line.Substring(1), LineChangeType.Add));
                return;
            }

            CurrentFileSection.AddLine(new DiffLine(line.Substring(1), LineChangeType.None));
        }
Exemple #21
0
        public void SimpleTest(string expected)
        {
            var model = new FileChangeType();
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<FileChangeType>(expected);
            deresult.ShouldBeEquivalentTo(model);
        }
Exemple #22
0
 public FileChangeInformation(string id, FileChangeType changeType,
                              string oldPath, string newPath, string oldName, string newName)
 {
     ID         = id;
     ChangeType = changeType;
     OldPath    = oldPath;
     NewPath    = newPath;
     OldName    = oldName;
     NewName    = newName;
 }
Exemple #23
0
 public CompareInfoObject(string origin, string fullName, string name, long lastWriteTime, long length, string hash)
 {
     _origin = origin;
     _fullName = fullName;
     _name = name;
     _lastWriteTime = lastWriteTime;
     _length = length;
     _hash = hash;
     _changeType = FileChangeType.None;
 }
Exemple #24
0
        public void SimpleTest(string expected)
        {
            var model  = new FileChangeType();
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <FileChangeType>(expected);

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
        public void SimpleTest(string expected)
        {
            var model  = new FileChangeType();
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = JsonConvert.DeserializeObject <FileChangeType>(expected);

            deresult.ShouldBeEquivalentTo(model);
        }
Exemple #26
0
        public void AddFile(string filename, FileChangeType fileChangeType)
        {
            if (CurrentFile != null && CurrentFile.FileName == filename)
            {
                return;
            }

            Files.Add(new DiffFile()
            {
                FileName = filename, FileChangeType = fileChangeType
            });
        }
        private void OnCakeFileChanged(string filePath, FileChangeType changeType)
        {
            if (changeType == FileChangeType.Unspecified && !File.Exists(filePath) || changeType == FileChangeType.Delete)
            {
                RemoveCakeFile(filePath);
            }

            if (changeType == FileChangeType.Unspecified && File.Exists(filePath) || changeType == FileChangeType.Create)
            {
                AddCakeFile(filePath);
            }
        }
Exemple #28
0
        /// <summary>
        /// 监听事件触发的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnProcess(object sender, FileSystemEventArgs e)
        {
            try
            {
                FileChangeType changeType = FileChangeType.Unknown;
                if (e.ChangeType == WatcherChangeTypes.Created)
                {
                    if (File.GetAttributes(e.FullPath) == FileAttributes.Directory)
                    {
                        changeType = FileChangeType.NewFolder;
                    }
                    else
                    {
                        changeType = FileChangeType.NewFile;
                    }
                }
                else if (e.ChangeType == WatcherChangeTypes.Changed)
                {
                    //部分文件创建时同样触发文件变化事件,此时记录变化操作没有意义
                    //如果
                    //if (_queue.SelectAll(
                    //    delegate (FileChangeInformation fcm)
                    //    {
                    //        return fcm.NewPath == e.FullPath && fcm.ChangeType == FileChangeType.Change;
                    //    }).Count<FileChangeInformation>() > 0)
                    //{
                    //    return;
                    //}

                    //文件夹的变化,只针对创建,重命名和删除动作,修改不做任何操作。
                    //因为文件夹下任何变化同样会触发文件的修改操作,没有任何意义.
                    if (File.GetAttributes(e.FullPath) == FileAttributes.Directory)
                    {
                        return;
                    }

                    changeType = FileChangeType.Change;
                }
                else if (e.ChangeType == WatcherChangeTypes.Deleted)
                {
                    changeType = FileChangeType.Delete;
                }

                //创建消息,并压入队列中
                FileChangeInformation info = new FileChangeInformation(Guid.NewGuid().ToString(), changeType, e.FullPath, e.FullPath, e.Name, e.Name);
                _queue.Enqueue(info);
            }
            catch
            {
                Close();
            }
        }
        public async Task <string> SendMessage(string fileName, FileChangeType type)
        {
            string typeAction = Enum.GetName(typeof(FileChangeType), type).ToLower();
            var    message    = new
            {
                Type = MessageType.Email,
                Text = $"A file {fileName} was {typeAction}"
            };
            var data     = new StringContent(JsonConvert.SerializeObject(message), Encoding.UTF8, "application/json");
            var response = await client.PostAsync(configuration.GetSection("MessageRequests")["Add"], data);

            return(response.Content.ReadAsStringAsync().Result);
        }
Exemple #30
0
        private void OnDirectoryRemoved(string path, FileChangeType changeType)
        {
            if (changeType == FileChangeType.DirectoryDelete)
            {
                var docs = CurrentSolution.Projects.SelectMany(x => x.Documents)
                           .Where(x => x.FilePath.StartsWith(path + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase));

                foreach (var doc in docs)
                {
                    OnDocumentRemoved(doc.Id);
                }
            }
        }
        private void OnCsxFileChanged(string filePath, FileChangeType changeType)
        {
            if (changeType == FileChangeType.Unspecified && !File.Exists(filePath) ||
                changeType == FileChangeType.Delete)
            {
                RemoveFromWorkspace(filePath);
            }

            if (changeType == FileChangeType.Unspecified && File.Exists(filePath) ||
                changeType == FileChangeType.Create)
            {
                AddToWorkspace(filePath);
            }
        }
Exemple #32
0
        private void OnMiscellaneousFileChanged(string filePath, FileChangeType changeType)
        {
            if (changeType == FileChangeType.Unspecified && File.Exists(filePath) ||
                changeType == FileChangeType.Create)
            {
                TryAddMiscellaneousFile(filePath);
            }

            else if (changeType == FileChangeType.Unspecified && !File.Exists(filePath) ||
                     changeType == FileChangeType.Delete)
            {
                RemoveFromWorkspace(filePath);
            }
        }
        public void Notify(string filePath, FileChangeType changeType = FileChangeType.Unspecified)
        {
            lock (_gate)
            {
                if (_callbacks.TryGetValue(filePath, out var fileCallback))
                {
                    fileCallback(filePath, changeType);
                }

                var directoryPath = Path.GetDirectoryName(filePath);
                if (_callbacks.TryGetValue(directoryPath, out var directoryCallback))
                {
                    directoryCallback(filePath, changeType);
                }
            }
        }
        private static void OnFileExternallyChanged(string filePath, FileChangeType changeType)
        {
            filePath = filePath.ToLowerInvariant();

            var fileRecord = _cache[filePath];

            if (fileRecord == null ||
                fileRecord.FileModificationDate == DateTime.MinValue ||
                C1File.GetLastWriteTime(filePath) == fileRecord.FileModificationDate)
            {
                // Ignoring this notification since it's very very probably caused by XmlDataProvider itself
                return;
            }

            lock (_documentEditingSyncRoot)
            {
                lock (_cacheSyncRoot)
                {
                    fileRecord = _cache[filePath];

                    if (fileRecord == null ||
                        fileRecord.FileModificationDate == DateTime.MinValue ||
                        C1File.GetLastWriteTime(filePath) == fileRecord.FileModificationDate)
                    {
                        // Ignoring this notification since it's very very probably caused by XmlDataProvider itself
                        return;
                    }

                    _cache.Remove(filePath);

                    Log.LogVerbose(LogTitle, "File '{0}' changed by another process. Flushing cache.", filePath);

                    if (_externalFileChangeActions.Any(f => f.Key == filePath))
                    {
                        var actions = _externalFileChangeActions.Where(f => f.Key == filePath).Select(f => f.Value).ToList();
                        foreach (var action in actions)
                        {
                            action.Invoke();
                        }
                    }
                    else
                    {
                        Log.LogWarning(LogTitle, "File '{0}' has not been related to a scope - unable to raise store change event", filePath);
                    }
                }
            }
        }
 private void ClearCachedData(string filePath, FileChangeType changeType)
 {
     lock(_lock)
     {
         _xslTransformations.Clear();
     }
 }
Exemple #36
0
        public void AddFile(string filename, FileChangeType fileChangeType)
        {
            if (CurrentFile != null && CurrentFile.FileName == filename) return;

            Files.Add(new DiffFile() { FileName = filename, FileChangeType = fileChangeType });
        }
Exemple #37
0
 public CompareResult(FileChangeType changeType, string from, string to)
 {
     base.ChangeType = changeType;
     base.From = from;
     base.To = to;
 }
Exemple #38
0
 public FileChangeEventArgs(IFileHandle handle, FileChangeType changeType)
 {
     Handle = handle;
     ChangeType = changeType;
 }
 /// <inheritdoc />
 public void FileChangedTest(string filePath, FileChangeType changeType, string oldFilePath = "")
 {
     this.FileChanged(filePath, changeType, oldFilePath);
 }
 public FileChangedEventArgs(FileChangeType changeType, params string[] paths)
 {
     ChangeType = changeType;
     Paths = paths;
 }
 public SingleFileChangedEventArgs(FileChangeType changeType, string path) : base(changeType,path)
 {
     Path = path;
 }
Exemple #42
0
        /// <summary>
        /// Takes appropriate actions based on the resource file type
        /// </summary>
        /// <param name="path">The file path.</param>
        /// <param name="changeType">Type of the change.</param>
        /// <param name="oldFilePath">The old file path.</param>
        protected virtual void FileChanged(string filePath, FileChangeType changeType, string oldFilePath = "")
        {
            var virtualFilePath = this.ConvertToVirtualPath(filePath);
            var oldFileVirtualPath = this.ConvertToVirtualPath(oldFilePath);

            var watchedDirInfo = this.WatchedFoldersAndPackages.FirstOrDefault(dirInfo => virtualFilePath.StartsWith(dirInfo.Path, StringComparison.Ordinal));

            if (watchedDirInfo == null)
                return;

            string packageName = string.Empty;

            var resourceDirecotryPath = VirtualPathUtility.GetDirectory(virtualFilePath);
            var resourceDirectoryTree = resourceDirecotryPath.Split('/');

            if (resourceDirectoryTree.Length < 3)
                return;

            if (watchedDirInfo.IsPackage)
                packageName = resourceDirectoryTree[2];

            string resourceFolder = resourceDirectoryTree[resourceDirectoryTree.Length - 2];

            var fileName = virtualFilePath.Replace(resourceDirecotryPath, string.Empty);

            SystemManager.RunWithElevatedPrivilegeDelegate elevDelegate = this.GetFileChangedDelegate(new FileChangedDelegateArguments()
            {
                FilePath = virtualFilePath,
                ChangeType = changeType,
                OldFilePath = oldFileVirtualPath, 
                PackageName = packageName,
                ResourceFolder = resourceFolder,
                FileName = fileName
            });
            SystemManager.RunWithElevatedPrivilege(elevDelegate);
        }
        private static void OnFileExternallyChanged(string filePath, FileChangeType changeType)
        {
            filePath = filePath.ToLowerInvariant();

            var fileRecord = _cache[filePath];

            if (fileRecord == null
                || fileRecord.FileModificationDate == DateTime.MinValue
                || C1File.GetLastWriteTime(filePath) == fileRecord.FileModificationDate)
            {
                // Ignoring this notification since it's very very probably caused by XmlDataProvider itself
                return;
            }

            lock (_documentEditingSyncRoot)
            {
                lock (_cacheSyncRoot)
                {
                    fileRecord = _cache[filePath];

                    if (fileRecord == null
                        || fileRecord.FileModificationDate == DateTime.MinValue
                        || C1File.GetLastWriteTime(filePath) == fileRecord.FileModificationDate)
                    {
                        // Ignoring this notification since it's very very probably caused by XmlDataProvider itself
                        return;
                    }

                    _cache.Remove(filePath);

                    Log.LogVerbose(LogTitle, "File '{0}' changed by another process. Flushing cache.", filePath);

                    if (_externalFileChangeActions.Any(f => f.Key == filePath))
                    {
                        var actions = _externalFileChangeActions.Where(f => f.Key == filePath).Select(f => f.Value).ToList();
                        foreach (var action in actions)
                        {
                            action.Invoke();
                        }
                    }
                    else
                    {
                        Log.LogWarning(LogTitle, "File '{0}' has not been related to a scope - unable to raise store change event", filePath);
                    }
                }
            }
        }
 public FileChangeEventArgs(IFileInfo fileInfo, FileChangeType changeType)
 {
     FileInfo = fileInfo;
     ChangeType = changeType;
 }
 /// <summary>
 /// Sync a source Path to a list of  destination paths. The path can be File or Folder.
 /// 
 /// </summary>
 /// <param name="sourcePath">The source path</param>
 /// <param name="destinationPath">The list of destination path</param>
 /// <param name="changeType">The Change that was detected on source path</param>
 /// <returns>The list of Sync Results</returns>
 public List<SyncResult> SyncPath(string sourcePath, List<string> destinationPath, FileChangeType changeType)
 {
     return null;
 }
        private void HandleAddRemoveFiles(FileChangeType changeType, int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments, FileChangedEventHandler csFileEvent, FileChangedEventHandler templateEvent)
        {
            if (csFileEvent == null && templateEvent == null)
            {
                return;
            }

            var paths = ExtractPath(cProjects, cFiles, rgpProjects, rgFirstIndices, rgpszMkDocuments);
            var templates = ImmutableArray.CreateBuilder<string>();
            var csFiles = ImmutableArray.CreateBuilder<string>(cFiles);
            foreach (var path in paths)
            {
                if (path.EndsWith(Constants.CsExtension, StringComparison.InvariantCultureIgnoreCase))
                {
                    csFiles.Add(path);
                }
                else if (path.EndsWith(Constants.TemplateExtension, StringComparison.InvariantCultureIgnoreCase))
                {
                    templates.Add(path);
                }
            }

            if (csFileEvent != null && csFiles.Count > 0)
            {
                csFileEvent(this, new FileChangedEventArgs(changeType, csFiles.ToArray()));
            }
            if (templateEvent != null && templates.Count > 0)
            {
                templateEvent(this, new FileChangedEventArgs(changeType, templates.ToArray()));
            }
        }
Exemple #47
0
 private void OnFileChanged(string filePath, FileChangeType changeType)
 {
     _cache.Remove(_pageTemplateFilePath);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PullRequestFileViewModel"/> class.
 /// </summary>
 /// <param name="path">The path to the file, relative to the repository.</param>
 /// <param name="changeType">The way the file was changed.</param>
 public PullRequestFileViewModel(string path, FileChangeType changeType)
 {
     ChangeType = changeType;
     FileName = System.IO.Path.GetFileName(path);
     Path = path;
 }
 void HandleFileChangedEvent(FileChangeType eventType, string path)
 {
     // Event from the monitor usually comes from non-UI threads.
     App.Current.GUIToolkit.Invoke ((s, e) => {
         if (eventType == FileChangeType.Created) {
             string ext = Path.GetExtension (path);
             try {
                 if (ImportTeams && ext == Constants.TEAMS_TEMPLATE_EXT) {
                     SportsTeam team = App.Current.DependencyRegistry.
                     Retrieve<IFileStorage> (InstanceType.Default, null).RetrieveFrom<SportsTeam> (path);
                     App.Current.TeamTemplatesProvider.Add (team);
                     File.Delete (path);
                 } else if (ImportDashboards && ext == Constants.CAT_TEMPLATE_EXT) {
                     Dashboard team = App.Current.DependencyRegistry.
                     Retrieve<IFileStorage> (InstanceType.Default, null).RetrieveFrom<Dashboard> (path);
                     App.Current.CategoriesTemplatesProvider.Add (team as DashboardLongoMatch);
                     File.Delete (path);
                 } else if (ImportProjects && ext == Constants.PROJECT_EXT) {
                     ProjectLongoMatch project = App.Current.DependencyRegistry.
                     Retrieve<IFileStorage> (InstanceType.Default, null).RetrieveFrom<ProjectLongoMatch> (path);
                     App.Current.DatabaseManager.ActiveDB.Store<ProjectLongoMatch> (project, true);
                     File.Delete (path);
                 }
             } catch (Exception ex) {
                 Log.Exception (ex);
             }
         }
     });
 }