Ejemplo n.º 1
0
 private void ReloadItem(CertificateFile f)
 {
     f.Reload();
     lstFiles.Items.Remove(f);
     AssignToGroup(f);
     lstFiles.Items.Add(f);
 }
Ejemplo n.º 2
0
        private void SetupWatcher()
        {
            var fullPath = CurrentWorkingDirectory == null ? null : PathUtils.GetFullPath(CurrentWorkingDirectory);

            if (fullPath == null || watcher == null || !string.Equals(watcher.Path, fullPath))
            {
                watcher?.Dispose();

                if (fullPath != null && Directory.Exists(fullPath))
                {
                    watcher = new FileSystemWatcher(fullPath);
                    watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
                    watcher.Filter       = "*.*";
                    watcher.Changed     += File_Changed;
                    watcher.Created     += File_Changed;
                    watcher.Deleted     += File_Changed;
                    watcher.Renamed     += File_Changed;

                    lstFiles.Items.Clear();
                    foreach (var item in new DirectoryInfo(fullPath)
                             .GetFiles("*.*", SearchOption.AllDirectories)
                             .Select(x => CertificateFile.FromFile(fullPath, x.FullName)))
                    {
                        AddItem(item);
                    }

                    UpdateCaList();
                    UpdateCsrToSignList();
                    watcher.EnableRaisingEvents = true;
                }
            }
        }
Ejemplo n.º 3
0
        public static CertificateFile FromFile(string folderPath, string filePath)
        {
            var certFile = new CertificateFile
            {
                Filename = filePath.Substring(folderPath.Length + 1),
                FullPath = filePath
            };

            certFile.Reload();

            return(certFile);
        }
Ejemplo n.º 4
0
        private void File_Changed(object sender, FileSystemEventArgs e)
        {
            Invoke(new Action(() =>
            {
                bool mutated = false;
                if ((e.ChangeType & WatcherChangeTypes.Created) != 0)
                {
                    if (File.Exists(e.FullPath))
                    {
                        AddItem(CertificateFile.FromFile(PathUtils.GetFullPath(CurrentWorkingDirectory), e.FullPath));
                        mutated = true;
                    }
                }

                if ((e.ChangeType & WatcherChangeTypes.Deleted) != 0)
                {
                    var files = lstFiles.Items.Cast <CertificateFile>()
                                .Where(x => string.Equals(x.FullPath, e.FullPath, StringComparison.OrdinalIgnoreCase))
                                .ToArray();
                    foreach (var f in files)
                    {
                        RemoveItem(f);
                        mutated = true;
                    }
                }

                if ((e.ChangeType & WatcherChangeTypes.Renamed) != 0)
                {
                    // huh?
                }

                if ((e.ChangeType & WatcherChangeTypes.Changed) != 0)
                {
                    var files = lstFiles.Items.Cast <CertificateFile>()
                                .Where(x => string.Equals(x.FullPath, e.FullPath, StringComparison.OrdinalIgnoreCase))
                                .ToArray();
                    foreach (var f in files)
                    {
                        ReloadItem(f);
                        mutated = true;
                    }
                }

                if (mutated)
                {
                    UpdateCaList();
                    UpdateCsrToSignList();
                }
            }));
        }
Ejemplo n.º 5
0
 private void AssignToGroup(CertificateFile f)
 {
     f.Group = lstFiles.Groups[f.Type.ToString()];
 }
Ejemplo n.º 6
0
 private void RemoveItem(CertificateFile f)
 {
     lstFiles.Items.Remove(f);
 }
Ejemplo n.º 7
0
 private void AddItem(CertificateFile f)
 {
     lstFiles.Items.Add(f);
     AssignToGroup(f);
 }