public bool UpdateConfigFile(CustomFilterManager filterManager)
        {
            FileStream fileStream = null;
            int        num        = 5;
            bool       flag       = true;

            while (flag)
            {
                try
                {
                    fileStream = Utilities.CreateFileStreamHelper(configFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
                    if (fileStream != null)
                    {
                        flag = false;
                    }
                }
                catch (LogFileException ex)
                {
                    if (ex.InnerException == null || !(ex.InnerException is IOException) || num < 0)
                    {
                        switch (userIP.ShowMessageBox(SR.GetString("CF_Err10") + ex.Message, null, MessageBoxIcon.Hand, MessageBoxButtons.AbortRetryIgnore))
                        {
                        case DialogResult.Abort:
                            return(false);

                        case DialogResult.Ignore:
                            return(true);

                        case DialogResult.Retry:
                            flag = true;
                            break;
                        }
                    }
                    else
                    {
                        flag = true;
                        num--;
                        Thread.Sleep(new Random((int)DateTime.Now.Ticks).Next(200, 600));
                    }
                }
            }
            XmlTextWriter xmlTextWriter = null;

            try
            {
                xmlTextWriter = new XmlTextWriter(fileStream, Encoding.UTF8);
                xmlTextWriter.WriteStartElement("appSettings");
                xmlTextWriter.WriteStartElement("customFilters");
                filterManager.UpdateCurrentFilters(xmlTextWriter);
                xmlTextWriter.WriteEndElement();
                xmlTextWriter.WriteStartElement("filterOptions");
                customFilterOptionSettings.OutputToStream(xmlTextWriter);
                xmlTextWriter.WriteEndElement();
                xmlTextWriter.WriteStartElement("uiSettings");
                InternalPersisitRegisteredObjects(xmlTextWriter);
                xmlTextWriter.WriteEndElement();
                xmlTextWriter.WriteEndElement();
                xmlTextWriter.Flush();
                return(true);
            }
            catch (XmlException)
            {
                errorReport.ReportErrorToUser(SR.GetString("CF_Err10"));
                return(true);
            }
            finally
            {
                Utilities.CloseStreamWithoutException(fileStream, isFlushStream: false);
            }
        }
Beispiel #2
0
 public void Initialize(CustomFilterManager filterManager, IUserInterfaceProvider userIP, TraceViewerForm appForm)
 {
     this.filterManager = filterManager;
     this.userIP        = userIP;
     this.appForm       = appForm;
 }