示例#1
0
        public static void ValidationTest()
        {
            TypeSet ts = new TypeSet();
            StructDef sd = new StructDef();
            sd.ParentTypeSet = ts;
            sd.Name = "T1";
            sd.Members.Add(new MemberDef("F1", "string", false, false));
            sd.Members.Add(new MemberDef("F2", "int", true, true));

            DataObject dob = new DataObject();
            dob["F1"] = 399;
            List<int> lst = new List<int>();
            lst.AddRange(new int[] {1, 2, 3, 4});
            dob["F2"] = lst;
            dob["F3"] = null;
            dob.Validate(sd);
        }
示例#2
0
 public void ScanTypes(TypeSet types, Registry registry)
 {
     throw new NotImplementedException();
 }
示例#3
0
        public static ReadOnlyCollection <Type> GetTypeSetFromAttribute(IAttributeProvider attributeProvider, TypeSet fallback = TypeSet.SettingsTypes)
        {
            var typeset = GetTypeSet(attributeProvider.GetAttribute <TypeSetAttribute>()?.typeSet ?? fallback);

            return(typeset);
        }
示例#4
0
        private static IParameter CheckBasicMake(string name, Id <Parameter> id, string def, TypeSet t, ParameterType typeId, object document, bool useDefault)
        {
            IParameter parameter = t.Make(typeId, name, id, def, document);

            Assert.That(parameter.TypeId, Is.EqualTo(typeId));
            Assert.That(parameter.Name, Is.EqualTo(name));
            Assert.That(parameter.Id, Is.EqualTo(id));
            if (useDefault)
            {
                Assert.That(parameter.ValueAsString(), Is.EqualTo(def));
            }
            else
            {
                Assert.That(parameter.ValueAsString(), Is.EqualTo(""));
            }
            return(parameter);
        }
示例#5
0
        private static void CheckDynamicEnums(List <DynamicEnumerationData> dynamicEnums, TypeSet t, Action CheckContents, ref ParameterType modifiedType)
        {
            DynamicEnumerationData DE1 = new DynamicEnumerationData("DE1", ParameterType.Parse("89e54648-0572-4de2-82a6-3cdf5ea8aebc"));
            DynamicEnumerationData DE2 = new DynamicEnumerationData("DE2", ParameterType.Parse("17b8ce6a-da16-459e-ab58-c77f62c5eba4"));
            DynamicEnumerationData DE3 = new DynamicEnumerationData("DE3", ParameterType.Parse("882d169d-b697-4ff3-8f4d-d0a3b18549c7"));

            t.AddDynamicEnum(DE1);
            dynamicEnums.Add(DE1);
            Assert.That(modifiedType, Is.EqualTo(DE1.TypeId));
            modifiedType = null;
            CheckContents();

            t.Remove(DE1.TypeId);
            dynamicEnums.Remove(DE1);
            Assert.That(modifiedType, Is.EqualTo(DE1.TypeId));
            modifiedType = null;
            CheckContents();

            t.AddDynamicEnum(DE2);
            dynamicEnums.Add(DE2);
            Assert.That(modifiedType, Is.EqualTo(DE2.TypeId));
            modifiedType = null;
            CheckContents();

            t.AddDynamicEnum(DE3);
            dynamicEnums.Add(DE3);
            Assert.That(modifiedType, Is.EqualTo(DE3.TypeId));
            modifiedType = null;
            CheckContents();

            DynamicEnumerationData DE3Modified = new DynamicEnumerationData("DE3Modified", ParameterType.Parse("882d169d-b697-4ff3-8f4d-d0a3b18549c7"));

            t.RenameType(DE3.TypeId, DE3Modified.Name);
            dynamicEnums[dynamicEnums.IndexOf(DE3)] = DE3Modified;
            Assert.That(modifiedType, Is.EqualTo(DE3Modified.TypeId));
            modifiedType = null;
            CheckContents();
        }
示例#6
0
        public static void Test()
        {
            Random                 random            = new Random(0);
            Func <string>          randomString      = () => "test" + random.NextDouble().ToString(CultureInfo.InvariantCulture);
            Func <Id <Parameter> > randomParameterId = () =>
            {
                byte[] bytes = new byte[16];
                random.NextBytes(bytes);
                return(Id <Parameter> .FromGuid(new Guid(bytes))); //Not really a guid but should be unique enough for this test
            };


            List <DecimalData>                 decimals          = new List <DecimalData>();
            List <IntegerData>                 integers          = new List <IntegerData>();
            List <EnumerationData>             enums             = new List <EnumerationData>();
            List <EnumerationData>             hiddenEnums       = new List <EnumerationData>();
            List <DynamicEnumerationData>      dynamicEnums      = new List <DynamicEnumerationData>();
            List <LocalDynamicEnumerationData> localDynamicEnums = new List <LocalDynamicEnumerationData>();
            List <LocalizedStringData>         localizedStrings  = new List <LocalizedStringData>();
            List <OtherData> others = new List <OtherData>();

            TypeSet t = new TypeSet();

            Action CheckContents = () =>
            {
                foreach (var x in decimals)
                {
                    CheckIs(t, x.TypeId, dec: true);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));

                    IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, x.TypeId, null, true); //This type shouldn't care about document
                    Assert.That(parameter, Is.InstanceOf <IDecimalParameter>());
                    IDecimalParameter p = parameter as IDecimalParameter;
                    Assert.That(p.Min, Is.EqualTo(x.Min));
                    Assert.That(p.Max, Is.EqualTo(x.Max));
                }
                foreach (var x in integers)
                {
                    CheckIs(t, x.TypeId, integer: true);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));

                    IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, x.TypeId, null, true); //This type shouldn't care about document
                    Assert.That(parameter, Is.InstanceOf <IIntegerParameter>());
                    IIntegerParameter p = parameter as IIntegerParameter;
                    Assert.That(p.Min, Is.EqualTo(x.Min));
                    Assert.That(p.Max, Is.EqualTo(x.Max));
                }
                foreach (var x in enums)
                {
                    CheckIs(t, x.TypeId, enumeration: true);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));

                    {
                        IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, x.TypeId, null, true); //This type shouldn't care about document
                        Assert.That(parameter, Is.InstanceOf <IEnumParameter>());
                        IEnumParameter p = parameter as IEnumParameter;
                        Assert.That(p.Options, Is.EquivalentTo(x.Elements.Select(a => a.Guid)));
                    }

                    //Check set parameter creation
                    {
                        IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, ParameterType.ValueSetType.Of(x.TypeId), null, true); //This type shouldn't care about document
                        Assert.That(parameter, Is.InstanceOf <ISetParameter>());
                        ISetParameter p = parameter as ISetParameter;
                        Assert.That(p.Options, Is.EquivalentTo(x.Elements.Select(a => a.Guid)));
                    }
                }
                foreach (var x in dynamicEnums)
                {
                    CheckIs(t, x.TypeId, dynamicEnum: true);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));
                    IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, x.TypeId, null, true); //This type shouldn't care about document
                    Assert.That(parameter, Is.InstanceOf <IDynamicEnumParameter>());
                    IDynamicEnumParameter p = parameter as IDynamicEnumParameter;
                    Assert.That(p.Local, Is.False);
                }
                foreach (var x in localDynamicEnums)
                {
                    CheckIs(t, x.TypeId, localDynamicEnum: true);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));
                    object     document  = new object();
                    IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, x.TypeId, document, true);
                    Assert.That(parameter, Is.InstanceOf <IDynamicEnumParameter>());
                    IDynamicEnumParameter p = parameter as IDynamicEnumParameter;
                    Assert.That(p.Local, Is.True);
                }
                foreach (var x in localizedStrings)
                {
                    CheckIs(t, x.TypeId, localizedString: true);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));
                    object     document  = new object();
                    IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, x.TypeId, document, false);
                    Assert.That(parameter, Is.InstanceOf <ILocalizedStringParameter>());
                }
                foreach (var x in others)
                {
                    CheckIs(t, x.TypeId);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));
                    string     name      = randomString();
                    var        id        = randomParameterId();
                    var        def       = randomString();
                    object     document  = new object();
                    IParameter parameter = CheckBasicMake(name, id, def, t, x.TypeId, document, true);
                    Assert.That(x.LastGeneratorParameters, Is.Not.Null);
                    Assert.That(x.LastGeneratorParameters.name, Is.EqualTo(name));
                    Assert.That(x.LastGeneratorParameters.id, Is.EqualTo(id));
                    Assert.That(x.LastGeneratorParameters.defaultValue, Is.EqualTo(def));
                    Assert.That(x.LastGeneratorParameters.document, Is.EqualTo(document));
                    Assert.That(x.LastGeneratorParameters.createdParameter, Is.EqualTo(parameter));
                    x.LastGeneratorParameters = null;
                }

                Assert.That(t.VisibleDecimals, Is.EquivalentTo(decimals));
                Assert.That(t.VisibleDynamicEnums, Is.EquivalentTo(dynamicEnums));
                CheckEnumsMatch(t.VisibleEnums, enums);
                Assert.That(t.VisibleIntegers, Is.EquivalentTo(integers));
                Assert.That(t.VisibleLocalDynamicEnums, Is.EquivalentTo(localDynamicEnums));
                Assert.That(t.VisibleLocalizedStrings, Is.EquivalentTo(localizedStrings));

                var expected = decimals.Select(x => x.TypeId).
                               Concat(integers.Select(x => x.TypeId)).
                               Concat(enums.Select(x => x.TypeId)).
                               Concat(dynamicEnums.Select(x => x.TypeId)).
                               Concat(localDynamicEnums.Select(x => x.TypeId)).
                               Concat(localizedStrings.Select(x => x.TypeId)).
                               Concat(others.Select(x => x.TypeId)).
                               Concat(enums.Select(x => ParameterType.ValueSetType.Of(x.TypeId))).
                               Concat(hiddenEnums.Select(x => x.TypeId)).          //AllTypes includes hidden types
                               Concat(hiddenEnums.Select(x => ParameterType.ValueSetType.Of(x.TypeId))).
                               ToList();

                Assert.That(t.AllTypes, Is.EquivalentTo(expected));
            };

            ParameterType          modifiedType     = null;
            Action <ParameterType> modifiedCallback = x => { Assert.That(modifiedType, Is.Null); modifiedType = x; };

            t.Modified += modifiedCallback;

            CheckDecimals(decimals, t, CheckContents, ref modifiedType);

            CheckIntegers(integers, t, CheckContents, ref modifiedType);

            CheckEnums(enums, t, CheckContents, ref modifiedType, false);

            CheckEnums(hiddenEnums, t, CheckContents, ref modifiedType, true);

            CheckDynamicEnums(dynamicEnums, t, CheckContents, ref modifiedType);

            CheckLocalDynamicEnums(localDynamicEnums, t, CheckContents, ref modifiedType);

            CheckLocalizedStrings(localizedStrings, t, CheckContents, ref modifiedType);

            CheckOthers(others, t, CheckContents, ref modifiedType);
        }
    private static void AnalyzeConstructorBody(OperationAnalysisContext context)
    {
        IConstructorBodyOperation operation = ((IConstructorBodyOperation)context.Operation);
        Compilation compilation             = context.Compilation;

        TypeSet exceptions = GetIgnoredExceptionSet(compilation);

        IMethodSymbol symbol = operation.GetSymbol();

        if (symbol.IsStatic)
        {
            foreach (CrefSyntax cref in operation.GetDeclarationSyntax().GetDocumentedExceptions())
            {
                Diagnostic diagnostic = Diagnostic.Create(
                    descriptor: Descriptors.StaticConstructorsShouldNotThrowExceptions,
                    location: cref.Ancestors().OfType <XmlNodeSyntax>().FirstOrDefault()?.GetLocation()
                    );

                context.ReportDiagnostic(diagnostic);
            }

            context.ReportUndocumentedExceptions(
                descriptorForThrow: Descriptors.StaticConstructorsShouldNotThrowExceptions,
                descriptorForInvocation: Descriptors.StaticConstructorsShouldCatchCalleeExceptions,
                documented: exceptions,
                exceptions: operation.GetExceptionalOperations(compilation)
                );
        }
        else
        {
            exceptions = exceptions.Add(operation.GetDocumentedExceptions());

            context.ReportUndocumentedExceptions(
                descriptorForThrow: Descriptors.DocumentThrownExceptions,
                descriptorForInvocation: Descriptors.DocumentCalleeExceptions,
                documented: exceptions,
                exceptions: operation.GetExceptionalOperations(compilation)
                );

            if (operation.Initializer is null)
            {
                //
                // HACK: Implicit/compiler-generated calls to parameterless base-class constructors are
                //       not included in the operation hierarchy and need to be handled explicitly.
                //
                if (
                    (symbol is IMethodSymbol constructor) && !constructor.IsStatic &&
                    (constructor.ContainingType is INamedTypeSymbol type) && (type.TypeKind == TypeKind.Class) &&
                    (type.BaseType is INamedTypeSymbol baseType) &&
                    (baseType.GetParameterlessInstanceConstructor() is IMethodSymbol baseParameterlessConstructor)
                    )
                {
                    Location location = operation.GetDeclarationSyntax().GetIdentifierLocations().First();

                    //
                    // TODO: better diagnostic message which refers to the implicit parameterless constructor call
                    //
                    context.ReportUndocumentedExceptions(
                        descriptorForThrow: Descriptors.DocumentThrownExceptions,
                        descriptorForInvocation: Descriptors.DocumentCalleeExceptions,
                        documented: exceptions,
                        exceptions: baseParameterlessConstructor
                        .GetDocumentedExceptions(compilation)
                        .Select(exception => new ExceptionalOperation(location, baseParameterlessConstructor, exception))
                        );
                }
            }
        }
    }
示例#8
0
 void Visitor.Visit(TypeSet type)
 {
     throw new NotImplementedException();
 }
示例#9
0
        public static void Test()
        {
            Dictionary <Id <TConnectorDefinition>, ConnectorDefinitionData> connectorDefinitions = new Dictionary <Id <TConnectorDefinition>, ConnectorDefinitionData>()
            {
                { Id <TConnectorDefinition> .Parse("cc901520-7d05-4274-87d9-b86cf00e6ee4"), new ConnectorDefinitionData("Basdas", Id <TConnectorDefinition> .Parse("9fd8b8af-35f2-4d60-8533-45b065d02057"), new List <NodeData.ParameterData>()
                    {
                    }, ConnectorPosition.Bottom, false) },
                { Id <TConnectorDefinition> .Parse("37e0f309-9a40-4b43-a700-2c723062f982"), new ConnectorDefinitionData("AsdasD", Id <TConnectorDefinition> .Parse("81efd7b0-91c6-4ce1-899e-9a342477a287"), new List <NodeData.ParameterData>()
                    {
                    }, ConnectorPosition.Bottom, false) },
            };

            NodeData.ConnectorData[] connectors = new NodeData.ConnectorData[]
            {
                new NodeData.ConnectorData(Id <TConnector> .Parse("6ae078da-1aad-426d-a6cc-614372319957"), connectorDefinitions.Keys.ElementAt(0), new IParameter[] { new DummyParameter("", Id <Parameter> .Parse("b8426482-8dd1-4b0b-ac00-69fad7bb66a0"), "asd", ParameterType.Parse("2e781d14-a0c7-4908-97a7-20db93588218")) }),
                new NodeData.ConnectorData(Id <TConnector> .Parse("d435ccd6-95a0-46c6-8867-732f6f405fb8"), connectorDefinitions.Keys.ElementAt(1), new IParameter[0]),
            };

            List <NodeData.ConfigData> parameter0Config = new List <NodeData.ConfigData>()
            {
                new NodeData.ConfigData(Id <NodeTypeTemp> .Parse("f174adb6-709a-4632-ba95-aa33706a8886"), new IParameter[0]),
            };

            NodeData.ParameterData[] parameters = new NodeData.ParameterData[]
            {
                new NodeData.ParameterData("parameter name 1", Id <Parameter> .Parse("e335ab11-3ef1-49d8-ba8f-82ebba25aa90"), ParameterType.Parse("78c4517b-bf10-4c7b-8ec1-4edf066e4d0a"), new ReadOnlyCollection <NodeData.ConfigData>(parameter0Config), "A"),
                new NodeData.ParameterData("parameter name 2", Id <Parameter> .Parse("5416af30-e832-4330-9a29-57907c403f5a"), ParameterType.Parse("1957bc04-ff26-415a-9a13-7eca6419b20a"), new ReadOnlyCollection <NodeData.ConfigData>(new List <NodeData.ConfigData>()), null),
            };

            NodeData.ConfigData[] config = new NodeData.ConfigData[]
            {
                new NodeData.ConfigData(Id <NodeTypeTemp> .Parse("e00fc031-1c94-4a67-8631-d8460a6db69e"), new IParameter[0]),
                new NodeData.ConfigData(Id <NodeTypeTemp> .Parse("6b0c0410-48cd-4807-9cbf-00d9b6d823ed"), new IParameter[0]),
            };

            NodeData nodeData = new NodeData("node name", Guid.Parse("9c9fea17-13fb-4eb0-be9b-7ad44a580601"), "node decsription", Id <NodeTypeTemp> .Parse("7ddb7ef4-4ba5-49b5-96bc-e540851ddbf0"), connectors, parameters, config);

            TypeSet types = new TypeSet();

            types.AddOther(parameters[0].Type, "Parameter Type 1", (name, id, defaultValue, d) => new DummyParameter(name, id, defaultValue, parameters[0].Type));
            types.AddOther(parameters[1].Type, "Parameter Type 2", (name, id, defaultValue, d) => new DummyParameter(name, id, defaultValue, parameters[1].Type));

            NodeDataGenerator g = new NodeDataGenerator(nodeData, types, connectorDefinitions, Rules.Instance, a => new List <IParameter>());

            Assert.That(g.Config, Is.EquivalentTo(config));
            Assert.That(g.Name, Is.EqualTo(nodeData.Name));
            Assert.That(g.Guid, Is.EqualTo(nodeData.Guid));
            Assert.That(g.Description, Is.EqualTo(nodeData.Description));
            Assert.That(g.GetParameterConfig(parameters[0].Id), Is.EqualTo(parameter0Config));
            Assert.That(g.GetParameterConfig(parameters[1].Id), Is.EqualTo(new List <NodeData.ConfigData>()));

            //Generate with no parameter data (as if adding a brand new node)
            {
                object document = new object();
                var    nodeId1  = Id <NodeTemp> .Parse("bcc17300-62dc-4625-8245-dafcf9f8ebfa");

                IEnumerable <NodeDataGeneratorParameterData> parameterData = Enumerable.Empty <NodeDataGeneratorParameterData>();
                var node = g.Generate(nodeId1, parameterData, document);
                CheckNode(connectorDefinitions, connectors, parameters, parameterData, g, nodeId1, node);
            }

            //Generate with completely supplied parameter data
            {
                object document = new object();
                var    nodeId1  = Id <NodeTemp> .Parse("cd86cc66-0a9a-42b2-b4de-ce3e2410ce69");

                IEnumerable <NodeDataGeneratorParameterData> parameterData = parameters.Select(p => new NodeDataGeneratorParameterData(p.Id, p.Id.Serialized().Substring(0, 3)));
                var node = g.Generate(nodeId1, parameterData, document);
                CheckNode(connectorDefinitions, connectors, parameters, parameterData, g, nodeId1, node);
            }

            //Generate with partially supplied parameter data and some unrecognised supplied parameter data
            {
                object document = new object();
                var    nodeId1  = Id <NodeTemp> .Parse("cd86cc66-0a9a-42b2-b4de-ce3e2410ce69");

                //Partially supplied data
                IEnumerable <NodeDataGeneratorParameterData> parameterData = parameters.Take(1).Select(p => new NodeDataGeneratorParameterData(p.Id, p.Id.Serialized().Substring(0, 3)));
                //unrecognised data
                parameterData = parameterData.Concat(new NodeDataGeneratorParameterData[] { new NodeDataGeneratorParameterData(Id <Parameter> .Parse("90660d64-0ea7-4125-8f5c-cb845c127061"), "90660d64"),
                                                                                            new NodeDataGeneratorParameterData(Id <Parameter> .Parse("2e49733d-56f7-4b24-a9e8-8cc07ecfc2aa"), "2e49733d") });
                var node = g.Generate(nodeId1, parameterData, document);
                CheckNode(connectorDefinitions, connectors, parameters, parameterData, g, nodeId1, node);
            }

            g.Removed();
            Assert.That(g.Name, Is.EqualTo("Definition Deleted"));
        }
示例#10
0
 public void Visit(TypeSet type)
 {
     WriteCollectionLog(type);
 }
        public void ScanTypes(TypeSet types, Registry registry)
        {
            foreach (var concreteClass in types.FindTypes(TypeClassification.Concretes))
            {
                if (concreteClass.GetInterfaces().Contains(typeof(IBaseEntity)))
                {
                    var listType       = typeof(IEnumerable <>).MakeGenericType(concreteClass);
                    var iQueryableType = typeof(IQueryable <>).MakeGenericType(concreteClass);

                    var genericCreateCommand = typeof(CreateCommand <>).MakeGenericType(concreteClass);
                    var interfaceCreateCommandHandlerType = typeof(IRequestHandler <,>).MakeGenericType(genericCreateCommand, concreteClass);
                    var concreteHandlerTypeCreate         = typeof(CreateCommandHandler <>).MakeGenericType(concreteClass);
                    registry.For(interfaceCreateCommandHandlerType).Use(concreteHandlerTypeCreate);

                    var genericUpdateCommand = typeof(UpdateCommand <>).MakeGenericType(concreteClass);
                    var interfaceUpdateCommandHandlerType = typeof(IRequestHandler <,>).MakeGenericType(genericUpdateCommand, concreteClass);
                    var concreteHandlerTypeUpdate         = typeof(UpdateCommandHandler <>).MakeGenericType(concreteClass);
                    registry.For(interfaceUpdateCommandHandlerType).Use(concreteHandlerTypeUpdate);

                    var genericDeleteCommand = typeof(DeleteEntityCommand <>).MakeGenericType(concreteClass);
                    var interfaceDeleteCommandHandlerType = typeof(IRequestHandler <,>).MakeGenericType(genericDeleteCommand, typeof(bool));
                    var concreteHandlerTypeDelete         = typeof(DeleteEntityCommandHandler <>).MakeGenericType(concreteClass);
                    registry.For(interfaceDeleteCommandHandlerType).Use(concreteHandlerTypeDelete);

                    var genericEntityCommand = typeof(GetEntityCommand <>).MakeGenericType(concreteClass);
                    var interfaceEntityCommandHandlerType = typeof(IRequestHandler <,>).MakeGenericType(genericEntityCommand, concreteClass);
                    var concreteHandlerTypeEntity         = typeof(GetEntityCommandHandler <>).MakeGenericType(concreteClass);
                    registry.For(interfaceEntityCommandHandlerType).Use(concreteHandlerTypeEntity);

                    var genericEntitiesCommand = typeof(GetEntitiesCommand <>).MakeGenericType(concreteClass);
                    var interfaceEntitiesCommandHandlerType = typeof(IRequestHandler <,>).MakeGenericType(genericEntitiesCommand, listType);
                    var concreteHandlerTypeEntities         = typeof(GetEntitiesCommandHandler <>).MakeGenericType(concreteClass);
                    registry.For(interfaceEntitiesCommandHandlerType).Use(concreteHandlerTypeEntities);


                    var listActiveEntitiesCommand             = typeof(ListActiveEntitiesCommand <>).MakeGenericType(concreteClass);
                    var interfaceListActiveCommandHandlerType = typeof(IRequestHandler <,>).MakeGenericType(listActiveEntitiesCommand, listType);

                    var concreteHandlerTypeListActive = typeof(ListActiveEntitiesCommandHandler <>).MakeGenericType(concreteClass);
                    registry.For(interfaceListActiveCommandHandlerType).Use(concreteHandlerTypeListActive);

                    var listEntitiesCommand             = typeof(ListEntitiesCommand <>).MakeGenericType(concreteClass);
                    var interfaceListCommandHandlerType = typeof(IRequestHandler <,>).MakeGenericType(listEntitiesCommand, listType);
                    var concreteHandlerTypeList         = typeof(ListEntitiesCommandHandler <>).MakeGenericType(concreteClass);
                    registry.For(interfaceListCommandHandlerType).Use(concreteHandlerTypeList);

                    var rangeEntitiesCommand = typeof(AddRangeEntitiesCommand <>).MakeGenericType(concreteClass);
                    var interfaceRangeEntitiesCommandHandlerType = typeof(IRequestHandler <,>).MakeGenericType(rangeEntitiesCommand, typeof(bool));
                    var concreteHandlerTypeRangeEntities         = typeof(AddRangeEntitiesCommandHandler <>).MakeGenericType(concreteClass);
                    registry.For(interfaceRangeEntitiesCommandHandlerType).Use(concreteHandlerTypeRangeEntities);

                    var findEntitiesCommand = typeof(FindEntitiesCommand <>).MakeGenericType(concreteClass);
                    var interfaceFindEntitiesCommandHandlerType = typeof(IRequestHandler <,>).MakeGenericType(findEntitiesCommand, iQueryableType);
                    var concreteHandlerTypeFindEntities         = typeof(FindEntitiesCommandHandler <>).MakeGenericType(concreteClass);
                    registry.For(interfaceFindEntitiesCommandHandlerType).Use(concreteHandlerTypeFindEntities);

                    var findByNameCommand = typeof(FindEntityByNameCommand <>).MakeGenericType(concreteClass);
                    var interfaceFindEntitiesByNameCommandHandlerType = typeof(IRequestHandler <,>).MakeGenericType(findByNameCommand, typeof(bool));
                    var concreteHandlerTypeFindEntitiesByName         = typeof(FindEntityByNameCommandHandler <>).MakeGenericType(concreteClass);
                    registry.For(interfaceFindEntitiesByNameCommandHandlerType).Use(concreteHandlerTypeFindEntitiesByName);
                }
            }
        }
示例#12
0
 public void ScanTypes(TypeSet types, Registry registry)
 {
     types.FindTypes(TypeClassification.Interfaces).Each(type => registry.For(type));
 }
示例#13
0
文件: Default.cs 项目: e2wugui/zeze
 void Visitor.Visit(TypeSet type)
 {
     Value = "null";
 }
示例#14
0
 public void ScanTypes(TypeSet types, Registry registry)
 {
     types.FindTypes(TypeClassification.Closed | TypeClassification.Concretes)
     .Where(Registry.IsPublicRegistry)
     .Each(type => registry.Configure(x => x.ImportRegistry(type)));
 }
 /// <summary>
 /// Determine if the type should be registered as a plug-in of T
 /// </summary>
 /// <param name="types"></param>
 /// <returns>True if is a plugged type</returns>
 protected Type Matches(TypeSet types)
 {
     return(types.FindTypes(TypeClassification.Concretes).FirstOrDefault(type => type.CanBeCastTo(PluginType)));
 }
示例#16
0
        protected void LoadPackageDataTypes()
        {
            _packageTypes = new TypeSet();
            XmlReaderSettings rs = new XmlReaderSettings();
            rs.ValidationType = ValidationType.Schema;
            rs.Schemas.XmlResolver = new AssemblyResourceXmlResolver();
            rs.Schemas.Add(ProcessDefinition.WORKFLOW_NAMESPACE, "TypeSetDefinition.xsd");

            foreach (string fileName in _schemaFiles)
            {
                try
                {
                    log.Info("Will load type definitions from file: {0}", fileName);
                    using (Stream stm = DataStore.GetPackageContentStream(fileName))
                    {
                        XmlDocument doc = new XmlDocument();
                        using (XmlReader xr = XmlReader.Create(stm, rs))
                        {
                            doc.Load(xr);
                        }
                        XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                        nsmgr.AddNamespace(string.Empty, ProcessDefinition.WORKFLOW_NAMESPACE);
                        nsmgr.AddNamespace("wf", ProcessDefinition.WORKFLOW_NAMESPACE);
                        _packageTypes.LoadXml(doc.DocumentElement, nsmgr);
                    }
                }
                catch (Exception ex)
                {
                    log.Error("Error loading package schema file: {0}.{1}", PackageName, fileName);
                    throw;
                }
            }
        }
        /// <summary>
        /// Generates usage information for a terminal
        /// </summary>
        public static string HelpOn(ITerminal terminal)
        {         //****************************************
            var  HasCommands  = false;
            var  HasVariables = false;
            var  HasTypes     = false;
            var  Builder      = new StringBuilder();
            bool IsFirst;

            //****************************************

            foreach (var Registry in terminal.Registries)
            {
                HasCommands  |= Registry.Commands.Count > 0;
                HasVariables |= Registry.Variables.Count > 0;
                HasTypes     |= Registry.TypeSets.Count > 0;
            }

            if (HasCommands)
            {
                Builder.AppendLine("Available Commands:").Append("  ");

                IsFirst = true;

                foreach (var Command in
                         terminal.Registries.SelectMany(registry => registry.Commands)
                         .Concat(terminal.Registries.SelectMany(registry => registry.DefaultInstances).SelectMany(instance => instance.Type.Commands))
                         .OrderBy(command => command)
                         )
                {
                    if (IsFirst)
                    {
                        IsFirst = false;
                    }
                    else
                    {
                        Builder.Append(", ");
                    }

                    Builder.Append(Command.ToString());
                }
            }

            if (HasVariables)
            {
                if (Builder.Length > 0)
                {
                    Builder.AppendLine();
                }

                Builder.AppendLine("Available Variables:").Append("  ");

                IsFirst = true;

                foreach (var Variable in
                         terminal.Registries.SelectMany(registry => registry.Variables)
                         .Concat(terminal.Registries.SelectMany(registry => registry.DefaultInstances).SelectMany(instance => instance.Type.Variables))
                         .OrderBy(variable => variable))
                {
                    if (IsFirst)
                    {
                        IsFirst = false;
                    }
                    else
                    {
                        Builder.Append(", ");
                    }

                    Builder.Append(Variable.ToString());
                }
            }

            if (HasTypes)
            {
                if (Builder.Length > 0)
                {
                    Builder.AppendLine();
                }

                Builder.AppendLine("Available Types:").Append("  ");

                IsFirst = true;

                foreach (var TypeSet in terminal.Registries.SelectMany(registry => registry.TypeSets).Where(type => type.HasInstance).OrderBy(type => type))
                {
                    if (IsFirst)
                    {
                        IsFirst = false;
                    }
                    else
                    {
                        Builder.Append(", ");
                    }

                    Builder.Append(TypeSet.ToString());
                }
            }

            return(Builder.ToString());
        }
示例#18
0
文件: Construct.cs 项目: e2wugui/zeze
        public void Visit(TypeSet type)
        {
            String typeName = TypeName.GetName(type);

            sw.WriteLine(prefix + variable.NamePrivate + " = new " + typeName + "(ObjectId + " + variable.Id + ", _v => new Log_" + variable.NamePrivate + "(this, _v));");
        }
    private void AnalyzeSymbolInitializer(OperationAnalysisContext context)
    {
        ISymbolInitializerOperation operation = ((ISymbolInitializerOperation)context.Operation);
        Compilation compilation = context.Compilation;

        ISymbol initializedMember = operation.GetInitializedMembers().First();
        IEnumerable <ExceptionalOperation> initializerExceptions = operation.GetExceptionalOperations(compilation);

        if (initializedMember.IsStatic)
        {
            foreach (ExceptionalOperation initializerException in initializerExceptions)
            {
                context.ReportDiagnostic(Diagnostic.Create(
                                             Descriptors.StaticInitializersShouldNotThrowExceptions,
                                             initializerException.Location
                                             ));
            }
        }
        else
        {
            IEnumerable <IMethodSymbol> initializationConstructors = operation.GetInitializationConstructors();

            TypeSet documentedExceptionsInAllInitializationConstructors = TypeSet.Universal;

            foreach (IMethodSymbol constructor in initializationConstructors)
            {
                TypeSet documentedExceptions = constructor.GetDocumentedExceptionSet(compilation);

                documentedExceptionsInAllInitializationConstructors &= documentedExceptions;

                foreach (ExceptionalOperation exception in initializerExceptions)
                {
                    ITypeSymbol exceptionType = exception.Type;

                    if (!documentedExceptions.Contains(exceptionType))
                    {
                        foreach (Location location in constructor.Locations)
                        {
                            context.ReportDiagnostic(Diagnostic.Create(
                                                         Descriptors.DocumentInstanceMemberInitializerExceptions,
                                                         location,
                                                         exceptionType.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat),
                                                         initializedMember.Name
                                                         ));
                        }
                    }
                }
            }

            // For each exception that isn't documented in all the right places, add an additional diagnostic at the throw/invocation site
            foreach (ExceptionalOperation exception in initializerExceptions)
            {
                Boolean documentedInAllInitializationConstructors =
                    documentedExceptionsInAllInitializationConstructors.Contains(exception.Type);

                if (!documentedInAllInitializationConstructors)
                {
                    context.ReportUndocumentedException(
                        descriptorForThrow: Descriptors.DocumentInstanceMemberInitializerThrownExceptions,
                        descriptorForInvocation: Descriptors.DocumentInstanceMemberInitializerCalleeExceptions,
                        exception: exception
                        );
                }
            }
        }
    }
示例#20
0
 void Visitor.Visit(TypeSet type)
 {
     Name = "Zeze.ByteBuffer.SET";
 }
示例#21
0
 public void ScanTypes(TypeSet types, Registry registry)
 {
 }
 public void ScanTypes(TypeSet types, Registry registry)
 {
     types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed)
     .Where(t => t.CanBeCastTo <Controller>())
     .ForEach(t => registry.For(t).LifecycleIs(new UniquePerRequestLifecycle()));
 }
示例#23
0
        private static void CheckLocalizedStrings(List <LocalizedStringData> localizedStrings, TypeSet t, Action CheckContents, ref ParameterType modifiedType)
        {
            LocalizedStringData string1 = new LocalizedStringData("string1", ParameterType.Parse("03d7b9f3-cc7e-4639-b809-20f92860c041"));
            LocalizedStringData string2 = new LocalizedStringData("repeat", ParameterType.Parse("3f0af919-8c61-4863-9039-9d4b59a2b2e6"));
            LocalizedStringData string3 = new LocalizedStringData("repeat", ParameterType.Parse("3771aec9-a2ea-4f06-a426-fb245de56199"));

            var a = string1;

            t.AddLocalizedString(a);
            localizedStrings.Add(a);
            Assert.That(modifiedType, Is.EqualTo(a.TypeId));
            modifiedType = null;
            CheckContents();

            a = string2;
            t.AddLocalizedString(a);
            localizedStrings.Add(a);
            Assert.That(modifiedType, Is.EqualTo(a.TypeId));
            modifiedType = null;
            CheckContents();

            a = string1;
            t.Remove(a.TypeId);
            localizedStrings.Remove(a);
            Assert.That(modifiedType, Is.EqualTo(a.TypeId));
            modifiedType = null;
            CheckContents();

            a = string3;
            t.AddLocalizedString(a);
            localizedStrings.Add(a);
            Assert.That(modifiedType, Is.EqualTo(a.TypeId));
            modifiedType = null;
            CheckContents();

            LocalizedStringData string2Replacement = new LocalizedStringData("string2 replacement", string2.TypeId);

            t.ModifyLocalizedString(string2Replacement);
            localizedStrings[localizedStrings.IndexOf(string2)] = string2Replacement;
            Assert.That(modifiedType, Is.EqualTo(string2Replacement.TypeId));
            modifiedType = null;
            CheckContents();

            LocalizedStringData string3Replacement = new LocalizedStringData("replacement string 3", string3.TypeId);

            t.RenameType(string3.TypeId, string3Replacement.Name);
            localizedStrings[localizedStrings.IndexOf(string3)] = string3Replacement;
            Assert.That(modifiedType, Is.EqualTo(string3Replacement.TypeId));
            modifiedType = null;
            CheckContents();
        }
示例#24
0
 void Visitor.Visit(TypeSet type)
 {
     ChangeVariableCollectorName = "Zeze.Transaction.ChangeVariableCollectorSet()";
 }
示例#25
0
        private static void CheckLocalDynamicEnums(List <LocalDynamicEnumerationData> dynamicEnums, TypeSet t, Action CheckContents, ref ParameterType modifiedType)
        {
            LocalDynamicEnumerationData DE1 = new LocalDynamicEnumerationData("DE1", ParameterType.Parse("5200fb71-c373-457b-be1d-e11b45ce9d9a"));
            LocalDynamicEnumerationData DE2 = new LocalDynamicEnumerationData("DE2", ParameterType.Parse("ad9e7fd8-a86b-4059-b28a-697774aa3b63"));
            LocalDynamicEnumerationData DE3 = new LocalDynamicEnumerationData("DE3", ParameterType.Parse("f29f7131-e6b7-439b-b1cd-e09a6e1b9897"));

            t.AddLocalDynamicEnum(DE1);
            dynamicEnums.Add(DE1);
            Assert.That(modifiedType, Is.EqualTo(DE1.TypeId));
            modifiedType = null;
            CheckContents();

            t.Remove(DE1.TypeId);
            dynamicEnums.Remove(DE1);
            Assert.That(modifiedType, Is.EqualTo(DE1.TypeId));
            modifiedType = null;
            CheckContents();

            t.AddLocalDynamicEnum(DE2);
            dynamicEnums.Add(DE2);
            Assert.That(modifiedType, Is.EqualTo(DE2.TypeId));
            modifiedType = null;
            CheckContents();

            t.AddLocalDynamicEnum(DE3);
            dynamicEnums.Add(DE3);
            Assert.That(modifiedType, Is.EqualTo(DE3.TypeId));
            modifiedType = null;
            CheckContents();

            LocalDynamicEnumerationData DE3Modified = new LocalDynamicEnumerationData("DE3Modified", ParameterType.Parse("f29f7131-e6b7-439b-b1cd-e09a6e1b9897"));

            t.RenameType(DE3.TypeId, DE3Modified.Name);
            dynamicEnums[dynamicEnums.IndexOf(DE3)] = DE3Modified;
            Assert.That(modifiedType, Is.EqualTo(DE3Modified.TypeId));
            modifiedType = null;
            CheckContents();
        }
 public void ScanTypes(TypeSet types, Registry registry)
 {
     types.FindTypes(TypeClassification.Concretes);
 }
示例#27
0
 public TypeSetAttribute(TypeSet typeSet)
 {
     this.typeSet = typeSet;
 }
示例#28
0
 public void ScanTypes(TypeSet types, StructureMap.Registry registry)
 {
 }
示例#29
0
 public void ScanTypes(TypeSet types, Registry registry)
 {
     types.FindTypes(TypeClassification.Concretes | TypeClassification.Closed)
     .Where(_filter)
     .Each(type => Process(type, registry));
 }
示例#30
0
        private static int RenameNamelessNamespace(TypeSet types, string filename)
        {
            int count = 0;

            using (FileStream fs = File.OpenRead(filename))
                using (FileStream copy = File.Open(@"D:\Program Files (x86)\Steam\steamapps\common\TerraTech Beta\TerraTechWin64_Data\" + filename, FileMode.Create))
                {
                    FlexReader reader = new FlexReader(fs)
                    {
                        IsLittleEndian = false
                    };
                    FlexWriter writer = new FlexWriter(copy)
                    {
                        IsLittleEndian = false
                    };
                    var readerContext = new ReaderContext(types, reader);
                    var writerContext = new WriterContext(types, writer, readerContext.Scope);

                    var header     = Header.FromStream(fs, types);
                    var meta       = Metadata.FromStream(fs, types, header);
                    var collection = AssetCollection.FromStream(fs, types, header, meta);

                    var monoScriptDef  = types["MonoScript"];
                    var monoManagerDef = types["MonoManager"];
                    var assemblies     = new HashSet <string>();
                    foreach (Asset asset in collection)
                    {
                        if (asset.ClassID == AssetCode.MonoScript)
                        {
                            using (var ms = new MemoryStream(asset.Data))
                            {
                                var scriptReader = new FlexReader(ms)
                                {
                                    IsLittleEndian = !header.IsBigEndian
                                };
                                var scriptReaderContext = new ReaderContext(types, scriptReader);
                                scriptReaderContext.Scope.GlobalFrame["Format"] = header.Format;
                                var scriptJson = monoScriptDef.Read(scriptReaderContext);
                                var script     = scriptJson.ToObject <MonoScript>();
                                if (script.AssemblyName == "Assembly-CSharp.dll" && script.Namespace.Length == 0)
                                {
                                    if (script.ClassName.StartsWith("uScript"))
                                    {
                                        script.Namespace = "TerraTech.uScript";
                                    }
                                    else if (script.ClassName.StartsWith("Man"))
                                    {
                                        script.Namespace = "TerraTech.Managers";
                                    }
                                    else if (script.ClassName.StartsWith("Mission"))
                                    {
                                        script.Namespace = "TerraTech.uScript.Missions";
                                    }

                                    using (var newMS = new MemoryStream())
                                    {
                                        var scriptWriter = new FlexWriter(newMS)
                                        {
                                            IsLittleEndian = !header.IsBigEndian
                                        };
                                        var scriptWriterContext = new WriterContext(types, scriptWriter);
                                        scriptWriterContext.Scope.GlobalFrame["Format"] = header.Format;
                                        var newJson = JObject.FromObject(script);
                                        monoScriptDef.Write(newJson, scriptWriterContext);
                                        asset.Data = newMS.ToArray();
                                    }
                                    count++;
                                }
                            }
                        }
                        else if (asset.ClassID == AssetCode.MonoManager)
                        {
                            using (var ms = new MemoryStream(asset.Data))
                            {
                                var scriptReader = new FlexReader(ms)
                                {
                                    IsLittleEndian = !header.IsBigEndian
                                };
                                var scriptReaderContext = new ReaderContext(types, scriptReader);
                                scriptReaderContext.Scope.GlobalFrame["Format"] = header.Format;
                                var scriptJson = monoManagerDef.Read(scriptReaderContext);
                                var manager    = scriptJson.ToObject <MonoManager>();
                            }
                        }
                    }

                    collection.WriteTo(copy, types, header, meta);
                }
            return(count);
        }
示例#31
0
 public ModifyTypeParameters(TypeSet typeSet, ITarget targetWrapper)
 {
     this.typeSet       = typeSet;
     this.targetWrapper = targetWrapper;
 }
示例#32
0
 public abstract void ScanTypes(TypeSet types, Registry registry);