示例#1
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;
            }
        }
示例#2
0
        private static int GetDefaultConstructorId(
            [NotNull] ClassDescriptor testClassDescriptor)
        {
            Assert.ArgumentNotNull(testClassDescriptor, nameof(testClassDescriptor));

            Type testType = testClassDescriptor.GetInstanceType();

            var constructorIndex = 0;

            foreach (ConstructorInfo ctorInfo in testType.GetConstructors())
            {
                // return the first non-obsolete
                if (!ReflectionUtils.IsObsolete(ctorInfo))
                {
                    return(constructorIndex);
                }

                constructorIndex++;
            }

            // if there is no non-obsolete constructor, just return the first
            return(0);
        }