Пример #1
0
        public int Execute()
        {
            return(ConsoleTask.Execute(this, console =>
            {
                console.WriteLine("Getting package information...");
                var dirs = SharedOptions.GetDirectories(BasePackage, OurPackage).ToList();

                var script = default(InstallScript);
                console.Write("Calculating diffs... ");
                using (var prog = new ProgressBar())
                {
                    var processor = new MergeProcessor()
                    {
                        SortDependencies = true
                    };
                    if (!string.IsNullOrEmpty(FirstOfGroup))
                    {
                        processor.FirstOfGroup.UnionWith(FirstOfGroup.Split(','));
                    }
                    processor.ProgressChanged += (s, ev) => prog.Report(ev.Progress / 100.0);
                    script = processor.Merge(dirs[0], dirs[1]);
                }
                console.WriteLine("Done.");

                SharedOptions.WritePackage(console, script, Output, MultipleDirectories, CleanOutput);
            }));
        }
Пример #2
0
        /// <summary>
        ///     Imports the entity
        /// </summary>
        /// <param name="tenantId"></param>
        /// <param name="importSource"></param>
        /// <param name="settings"></param>
        /// <param name="context"></param>
        internal IEnumerable <Guid> ImportEntity(long tenantId, IDataSource importSource, EntityXmlImportSettings settings, IProcessingContext context)
        {
            IList <Guid> rootGuids = GetRootGuidsFromMetadata(importSource, context);

            using (IDataSource baseline = GetBaselineSourceForImport(tenantId, rootGuids))
                using (TenantMergeTarget target = new TenantMergeTarget
                {
                    TenantId = tenantId,
                    IgnoreExternalReferences = true
                })
                {
                    /////
                    // Copy the data
                    /////
                    using (var processor = new MergeProcessor(context)
                    {
                        OldVersion = baseline,
                        NewVersion = importSource,
                        Target = target
                    })
                    {
                        processor.MergeData( );

                        CheckForMissingDependencies(context, settings);

                        target.Commit( );
                    }
                }

            CacheManager.ClearCaches(tenantId);

            return(rootGuids);
        }
Пример #3
0
        public void MergeFiles()
        {
            DataFile.Instance.MergedFile = DataFile.Instance.SchemaFile.Clone();
            var merger = new MergeProcessor();

            merger.PrePopulateMergedFile(DataFile.Instance.SchemaFile, DataFile.Instance.MergedFile);
            merger.Merge(DataFile.Instance.ConfigFile);
            merger.SetMergedRootObject(DataFile.Instance.MergedFile);
        }
Пример #4
0
        /// <summary>
        /// Осуществляет слияние 2 строк с помощью QA_Merger
        /// </summary>
        /// <param name="s1">строка 1</param>
        /// <param name="s2">строка 2</param>
        /// <returns>результат слияния</returns>
        public static string Merge(string s1, string s2)
        {
            var prefix      = "<html><body>";
            var suffix      = "</body></html>";
            var mergeFormat = "{0}{1}{2}";
            var merger      = new MergeProcessor(string.Format(mergeFormat, prefix, s1, suffix), string.Format(mergeFormat, prefix, s2, suffix));
            var result      = merger.Merge();

            return(result.Replace(prefix, "").Replace(suffix, ""));
        }
Пример #5
0
        public void ShouldGetResultOfSingleGraph()
        {
            Models.Graph graph_01 = mockProvider.Graph_01;

            MergeProcessor processor = new MergeProcessor();

            processor.Queue(graph_01);

            Models.Graph result = processor.GetFinalResult().Result;

            Assert.Equal(2, result.Multitrees.Count);
        }
Пример #6
0
        public void ShouldMergeMultipleGraphs()
        {
            Models.Graph graph_01 = mockProvider.Graph_01;
            Models.Graph graph_02 = mockProvider.Graph_02;
            Models.Graph graph_03 = new Models.Graph();

            MergeProcessor processor = new MergeProcessor();

            processor.Queue(graph_01);
            processor.Queue(graph_02);
            processor.Queue(graph_03);

            Models.Graph result = processor.GetFinalResult().Result;
        }
Пример #7
0
        public void ShouldMergeLandscapesWithMergeProcessor()
        {
            Models.Graph graph_01 = mockProvider.Graph_01;
            Models.Graph graph_02 = mockProvider.Graph_02;

            MergeProcessor processor = new MergeProcessor();

            processor.Queue(graph_01);
            processor.Queue(graph_02);

            Models.Graph result = processor.GetFinalResult().Result;

            Assert.Equal(3, result.Multitrees.Count);
            Assert.Equal(6, TestHelper.CountEdges(result.AdjacencyList));
        }
Пример #8
0
        /// <summary>
        /// Runs a task of merging two graphs until its interrupted by its processor
        /// </summary>
        /// <param name="processor">The processor this task runs on</param>
        /// <param name="graph_01">The initial first graph this task is started with</param>
        /// <param name="graph_02">The initial second graph this task is started with</param>
        /// <returns>The task</returns>
        internal Task Run(MergeProcessor processor, Graph graph_01, Graph graph_02)
        {
            bool  anotherRound = true;
            Graph nextGraph_01 = graph_01;
            Graph nextGraph_02 = graph_02;

            return(Task.Run(() =>
            {
                while (anotherRound || processor.state.Equals(MergeProcessorState.AWAITING_TASKS))
                {
                    if (anotherRound)
                    {
                        nextGraph_01.Merge(nextGraph_02);

                        lock (processor.enqueueSync)
                        {
                            processor.queue.Enqueue(nextGraph_01);
                        }
                    }

                    lock (processor.enqueueSync)
                    {
                        if (processor.queue.Count >= 2)
                        {
                            nextGraph_01 = processor.queue.Dequeue();
                            nextGraph_02 = processor.queue.Dequeue();

                            if (nextGraph_02 == null)
                            {
                                throw new InvalidOperationException("WTF");
                            }
                            anotherRound = true;
                        }
                        else
                        {
                            anotherRound = false;
                        }
                    }
                }
            }));
        }
Пример #9
0
        private void TryExportConfig()
        {
            try
            {
                if (DialogResult.Yes ==
                    MessageBox.Show("Do you want to use the built in newrelic.config file?", "Use built in newrelic.config?",
                                    MessageBoxButtons.YesNo))
                {
                    using (
                        var resource =
                            Assembly.GetExecutingAssembly()
                            .GetManifestResourceStream("NewRelic.AgentConfiguration.Resources.newrelic.config"))
                    {
                        using (
                            var file = new FileStream(Application.StartupPath + "\\newrelic.config", FileMode.Create,
                                                      FileAccess.Write))
                        {
                            resource.CopyTo(file);
                        }
                    }

                    var configProcessor = new ConfigProcessor();
                    configProcessor.ProcessConfig(Application.StartupPath + "\\newrelic.config");
                    ConfigPath = Application.StartupPath + "\\newrelic.config";
                    var mergeProcessor = new MergeProcessor();
                    mergeProcessor.PrePopulateMergedFile(DataFile.Instance.SchemaFile, DataFile.Instance.MergedFile);
                    mergeProcessor.Merge(DataFile.Instance.ConfigFile);
                    mergeProcessor.SetMergedRootObject(DataFile.Instance.MergedFile);
                    LoadUI();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
            }
        }
Пример #10
0
		protected override IList<QueueProcessor> GetProcessors()
		{
			var p = new MergeProcessor(new MergeShredSettings());
			return new [] { p };
		}
 public void Setup()
 {
     processor = new MergeProcessor<BundleImpl>();
     bundle = new BundleImpl();
 }
Пример #12
0
        public void ShouldReturnIfQueueIsEmpty()
        {
            MergeProcessor processor = new MergeProcessor();

            Models.Graph result = processor.GetFinalResult().Result;;
        }
Пример #13
0
        /// <summary>
        /// Click event handler for the Open button.  This handles finding and opening the XSD file and the CONFIG file.
        /// Will always prompt for CONFIG and only prompts for XSD if it cannot locate it.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenFile_Click(object sender, EventArgs e)
        {
            LoadingLabel.Visible = true;
            var schemaProcessor = new SchemaProcessor();

            DataFile.Instance.SchemaFile = schemaProcessor.ProcessSchema(FilePaths.Instance.SchemaFile);

            if (DataFile.Instance.SchemaFile != null)
            {
                SchemaPath = FilePaths.Instance.SchemaFile;
            }
            else
            {
                var openFile = new OpenFileDialog();
                openFile.Title            = "Select the newrelic.xsd file";
                openFile.InitialDirectory = "c:\\ProgramData\\New Relic\\.Net Agent";
                openFile.FileName         = "newrelic.xsd";
                openFile.Filter           = "xsd files (*.xsd)|*.xsd|All files (*.*)|*.*";
                openFile.FilterIndex      = 0;
                openFile.Multiselect      = false;
                openFile.RestoreDirectory = true;

                if (openFile.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        DataFile.Instance.SchemaFile = schemaProcessor.ProcessSchema(openFile.FileName);
                        SchemaPath = openFile.FileName;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    }
                }
                else
                {
                    TryExportSchema(schemaProcessor);
                }
            }

            if (DataFile.Instance.SchemaFile != null)
            {
                var openFile = new OpenFileDialog();
                openFile.Title            = "Select the newrelic.config file";
                openFile.InitialDirectory = Path.GetDirectoryName(FilePaths.Instance.ConfigFile);
                openFile.FileName         = "newrelic.config";
                openFile.Filter           = "config files (*.config)|*.config|All files (*.*)|*.*";
                openFile.FilterIndex      = 0;
                openFile.Multiselect      = false;
                openFile.RestoreDirectory = true;


                if (openFile.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        var configProcessor = new ConfigProcessor();
                        DataFile.Instance.ConfigFile = configProcessor.ProcessConfig(openFile.FileName);
                        ConfigPath = openFile.FileName;
                        DataFile.Instance.MergedFile = DataFile.Instance.SchemaFile.Clone();
                        var mergeProcessor = new MergeProcessor();
                        mergeProcessor.PrePopulateMergedFile(DataFile.Instance.SchemaFile, DataFile.Instance.MergedFile);
                        mergeProcessor.Merge(DataFile.Instance.ConfigFile);
                        mergeProcessor.SetMergedRootObject(DataFile.Instance.MergedFile);
                        LoadUI();
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    }
                }
                else
                {
                    TryExportConfig();
                }
            }
            LoadingLabel.Visible = false;
        }
Пример #14
0
 public string GetMergedVersion(string original, string modified)
 {
     _mymerger = new MergeProcessor(original, modified);
     return(_mymerger.Merge());
 }
Пример #15
0
 public void Reset()
 {
     _mymerger = null;
 }