Beispiel #1
0
        private object GetOneDatabaseEntity <T>()
        {
            //if there are not exactly 1 database entity
            if (DatabaseEntities == null)
            {
                return(null);
            }

            if (DatabaseEntities.Count != 1)
            {
                var latest = NewObjectPool.Latest(DatabaseEntities.Where(d => d is T));

                if (latest == null)
                {
                    _logger.Warn($"Pattern matched {DatabaseEntities.Count} objects '{RawValue}':{Environment.NewLine} {string.Join(Environment.NewLine, DatabaseEntities)}");
                }

                return(latest);
            }

            //return the single object as the type you want e.g. ICheckable
            if (DatabaseEntities[0] is T)
            {
                return(DatabaseEntities.Single());
            }

            //it's not ICheckable, user made an invalid object selection
            throw new CommandLineObjectPickerParseException($"Specified object was not an '{typeof(T)}''", Index, RawValue);
        }
Beispiel #2
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)));
            }
        }
        /// <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);
                    }
                }
            }
        }
Beispiel #4
0
 void Awake()
 {
     //static variable
     current = this;
 }