Ejemplo n.º 1
0
        public void TwoCataloguesWithSameName_WithSession()
        {
            SetupMEF();

            using (NewObjectPool.StartSession())
            {
                var cata1 = new Catalogue(Repository, "Hey");

                // When there is only one object we can pick it by name
                var picker = new CommandLineObjectPicker(new string[] { "Catalogue:Hey" }, GetActivator());
                Assert.IsTrue(picker.HasArgumentOfType(0, typeof(Catalogue)));
                Assert.AreEqual(cata1, picker.Arguments.First().GetValueForParameterOfType(typeof(Catalogue)));

                // There are now 2 objects with the same name but because we are in a session we can pick the latest
                var cata2   = new Catalogue(Repository, "Hey");
                var picker2 = new CommandLineObjectPicker(new string[] { "Catalogue:Hey" }, GetActivator());

                Assert.IsTrue(picker2.HasArgumentOfType(0, typeof(Catalogue)));
                Assert.AreEqual(cata2, picker2.Arguments.First().GetValueForParameterOfType(typeof(Catalogue)));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs all commands in the provided script
        /// </summary>
        /// <param name="script">Location of the file to run</param>
        /// <param name="repositoryLocator"></param>
        private void RunScript(RdmpScript script, IRDMPPlatformRepositoryServiceLocator repositoryLocator)
        {
            if ((script.Commands?.Length ?? 0) == 0)
            {
                throw new ArgumentException("script was empty", nameof(script));
            }

            using (script.UseScope ? NewObjectPool.StartSession() : null)
            {
                foreach (string s in script.Commands)
                {
                    try
                    {
                        var cmd = GetCommandAndPickerFromLine(s, out _picker, repositoryLocator);
                        RunCommand(cmd);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception($"Error executing script.  Problem line was '{s}':{ex.Message}", ex);
                    }
                }
            }
        }