private static void PopulateGeneralFacets(
            StructuredProperty somProperty,
            ref TypeUsage propertyTypeUsage)
        {
            bool flag = false;
            Dictionary <string, Facet> dictionary = propertyTypeUsage.Facets.ToDictionary <Facet, string>((Func <Facet, string>)(f => f.Name));

            if (!somProperty.Nullable)
            {
                dictionary["Nullable"] = Facet.Create(MetadataItem.NullableFacetDescription, (object)false);
                flag = true;
            }
            if (somProperty.Default != null)
            {
                dictionary["DefaultValue"] = Facet.Create(MetadataItem.DefaultValueFacetDescription, somProperty.DefaultAsObject);
                flag = true;
            }
            if (somProperty.Schema.SchemaVersion == 1.1)
            {
                Facet facet = Facet.Create(MetadataItem.CollectionKindFacetDescription, (object)somProperty.CollectionKind);
                dictionary.Add(facet.Name, facet);
                flag = true;
            }
            if (!flag)
            {
                return;
            }
            propertyTypeUsage = TypeUsage.Create(propertyTypeUsage.EdmType, (IEnumerable <Facet>)dictionary.Values);
        }
Пример #2
0
        public override StructuredPropertyDetails LoadStructuredPropertyDetails(StructuredProperty property)
        {
            var propInfo = property.PropertyInfo;

            var isAttributes   = propInfo.HasAttribute <ResourceAttributesPropertyAttribute>(true);
            var isPrimaryId    = propInfo.HasAttribute <ResourceIdPropertyAttribute>(true);
            var isEtagProperty = propInfo.HasAttribute <ResourceEtagPropertyAttribute>(true);
            var info           =
                propInfo.GetCustomAttributes(typeof(ResourcePropertyAttribute), true).OfType <ResourcePropertyAttribute>()
                .FirstOrDefault()
                ?? new ResourcePropertyAttribute()
            {
                AccessMode     = HttpMethod.Get,
                ItemAccessMode = HttpMethod.Get,
                Required       = false
            };

            return(new StructuredPropertyDetails(isAttributes,
                                                 isEtagProperty,
                                                 isPrimaryId,
                                                 true,
                                                 info.AccessMode,
                                                 info.ItemAccessMode,
                                                 ExpandMode.Full));
        }
Пример #3
0
        public static IEnumerable <Route> GetRoutes(this StructuredProperty property, Route parent)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }
            var routes = property.PropertyType.Maybe().Switch(
                x =>
                x.Case <ResourceType>().Then(y => y.GetRoutes(parent)).Case <EnumerableTypeSpec>().Then(
                    y => new GetByIdRoute((ResourceType)y.ItemType, parent, property.ItemAccessMode).WrapAsEnumerable())).OrDefault(
                Enumerable.Empty <Route>);

            return(routes);
        }
        private static EdmProperty ConvertToProperty(
            StructuredProperty somProperty,
            DbProviderManifest providerManifest,
            Converter.ConversionCache convertedItemCache,
            Dictionary <SchemaElement, GlobalItem> newGlobalItems)
        {
            ScalarType type = somProperty.Type as ScalarType;
            TypeUsage  typeUsage;

            if (type != null && somProperty.Schema.DataModel != SchemaDataModelOption.EntityDataModel)
            {
                typeUsage = somProperty.TypeUsage;
                Converter.UpdateSentinelValuesInFacets(ref typeUsage);
            }
            else
            {
                EdmType edmType = type == null ? (EdmType)Converter.LoadSchemaElement(somProperty.Type, providerManifest, convertedItemCache, newGlobalItems) : (EdmType)convertedItemCache.ItemCollection.GetItem <PrimitiveType>(somProperty.TypeUsage.EdmType.FullName);
                if (somProperty.CollectionKind != CollectionKind.None)
                {
                    typeUsage = TypeUsage.Create((EdmType) new CollectionType(edmType));
                }
                else
                {
                    SchemaEnumType schemaEnumType = type == null ? somProperty.Type as SchemaEnumType : (SchemaEnumType)null;
                    typeUsage = TypeUsage.Create(edmType);
                    if (schemaEnumType != null)
                    {
                        somProperty.EnsureEnumTypeFacets(convertedItemCache, newGlobalItems);
                    }
                    if (somProperty.TypeUsage != null)
                    {
                        Converter.ApplyTypePropertyFacets(somProperty.TypeUsage, ref typeUsage);
                    }
                }
            }
            Converter.PopulateGeneralFacets(somProperty, ref typeUsage);
            EdmProperty edmProperty = new EdmProperty(somProperty.Name, typeUsage);

            if (somProperty.Documentation != null)
            {
                edmProperty.Documentation = Converter.ConvertToDocumentation(somProperty.Documentation);
            }
            Converter.AddOtherContent((SchemaElement)somProperty, (MetadataItem)edmProperty);
            return(edmProperty);
        }
Пример #5
0
        public override StructuredPropertyDetails LoadStructuredPropertyDetails(StructuredProperty property)
        {
            var propInfo = property.PropertyInfo;

            var reflectedType = property.ReflectedType;
            var expandMode    = Filter.GetPropertyExpandMode(reflectedType, propInfo);
            var accessMode    = Filter.GetPropertyAccessMode(propInfo, property.DeclaringType.Constructor);

            var details = new StructuredPropertyDetails(
                Filter.PropertyIsAttributes(reflectedType, propInfo),
                Filter.PropertyIsEtag(reflectedType, propInfo),
                Filter.PropertyIsPrimaryId(reflectedType, propInfo),
                accessMode.HasFlag(HttpMethod.Get),
                accessMode,
                Filter.GetPropertyItemAccessMode(reflectedType, propInfo),
                expandMode);

            return(details);
        }
Пример #6
0
        private SchemaPropertyEntry GenerateForProperty(StructuredProperty propertyInfo)
        {
            var propType = propertyInfo.PropertyType;

            var propEntry = new SchemaPropertyEntry
            {
                Required = propertyInfo.IsRequiredForConstructor,
                Access   = propertyInfo.AccessMode,
                Name     = propertyInfo.Name,
                Type     = propType.GetSchemaTypeName()
            };

            var enumerablePropType = propType as EnumerableTypeSpec;

            if (enumerablePropType != null)
            {
                propEntry.Items = new List <SchemaArrayItem>
                {
                    new SchemaArrayItem
                    {
                        Type   = enumerablePropType.ItemType.GetSchemaTypeName(),
                        Access = propertyInfo.ItemAccessMode
                    }
                };
            }

            var dictPropType = propType as DictionaryTypeSpec;

            if (dictPropType != null && propEntry.Type == "dictionary")
            {
                propEntry.Items = new List <SchemaArrayItem>()
                {
                    new SchemaArrayItem()
                    {
                        Type   = dictPropType.ValueType.GetSchemaTypeName(),
                        Access = propertyInfo.ItemAccessMode
                    }
                };
            }

            return(propEntry);
        }
        private void GenerateDBContent()
        {
            #region define type "Tag"

            //create a VertexTypePredefinition
            var Tag_VertexTypePredefinition = new ServiceVertexTypePredefinition();
            Tag_VertexTypePredefinition.VertexTypeName = "Tag";
            Tag_VertexTypePredefinition.Properties = new List<ServicePropertyPredefinition>();
            Tag_VertexTypePredefinition.OutgoingEdges = new List<ServiceOutgoingEdgePredefinition>();

            //create property
            var PropertyName = new ServicePropertyPredefinition();
            PropertyName.AttributeName = "Name";
            PropertyName.AttributeType = "String";
            PropertyName.Comment = "This is a property on type 'Tag' named 'Name' and is of type 'String'";

            //add property
            Tag_VertexTypePredefinition.Properties.Add(PropertyName);

            //create outgoing edge to "Website"
            var OutgoingEdgesTaggedWebsites = new ServiceOutgoingEdgePredefinition();
            OutgoingEdgesTaggedWebsites.AttributeName = "TaggedWebsites";
            OutgoingEdgesTaggedWebsites.AttributeType = "Website";
            OutgoingEdgesTaggedWebsites.Multiplicity = ServiceEdgeMultiplicity.MultiEdge;
            OutgoingEdgesTaggedWebsites.Comment = @"This is an outgoing edge on type 'Tag' wich points to the type 'Website' (the AttributeType)
                                                                            and is defined as 'MultiEdge', which means that this edge can contain multiple single edges";

            //add outgoing edge
            Tag_VertexTypePredefinition.OutgoingEdges.Add(OutgoingEdgesTaggedWebsites);

            #endregion

            #region define type "Website"

            //create a VertexTypePredefinition
            var Website_VertexTypePredefinition = new ServiceVertexTypePredefinition();
            Website_VertexTypePredefinition.VertexTypeName = "Website";
            Website_VertexTypePredefinition.Properties = new List<ServicePropertyPredefinition>();
            Website_VertexTypePredefinition.Indices = new List<ServiceIndexPredefinition>();
            Website_VertexTypePredefinition.IncomingEdges = new List<ServiceIncomingEdgePredefinition>();

            //create properties
            PropertyName = new ServicePropertyPredefinition();
            PropertyName.AttributeName = "Name";
            PropertyName.AttributeType = "String";
            PropertyName.Comment = "This is a property on type 'Website' named 'Name' and is of type 'String'";

            var PropertyUrl = new ServicePropertyPredefinition();
            PropertyUrl.AttributeName = "URL";
            PropertyUrl.AttributeType = "String";

            //add properties
            Website_VertexTypePredefinition.Properties.Add(PropertyName);
            Website_VertexTypePredefinition.Properties.Add(PropertyUrl);

            #region create an index on type "Website" on property "Name"

            var MyIndex = new ServiceIndexPredefinition();
            MyIndex.Name = "MyIndex";
            MyIndex.IndexType = "SonesIndex";
            MyIndex.Properties = new List<string>();
            MyIndex.Properties.Add("Name");
            MyIndex.VertexTypeName = "Website";

            //add index
            Website_VertexTypePredefinition.Indices.Add(MyIndex);

            #endregion

            //add IncomingEdge "Tags", the related OutgoingEdge is "TaggedWebsites" on type "Tag"
            ServiceIncomingEdgePredefinition Incoming = new ServiceIncomingEdgePredefinition();
            Incoming.AttributeName = "Tags";
            Incoming.AttributeType = "Tag";
            Incoming.OutgoingEdgeName = "TaggedWebsites";

            Website_VertexTypePredefinition.IncomingEdges.Add(Incoming);
            #endregion

            #region create types by sending requests

            //create the types "Tag" and "Website"

            var DBTypes = _GraphDS_Service.CreateVertexTypes(SecToken, TransToken, new List<ServiceVertexTypePredefinition>(){Tag_VertexTypePredefinition,
                    Website_VertexTypePredefinition});
            Console.WriteLine("CreateVertexTypes ('Websites', 'Tag') successful executed!");

            var Tag = DBTypes.Where(type => type.Name == "Tag").FirstOrDefault();

            var Website = DBTypes.Where(type => type.Name == "Website").FirstOrDefault();

            #endregion

            #region insert some Websites by sending requests

            ServiceInsertPayload Insert = new ServiceInsertPayload();
            Insert.StructuredProperties = new List<StructuredProperty>();
            Insert.UnstructuredProperties = new List<UnstructuredProperty>();

            StructuredProperty Property = new StructuredProperty();
            Property.PropertyName = "Name";
            Property.PropertyValue = "CNN";
            Insert.StructuredProperties.Add(Property);
            Property = new StructuredProperty();
            Property.PropertyName = "URL";
            Property.PropertyValue = "http://cnn.com/";
            Insert.StructuredProperties.Add(Property);

            var cnn = _GraphDS_Service.Insert(SecToken, TransToken, "Website", Insert);
            Console.WriteLine("Insert into 'Websites' successful executed!");

            Insert = new ServiceInsertPayload();
            Insert.StructuredProperties = new List<StructuredProperty>();
            Insert.UnstructuredProperties = new List<UnstructuredProperty>();
            Property = new StructuredProperty();
            Property.PropertyName = "Name";
            Property.PropertyValue = "xkcd";
            Insert.StructuredProperties.Add(Property);
            Property = new StructuredProperty();
            Property.PropertyName = "URL";
            Property.PropertyValue = "http://xkcd.com/";
            Insert.StructuredProperties.Add(Property);

            var xkcd = _GraphDS_Service.Insert(SecToken, TransToken, "Website", Insert);
            Console.WriteLine("Insert into 'Websites' successful executed!");

            Insert = new ServiceInsertPayload();
            Insert.StructuredProperties = new List<StructuredProperty>();
            Insert.UnstructuredProperties = new List<UnstructuredProperty>();
            Property = new StructuredProperty();
            Property.PropertyName = "Name";
            Property.PropertyValue = "onion";
            Insert.StructuredProperties.Add(Property);
            Property = new StructuredProperty();
            Property.PropertyName = "URL";
            Property.PropertyValue = "http://theonion.com/";
            Insert.StructuredProperties.Add(Property);

            var onion = _GraphDS_Service.Insert(SecToken, TransToken, "Website", Insert);
            Console.WriteLine("Insert into 'Websites' successful executed!");

            Insert = new ServiceInsertPayload();
            Insert.StructuredProperties = new List<StructuredProperty>();
            Insert.UnstructuredProperties = new List<UnstructuredProperty>();
            Property = new StructuredProperty();
            Property.PropertyName = "Name";
            Property.PropertyValue = "Test";
            Insert.StructuredProperties.Add(Property);
            Property = new StructuredProperty();
            Property.PropertyName = "URL";
            Property.PropertyValue = "";
            Insert.StructuredProperties.Add(Property);
            UnstructuredProperty UnsProp = new UnstructuredProperty();
            UnsProp.PropertyName = "IsValide";
            UnsProp.PropertyValue = false;
            Insert.UnstructuredProperties.Add(UnsProp);

            //adding an unstructured property means the property isn't defined before
            var test = _GraphDS_Service.Insert(SecToken, TransToken, "Website", Insert);
            Console.WriteLine("Insert into 'Websites' successful executed!");

            #endregion

            #region insert some Tags by sending requests

            //insert a "Tag" with an OutgoingEdge to a "Website" include that the GraphDB creates an IncomingEdge on the given Website instances
            //(because we created an IncomingEdge on type "Website") --> as a consequence we never have to set any IncomingEdge

            Insert = new ServiceInsertPayload();
            Insert.StructuredProperties = new List<StructuredProperty>();
            Insert.Edges = new List<ServiceEdgePredefinition>();
            Insert.UnstructuredProperties = new List<UnstructuredProperty>();

            Property = new StructuredProperty();
            Property.PropertyName = "Name";
            Property.PropertyValue = "good";
            Insert.StructuredProperties.Add(Property);

            ServiceEdgePredefinition Edge = new ServiceEdgePredefinition();
            Edge.EdgeName = "TaggedWebsites";
            Edge.ContainedEdges = new List<ServiceEdgePredefinition>();

            ServiceEdgePredefinition InnerEdge = new ServiceEdgePredefinition();
            InnerEdge.VertexIDsByID = new List<Tuple<long, List<long>>>();
            var VertexIDs = new List<long>();
            VertexIDs.Add(cnn.VertexID);
            VertexIDs.Add(xkcd.VertexID);

            InnerEdge.VertexIDsByID.Add(new Tuple<long, List<long>>(Website.ID, VertexIDs));
            Edge.ContainedEdges.Add(InnerEdge);

            Insert.Edges.Add(Edge);

            var good = _GraphDS_Service.Insert(SecToken, TransToken, "Tag", Insert);
            Console.WriteLine("Insert into 'Tag' successful executed!");

            Insert = new ServiceInsertPayload();
            Insert.StructuredProperties = new List<StructuredProperty>();
            Insert.Edges = new List<ServiceEdgePredefinition>();
            Insert.UnstructuredProperties = new List<UnstructuredProperty>();

            Property = new StructuredProperty();
            Property.PropertyName = "Name";
            Property.PropertyValue = "funny";
            Insert.StructuredProperties.Add(Property);

            Edge = new ServiceEdgePredefinition();
            Edge.EdgeName = "TaggedWebsites";
            Edge.ContainedEdges = new List<ServiceEdgePredefinition>();

            InnerEdge = new ServiceEdgePredefinition();
            InnerEdge.VertexIDsByID = new List<Tuple<long, List<long>>>();
            VertexIDs = new List<long>();
            VertexIDs.Add(xkcd.VertexID);
            VertexIDs.Add(onion.VertexID);

            InnerEdge.VertexIDsByID.Add(new Tuple<long, List<long>>(Website.ID, VertexIDs));

            Edge.ContainedEdges.Add(InnerEdge);

            Insert.Edges.Add(Edge);

            var funny = _GraphDS_Service.Insert(SecToken, TransToken, "Tag", Insert);
            Console.WriteLine("Insert into 'Tag' successful executed!");

            #endregion
        }
Пример #8
0
 protected virtual Func <PomonaContext, PomonaResponse> ResolveGetSingleProperty(ResourcePropertyRoute route,
                                                                                 StructuredProperty property,
                                                                                 ResourceType resourceType)
 {
     return
         (pr =>
          new PomonaResponse(pr,
                             pr.Node.Parent.Query()
                             .SelectEx(x => x.Apply(property.CreateGetterExpression))
                             .WrapActionResult(QueryProjection.FirstOrDefault)));
 }
Пример #9
0
        // Code History:
        // 2014-03-19 mws
        // *******************************************************************************
        /// <summary>
        /// Adds a structured nar: element/property (provided as object) to a parent element
        /// </summary>
        /// <param name="newStructProp">The property to be added as StructuredProperty</param>
        /// <returns>True if successfully executed</returns>
        public bool AddStructNarProp(StructuredProperty newStructProp)
        {
            ResetErrState();
            // check if the required things are present
            if (string.IsNullOrEmpty(newStructProp.ParentXPath))
            {
                SetErrState(G2DocProcErrEnum.NoXPathAvailable);
                return false;
            }
            if (newStructProp.CoreProp == null)
            {
                SetErrState(G2DocProcErrEnum.NoCoreProp);
                return false;
            }

            // add the core property
            XmlElement corePropXe;
            if (!AddNarPropertyToParent(newStructProp.ParentXPath, newStructProp.ParentChildNameSeq, newStructProp.CoreProp, out corePropXe))
            {
                return false;
            }

            // add the child properties
            string coreXPath = newStructProp.ParentXPath + "/nar:" + corePropXe.Name;
            if (corePropXe.HasAttribute("id")) // try to be as precise as possible
                coreXPath += "[@id='" + corePropXe.GetAttribute("id") + "']";
            foreach (var childProp in newStructProp.ChildProps)
            {
                AddNarPropertyToParent(coreXPath, newStructProp.ChildNameSeq, childProp);
            }
            return true;
        }