Exemplo n.º 1
0
        public void CanInstantiateWithType()
        {
            var descriptor = new ClassDescriptor(typeof(TestClass));

            var target = descriptor.CreateInstance <TestClass>("someName", 99);

            Assert.AreEqual("ProSuite.DomainModel.Core.Test.TestClass", descriptor.TypeName);
            Assert.AreEqual("ProSuite.DomainModel.Core.Test", descriptor.AssemblyName);

            Assert.AreEqual("someName", target.Name);
            Assert.AreEqual(99, target.Number);
        }
Exemplo n.º 2
0
        public void CanInstantiateWithoutParameters()
        {
            var descriptor =
                new ClassDescriptor(
                    "ProSuite.DomainModel.Core.ClassDescriptor",
                    "ProSuite.DomainModel.Core");
            var target = descriptor.CreateInstance <ClassDescriptor>();

            Assert.IsNotNull(target);
            Assert.IsNull(target.AssemblyName);
            Assert.IsNull(target.TypeName);
        }
Exemplo n.º 3
0
        public void CanInstantiateWithParameters()
        {
            const string typeName     = "someTypeName";
            const string assemblyName = "someAssemblyName";

            var descriptor =
                new ClassDescriptor(
                    "ProSuite.DomainModel.Core.ClassDescriptor",
                    "ProSuite.DomainModel.Core");
            var target =
                descriptor.CreateInstance <ClassDescriptor>(typeName, assemblyName);

            Assert.IsNotNull(target);
            Assert.AreEqual(typeName, target.TypeName);
            Assert.IsNotNull(assemblyName, target.AssemblyName);
        }
Exemplo n.º 4
0
        public static IWorkList Create([NotNull] XmlWorkListDefinition definition)
        {
            Assert.ArgumentNotNull(definition, nameof(definition));

            var descriptor = new ClassDescriptor(definition.TypeName, definition.AssemblyName);

            Type type = descriptor.GetInstanceType();

            Dictionary <Geodatabase, List <Table> > tablesByGeodatabase = GetTablesByGeodatabase(definition.Workspaces);

            IRepository         stateRepository;
            IWorkItemRepository repository;

            if (type == typeof(IssueWorkList))
            {
                stateRepository = new XmlWorkItemStateRepository(definition.Path, definition.Name, type, definition.CurrentIndex);
                repository      = new IssueItemRepository(tablesByGeodatabase, stateRepository);
            }
            else if (type == typeof(SelectionWorkList))
            {
                stateRepository = new XmlWorkItemStateRepository(definition.Path, definition.Name, type, definition.CurrentIndex);

                Dictionary <long, Table> tablesById =
                    tablesByGeodatabase.Values
                    .SelectMany(table => table)
                    .ToDictionary(table => new GdbTableIdentity(table).Id, table => table);

                Dictionary <Table, List <long> > oidsByTable = GetOidsByTable(definition.Items, tablesById);

                repository = new SelectionItemRepository(tablesByGeodatabase, oidsByTable, stateRepository);
            }
            else
            {
                throw new ArgumentException("Unkown work list type");
            }

            try
            {
                return(descriptor.CreateInstance <IWorkList>(repository, definition.Name));
            }
            catch (Exception e)
            {
                _msg.Error("Cannot create work list", e);
                throw;
            }
        }