Esempio n. 1
0
        private static void MoveSourceMediaFile(FileEvent renameEvent, string[] oldMediaPaths)
        {
            if (!renameEvent.IsDirectory)
            {
                string[] newMediaPaths = AssetManager.GetAssetSourceFiles(new ContentRef <Resource>(renameEvent.Path));
                for (int i = 0; i < oldMediaPaths.Length; i++)
                {
                    string oldPath = oldMediaPaths[i];
                    string newPath = newMediaPaths.Length > i ? newMediaPaths[i] : oldPath;

                    // Move the media file to mirror the data files movement
                    if (!PathOp.ArePathsEqual(oldPath, newPath))
                    {
                        if (File.Exists(oldPath) && !File.Exists(newPath))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(newPath));
                            try
                            {
                                File.Move(oldPath, newPath);
                            }
                            catch (IOException exception)
                            {
                                Logs.Editor.WriteWarning(
                                    "Unable to move source media file '{0}' to '{1}' ({2}). Copying the file instead.",
                                    oldPath,
                                    newPath,
                                    exception.Message);
                                File.Copy(oldPath, newPath);
                            }
                            PathHelper.DeleteEmptyDirectory(Path.GetDirectoryName(oldPath), true);
                        }
                    }
                }
            }
            else
            {
                // Determine which source/media directory we're going to move
                string oldMediaPath = Path.Combine(
                    EditorHelper.ImportDirectory,
                    PathHelper.MakeFilePathRelative(renameEvent.OldPath, DualityApp.DataDirectory));

                // Determine where that old source/media directory needs to be moved
                string newMediaPath = Path.Combine(
                    EditorHelper.ImportDirectory,
                    PathHelper.MakeFilePathRelative(renameEvent.Path, DualityApp.DataDirectory));

                // Move the media directory to mirror the data directories movement
                if (!PathOp.ArePathsEqual(newMediaPath, oldMediaPath))
                {
                    if (Directory.Exists(oldMediaPath) && !Directory.Exists(newMediaPath))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(newMediaPath));
                        try
                        {
                            Directory.Move(oldMediaPath, newMediaPath);
                        }
                        catch (IOException exception)
                        {
                            Logs.Editor.WriteWarning(
                                "Unable to move source media directory '{0}' to '{1}' ({2}). Copying the directory instead.",
                                oldMediaPath,
                                newMediaPath,
                                exception.Message);
                            PathHelper.CopyDirectory(oldMediaPath, newMediaPath);
                        }
                        PathHelper.DeleteEmptyDirectory(Path.GetDirectoryName(oldMediaPath), true);
                    }
                }
            }
        }
Esempio n. 2
0
        private async Task <AssemblyChangedEvent> FileChangeTransformation(FileEvent e)
        {
            string changedFile;
            var    renameEvent = e as FileRenameEvent;

            changedFile = renameEvent?.OldFullPath ?? e.FullPath;

            foreach (var trackedAssembly in trackedAssemblies)
            {
                // Report change of the assembly binary
                if (string.Equals(trackedAssembly.LoadedAssembly.Path, changedFile, StringComparison.OrdinalIgnoreCase))
                {
                    return(new AssemblyChangedEvent(trackedAssembly.LoadedAssembly, AssemblyChangeType.Binary, changedFile, trackedAssembly.Project));
                }

                var needProjectReload = string.Equals(trackedAssembly.Project.FilePath, changedFile, StringComparison.OrdinalIgnoreCase);

                // Also check for .cs file changes (DefaultItems auto import *.cs, with some excludes such as obj subfolder)
                // TODO: Check actual unevaluated .csproj to get the auto includes/excludes?
                if (needProjectReload == false &&
                    (e.ChangeType == FileEventChangeType.Deleted || e.ChangeType == FileEventChangeType.Renamed || e.ChangeType == FileEventChangeType.Created) &&
                    Path.GetExtension(changedFile)?.ToLowerInvariant() == ".cs" &&
                    !UPath.Combine(new UFile(trackedAssembly.Project.FilePath).GetFullDirectory(), new UDirectory("obj")).Contains(new UFile(changedFile)))
                {
                    needProjectReload = true;
                }

                // Reparse the project file and report source changes
                if (needProjectReload)
                {
                    // Reparse the project file and report source changes
                    await UpdateProject(trackedAssembly);

                    return(new AssemblyChangedEvent(trackedAssembly.LoadedAssembly, AssemblyChangeType.Project, trackedAssembly.Project.FilePath, trackedAssembly.Project));
                }

                // Only deal with file changes
                if (e.ChangeType != FileEventChangeType.Changed)
                {
                    continue;
                }

                // Check if we have a matching document
                var document = trackedAssembly.Project.Documents.FirstOrDefault(x => string.Equals(x.FilePath, changedFile, StringComparison.OrdinalIgnoreCase));
                if (document == null)
                {
                    continue;
                }

                string source = null;
                // Try multiple times
                for (int i = 0; i < 10; ++i)
                {
                    try
                    {
                        using (var streamReader = new StreamReader(File.Open(changedFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8, true))
                        {
                            source = streamReader.ReadToEnd();
                        }
                        break;
                    }
                    catch (IOException)
                    {
                    }
                    await Task.Delay(1);
                }

                if (source == null)
                {
                    // Something went wrong reading the file
                    return(null);
                }

                // Remove and readd new source
                trackedAssembly.Project = trackedAssembly.Project.RemoveDocument(document.Id);
                var documentId = DocumentId.CreateNewId(trackedAssembly.Project.Id);
                trackedAssembly.Project = trackedAssembly.Project.Solution.AddDocument(documentId, document.Name, SourceText.From(source, Encoding.UTF8), null, document.FilePath).GetDocument(documentId).Project;

                return(new AssemblyChangedEvent(trackedAssembly.LoadedAssembly, AssemblyChangeType.Source, changedFile, trackedAssembly.Project));
            }

            return(null);
        }
Esempio n. 3
0
        static void FileUtility(ConcurrentQueue <FileEvent> fileEvents, ConcurrentDictionary <string, int> pipe, FileEvent fileEvent)
        {
            int fileCount;

            try
            {
                fileEvents.Enqueue(fileEvent);
                if (int.TryParse(pipe.FirstOrDefault(x => x.Key == fileEvent.ProcessName).Value.ToString(), out fileCount))
                {
                    pipe.AddOrUpdate(fileEvent.ProcessName, fileCount + 1, (key, oldvalue) => fileCount + 1);
                }
            }
            catch
            {
            }
        }
Esempio n. 4
0
 public void Handle(FileEvent message)
 {
     CreateScriptViewModel(message.Data);
 }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VersionControlTest" /> class.
        /// </summary>
        public VersionControlTest()
        {
            // Initialize
            if (!Directory.Exists(".Distribox"))
            {
                Directory.CreateDirectory(".Distribox");
            }

            if (!Directory.Exists(".Distribox/data"))
            {
                Directory.CreateDirectory(".Distribox/data");
            }
            if (Directory.Exists("Dir"))
            {
                Directory.Delete("Dir");
            }

            FileEvent e1 = new FileEvent();

            e1.Type    = FileEventType.Created;
            e1.EventId = "1";
            e1.FileId  = "1";
            e1.Name    = "haha";

            FileEvent e2 = new FileEvent();

            e2.Type    = FileEventType.Changed;
            e2.EventId = "2";
            e2.FileId  = "1";
            e2.SHA1    = "11";
            e2.Name    = "haha";
            File.WriteAllText(".Distribox/data/11", "haha");

            FileEvent e3 = new FileEvent();

            e3.Type    = FileEventType.Renamed;
            e3.EventId = "3";
            e3.FileId  = "1";
            e3.SHA1    = "11";
            e3.Name    = "XX";

            FileEvent e4 = new FileEvent();

            e4.Type    = FileEventType.Deleted;
            e4.EventId = "4";
            e4.FileId  = "1";
            e4.Name    = "XX";

            FileEvent e5 = new FileEvent();

            e5.Type    = FileEventType.Created;
            e5.EventId = "5";
            e5.FileId  = "2";
            e5.Name    = "TT";

            FileEvent e6 = new FileEvent();

            e6.Type    = FileEventType.Changed;
            e6.EventId = "6";
            e6.FileId  = "2";
            e6.SHA1    = "11";
            e6.Name    = "TT";

            FileEvent e7 = new FileEvent();

            e7.Type        = FileEventType.Created;
            e7.EventId     = "7";
            e7.FileId      = "3";
            e7.Name        = "Dir";
            e7.IsDirectory = true;
            e7.When        = DateTime.FromFileTimeUtc(7);

            FileItem item1 = new FileItem();

            item1.Merge(e1);
            item1.Merge(e2);
            item1.Merge(e3);
            item1.Merge(e4);

            FileItem item2 = new FileItem();

            item2.Merge(e5);
            item2.Merge(e6);

            FileItem item3 = new FileItem();

            item3.Merge(e7);

            this.list.Add(item1);
            this.list.Add(item2);
            this.list.Add(item3);
        }
Esempio n. 6
0
        static int Main(string[] args)
        {
            Console.Title = "SysManager";
            //using (var sw = new StreamWriter(@"E:\EventLogInCS\PropertyInfo.txt"))
            //{
            //    sw.Write(FillPropertyInfo(new NetworkEvent()));
            //}
            //Environment.Exit(0);
            GetRuleConfig();
            ProcessEvent  proEvent  = new ProcessEvent();
            RegistryEvent regEvent  = new RegistryEvent();
            NetworkEvent  netEvent  = new NetworkEvent();
            FileEvent     fileEvent = new FileEvent();

            Console.WriteLine("Please Choose One Operation To Manage Your System:");
            int opi;

            while (true)
            {
                Console.WriteLine("For Process Enter 1");
                Console.WriteLine("For Reistry Enter 2");
                Console.WriteLine("For Network Enter 3");
                Console.WriteLine("For File Enter 4");


                Console.Write("Enter Your Choice:");
                var op = Console.ReadLine();

                if (int.TryParse(op, out opi))
                {
                    if (opi < 5 && opi > 0)
                    {
                        gec.Operation            = opi;
                        PipLineManager.operation = opi;
                        break;
                    }
                }
                Console.WriteLine(">>>>>>>>>>  Please Enter A Right One!  <<<<<<<<<<<");
            }
            Console.Clear();
            Thread th = new Thread(FireForm);

            th.SetApartmentState(ApartmentState.STA);
            th.Start();

            var  pipe = PipLineManager.FileAccessCount;
            var  processUseNetWork = PipLineManager.ProcessUseNetwork;
            var  processDic        = PipLineManager.ProcessDictionary;
            var  NetUsage          = PipLineManager.NetworkUsage;
            var  netu       = PipLineManager.netU;
            var  regDic     = PipLineManager.RegistryUsage;
            var  fileEvents = PipLineManager.FileEvents;
            uint pid        = 0;

            Action saveLogAction = null;

            saveLogAction = async() =>
            {
                var conqueEvents = gec.ConqueEvent;
                if (conqueEvents.Count > 0)
                {
                    string da;
                    while (conqueEvents.TryDequeue(out da))
                    {
                        var desxml = JsonConvert.DeserializeXmlNode(da);
                        #region Process

                        if (opi == 1)
                        {
                            int procid = desxml.DocumentElement.HasAttribute("ProcessID")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("ProcessID"))
                                : -1;
                            proEvent.ProcessId = procid;
                            int pprocid;
                            if (int.TryParse(desxml.DocumentElement.GetAttribute(ProcessEventProperty.ParentProcessID),
                                             out pprocid))
                            {
                                var imagename = desxml.DocumentElement.HasAttribute("ImageName")
                                    ? desxml.DocumentElement.GetAttribute("ImageName")
                                    : "";
                                proEvent.ProcessImage = imagename;
                                await Task.Run(() => { GetProcessInfo(proEvent, proEvent.ProcessId, pprocid, EventName.Process, imagename, proEvent.ProcessId.ToString()); });
                            }
                            else
                            {
                                await Task.Run(() => { GetProcessInfo(proEvent, procid, null, EventName.Process, null); });
                            }

                            proEvent.ThreadId = desxml.DocumentElement.HasAttribute("TID")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("TID"))
                                : -1;
                            proEvent.StartAddress = desxml.DocumentElement.HasAttribute("StartAddress")
                                ? desxml.DocumentElement.GetAttribute("StartAddress")
                                : "";
                            proEvent.Win32StartAddress = desxml.DocumentElement.HasAttribute("Win32StartAddress")
                                ? desxml.DocumentElement.GetAttribute("Win32StartAddress")
                                : "";
                            proEvent.CycleTime = desxml.DocumentElement.HasAttribute("CycleTime")
                                ? long.Parse(desxml.DocumentElement.GetAttribute("CycleTime"))
                                : -1;
                            proEvent.FormattedMessage = desxml.DocumentElement.HasAttribute("FormattedMessage")
                                ? desxml.DocumentElement.GetAttribute("FormattedMessage")
                                : "";
                            proEvent.CreateTime = desxml.DocumentElement.HasAttribute("CreateTime")
                                ? desxml.DocumentElement.GetAttribute("CreateTime")
                                : "";
                            proEvent.TaskName = desxml.DocumentElement.HasAttribute("TaskName")
                                ? desxml.DocumentElement.GetAttribute("TaskName")
                                : "";
                            proEvent.SessionId = desxml.DocumentElement.HasAttribute("SessionId")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("SessionId"))
                                : -1;
                            proEvent.ProviderName = desxml.DocumentElement.HasAttribute("ProviderName")
                                ? desxml.DocumentElement.GetAttribute("ProviderName")
                                : "";
                            proEvent.EventName = desxml.DocumentElement.HasAttribute("EventName")
                                ? desxml.DocumentElement.GetAttribute("EventName")
                                : "";
                            if (proEvent.EventName == "ProcessStop/Stop")
                            {
                                proEvent.ExitTime = desxml.DocumentElement.HasAttribute("Time")
                                    ? desxml.DocumentElement.GetAttribute("Time")
                                    : "";
                                proEvent.ExitCode = desxml.DocumentElement.HasAttribute("ExitCode")
                                    ? int.Parse(desxml.DocumentElement.GetAttribute("ExitCode"))
                                    : -1;
                                //string mgs;
                                //processDic.TryRemove(proEvent.ProcessName, out mgs);
                            }
                            else
                            {
                                processDic.AddOrUpdate(proEvent.ProcessName ?? "--", proEvent.ProcessHistory,
                                                       (key, value) => proEvent.ProcessHistory);
                            }
                        }
                        #endregion
                        #region Registry

                        else if (opi == 2)
                        {
                            regEvent.ProcessId = desxml.DocumentElement.HasAttribute("PID")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("PID"))
                                : -1;
                            await Task.Run(() => { GetProcessInfo(regEvent, regEvent.ProcessId, null, EventName.Registry, null); });

                            regEvent.BaseName = desxml.DocumentElement.HasAttribute("BaseName")
                                ? desxml.DocumentElement.GetAttribute("BaseName")
                                : "";
                            regEvent.BaseObject = desxml.DocumentElement.HasAttribute("BaseObject")
                                ? desxml.DocumentElement.GetAttribute("BaseObject")
                                : "";
                            regEvent.CapturedData = desxml.DocumentElement.HasAttribute("CapturedData")
                                ? desxml.DocumentElement.GetAttribute("CapturedData")
                                : "";
                            regEvent.CapturedDataSize = desxml.DocumentElement.HasAttribute("CapturedDataSize")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("CapturedDataSize"))
                                : -1;
                            regEvent.DataSize = desxml.DocumentElement.HasAttribute("DataSize")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("DataSize"))
                                : -1;
                            regEvent.EventName = desxml.DocumentElement.HasAttribute("EventName")
                                ? desxml.DocumentElement.GetAttribute("EventName")
                                : "";
                            regEvent.ProviderName = desxml.DocumentElement.HasAttribute("ProviderName")
                                ? desxml.DocumentElement.GetAttribute("ProviderName")
                                : "";
                            regEvent.Disposition = desxml.DocumentElement.HasAttribute("Disposition")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("Disposition"))
                                : -1;
                            regEvent.KeyName = desxml.DocumentElement.HasAttribute("KeyName")
                                ? desxml.DocumentElement.GetAttribute("KeyName")
                                : "";
                            regEvent.KeyObject = desxml.DocumentElement.HasAttribute("KeyObject")
                                ? desxml.DocumentElement.GetAttribute("KeyObject")
                                : "";
                            regEvent.PreviousData = desxml.DocumentElement.HasAttribute("PreviousData")
                                ? desxml.DocumentElement.GetAttribute("PreviousData")
                                : "";
                            regEvent.PreviousDataCapturedSize =
                                desxml.DocumentElement.HasAttribute("PreviousDataCapturedSize")
                                    ? int.Parse(desxml.DocumentElement.GetAttribute("PreviousDataCapturedSize"))
                                    : -1;
                            regEvent.PreviousDataSize = desxml.DocumentElement.HasAttribute("PreviousDataSize")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("PreviousDataSize"))
                                : -1;
                            regEvent.PreviousDataType = desxml.DocumentElement.HasAttribute("PreviousDataType")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("PreviousDataType"))
                                : -1;
                            regEvent.RelativeName = desxml.DocumentElement.HasAttribute("RelativeName")
                                ? desxml.DocumentElement.GetAttribute("RelativeName")
                                : "";
                            regEvent.ThreadId = desxml.DocumentElement.HasAttribute("TID")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("TID"))
                                : -1;
                            regEvent.Type = desxml.DocumentElement.HasAttribute("Type")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("Type"))
                                : -1;
                            regEvent.ValueName = desxml.DocumentElement.HasAttribute("ValueName")
                                ? desxml.DocumentElement.GetAttribute("ValueName")
                                : "";
                            //sw.WriteLine(regEvent.ProviderName + regEvent.EventName + regEvent.ProcessHistory);
                            RegistryUtility(regDic, regEvent);
                        }
                        #endregion
                        #region Network
                        else if (opi == 3)
                        {
                            netEvent.ProcessId = desxml.DocumentElement.HasAttribute("PID") ? int.Parse(desxml.DocumentElement.GetAttribute("PID")) : -1;
                            netEvent.ProcessId = desxml.DocumentElement.HasAttribute("PIDD") ? int.Parse(desxml.DocumentElement.GetAttribute("PIDD")) : -1;
                            await Task.Run(() => { GetProcessInfo(netEvent, netEvent.ProcessId, null, EventName.Network); });

                            netEvent.ProviderName       = desxml.DocumentElement.HasAttribute("ProviderName") ? desxml.DocumentElement.GetAttribute("ProviderName") : "";
                            netEvent.EventName          = desxml.DocumentElement.HasAttribute("EventName") ? desxml.DocumentElement.GetAttribute("EventName") : "";
                            netEvent.DestinationAddress = desxml.DocumentElement.HasAttribute("daddr") ? Utility.LongToIpAddress(desxml.DocumentElement.GetAttribute("daddr")) : "-1";
                            netEvent.SourceAddress      = desxml.DocumentElement.HasAttribute("saddr") ? Utility.LongToIpAddress(desxml.DocumentElement.GetAttribute("saddr")) : "-1";
                            netEvent.Dport    = desxml.DocumentElement.HasAttribute("dport") ? int.Parse(desxml.DocumentElement.GetAttribute("dpoort")) : -1;
                            netEvent.Sport    = desxml.DocumentElement.HasAttribute("sport") ? int.Parse(desxml.DocumentElement.GetAttribute("sport")) : -1;
                            netEvent.ConnId   = desxml.DocumentElement.HasAttribute("connid") ? int.Parse(desxml.DocumentElement.GetAttribute("connid")) : -1;
                            netEvent.SeqNum   = desxml.DocumentElement.HasAttribute("seqnum") ? int.Parse(desxml.DocumentElement.GetAttribute("seqnum")) : -1;
                            netEvent.ThreadId = desxml.DocumentElement.HasAttribute("TID") ? int.Parse(desxml.DocumentElement.GetAttribute("TID")) : -1;
                            netEvent.Size     = desxml.DocumentElement.HasAttribute("size") ? int.Parse(desxml.DocumentElement.GetAttribute("size")) : 0;
                            //Task.Run(() => { NetworkUtility(netu, netEvent, processUseNetWork, netEvent.ProcessHistoryD, netEvent.SourceAddress, netEvent.DestinationAddress); });
                            NetUsage.Enqueue(netEvent);
                        }
                        #endregion
                        #region File
                        else
                        {
                            fileEvent.ProcessId = desxml.DocumentElement.HasAttribute("PID")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("PID"))
                                : -1;
                            await Task.Run(() => { GetProcessInfo(fileEvent, fileEvent.ProcessId, null, EventName.File); });

                            fileEvent.ThreadId = desxml.DocumentElement.HasAttribute("TID")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("TID"))
                                : -1;
                            fileEvent.FileName = desxml.DocumentElement.HasAttribute("FileName")
                                ? desxml.DocumentElement.GetAttribute("FileName")
                                : "";
                            fileEvent.FilePath = desxml.DocumentElement.HasAttribute("FilePath")
                                ? desxml.DocumentElement.GetAttribute("FilePath")
                                : "";
                            fileEvent.ProviderName = desxml.DocumentElement.HasAttribute("ProviderName")
                                ? desxml.DocumentElement.GetAttribute("ProviderName")
                                : "";
                            fileEvent.EventName = desxml.DocumentElement.HasAttribute("EventName")
                                ? desxml.DocumentElement.GetAttribute("EventName")
                                : "";
                            fileEvent.Irp = desxml.DocumentElement.HasAttribute("Irp")
                                ? desxml.DocumentElement.GetAttribute("Irp")
                                : "";
                            fileEvent.FileObject = desxml.DocumentElement.HasAttribute("FileObject")
                                ? desxml.DocumentElement.GetAttribute("FileObject")
                                : "";

                            //fileEvent.IssuingThreadId = desxml.DocumentElement.HasAttribute("IssuingThreadId")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("IssuingThreadId"))
                            //    : -1;
                            //fileEvent.CreateOptions = desxml.DocumentElement.HasAttribute("CreateOptions")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("CreateOptions"))
                            //    : -1;
                            //fileEvent.CreateAttributes = desxml.DocumentElement.HasAttribute("CreateAttributes")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("CreateAttributes"))
                            //    : -1;
                            fileEvent.ShareAccess = desxml.DocumentElement.HasAttribute("ShareAccess")
                                ? desxml.DocumentElement.GetAttribute("ShareAccess")
                                : "";
                            fileEvent.FileKey = desxml.DocumentElement.HasAttribute("FileKey")
                                ? desxml.DocumentElement.GetAttribute("FileKey")
                                : "";
                            //long iit = Convert.ToInt64(fileEvent.FileKey, 16)*-1;

                            // var filena = Utility.GetFileNameFromHandle(new IntPtr(Convert.ToInt64(fileEvent.FileKey, 16)));
                            fileEvent.IOSize = desxml.DocumentElement.HasAttribute("IOSize")
                                ? int.Parse(desxml.DocumentElement.GetAttribute("IOSize"))
                                : -1;
                            //fileEvent.IOFlags = desxml.DocumentElement.HasAttribute("IOFlags")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("IOFlags"))
                            //    : -1;
                            //fileEvent.ExtraFlags = desxml.DocumentElement.HasAttribute("ExtraFlags")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("ExtraFlags"))
                            //    : -1;
                            //fileEvent.ByteOffset = desxml.DocumentElement.HasAttribute("ByteOffset")
                            //    ? long.Parse(desxml.DocumentElement.GetAttribute("ByteOffset"))
                            //    : -1;
                            //fileEvent.ExtraInformation = desxml.DocumentElement.HasAttribute("ExtraInformation")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("ExtraInformation"))
                            //    : -1;
                            //fileEvent.Status = desxml.DocumentElement.HasAttribute("Status")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("Status"))
                            //    : -1;
                            //fileEvent.InfoClass = desxml.DocumentElement.HasAttribute("InfoClass")
                            //    ? int.Parse(desxml.DocumentElement.GetAttribute("InfoClass"))
                            //    : -1;
                            Task.Run(() => { FileUtility(fileEvents, pipe, fileEvent); });
                        }

                        #endregion
                    }
                }
                try
                {
                    Thread.Sleep(500);
                    Parallel.Invoke(saveLogAction);
                }
                catch (Exception)
                {
                    Thread.Sleep(500);
                    saveLogAction.Invoke();
                }
            };
            Task t = new Task(() => { gec.FetchEvents(); });
            t.Start();
            saveLogAction.Invoke();
            Console.Read();
            return(0);
        }
Esempio n. 7
0
        public void RemotePathIsNullIfNoRemoteFileIsSet()
        {
            var fileEvent = new FileEvent(localFile: Mock.Of <IFileInfo>());

            Assert.That(fileEvent.RemotePath, Is.Null);
        }
Esempio n. 8
0
        void visualTree1_NodeDoubleClick(FileEvent e)
        {
            string file = GetTempFile(e);

            this.Command("start", file);
        }
Esempio n. 9
0
        public LineCountProgress Count(FileEvent fileEvent)
        {
            const double TimeoutSeconds = 5.0;
            const int    RetryInterval  = 900; // milliseconds
            var          report         = new LineCountProgress(fileEvent);

            DateTime startTime  = DateTime.Now;
            TimeSpan elapsed    = new TimeSpan(ticks: 0);
            bool     keepTrying = true;

            while (keepTrying)
            {
                try
                {
                    int    count = FileEntry.NotCounted;
                    string path  = Path.Combine(FolderPath ?? "", fileEvent.FileEntry.Name);

                    using (var f = new StreamReader(path, detectEncodingFromByteOrderMarks: true))
                    {
                        string line;
                        do
                        {
                            count++;
                            line = f.ReadLine();
                        }while (line != null);
                    }
                    report.Count  = count;
                    report.Status = LineCountStatus.Success;
                    keepTrying    = false;
                }
                catch (IOException ex)
                {
                    if (ex is DirectoryNotFoundException ||
                        ex is DriveNotFoundException ||
                        ex is FileNotFoundException ||
                        ex is PathTooLongException)
                    {
                        report.Status = LineCountStatus.FileNotFound;
                        report.Note   = ex.Message;
                        keepTrying    = false;
                    }
                    else
                    {
                        // locked file raises IOException base class
                        elapsed = DateTime.Now - startTime;
                        if (elapsed.TotalSeconds >= TimeoutSeconds)
                        {
                            report.Status = LineCountStatus.TimedOut;
                            report.Note   = "Timed out after " + elapsed;
                            keepTrying    = false;
                        }
                        else
                        {
                            Thread.Sleep(RetryInterval);
                        }
                    }
                }
                catch (Exception ex)
                {
                    report.Status = LineCountStatus.Exception;
                    report.Note   = ex.Message;
                    keepTrying    = false;
                }
            }

            return(report);
        }
Esempio n. 10
0
 public Task <LineCountProgress> CountAsync(FileEvent fileEvent)
 {
     return(Task.Run(() => Count(fileEvent)));
 }
Esempio n. 11
0
        void CountAndSave(FileEvent fileEvent, List <LineCountProgress> results)
        {
            LineCountProgress report = Count(fileEvent);

            results.Add(report);
        }
Esempio n. 12
0
 public void DeleteFileEvent(FileEvent f)
 {
     throw new NotImplementedException();
 }
Esempio n. 13
0
 internal void RaiseDeleted(VirtualFile file)
 {
     FileEvent?.Invoke(this, new FileEventArgs(file, WatcherEvent.Deleted));
 }
Esempio n. 14
0
 private void directoryWatcher_Modified(object sender, FileEvent e)
 {
     fileChanged.Post(e);
 }
Esempio n. 15
0
        public void RemotePathIsNullIfRemoteObjectDoesNotContainAPath()
        {
            var fileEvent = new FileEvent(remoteFile: Mock.Of <IDocument>());

            Assert.That(fileEvent.RemotePath, Is.Null);
        }
Esempio n. 16
0
        private async Task OnFileChanged(object sender, System.IO.FileSystemEventArgs e)
        {
            // Skip directory change events
            if (!e.IsDirectoryChanged())
            {
                // Create something to match with
                var item = new InMemoryDirectoryInfo(_root, new string[] { e.FullPath });

                // See if this matches one of our patterns.
                if (_matcher.Execute(item).HasMatches)
                {
                    // Send out the event to the language server
                    var renamedArgs     = e as System.IO.RenamedEventArgs;
                    var didChangeParams = new DidChangeWatchedFilesParams();

                    // Visual Studio actually does a rename when saving. The rename is from a file ending with '~'
                    if (renamedArgs == null || renamedArgs.OldFullPath.EndsWith("~"))
                    {
                        renamedArgs                    = null;
                        didChangeParams.Changes        = new FileEvent[] { new FileEvent() };
                        didChangeParams.Changes[0].Uri = new Uri(e.FullPath);

                        switch (e.ChangeType)
                        {
                        case WatcherChangeTypes.Created:
                            didChangeParams.Changes[0].FileChangeType = FileChangeType.Created;
                            break;

                        case WatcherChangeTypes.Deleted:
                            didChangeParams.Changes[0].FileChangeType = FileChangeType.Deleted;
                            break;

                        case WatcherChangeTypes.Changed:
                            didChangeParams.Changes[0].FileChangeType = FileChangeType.Changed;
                            break;

                        case WatcherChangeTypes.Renamed:
                            didChangeParams.Changes[0].FileChangeType = FileChangeType.Changed;
                            break;

                        default:
                            didChangeParams.Changes = Array.Empty <FileEvent>();
                            break;
                        }
                    }
                    else
                    {
                        // file renamed
                        var deleteEvent = new FileEvent();
                        deleteEvent.FileChangeType = FileChangeType.Deleted;
                        deleteEvent.Uri            = new Uri(renamedArgs.OldFullPath);

                        var createEvent = new FileEvent();
                        createEvent.FileChangeType = FileChangeType.Created;
                        createEvent.Uri            = new Uri(renamedArgs.FullPath);

                        didChangeParams.Changes = new FileEvent[] { deleteEvent, createEvent };
                    }

                    if (didChangeParams.Changes.Any())
                    {
                        await _rpc.NotifyWithParameterObjectAsync(Methods.WorkspaceDidChangeWatchedFiles.Name, didChangeParams);

                        if (renamedArgs != null)
                        {
                            var textDocumentIdentifier = new TextDocumentIdentifier();
                            textDocumentIdentifier.Uri = new Uri(renamedArgs.OldFullPath);

                            var closeParam = new DidCloseTextDocumentParams();
                            closeParam.TextDocument = textDocumentIdentifier;

                            await _rpc.NotifyWithParameterObjectAsync(Methods.TextDocumentDidClose.Name, closeParam);

                            var textDocumentItem = new TextDocumentItem();
                            textDocumentItem.Uri = new Uri(renamedArgs.FullPath);

                            var openParam = new DidOpenTextDocumentParams();
                            openParam.TextDocument = textDocumentItem;
                            await _rpc.NotifyWithParameterObjectAsync(Methods.TextDocumentDidOpen.Name, openParam);
                        }
                    }
                }
            }
        }
Esempio n. 17
0
 public Tree(FileEvent e)
 {
     this.Event    = e;
     this.Children = new List <Tree>();
 }