Exemplo n.º 1
0
        internal static void SaveHighlight(AHighlightRequest ahr)
        {
            XmlSerializer xmls = new XmlSerializer(typeof(AHighlightRequest));

            string pathToSave = GetHighlightFilenameFromHighlightName(ahr.NameString);

            if (File.Exists(pathToSave))
            {
                File.Delete(pathToSave);
            }

            using (FileStream fs = new FileStream(pathToSave, FileMode.CreateNew)) {
                xmls.Serialize(fs, ahr);
                fs.Close();
            }
        }
Exemplo n.º 2
0
        internal static AHighlightRequest LoadHighlight(string textName)
        {
            XmlSerializer     xmls   = new XmlSerializer(typeof(AHighlightRequest));
            AHighlightRequest result = null;

            string path = Path.Combine(MexCore.TheCore.Options.FilterAndHighlightStoreDirectory, textName + MexCore.TheCore.Options.HighlightExtension);

            if (File.Exists(path))
            {
                using (FileStream fs = new FileStream(path, FileMode.Open)) {
                    result = (AHighlightRequest)xmls.Deserialize(fs);
                    fs.Close();
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        internal static AHighlightRequest[] LoadKnownHighlights()
        {
            XmlSerializer            xmls   = new XmlSerializer(typeof(AHighlightRequest));
            List <AHighlightRequest> result = new List <AHighlightRequest>();

            string[] matchedFilters = Directory.GetFiles(MexCore.TheCore.Options.FilterAndHighlightStoreDirectory, "*" + MexCore.TheCore.Options.HighlightExtension);

            foreach (string s in matchedFilters)
            {
                using (FileStream fs = new FileStream(s, FileMode.Open)) {
                    AHighlightRequest loaded = (AHighlightRequest)xmls.Deserialize(fs);
                    fs.Close();
                    result.Add(loaded);
                }
            }

            return(result.ToArray());
        }
Exemplo n.º 4
0
        internal void ApplyOptionsToApplication(MexOptions newOptions, bool isStartup)
        {
            //Bilge.Log("Dispatching notificaiton event of options changed");
            MexCore.TheCore.ViewManager.AddUserNotificationMessageByIndex(ViewSupportManager.UserMessages.BackgroundApplyOptionsBegins, ViewSupportManager.UserMessageType.InformationMessage, "");

            bool forceResetOfIPListener = false;
            bool fullRefreshRequired    = false;

            // Some of the options occur during application startup.
            if (isStartup)
            {
                fullRefreshRequired = true;
                if ((newOptions.FilterFilenameToLoadOnStartup != null) && (newOptions.FilterFilenameToLoadOnStartup.Length > 0) && (File.Exists(newOptions.FilterFilenameToLoadOnStartup)))
                {
                    ViewFilter vf = ViewFilter.LoadFilterFromFile(newOptions.FilterFilenameToLoadOnStartup);
                    MexCore.TheCore.ViewManager.CurrentFilter = vf;
                }

                if ((newOptions.HighlightDefaultProfileName != null) && (newOptions.HighlightDefaultProfileName.Length > 0))
                {
                    string[]      matchedHighlights = newOptions.HighlightDefaultProfileName.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    XmlSerializer xmls = new XmlSerializer(typeof(AHighlightRequest));
                    foreach (string s in matchedHighlights)
                    {
                        string path = Path.Combine(MexCore.TheCore.Options.FilterAndHighlightStoreDirectory, s + MexCore.TheCore.Options.HighlightExtension);
                        if (File.Exists(path))
                        {
                            using (FileStream fs = new FileStream(path, FileMode.Open)) {
                                AHighlightRequest loaded = (AHighlightRequest)xmls.Deserialize(fs);
                                fs.Close();
                                MexCore.TheCore.ViewManager.CurrentHighlightOptions.HighlightRequests.Add(loaded);
                                MexCore.TheCore.ViewManager.ReapplyHighlight();
                            }
                        }
                    }
                }
            }

            #region check the option differences and decide if a refresh or IP reset required

            // This is not thread safe but instead we suspend the other thread that could be accessing it
            if ((newOptions.IPAddressToBind != MexCore.TheCore.Options.IPAddressToBind) ||
                (newOptions.PortAddressToBind != MexCore.TheCore.Options.PortAddressToBind))
            {
                forceResetOfIPListener = true;
            }

            if ((newOptions.BeautifyDisplayedStrings != MexCore.TheCore.Options.BeautifyDisplayedStrings))
            {
                fullRefreshRequired = true;
            }
            if (newOptions.DisplayInternalMessages != MexCore.TheCore.Options.DisplayInternalMessages)
            {
                fullRefreshRequired = true;
            }
            if (newOptions.UsePreferredNameInsteadOfProcessId != MexCore.TheCore.Options.UsePreferredNameInsteadOfProcessId)
            {
                fullRefreshRequired = true;
            }

            #endregion

            MexCore.TheCore.Options = newOptions;
            if (forceResetOfIPListener)
            {
                MexCore.TheCore.WorkManager.AddJob(new Job_ChangeTCPGathererState(false));
                MexCore.TheCore.WorkManager.AddJob(new Job_ChangeTCPGathererState(true));
            }
            if (fullRefreshRequired)
            {
                MexCore.TheCore.WorkManager.AddJob(new Job_NotifyRefreshRequired());
            }
            // When the threads come back online they should process any of the changes that are requested.
        } // End MexOptions.ApplyOptionstoApplication