Exemple #1
0
        private void CloseFile()
        {
            if (m_Database != null)
            {
                m_ItemTree.ItemDatabase = null;

                foreach (IModule module in m_ModuleManager.Modules)
                {
                    module.Database = null;
                }

                m_Database.MultipleLogFilesQuery -= OnMultipleLogFileQuery;
                m_Database.OnParserReadError     -= OnParserReadErrorCallback;
                m_Database.Dispose();
                m_Database = null;
            }
        }
Exemple #2
0
        private void CompareLogFile(object o, EventArgs args)
        {
            var textWindow = new Form
            {
                Text   = "Compare themes",
                Width  = 600,
                Height = 600
            };
            var txt = new RichTextBox
            {
                ShortcutsEnabled = true,
                Text             = "Loading second file...",
                Width            = 580,
                Height           = 570,
                Anchor           = AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Left,
                ScrollBars       = RichTextBoxScrollBars.Vertical,
                ReadOnly         = true,
                Multiline        = true
            };

            textWindow.Controls.Add(txt);
            textWindow.Show();
            LogDatabase referenceDb = null;

            try
            {
                var openReferenceLogFileDialog = new OpenFileDialog
                {
                    Filter      = "Log files |*.zip; *.plg|All files (*.*)|*.*",
                    FilterIndex = 1,
                    Multiselect = false,
                    Title       = "Select reference file"
                };

                DialogResult userClickedOK = openReferenceLogFileDialog.ShowDialog();
                if (userClickedOK != DialogResult.OK)
                {
                    return;
                }

                referenceDb = new LogDatabase(openReferenceLogFileDialog.FileName, true, null);
                referenceDb.Start();
                //wait while indexing reference log file database
                while (referenceDb.State != ProgressStateEnum.Done && referenceDb.State != ProgressStateEnum.Monitoring)
                {
                    Thread.Sleep(500);
                }

                //Add ids in themes and machine, except process themes
                Func <string[], Dictionary <string, string> > getIds = ids =>
                                                                       ids.Where(p => p.StartsWith("Machine.")).Concat(ids.Where(p => p.StartsWith("Themes.") &&
                                                                                                                                 !p.StartsWith(
                                                                                                                                     "Themes.ProcessStep[")))
                                                                       .ToDictionary(p => p);

                Dictionary <string, string> loadedIds    = getIds(m_Database.GetItemsIDs().ToArray());
                Dictionary <string, string> referenceIds = getIds(referenceDb.GetItemsIDs().ToArray());

                KeyValuePair <string, string>[] changesInLoadedIds =
                    loadedIds.Where(p => m_Database.GetAll(p.Key).Count() > 1).ToArray();
                KeyValuePair <string, string>[] changesInReferenceIds =
                    referenceIds.Where(p => referenceDb.GetAll(p.Key).Count() > 1).ToArray();

                string output = $"Comparing {m_Database.Filename} with reference {referenceDb.Filename}" +
                                Environment.NewLine + Environment.NewLine;
                if (changesInLoadedIds.Length > 0)
                {
                    output += "These items have multiple entries in the log file. Using the last entry as comparison:" +
                              Environment.NewLine;
                }
                output = changesInLoadedIds.Aggregate(output,
                                                      (current, changesInLoadedId) => current + changesInLoadedId.Key + Environment.NewLine);
                if (changesInReferenceIds.Length > 0)
                {
                    output += Environment.NewLine +
                              "These items have multiple entries in the reference file. Using the last entry as comparison:" +
                              Environment.NewLine;
                }
                output = changesInReferenceIds.Aggregate(output,
                                                         (current, changesInRefId) => current + changesInRefId.Key + Environment.NewLine);
                output += Environment.NewLine;

                output += "Changes compared to reference file:" + Environment.NewLine;
                foreach (KeyValuePair <string, string> id in referenceIds)
                {
                    bool   compareExist = m_Database.Exists(id.Key);
                    string refValue     = referenceDb.GetLastItem(id.Key, t => t.CycleIndex >= 0).Value;
                    if (compareExist)
                    {
                        string compareValue = m_Database.GetLastItem(id.Key, t => t.CycleIndex >= 0).Value;
                        if (compareValue != refValue)
                        {
                            output += $"Change \t{id.Value} \t{refValue} \t->\t {compareValue}" + Environment.NewLine;
                        }
                    }
                    else
                    {
                        output += $"Removed \t{id.Value} \t{refValue}" + Environment.NewLine;
                    }
                }

                foreach (KeyValuePair <string, string> loadedId in loadedIds.Where(p => !referenceDb.Exists(p.Key)))
                {
                    string compareValue = m_Database.GetLastItem(loadedId.Key, t => t.CycleIndex >= 0).Value;
                    output += $"New \t{loadedId.Value} \t{compareValue}" + Environment.NewLine;
                }
                txt.Text = output;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                referenceDb?.Dispose();
            }
        }
Exemple #3
0
 private void OnFormClosed(object sender, FormClosedEventArgs e)
 {
     m_ModifiedTimer.Enabled = false;
     m_Database?.Dispose();
     m_MruMenu.SaveToRegistry();
 }