Exemplo n.º 1
0
        public override bool Equals(Object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            CertificateProfile certObj = obj as CertificateProfile;

            if (!String.IsNullOrEmpty(activeProfile) &&
                !String.IsNullOrEmpty(certObj.activeProfile) &&
                !this.activeProfile.Equals(certObj.activeProfile))
            {
                return(false);
            }

            if (this.profileDic.Count != certObj.profileDic.Count)
            {
                return(false);
            }

            bool isContentEquals = this.profileDic.Keys.All(
                k =>
                certObj.profileDic.ContainsKey(k) &&
                object.Equals(this.profileDic[k], certObj.profileDic[k]));

            return(isContentEquals);
        }
        public static void RegisterProfileFile(string filePath)
        {
            DeregisterWatchFile();

            if (!File.Exists(filePath))
            {
                return;
            }

            // Create new instance of certificate profile
            certProfile = new CertificateProfile(filePath);

            // Add watch event of profiles.xml
            String FileDirName = Path.GetDirectoryName(filePath);

            String FileName = Path.GetFileName(filePath);

            watcher = new FileSystemWatcher();

            watcher.NotifyFilter = NotifyFilters.LastWrite;
            watcher.Path         = FileDirName;
            watcher.Filter       = FileName;

            watcher.Changed += new FileSystemEventHandler(OnFileChanged);

            listEventDelegates = new EventHandlerList();

            watcher.EnableRaisingEvents = true;

            profileFilePath = String.Copy(filePath);
        }
 public static void DeregisterWatchFile()
 {
     listEventDelegates?.Dispose();
     listEventDelegates = null;
     watcher?.Dispose();
     watcher     = null;
     certProfile = null;
 }
        private static void OnFileChanged(object source, FileSystemEventArgs e)
        {
            if (certProfile == null)
            {
                return;
            }

            CertificateProfile changedCertProfile;

            try
            {
                changedCertProfile = new CertificateProfile(e.FullPath);
            }
            catch
            {
                return;
            }

            // Check Something changed
            if (!Object.Equals(certProfile, changedCertProfile))
            {
                certProfile.LoadProfileXml(e.FullPath); // reload xml

                EventHandler <CertificateProfileChangedEventArgs> handler =
                    (EventHandler <CertificateProfileChangedEventArgs>)
                    listEventDelegates?[EventKey];

                if (handler == null)
                {
                    return;
                }

                CertificateProfileChangedEventArgs eArgs =
                    new CertificateProfileChangedEventArgs();

                eArgs.ProfileFilePath     = e.FullPath;
                eArgs.ActiveProfile       = certProfile.GetActiveProfileName();
                eArgs.ProfileFileContents = true;

                handler(source, eArgs);
            }
        }