示例#1
0
        public TypeData(Type type, string elementName, bool isPrimitive)
        {
            this.type         = type;
            this.elementName  = elementName;
            this.typeName     = type.Name;
            this.fullTypeName = type.FullName.Replace('+', '.');

            if (isPrimitive)
            {
                sType = SchemaTypes.Primitive;
            }
            else
            {
                if (type.IsEnum)
                {
                    sType = SchemaTypes.Enum;
                }
                else if (typeof(IXmlSerializable).IsAssignableFrom(type))
                {
                    sType = SchemaTypes.XmlSerializable;
                }
                else if (typeof(System.Xml.XmlNode).IsAssignableFrom(type))
                {
                    sType = SchemaTypes.XmlNode;
                }
                else if (type.IsArray || typeof(IEnumerable).IsAssignableFrom(type))
                {
                    sType = SchemaTypes.Array;
                }
                else
                {
                    sType = SchemaTypes.Class;
                }
            }
        }
示例#2
0
 protected void TryAddType(SchemaType schemaType, bool doNotAddErrorForEmptyName)
 {
     SchemaManager.SchemaTypes.Add(
         schemaType, doNotAddErrorForEmptyName,
         Strings.TypeNameAlreadyDefinedDuplicate);
     SchemaTypes.Add(schemaType);
 }
示例#3
0
 static void AddSchemaTypes(DiscoveryVersion discoveryVersion, SchemaTypes typesFound, XmlSchema discoverySchema)
 {
     if ((typesFound & SchemaTypes.ProbeMatchType) == 0)
     {
         AddProbeMatchType(discoveryVersion, discoverySchema);
     }
     if ((typesFound & SchemaTypes.ProbeType) == 0)
     {
         AddProbeType(discoveryVersion, discoverySchema);
     }
     if ((typesFound & SchemaTypes.ResolveType) == 0)
     {
         AddResolveType(discoveryVersion, discoverySchema);
     }
     if ((typesFound & SchemaTypes.QNameListType) == 0)
     {
         AddQNameListType(discoveryVersion, discoverySchema);
     }
     if ((typesFound & SchemaTypes.ScopesType) == 0)
     {
         AddScopesType(discoveryVersion, discoverySchema);
     }
     if ((typesFound & SchemaTypes.UriListType) == 0)
     {
         AddUriListType(discoveryVersion, discoverySchema);
     }
 }
        /// <summary>
        /// Load Schemas from data source
        /// </summary>
        /// <returns>Schemas</returns>
        public virtual async Task<IEnumerable<ISchema>> Schemas(SchemaTypes type = SchemaTypes.StoredProcedure)
        {
            var sql = this.statements.Get(type);

            var ds = await this.executor.Query(sql);
            return ds.Models<Schema>();
        }
示例#5
0
        public IEnumerable <PropertyDeclarationSyntax> GeneratePropertyDeclarations(SourceFileContext ctx)
        {
            var propertyTyp = SchemaTypes.GetTypFromSchema(Parent.Package, _schema, Name, ctx.CurrentTyp, inParameter: false);

            if (propertyTyp.FullName == "System.Nullable<System.DateTime>")
            {
                // DateTime values generate two properties: one raw as a string, and one DateTime version.
                var rawProperty = AutoProperty(Modifier.Public | Modifier.Virtual, ctx.Type <string>(), PropertyName + "Raw", hasSetter: true)
                                  .WithAttribute(ctx.Type <JsonPropertyAttribute>())(Name);
                if (_schema.Description is object)
                {
                    rawProperty = rawProperty.WithXmlDoc(XmlDoc.Summary(_schema.Description));
                }
                yield return(rawProperty);

                var valueParameter = Parameter(ctx.Type(propertyTyp), "value");
                yield return(Property(Modifier.Public | Modifier.Virtual, ctx.Type(propertyTyp), PropertyName)
                             .WithAttribute(ctx.Type <JsonIgnoreAttribute>())()
                             .WithXmlDoc(XmlDoc.Summary(XmlDoc.SeeAlso(ctx.Type <DateTime>()), " representation of ", rawProperty, "."))
                             .WithGetBody(Return(ctx.Type(typeof(Utilities)).Call(nameof(Utilities.GetDateTimeFromString))(rawProperty)))
                             .WithSetBody(rawProperty.Assign(ctx.Type(typeof(Utilities)).Call(nameof(Utilities.GetStringFromDateTime))(valueParameter))));
            }
            else
            {
                var property = AutoProperty(Modifier.Public | Modifier.Virtual, ctx.Type(propertyTyp), PropertyName, hasSetter: true)
                               .WithAttribute(ctx.Type <JsonPropertyAttribute>())(Name);
                if (_schema.Description is object)
                {
                    property = property.WithXmlDoc(XmlDoc.Summary(_schema.Description));
                }
                yield return(property);
            }
        }
示例#6
0
 protected void TryAddContainer(SchemaType schemaType, bool doNotAddErrorForEmptyName)
 {
     SchemaManager.SchemaTypes.Add(
         schemaType, doNotAddErrorForEmptyName,
         Strings.EntityContainerAlreadyExists);
     SchemaTypes.Add(schemaType);
 }
示例#7
0
        protected void AddFunctionType(Function function)
        {
            var space = DataModel == SchemaDataModelOption.EntityDataModel ? "Conceptual" : "Storage";

            if (SchemaVersion >= XmlConstants.EdmVersionForV2 &&
                SchemaManager.SchemaTypes.ContainsKey(function.FQName))
            {
                function.AddError(
                    ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error,
                    Strings.AmbiguousFunctionAndType(function.FQName, space));
            }
            else
            {
                var error = SchemaManager.SchemaTypes.TryAdd(function);
                Debug.Assert(error != AddErrorKind.MissingNameError, "Function identity can never be null while adding global functions");

                if (error != AddErrorKind.Succeeded)
                {
                    function.AddError(
                        ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error,
                        Strings.AmbiguousFunctionOverload(function.FQName, space));
                }
                else
                {
                    SchemaTypes.Add(function);
                }
            }
        }
 public void DeselectAllBoundOperations()
 {
     foreach (var boundOperation in SchemaTypes.SelectMany(x => x.BoundOperations))
     {
         boundOperation.IsSelected = false;
     }
 }
        /// <summary>
        /// Load data from Database, and return the models.
        /// </summary>
        /// <returns>Schemas to process</returns>
        public virtual async Task<IEnumerable<IDefinition>> Load(SchemaTypes type = SchemaTypes.StoredProcedure)
        {
            var schemas = await this.Schemas(type);

            var definitions = this.Minimize(schemas);

            return this.BuildManifest(definitions, schemas);
        }
示例#10
0
 internal TypeData(string typeName, string fullTypeName, string xmlType, SchemaTypes schemaType, TypeData listItemTypeData)
 {
     this.elementName      = xmlType;
     this.typeName         = typeName;
     this.fullTypeName     = fullTypeName.Replace('+', '.');
     this.listItemTypeData = listItemTypeData;
     this.sType            = schemaType;
 }
示例#11
0
		internal TypeData (string typeName, string fullTypeName, string xmlType, SchemaTypes schemaType, TypeData listItemTypeData)
		{
			this.elementName = xmlType;
			this.typeName = typeName;
			this.fullTypeName = fullTypeName.Replace ('+', '.');
			this.listItemTypeData = listItemTypeData;
			this.sType = schemaType;
		}
示例#12
0
        public TypeData(Type type, string elementName, bool isPrimitive, TypeData mappedType, XmlSchemaPatternFacet facet)
        {
#if NET_2_0
            if (type.IsGenericTypeDefinition)
            {
                throw new InvalidOperationException("Generic type definition cannot be used in serialization. Only specific generic types can be used.");
            }
#endif
            this.mappedType   = mappedType;
            this.facet        = facet;
            this.type         = type;
            this.typeName     = type.Name;
            this.fullTypeName = type.FullName.Replace('+', '.');

            if (isPrimitive)
            {
                sType = SchemaTypes.Primitive;
            }
            else
            {
                if (type.IsEnum)
                {
                    sType = SchemaTypes.Enum;
                }
                else if (typeof(IXmlSerializable).IsAssignableFrom(type))
                {
                    sType = SchemaTypes.XmlSerializable;
                }
#if !MOONLIGHT
                else if (typeof(System.Xml.XmlNode).IsAssignableFrom(type))
                {
                    sType = SchemaTypes.XmlNode;
                }
#endif
                else if (type.IsArray || typeof(IEnumerable).IsAssignableFrom(type))
                {
                    sType = SchemaTypes.Array;
                }
                else
                {
                    sType = SchemaTypes.Class;
                }
            }

            if (IsListType)
            {
                this.elementName = TypeTranslator.GetArrayName(ListItemTypeData.XmlType);
            }
            else
            {
                this.elementName = elementName;
            }

            if (sType == SchemaTypes.Array || sType == SchemaTypes.Class)
            {
                hasPublicConstructor = !type.IsInterface && (type.IsArray || type.GetConstructor(Type.EmptyTypes) != null || type.IsAbstract || type.IsValueType);
            }
        }
示例#13
0
        public static XmlQualifiedName EnsureProbeMatchSchema(DiscoveryVersion discoveryVersion, XmlSchemaSet schemaSet)
        {
            Fx.Assert(schemaSet != null, "The schemaSet must be non null.");
            Fx.Assert(discoveryVersion != null, "The discoveryVersion must be non null.");

            // ensure that EPR is added to the schema.
            if (discoveryVersion == DiscoveryVersion.WSDiscoveryApril2005 || discoveryVersion == DiscoveryVersion.WSDiscoveryCD1)
            {
                EndpointAddressAugust2004.GetSchema(schemaSet);
            }
            else if (discoveryVersion == DiscoveryVersion.WSDiscovery11)
            {
                EndpointAddress10.GetSchema(schemaSet);
            }
            else
            {
                Fx.Assert("The discoveryVersion is not supported.");
            }

            // do not add/find Probe related schema items
            SchemaTypes    typesFound    = SchemaTypes.ProbeType | SchemaTypes.ResolveType;
            SchemaElements elementsFound = SchemaElements.None;

            XmlSchema   discoverySchema  = null;
            ICollection discoverySchemas = schemaSet.Schemas(discoveryVersion.Namespace);

            if ((discoverySchemas == null) || (discoverySchemas.Count == 0))
            {
                discoverySchema = CreateSchema(discoveryVersion);
                AddImport(discoverySchema, discoveryVersion.Implementation.WsaNamespace);
                schemaSet.Add(discoverySchema);
            }
            else
            {
                foreach (XmlSchema schema in discoverySchemas)
                {
                    discoverySchema = schema;
                    if (schema.SchemaTypes.Contains(discoveryVersion.Implementation.QualifiedNames.ProbeMatchType))
                    {
                        typesFound |= SchemaTypes.ProbeMatchType;
                        break;
                    }

                    LocateSchemaTypes(discoveryVersion, schema, ref typesFound);
                    LocateSchemaElements(discoveryVersion, schema, ref elementsFound);
                }
            }

            if ((typesFound & SchemaTypes.ProbeMatchType) != SchemaTypes.ProbeMatchType)
            {
                AddSchemaTypes(discoveryVersion, typesFound, discoverySchema);
                AddElements(discoveryVersion, elementsFound, discoverySchema);
                schemaSet.Reprocess(discoverySchema);
            }

            return(discoveryVersion.Implementation.QualifiedNames.ProbeMatchType);
        }
示例#14
0
        /// <summary>
        /// Executed when entering the page for selecting schema types.
        /// It fires PageEntering event which ensures all types are loaded on the UI.
        /// It also ensures all related entities are computed and cached.
        /// </summary>
        /// <param name="args">Event arguments being passed to the method.</param>
        public override async Task OnPageEnteringAsync(WizardEnteringArgs args)
        {
            this.IsEntered = true;
            await base.OnPageEnteringAsync(args);

            View = new SchemaTypes()
            {
                DataContext = this
            };
            PageEntering?.Invoke(this, EventArgs.Empty);
        }
示例#15
0
 internal TypeData(string typeName, string fullTypeName, string xmlType, SchemaTypes schemaType, TypeData listItemTypeData)
 {
     this.hasPublicConstructor = true;
     base..ctor();
     this.elementName          = xmlType;
     this.typeName             = typeName;
     this.fullTypeName         = fullTypeName.Replace('+', '.');
     this.listItemTypeData     = listItemTypeData;
     this.sType                = schemaType;
     this.hasPublicConstructor = true;
 }
 /// <summary>
 /// Get SQL Schema Statement
 /// </summary>
 /// <param name="type">Schema Type</param>
 /// <returns>Schema Select Statement</returns>
 public virtual string Get(SchemaTypes type = SchemaTypes.StoredProcedure)
 {
     switch (type)
     {
         case SchemaTypes.StoredProcedure:
             return StoredProcedures;
         case SchemaTypes.Table:
             return Tables;
         default:
             throw new ArgumentException("Unknown schema type.");
     }
 }
示例#17
0
        /// <summary>
        /// Resolve the type - if the type is not found, return appropriate error
        /// </summary>
        /// <returns></returns>
        public bool TryResolveType(string namespaceName, string typeName, out SchemaType schemaType)
        {
            // For resolving entity container names, namespace can be null
            string fullyQualifiedName = String.IsNullOrEmpty(namespaceName) ? typeName : namespaceName + "." + typeName;

            schemaType = SchemaTypes.LookUpEquivalentKey(fullyQualifiedName);
            if (schemaType != null)
            {
                return(true);
            }

            return(false);
        }
示例#18
0
        /// <summary>
        /// Determines how code referring to this data model should be refer to it; this takes
        /// into account whether it's a placeholder, an array etc.
        /// </summary>
        internal Typ GetTypForReference()
        {
            var ret = IsPlaceholder ? Typ.Of <object>() : Typ;

            if (IsArray)
            {
                ret = Typ.Generic(typeof(IList <>), ret);
            }
            if (_schema.AdditionalProperties is object)
            {
                ret = SchemaTypes.GetTypFromAdditionalProperties(Package, _schema.AdditionalProperties, Name, ret, inParameter: false);
            }
            return(ret);
        }
示例#19
0
        /// <summary>
        /// Create
        /// </summary>
        /// <param name="type">Type</param>
        /// <param name="name">Name</param>
        /// <param name="statement">Statement</param>
        /// <returns>Success</returns>
        public virtual async Task<bool> Create(SchemaTypes type, string name, string statement)
        {
            var exists = (from t in await this.reader.Load(type)
                          where t.Name == name
                           && t.Preface == SqlStatements.Schema
                          select true).FirstOrDefault();
            if (!exists)
            {
                Trace.TraceInformation("Creating {0} to load data into table: '{1}'.", type, this.tableName);

                return await this.executor.NonQuery(statement) == -1;
            }

            return true;
        }
示例#20
0
        /// <summary>
        /// Create
        /// </summary>
        /// <param name="type">Type</param>
        /// <param name="name">Name</param>
        /// <param name="statement">Statement</param>
        /// <returns>Success</returns>
        public virtual async Task <bool> Create(SchemaTypes type, string name, string statement)
        {
            var exists = (from t in await this.reader.Load(type)
                          where t.Name == name &&
                          t.Preface == SqlStatements.Schema
                          select true).FirstOrDefault();

            if (!exists)
            {
                Trace.TraceInformation("Creating {0} to load data into table: '{1}'.", type, this.tableName);

                return(await this.executor.NonQuery(statement) == -1);
            }

            return(true);
        }
示例#21
0
        public ParameterModel(PackageModel package, string name, JsonSchema schema, Typ parentTyp)
        {
            Name = name;
            CodeParameterName = name.ToLocalVariableName(package);

            // It's unclear why these properties don't get the "__" treatment, but apparently they don't.
            PropertyName = name.ToMemberName(addUnderscoresToEscape: false);
            Location     = schema.Location switch
            {
                "query" => RequestParameterType.Query,
                "path" => RequestParameterType.Path,
                _ => throw new InvalidOperationException($"Unhandled parameter location: '{_schema.Location}'")
            };
            EnumModel = schema.Enum__ is object?new EnumModel(name, schema) : null;
            _schema   = schema;
            Typ       = SchemaTypes.GetTypFromSchema(package, schema, name, currentTyp: parentTyp, inParameter: true);
        }
        /// <summary>
        /// Executed when entering the page for selecting schema types.
        /// It fires PageEntering event which ensures all types are loaded on the UI.
        /// It also ensures all related entities are computed and cached.
        /// </summary>
        /// <param name="args">Event arguments being passed to the method.</param>
        public override async Task OnPageEnteringAsync(WizardEnteringArgs args)
        {
            this.IsEntered = true;
            await base.OnPageEnteringAsync(args).ConfigureAwait(false);

            View = new SchemaTypes()
            {
                DataContext = this
            };
            PageEntering?.Invoke(this, EventArgs.Empty);
            if (this.View is SchemaTypes view)
            {
                view.SelectedSchemaTypesCount.Text     = SchemaTypes.Count(x => x.IsSelected).ToString(CultureInfo.InvariantCulture);
                view.SelectedBoundOperationsCount.Text = SchemaTypes
                                                         .Where(x => x.IsSelected && x.BoundOperations?.Any() == true).SelectMany(x => x.BoundOperations)
                                                         .Count(x => x.IsSelected).ToString(CultureInfo.InvariantCulture);
            }
        }
示例#23
0
    internal void CompleteSchema(
        SchemaTypesDefinition schemaTypesDefinition)
    {
        if (schemaTypesDefinition is null)
        {
            throw new ArgumentNullException(nameof(schemaTypesDefinition));
        }

        if (_sealed)
        {
            throw new InvalidOperationException(
                      "This schema is already sealed and cannot be mutated.");
        }

        DirectiveTypes  = schemaTypesDefinition.DirectiveTypes;
        _types          = new SchemaTypes(schemaTypesDefinition);
        _directiveTypes = DirectiveTypes.ToDictionary(t => t.Name);
        _sealed         = true;
    }
示例#24
0
        public static XmlQualifiedName EnsureProbeSchema(DiscoveryVersion discoveryVersion, XmlSchemaSet schemaSet)
        {
            Fx.Assert(schemaSet != null, "The schemaSet must be non null.");
            Fx.Assert(discoveryVersion != null, "The discoveryVersion must be non null.");

            // do not find/add ProbeMatch related schema items
            SchemaTypes    typesFound    = SchemaTypes.ProbeMatchType | SchemaTypes.ResolveType;
            SchemaElements elementsFound = SchemaElements.XAddrs | SchemaElements.MetadataVersion;

            XmlSchema   discoverySchema  = null;
            ICollection discoverySchemas = schemaSet.Schemas(discoveryVersion.Namespace);

            if ((discoverySchemas == null) || (discoverySchemas.Count == 0))
            {
                discoverySchema = CreateSchema(discoveryVersion);
                schemaSet.Add(discoverySchema);
            }
            else
            {
                foreach (XmlSchema schema in discoverySchemas)
                {
                    discoverySchema = schema;
                    if (schema.SchemaTypes.Contains(discoveryVersion.Implementation.QualifiedNames.ProbeType))
                    {
                        typesFound |= SchemaTypes.ProbeType;
                        break;
                    }

                    LocateSchemaTypes(discoveryVersion, schema, ref typesFound);
                    LocateSchemaElements(discoveryVersion, schema, ref elementsFound);
                }
            }

            if ((typesFound & SchemaTypes.ProbeType) != SchemaTypes.ProbeType)
            {
                AddSchemaTypes(discoveryVersion, typesFound, discoverySchema);
                AddElements(discoveryVersion, elementsFound, discoverySchema);
                schemaSet.Reprocess(discoverySchema);
            }

            return(discoveryVersion.Implementation.QualifiedNames.ProbeType);
        }
示例#25
0
        public async Task GetSchemaTypesSuccess()
        {
            SchemaTypes expectedSchemaTypes = new SchemaTypes
            {
                AvailableSchemaTypes = new string[]
                {
                    "achievements", "userstats"
                }
            };

            Uri uri = new Uri(new Uri(ClientSettings.Singleton.XConEndpoint), "/schema");

            this.mockHandler.Expect(uri.ToString())
            .Respond(res => this.ExpectedJsonResponse(expectedSchemaTypes));

            ConfigResponse <IEnumerable <string> > schemaTypes = await ConfigurationManager.GetSchemaTypesAsync();

            Assert.AreEqual(DefaultCorrelationVector, schemaTypes.CorrelationId);
            Assert.AreEqual(2, schemaTypes.Result.Count());
        }
        private Schema InitSchema(IGraphQLClient gqlClient)
        {
            var request = new GraphQLRequest {
                Query = GetIntrospectionQuery()
            };

            var result = Task.Run(async() => await gqlClient.SendQueryAsync <JObject>(request, CancellationToken.None))
                         .GetAwaiter()
                         .GetResult()
                         .Data;

            var queryType = (JObject)result["__schema"]["queryType"];
            var types     = ((JArray)result["__schema"]["types"]).Cast <JObject>().ToArray();

            var dummySchema = new Schema();

            dummySchema.Initialize();
            var schemaTypes = new SchemaTypes(dummySchema, new DefaultServiceProvider());
            var cache       = new Dictionary <string, IGraphType>();

            var qt = ResolveGraphType(_ => schemaTypes[_] ?? (cache.ContainsKey(_) ? cache[_] : null), types, queryType, cache);

            var commonTypes = cache.Values.ToArray();

            foreach (var type in types)
            {
                ResolveGraphType(_ => schemaTypes[_] ?? (cache.ContainsKey(_) ? cache[_] : null), types, type, cache);
            }

            var newSchema = new Schema();

            newSchema.Query = (IObjectGraphType)qt;

            foreach (var type in cache.Values.Except(commonTypes))
            {
                newSchema.RegisterType(type);
            }

            newSchema.Initialize();
            return(newSchema);
        }
示例#27
0
文件: TypeData.cs 项目: jkells/mono
		public TypeData (Type type, string elementName, bool isPrimitive, TypeData mappedType, XmlSchemaPatternFacet facet)
		{
#if NET_2_0
			if (type.IsGenericTypeDefinition)
				throw new InvalidOperationException ("Generic type definition cannot be used in serialization. Only specific generic types can be used.");
#endif
			this.mappedType = mappedType;
			this.facet = facet;
			this.type = type;
			this.typeName = type.Name;
			this.fullTypeName = type.FullName.Replace ('+', '.');

			if (isPrimitive)
				sType = SchemaTypes.Primitive;
			else
			{
				if (type.IsEnum)
					sType = SchemaTypes.Enum;
				else if (typeof(IXmlSerializable).IsAssignableFrom (type))
					sType = SchemaTypes.XmlSerializable;
#if !MOONLIGHT
				else if (typeof (System.Xml.XmlNode).IsAssignableFrom (type))
					sType = SchemaTypes.XmlNode;
#endif
				else if (type.IsArray || typeof(IEnumerable).IsAssignableFrom (type))
					sType = SchemaTypes.Array;
				else
					sType = SchemaTypes.Class;
			}
			
			if (IsListType)
				this.elementName = TypeTranslator.GetArrayName (ListItemTypeData.XmlType);
			else
				this.elementName = elementName;

			if (sType == SchemaTypes.Array || sType == SchemaTypes.Class) {
				hasPublicConstructor = !type.IsInterface && (type.IsArray || type.GetConstructor (Type.EmptyTypes) != null || type.IsAbstract || type.IsValueType);
			}
		}
示例#28
0
        public SchemaFieldBuilder(SchemaDocumentBuilder documentBuilder,
                                  VersionKey version)
        {
            Doc = documentBuilder;

            var state       = version.AsState();
            var interpreter = new Interpreter(state);

            var compoundFields = documentBuilder.Document
                                 .Compounds.Values
                                 .Select(c => (c.Name, c.Fields));
            var niObjectFields = documentBuilder.Document
                                 .NiObjects.Values
                                 .Select(ni => (ni.Name, ni.Fields));

            IncludedFieldsByTypeName = compoundFields.Concat(niObjectFields)
                                       .ToDictionary(
                p => p.Name,
                p => p.Fields
                .Where(f => IsFieldIncluded(f, interpreter, version))
                .ToList()
                );


            FieldTypes = IncludedFieldsByTypeName
                         .SelectMany(kvp =>
                                     kvp.Value.Select(field =>
                                                      (field, documentBuilder.SchemaTypes.GetFieldType(field))))
                         .ToDictionary(ft => ft.field, ft => ft.Item2);
            FieldTypes = IncludedFieldsByTypeName
                         .SelectMany(kvp =>
                                     kvp.Value.Select(field =>
                                                      (field, documentBuilder.SchemaTypes.GetFieldType(field))))
                         .ToDictionary(ft => ft.field, ft => ft.Item2);

            FieldBuilders = IncludedFieldsByTypeName
                            .SelectMany(kvp => kvp.Value.Select(field => (field, BuildField(kvp.Key, field))))
                            .ToDictionary(p => p.field, p => p.Item2);
        }
示例#29
0
		public TypeData (Type type, string elementName, bool isPrimitive)
		{
			this.type = type;
			this.elementName = elementName;
			this.typeName = type.Name;
			this.fullTypeName = type.FullName.Replace ('+', '.');

			if (isPrimitive)
				sType = SchemaTypes.Primitive;
			else
			{
				if (type.IsEnum)
					sType = SchemaTypes.Enum;
				else if (typeof(IXmlSerializable).IsAssignableFrom (type))
					sType = SchemaTypes.XmlSerializable;
				else if (typeof (System.Xml.XmlNode).IsAssignableFrom (type))
					sType = SchemaTypes.XmlNode;
				else if (type.IsArray || typeof(IEnumerable).IsAssignableFrom (type))
					sType = SchemaTypes.Array;
				else
					sType = SchemaTypes.Class;
			}
		}
示例#30
0
 IDataContext GetDB(SchemaTypes tipe)
 {
     if (tipe == SchemaTypes.StreamData)
     {
         return container.Get<InMemoryDb>();
     }
     else if (tipe == SchemaTypes.RelationalData)
     {
         return container.Get<DocumentDb>();
     }
     else
     {
         var dx = container.Get<ColumnarDb>();
         if (Context != null)
         {
             dx.UserName = Context.User.Identity.Name;
         }
         return dx;
     }
 }
        /// <summary>
        /// Loads bound operations except the ones that require a type that is excluded
        /// </summary>
        /// <param name="schemaType">a schema type model.</param>
        /// <param name="boundOperations">a list of all the bound operations.</param>
        /// <param name="excludedSchemaTypes">A collection of schema types that will be excluded from generated code.</param>
        /// <param name="schemaTypeModels">a dictionary of schema type and the associated schematypemodel.</param>
        private void LoadBoundOperations(SchemaTypeModel schemaType,
                                         IDictionary <IEdmType, List <IEdmOperation> > boundOperations, ICollection <string> excludedSchemaTypes,
                                         IDictionary <string, SchemaTypeModel> schemaTypeModels)
        {
            var toLoad       = new ObservableCollection <BoundOperationModel>();
            var alreadyAdded = new HashSet <string>();

            foreach (KeyValuePair <IEdmType, List <IEdmOperation> > boundOperation in boundOperations)
            {
                IEdmType edmType = boundOperation.Key;
                foreach (IEdmOperation operation in boundOperation.Value)
                {
                    string name = $"{operation.Name}({edmType.FullTypeName()})";
                    if (!alreadyAdded.Contains(name))
                    {
                        var boundOperationModel = new BoundOperationModel
                        {
                            Name       = name,
                            ShortName  = operation.Name,
                            IsSelected = IsBoundOperationIncluded(operation, excludedSchemaTypes)
                        };

                        boundOperationModel.PropertyChanged += (s, args) =>
                        {
                            if (s is BoundOperationModel currentBoundOperationModel)
                            {
                                IEnumerable <IEdmOperationParameter> parameters = operation.Parameters;

                                foreach (var parameter in parameters)
                                {
                                    var parameterTypeName = parameter.Type.IsCollection()
                                        ? parameter.Type.AsCollection()?.ElementType()?.FullName()
                                        : parameter.Type.FullName();

                                    if (parameterTypeName != null &&
                                        schemaTypeModels.TryGetValue(parameterTypeName, out SchemaTypeModel model) &&
                                        !model.IsSelected && model.IsSelected != currentBoundOperationModel.IsSelected)
                                    {
                                        model.IsSelected = currentBoundOperationModel.IsSelected;
                                    }
                                }

                                string returnTypeName = operation.ReturnType?.IsCollection() == true
                                    ? operation.ReturnType?.AsCollection()?.ElementType()?.FullName()
                                    : operation.ReturnType?.FullName();

                                if (returnTypeName != null &&
                                    schemaTypeModels.TryGetValue(returnTypeName, out SchemaTypeModel schemaTypeModel) &&
                                    !schemaTypeModel.IsSelected &&
                                    schemaTypeModel.IsSelected != currentBoundOperationModel.IsSelected)
                                {
                                    schemaTypeModel.IsSelected = currentBoundOperationModel.IsSelected;
                                }

                                if (this.View is SchemaTypes view)
                                {
                                    view.SelectedBoundOperationsCount.Text = SchemaTypes
                                                                             .Where(x => x.IsSelected && x.BoundOperations?.Any() == true)
                                                                             .SelectMany(x => x.BoundOperations).Count(x => x.IsSelected).ToString(CultureInfo.InvariantCulture);
                                }
                            }
                        };
                        toLoad.Add(boundOperationModel);

                        alreadyAdded.Add(name);
                    }
                }
            }

            schemaType.BoundOperations = toLoad.OrderBy(o => o.Name).ToList();
        }
示例#32
0
		public static TypeData CreateCustomType (string typeName, string fullTypeName, string xmlType, SchemaTypes schemaType, TypeData listItemTypeData)
		{
			TypeData td = new TypeData (typeName, fullTypeName, xmlType, schemaType, listItemTypeData);
			return td;
		}
示例#33
0
 public static TypeData CreateCustomType(string typeName, string fullTypeName, string xmlType, SchemaTypes schemaType, TypeData listItemTypeData)
 {
     return(new TypeData(typeName, fullTypeName, xmlType, schemaType, listItemTypeData));
 }
示例#34
0
		XmlTypeMapping CreateTypeMapping (XmlQualifiedName typeQName, SchemaTypes schemaType, XmlQualifiedName root)
		{
			string typeName = CodeIdentifier.MakeValid (typeQName.Name);
			typeName = typeIdentifiers.AddUnique (typeName, null);

			TypeData typeData = new TypeData (typeName, typeName, typeName, schemaType, null);

			string rootElem;
			string rootNs;
			if (root != null) {
				rootElem = root.Name;
				rootNs = root.Namespace;
			}
			else {
				rootElem = typeQName.Name;
				rootNs = "";
			}
			
			XmlTypeMapping map = new XmlTypeMapping (rootElem, rootNs, typeData, typeQName.Name, typeQName.Namespace);
			map.IncludeInSchema = true;
			RegisterTypeMapping (typeQName, typeData, map);

			return map;
		}
 static void LocateSchemaTypes(DiscoveryVersion discoveryVersion, XmlSchema schema, ref SchemaTypes typesFound)
 {
     if (((typesFound & SchemaTypes.QNameListType) != SchemaTypes.QNameListType) &&
         (schema.SchemaTypes.Contains(discoveryVersion.Implementation.QualifiedNames.QNameListType)))
     {
         typesFound |= SchemaTypes.QNameListType;
     }
     if (((typesFound & SchemaTypes.UriListType) != SchemaTypes.UriListType) &&
         (schema.SchemaTypes.Contains(discoveryVersion.Implementation.QualifiedNames.UriListType)))
     {
         typesFound |= SchemaTypes.UriListType;
     }
     if (((typesFound & SchemaTypes.ScopesType) != SchemaTypes.ScopesType) &&
         (schema.SchemaTypes.Contains(discoveryVersion.Implementation.QualifiedNames.ScopesType)))
     {
         typesFound |= SchemaTypes.ScopesType;
     }
 }
 static void AddSchemaTypes(DiscoveryVersion discoveryVersion, SchemaTypes typesFound, XmlSchema discoverySchema)
 {
     if ((typesFound & SchemaTypes.ProbeMatchType) == 0)
     {
         AddProbeMatchType(discoveryVersion, discoverySchema);
     }
     if ((typesFound & SchemaTypes.ProbeType) == 0)
     {
         AddProbeType(discoveryVersion, discoverySchema);
     }
     if ((typesFound & SchemaTypes.ResolveType) == 0)
     {
         AddResolveType(discoveryVersion, discoverySchema);
     }
     if ((typesFound & SchemaTypes.QNameListType) == 0)
     {
         AddQNameListType(discoveryVersion, discoverySchema);
     }
     if ((typesFound & SchemaTypes.ScopesType) == 0)
     {
         AddScopesType(discoveryVersion, discoverySchema);
     }
     if ((typesFound & SchemaTypes.UriListType) == 0)
     {
         AddUriListType(discoveryVersion, discoverySchema);
     }
 }
示例#37
0
        /// <summary>
        /// Creates a list of types that needs to be loaded on the UI.
        /// Initially all the types are loaded
        /// </summary>
        /// <param name="schemaTypes">A list of schema types that need to be laoded.</param>
        /// <param name="boundOperations">The associated bound operations.</param>
        public void LoadSchemaTypes(
            IEnumerable <IEdmSchemaType> schemaTypes, IDictionary <IEdmStructuredType, List <IEdmOperation> > boundOperations)
        {
            var toLoad = new List <SchemaTypeModel>();

            foreach (var type in schemaTypes)
            {
                if (!SchemaTypeModelMap.ContainsKey(type.FullName()) || SchemaTypeModelMap.Count() != schemaTypes.Count())
                {
                    SchemaTypes = toLoad;
                    SchemaTypeModelMap.Clear();
                    break;
                }
            }

            if (SchemaTypes.Any())
            {
                return;
            }

            foreach (var schemaType in schemaTypes)
            {
                var schemaTypeModel = new SchemaTypeModel()
                {
                    Name      = schemaType.FullTypeName(),
                    ShortName = EdmHelper.GetTypeNameFromFullName(schemaType.FullTypeName())
                };

                // Create propertyChange handler.
                // Anytime a property is selected/unslected, the handler ensures
                // all the related types and operations are selected/unselected
                schemaTypeModel.PropertyChanged += (s, args) =>
                {
                    if (schemaTypeModel.IsSelected && schemaType is IEdmStructuredType structuredType)
                    {
                        //Check for the base type and automatically select it if not selected already.
                        string baseTypeFullName = structuredType.BaseType?.FullTypeName();

                        if (baseTypeFullName != null)
                        {
                            AddRelatedType(baseTypeFullName, structuredType.FullTypeName());

                            if (SchemaTypeModelMap.TryGetValue(baseTypeFullName, out SchemaTypeModel baseTypeSchemaTypeModel) &&
                                !baseTypeSchemaTypeModel.IsSelected)
                            {
                                baseTypeSchemaTypeModel.IsSelected = true;
                            }
                        }

                        // Check the required navigational property types and ensure they are selected as well
                        foreach (var property in structuredType.DeclaredProperties)
                        {
                            string propertyName = property is IEdmNavigationProperty?property.Type.ToStructuredType().FullTypeName() : property.Type.FullName();

                            if (property.Type.ToStructuredType() != null || property.Type.IsEnum())
                            {
                                propertyName = property.Type.ToStructuredType()?.FullTypeName() ?? property.Type.FullName();
                                AddRelatedType(propertyName, structuredType.FullTypeName());

                                bool hasProperty = SchemaTypeModelMap.TryGetValue(propertyName, out SchemaTypeModel navigationPropertyModel);

                                if (hasProperty && !navigationPropertyModel.IsSelected)
                                {
                                    navigationPropertyModel.IsSelected = true;
                                }
                            }
                        }

                        // Check for bound operations and ensure related types are also selected.
                        // In this case related types means return types and parameter types.
                        if (boundOperations.TryGetValue(structuredType, out List <IEdmOperation> operations))
                        {
                            foreach (var operation in operations)
                            {
                                // Check if return type of associated bound operation has been selected.
                                if (operation.ReturnType != null && (operation.ReturnType.ToStructuredType() != null || operation.ReturnType.IsEnum()))
                                {
                                    string returnTypeFullName = operation.ReturnType.ToStructuredType()?.FullTypeName() ?? operation.ReturnType.FullName();
                                    AddRelatedType(returnTypeFullName, structuredType.FullTypeName());

                                    if (SchemaTypeModelMap.TryGetValue(returnTypeFullName, out SchemaTypeModel referencedSchemaTypeModel) &&
                                        !referencedSchemaTypeModel.IsSelected)
                                    {
                                        referencedSchemaTypeModel.IsSelected = true;
                                    }
                                }

                                // Check if parameter types of associated bound operations has been selected.
                                IEnumerable <IEdmOperationParameter> parameters = operation.Parameters;

                                foreach (var parameter in parameters)
                                {
                                    if (parameter.Type.ToStructuredType() != null || parameter.Type.IsEnum())
                                    {
                                        string parameterFullName = parameter.Type.ToStructuredType()?.FullTypeName() ?? parameter.Type.FullName();
                                        AddRelatedType(parameterFullName, structuredType.FullTypeName());

                                        if (SchemaTypeModelMap.TryGetValue(parameterFullName, out SchemaTypeModel model) && !model.IsSelected)
                                        {
                                            model.IsSelected = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (!schemaTypeModel.IsSelected)
                    {
                        // automatically deselect related types for deselected type
                        if (RelatedTypes.TryGetValue(schemaTypeModel.Name, out ICollection <string> relatedTypes))
                        {
                            foreach (var relatedType in relatedTypes)
                            {
                                if (SchemaTypeModelMap.TryGetValue(relatedType, out SchemaTypeModel relatedSchemaTypeModel) &&
                                    relatedSchemaTypeModel.IsSelected)
                                {
                                    relatedSchemaTypeModel.IsSelected = false;
                                }
                            }
                        }
                    }
                };

                toLoad.Add(schemaTypeModel);
                schemaTypeModel.IsSelected = true;
                SchemaTypeModelMap.Add(schemaType.FullTypeName(), schemaTypeModel);
            }

            SchemaTypes = toLoad.OrderBy(o => o.Name).ToList();
        }
示例#38
0
 static void LocateSchemaTypes(DiscoveryVersion discoveryVersion, XmlSchema schema, ref SchemaTypes typesFound)
 {
     if (((typesFound & SchemaTypes.QNameListType) != SchemaTypes.QNameListType) &&
         (schema.SchemaTypes.Contains(discoveryVersion.Implementation.QualifiedNames.QNameListType)))
     {
         typesFound |= SchemaTypes.QNameListType;
     }
     if (((typesFound & SchemaTypes.UriListType) != SchemaTypes.UriListType) &&
         (schema.SchemaTypes.Contains(discoveryVersion.Implementation.QualifiedNames.UriListType)))
     {
         typesFound |= SchemaTypes.UriListType;
     }
     if (((typesFound & SchemaTypes.ScopesType) != SchemaTypes.ScopesType) &&
         (schema.SchemaTypes.Contains(discoveryVersion.Implementation.QualifiedNames.ScopesType)))
     {
         typesFound |= SchemaTypes.ScopesType;
     }
 }
        /// <summary>
        /// Creates a list of types that needs to be loaded on the UI.
        /// Initially all the types are loaded
        /// </summary>
        /// <param name="schemaTypes">A list of schema types that need to be laoded.</param>
        /// <param name="boundOperations">The associated bound operations.</param>
        public void LoadSchemaTypes(
            IEnumerable <IEdmSchemaType> schemaTypes, IDictionary <IEdmType, List <IEdmOperation> > boundOperations)
        {
            var toLoad = new List <SchemaTypeModel>();

            foreach (var type in schemaTypes)
            {
                if (!SchemaTypeModelMap.ContainsKey(type.FullName()) ||
                    SchemaTypeModelMap.Count != schemaTypes.Count())
                {
                    SchemaTypes = toLoad;
                    SchemaTypeModelMap.Clear();
                    break;
                }
            }

            if (SchemaTypes.Any())
            {
                return;
            }

            foreach (var schemaType in schemaTypes)
            {
                var schemaTypeModel = new SchemaTypeModel
                {
                    Name      = schemaType.FullTypeName(),
                    ShortName = EdmHelper.GetTypeNameFromFullName(schemaType.FullTypeName())
                };

                // Create propertyChange handler.
                // Anytime a property is selected/unslected, the handler ensures
                // all the related types and operations are selected/unselected
                schemaTypeModel.PropertyChanged += (s, args) =>
                {
                    if (schemaTypeModel.IsSelected && schemaType is IEdmStructuredType structuredType)
                    {
                        //Check for the base type and automatically select it if not selected already.
                        string baseTypeFullName = structuredType.BaseType?.FullTypeName();

                        if (baseTypeFullName != null)
                        {
                            AddRelatedType(baseTypeFullName, structuredType.FullTypeName());

                            if (SchemaTypeModelMap.TryGetValue(baseTypeFullName,
                                                               out SchemaTypeModel baseTypeSchemaTypeModel) &&
                                !baseTypeSchemaTypeModel.IsSelected)
                            {
                                baseTypeSchemaTypeModel.IsSelected = true;
                            }
                        }

                        // Check the required property types and ensure they are selected as well
                        foreach (var property in structuredType.DeclaredProperties)
                        {
                            IEdmTypeReference propertyType = property.Type.IsCollection()
                                ? property.Type.AsCollection().ElementType()
                                : property.Type;

                            if (propertyType.ToStructuredType() != null || propertyType.IsEnum())
                            {
                                string propertyTypeName = propertyType.ToStructuredType()?.FullTypeName() ?? propertyType.FullName();
                                AddRelatedType(propertyTypeName, structuredType.FullTypeName());

                                bool hasProperty = SchemaTypeModelMap.TryGetValue(propertyTypeName, out SchemaTypeModel propertySchemaTypeModel);

                                if (hasProperty && !propertySchemaTypeModel.IsSelected)
                                {
                                    propertySchemaTypeModel.IsSelected = true;
                                }
                            }
                        }

                        // Check for bound operations and ensure related types are also selected.
                        // In this case related types means return types and parameter types.
                        if (boundOperations.TryGetValue(structuredType, out List <IEdmOperation> operations))
                        {
                            foreach (var operation in operations)
                            {
                                // Check if return type of associated bound operation has been selected.
                                if (operation.ReturnType != null &&
                                    (operation.ReturnType.ToStructuredType() != null || operation.ReturnType.IsEnum()))
                                {
                                    string returnTypeFullName =
                                        operation.ReturnType.ToStructuredType()?.FullTypeName() ??
                                        operation.ReturnType.FullName();
                                    AddRelatedType(returnTypeFullName, structuredType.FullTypeName());

                                    if (SchemaTypeModelMap.TryGetValue(returnTypeFullName,
                                                                       out SchemaTypeModel referencedSchemaTypeModel) &&
                                        !referencedSchemaTypeModel.IsSelected)
                                    {
                                        referencedSchemaTypeModel.IsSelected = true;
                                    }
                                }

                                // Check if parameter types of associated bound operations has been selected.
                                IEnumerable <IEdmOperationParameter> parameters = operation.Parameters;

                                foreach (var parameter in parameters)
                                {
                                    if (parameter.Type.ToStructuredType() != null || parameter.Type.IsEnum())
                                    {
                                        string parameterFullName =
                                            parameter.Type.ToStructuredType()?.FullTypeName() ??
                                            parameter.Type.FullName();
                                        AddRelatedType(parameterFullName, structuredType.FullTypeName());

                                        if (SchemaTypeModelMap.TryGetValue(parameterFullName,
                                                                           out SchemaTypeModel model) && !model.IsSelected)
                                        {
                                            model.IsSelected = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (!schemaTypeModel.IsSelected)
                    {
                        // automatically deselect related types for deselected type
                        if (RelatedTypes.TryGetValue(schemaTypeModel.Name, out ICollection <string> relatedTypes))
                        {
                            foreach (var relatedType in relatedTypes)
                            {
                                if (SchemaTypeModelMap.TryGetValue(relatedType,
                                                                   out SchemaTypeModel relatedSchemaTypeModel) &&
                                    relatedSchemaTypeModel.IsSelected)
                                {
                                    relatedSchemaTypeModel.IsSelected = false;
                                }
                            }
                        }

                        // deselect all related bound operations
                        foreach (var boundOperation in schemaTypeModel.BoundOperations)
                        {
                            boundOperation.IsSelected = false;
                        }
                    }

                    if (this.View is SchemaTypes view)
                    {
                        view.SelectedSchemaTypesCount.Text = SchemaTypes.Count(x => x.IsSelected).ToString(CultureInfo.InvariantCulture);
                    }
                };

                // load bound operations that require the schema type
                var boundOperationsToLoad = boundOperations
                                            .Where(x => x.Key == schemaType || x.Key.AsElementType() == schemaType)
                                            .ToDictionary(x => x.Key, x => x.Value);
                LoadBoundOperations(schemaTypeModel, boundOperationsToLoad,
                                    ExcludedSchemaTypeNames.ToList(), SchemaTypeModelMap);

                toLoad.Add(schemaTypeModel);
                schemaTypeModel.IsSelected = true;
                SchemaTypeModelMap.Add(schemaType.FullTypeName(), schemaTypeModel);
            }

            SchemaTypes = toLoad.OrderBy(o => o.Name).ToList();

            _schemaTypesCount     = SchemaTypes.Count();
            _boundOperationsCount = SchemaTypes.Where(x => x?.BoundOperations?.Any() == true)
                                    .SelectMany(x => x.BoundOperations).Count();
        }
示例#40
0
文件: TypeData.cs 项目: vninfo/mono
		internal TypeData (string typeName, string fullTypeName, string xmlType, SchemaTypes schemaType, TypeData listItemTypeData)
		{
			this.elementName = xmlType;
			this.typeName = typeName;
			this.fullTypeName = fullTypeName.Replace ('+', '.');
			this.listItemTypeData = listItemTypeData;
			this.sType = schemaType;
			this.hasPublicConstructor = true;

			LookupTypeConvertor ();
		}