示例#1
0
        private static JObject CreateProperties(ShapeMetadata metadata)
        {
            var    properties = new JObject();
            bool   tempBool;
            double tempDouble;

            if (!string.IsNullOrEmpty(metadata.Title))
            {
                properties.Add("title", JValue.CreateString(metadata.Title));
            }

            if (!string.IsNullOrEmpty(metadata.Description))
            {
                properties.Add("description", JValue.CreateString(metadata.Description));
            }

            foreach (var t in metadata.Properties)
            {
                object o = t.Value;
                if (o is string)
                {
                    properties.Add(t.Key, o.ToString());
                }
                else if (o is bool && bool.TryParse(o.ToString(), out tempBool))
                {
                    properties.Add(t.Key, tempBool);
                }
                else if (double.TryParse(o.ToString(), NumberStyles.Float, CultureInfo.InvariantCulture, out tempDouble))
                {
                    properties.Add(t.Key, tempDouble);
                }
            }

            return(properties);
        }
示例#2
0
        private void WriteMetadata(ShapeMetadata metadata, XmlWriter xmlWriter)
        {
            if (metadata != null)
            {
                if (!string.IsNullOrEmpty(metadata.Title))
                {
                    xmlWriter.WriteStartElement("title");
                    xmlWriter.WriteValue(metadata.Title);
                    xmlWriter.WriteEndElement();
                }

                if (!string.IsNullOrEmpty(metadata.Description))
                {
                    xmlWriter.WriteStartElement("description");
                    xmlWriter.WriteValue(metadata.Description);
                    xmlWriter.WriteEndElement();
                }

                foreach (var m in metadata.Properties)
                {
                    if (m.Value != null)
                    {
                        switch (m.Key.ToLowerInvariant())
                        {
                        case "title":
                        case "description":
                        case "subtitle":
                        case "content":
                        case "summary":
                        case "icon":
                            xmlWriter.WriteStartElement(m.Key);
                            xmlWriter.WriteValue(m.Value as string);
                            xmlWriter.WriteEndElement();
                            break;

                        case "mappoint:icon":
                            xmlWriter.WriteStartElement("icon", MapPointNamespace);
                            xmlWriter.WriteValue(m.Value as string);
                            xmlWriter.WriteEndElement();
                            break;

                        case "link":        //   <link href="http://example.org/"/>
                            xmlWriter.WriteStartElement(m.Key);
                            xmlWriter.WriteAttributeString("href", m.Value as string);
                            xmlWriter.WriteEndElement();
                            break;

                        case "updated":
                            xmlWriter.WriteStartElement(m.Key);
                            xmlWriter.WriteValue(((DateTime)m.Value).ToString());
                            xmlWriter.WriteEndElement();
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteStartObject();
            ShapeMetadata shapeMetadata = value as ShapeMetadata;

            // Type
            Utility.WriteProperty("Type", shapeMetadata.Type, writer, serializer);

            // DisplayType
            Utility.WriteProperty("DisplayType", shapeMetadata.DisplayType, writer, serializer);

            // Position
            Utility.WriteProperty("Position", shapeMetadata.Position, writer, serializer);

            // Tab
            Utility.WriteProperty("Tab", shapeMetadata.Tab, writer, serializer);

            // PlacementSource
            Utility.WriteProperty("PlacementSource", shapeMetadata.PlacementSource, writer, serializer);

            // Prefix
            Utility.WriteProperty("Prefix", shapeMetadata.Prefix, writer, serializer);

            // Wrappers
            Utility.WriteArray("Wrappers", shapeMetadata.Wrappers, writer, serializer);

            // Alternates
            Utility.WriteArray("Alternates", shapeMetadata.Alternates, writer, serializer);

            writer.WriteEnd();
        }
示例#4
0
        public async ValueTask <IShape> BuildDisplayAsync(ContentItem contentItem, string?displayType = default)
        {
            var     actualShapeType   = "Content";
            var     actualDisplayType = string.IsNullOrEmpty(displayType) ? "Detail" : displayType;
            dynamic itemShape         = await CreateContentShapeAsync(actualShapeType);

            itemShape.ContentItem = contentItem;

            ShapeMetadata metadata = itemShape.Metadata;

            metadata.DisplayType = actualDisplayType;
            metadata.Alternates.Add($"Content__{contentItem.ContentType}");

            var context = new BuildDisplayContext(
                itemShape,
                _shapeFactory,
                actualDisplayType
                );

            foreach (var handler in _contentDisplayHandlers)
            {
                await handler.BuildDisplayAsync(contentItem, context);
            }

            return(context.Shape);
        }
示例#5
0
        private void ParseCategories(XElement node, ShapeMetadata metadata)
        {
            //<gpxx:Categories>
            //<gpxx:Category>grocery store</gpxx:Category> [1...*]
            //</gpxx:Categories>

            if (node != null)
            {
                string nodeName;
                int    idx = 0;

                foreach (var n in node.Elements())
                {
                    if (n.Name.Namespace == gpxxNS)
                    {
                        nodeName = n.Name.LocalName;
                        switch (nodeName)
                        {
                        case "Category":
                            SetMetadataString(metadata, nodeName + ":" + idx, n, stripHtml);
                            idx++;
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
示例#6
0
        private void ParseRouteTrackExtensions(XElement node, ShapeMetadata metadata, ShapeStyle style)
        {
            if (node != null)
            {
                string nodeName;

                foreach (var n in node.Elements())
                {
                    if (n.Name.Namespace == gpxxNS)
                    {
                        nodeName = n.Name.LocalName;
                        switch (nodeName)
                        {
                        case "DisplayColor":
                            var c = XmlUtilities.GetColor(n);
                            if (c.HasValue)
                            {
                                style.StrokeColor = c;
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
示例#7
0
        private void ParseExtensions(XElement node, ShapeMetadata metadata, ShapeStyle style)
        {
            //<extensions>
            //<gpxx:WaypointExtension/>
            //</extensions>

            if (node != null)
            {
                string nodeName;

                foreach (var n in node.Elements())
                {
                    if (n.Name.Namespace == gpxxNS)
                    {
                        nodeName = n.Name.LocalName;
                        switch (nodeName)
                        {
                        case "WaypointExtension":
                            ParseWaypointExtensions(n, metadata);
                            break;

                        case "RouteExtension":
                        case "TrackExtension":
                            ParseRouteTrackExtensions(n, metadata, style);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
示例#8
0
        private void WriteMetadata(ShapeMetadata metadata, XmlWriter xmlWriter)
        {
            if (metadata != null)
            {
                if (!string.IsNullOrEmpty(metadata.Title) && !metadata.Properties.ContainsKey("name"))
                {
                    metadata.Properties.Add("name", metadata.Title);
                }

                if (!string.IsNullOrEmpty(metadata.Description) && !metadata.Properties.ContainsKey("description"))
                {
                    metadata.Properties.Add("description", metadata.Title);
                }

                foreach (var t in metadata.Properties)
                {
                    var val = t.Value;
                    switch (t.Key)
                    {
                    case "name":
                    case "description":
                        xmlWriter.WriteStartElement(t.Key);
                        if ((val as string).Contains("<"))
                        {
                            xmlWriter.WriteCData(val as string);
                        }
                        else
                        {
                            xmlWriter.WriteString(val as string);
                        }
                        xmlWriter.WriteEndElement();
                        break;

                    case "address":
                    case "phoneNumber":
                    case "Snippet ":
                        xmlWriter.WriteStartElement(t.Key);
                        xmlWriter.WriteString(val as string);
                        xmlWriter.WriteEndElement();
                        break;

                    case "visibility":
                        xmlWriter.WriteStartElement(t.Key);
                        xmlWriter.WriteString(((bool)val) ? "1" : "0");
                        xmlWriter.WriteEndElement();
                        break;

                    case "atom:link":
                        xmlWriter.WriteStartElement("link", AtomNamespace);
                        xmlWriter.WriteAttributeString("href", val as string);
                        xmlWriter.WriteEndElement();
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        private static object AddAlternates(dynamic shape, BuildShapeContext ctx, string differentiator)
        {
            // automatically add shape alternates for shapes added by fields
            // for fields on dynamic parts the part name is the same as the content type name

            ShapeMetadata metadata = shape.Metadata;

            // if no ContentItem property has been set, assign it
            if (shape.ContentItem == null)
            {
                shape.ContentItem = ctx.ContentItem;
            }

            var    shapeType   = metadata.Type;
            var    fieldName   = differentiator ?? String.Empty;
            var    partName    = ctx.ContentPart.PartDefinition.Name;
            string contentType = shape.ContentItem.ContentType;

            // whether the content type has been created dynamically or not
            var dynamicType = String.Equals(partName, contentType, StringComparison.Ordinal);

            // [ShapeType__FieldName] e.g. Fields/Common.Text-Teaser
            if (!String.IsNullOrEmpty(fieldName))
            {
                metadata.Alternates.Add(shapeType + "__" + EncodeAlternateElement(fieldName));
            }

            // [ShapeType__PartName] e.g. Fields/Common.Text-TeaserPart
            if (!String.IsNullOrEmpty(partName))
            {
                metadata.Alternates.Add(shapeType + "__" + EncodeAlternateElement(partName));
            }

            // [ShapeType]__[ContentType]__[PartName] e.g. Fields/Common.Text-Blog-TeaserPart
            if (!String.IsNullOrEmpty(partName) && !String.IsNullOrEmpty(contentType) && !dynamicType)
            {
                metadata.Alternates.Add(EncodeAlternateElement(shapeType + "__" + contentType + "__" + partName));
            }

            // [ShapeType]__[PartName]__[FieldName] e.g. Fields/Common.Text-TeaserPart-Teaser
            if (!String.IsNullOrEmpty(partName) && !String.IsNullOrEmpty(fieldName))
            {
                metadata.Alternates.Add(EncodeAlternateElement(shapeType + "__" + partName + "__" + fieldName));
            }

            // [ShapeType]__[ContentType]__[FieldName] e.g. Fields/Common.Text-Blog-Teaser
            if (!String.IsNullOrEmpty(contentType) && !String.IsNullOrEmpty(fieldName))
            {
                metadata.Alternates.Add(EncodeAlternateElement(shapeType + "__" + contentType + "__" + fieldName));
            }

            // [ShapeType]__[ContentType]__[PartName]__[FieldName] e.g. Fields/Common.Text-Blog-TeaserPart-Teaser
            if (!String.IsNullOrEmpty(contentType) && !String.IsNullOrEmpty(partName) && !String.IsNullOrEmpty(fieldName) && !dynamicType)
            {
                metadata.Alternates.Add(EncodeAlternateElement(shapeType + "__" + contentType + "__" + partName + "__" + fieldName));
            }

            return(shape);
        }
        public void ShapeHasAttributesType()
        {
            var           factory  = _container.Resolve <IShapeFactory>();
            dynamic       foo      = factory.Create("Foo", ArgsUtility.Empty());
            ShapeMetadata metadata = foo.Metadata;

            Assert.That(metadata.Type, Is.EqualTo("Foo"));
        }
示例#11
0
        public void WorkContextPageIsLayoutShape()
        {
            var           layout       = _workContext.Layout;
            ShapeMetadata pageMetadata = layout.Metadata;

            Assert.That(pageMetadata.Type, Is.EqualTo("Layout"));
            Assert.That(layout.Metadata.Type, Is.EqualTo("Layout"));
        }
示例#12
0
 private static void AddAlternates(ShapeMetadata metadata, ICollection <string> values)
 {
     for (var i = 0; i < values.Count; i++)
     {
         var alternate = EncodeAlternate($"{metadata.Type}__{String.Join("_", values.Take(i + 1))}");
         metadata.Alternates.Add(alternate);
     }
 }
示例#13
0
        public void ShapeHasAttributesType()
        {
            var           factory  = _serviceProvider.GetService <IShapeFactory>();
            dynamic       foo      = factory.Create("Foo", ArgsUtility.Empty());
            ShapeMetadata metadata = foo.Metadata;

            Assert.Equal("Foo", metadata.Type);
        }
示例#14
0
        public void CallSyntax()
        {
            dynamic       factory  = _serviceProvider.GetService <IShapeFactory>();
            var           foo      = factory.Foo();
            ShapeMetadata metadata = foo.Metadata;

            Assert.Equal("Foo", metadata.Type);
        }
示例#15
0
        public void CallSyntax()
        {
            dynamic       factory  = _container.Resolve <IShapeFactory>();
            var           foo      = factory.Foo();
            ShapeMetadata metadata = foo.Metadata;

            Assert.That(metadata.Type, Is.EqualTo("Foo"));
        }
示例#16
0
        internal void SetMetadataString(ShapeMetadata metadata, string nodeName, XElement node, bool stripHtml)
        {
            var s = XmlUtilities.GetString(node, stripHtml);

            if (!string.IsNullOrWhiteSpace(s) && !metadata.Properties.ContainsKey(nodeName))
            {
                metadata.Properties.Add(nodeName, s);
            }
        }
示例#17
0
        private ShapeMetadata ParseProperties(JObject json)
        {
            var metadata = new ShapeMetadata();

            var propJson = json["properties"] as JObject;
            var idJson   = json.Value <string>("id");

            if (!string.IsNullOrWhiteSpace(idJson))
            {
                metadata.Properties.Add("id", idJson);
            }

            if (propJson != null)
            {
                foreach (var child in propJson.Children())
                {
                    var p = child as JProperty;

                    try
                    {
                        switch (p.Value.Type)
                        {
                        case JTokenType.String:
                            metadata.Properties.Add(p.Name, p.Value.Value <string>());
                            break;

                        case JTokenType.Float:
                            metadata.Properties.Add(p.Name, p.Value.Value <double>());
                            break;

                        case JTokenType.Integer:
                            metadata.Properties.Add(p.Name, p.Value.Value <int>());
                            break;

                        case JTokenType.Boolean:
                            metadata.Properties.Add(p.Name, p.Value.Value <bool>());
                            break;

                        default:
                            break;
                        }
                    }
                    catch { }
                }
            }

            if (metadata.Properties.Count > 0)
            {
                return(metadata);
            }

            return(null);
        }
示例#18
0
        private void ParseWaypointExtensions(XElement node, ShapeMetadata metadata)
        {
            //<gpxx:WaypointExtension>
            //<gpxx:Categories/>
            //<gpxx:Address/>
            //</gpxx:WaypointExtension>

            if (node != null)
            {
                string nodeName;

                foreach (var n in node.Elements())
                {
                    nodeName = n.Name.LocalName;
                    if (n.Name.Namespace == gpxxNS)
                    {
                        switch (nodeName)
                        {
                        case "DisplayMode":
                            SetMetadataString(metadata, nodeName, n, stripHtml);
                            break;

                        case "Temperature":
                        case "Proximity":
                        case "Depth":
                            var d = XmlUtilities.GetDouble(n, double.NaN);
                            if (!double.IsNaN(d) && !metadata.Properties.ContainsKey(nodeName))
                            {
                                metadata.Properties.Add(nodeName, d);
                            }
                            break;

                        case "Categories":
                            ParseCategories(n, metadata);
                            break;

                        case "Address":
                            ParseAddress(n, metadata);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
示例#19
0
        public async Task <IShape> BuildDisplayAsync(ContentItem contentItem, IUpdateModel updater, string displayType, string groupId)
        {
            if (contentItem == null)
            {
                throw new ArgumentNullException(nameof(contentItem));
            }

            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType);

            var stereotype        = contentTypeDefinition.GetSettings <ContentTypeSettings>().Stereotype;
            var actualDisplayType = string.IsNullOrEmpty(displayType) ? "Detail" : displayType;
            var actualShapeType   = stereotype ?? "Content";

            // _[DisplayType] is only added for the ones different than Detail
            if (actualDisplayType != "Detail")
            {
                actualShapeType = actualShapeType + "_" + actualDisplayType;
            }

            dynamic itemShape = await CreateContentShapeAsync(actualShapeType);

            itemShape.ContentItem = contentItem;
            itemShape.Stereotype  = stereotype;

            ShapeMetadata metadata = itemShape.Metadata;

            metadata.DisplayType = actualDisplayType;

            // [Stereotype]_[DisplayType]__[ContentType] e.g. Content-BlogPost.Summary
            metadata.Alternates.Add($"{actualShapeType}__{contentItem.ContentType}");

            var context = new BuildDisplayContext(
                itemShape,
                actualDisplayType,
                groupId,
                _shapeFactory,
                await _layoutAccessor.GetLayoutAsync(),
                new ModelStateWrapperUpdater(updater)
                );

            await BindPlacementAsync(context);

            await _handlers.InvokeAsync((handler, contentItem, context) => handler.BuildDisplayAsync(contentItem, context), contentItem, context, _logger);

            return(context.Shape);
        }
示例#20
0
        private void GeometryTapped(object sender, RoutedEventArgs e)
        {
            ShapeMetadata tagMetadata = null;

            if (sender is MapShapeBase)
            {
                var shape = sender as MapShapeBase;

                tagMetadata = shape.Tag as ShapeMetadata;
            }
            else if (sender is System.Windows.UIElement)
            {
                var pin = sender as FrameworkElement;
                //Get the stored metadata from the Tag property
                tagMetadata = pin.Tag as ShapeMetadata;
            }

            DisplayMetadata(tagMetadata);
        }
示例#21
0
        private static dynamic AddAlternates(dynamic shape, BuildShapeContext ctx)
        {
            ShapeMetadata metadata = shape.Metadata;

            // if no ContentItem property has been set, assign it
            if (shape.ContentItem == null)
            {
                shape.ContentItem = ctx.ContentItem;
            }

            var shapeType = metadata.Type;

            // [ShapeType]__[Id] e.g. Parts/Common.Metadata-42
            metadata.Alternates.Add(shapeType + "__" + ctx.ContentItem.Id.ToString(CultureInfo.InvariantCulture));

            // [ShapeType]__[ContentType] e.g. Parts/Common.Metadata-BlogPost
            metadata.Alternates.Add(shapeType + "__" + ctx.ContentItem.ContentType);

            return(shape);
        }
示例#22
0
        private void ParseAddress(XElement node, ShapeMetadata metadata)
        {
            //<gpxx:Address>
            //<gpxx:StreetAddress>16900 North RR 620</gpxx:StreetAddress>
            //<gpxx:City>Round Rock</gpxx:City>
            //<gpxx:State>TX</gpxx:State>
            //<gpxx:Country>USA</gpxx:Country>
            //<gpxx:PostalCode>78681-3922</gpxx:PostalCode>
            //</gpxx:Address>

            if (node != null)
            {
                string nodeName;

                foreach (var n in node.Elements())
                {
                    if (n.Name.Namespace == gpxxNS)
                    {
                        nodeName = n.Name.LocalName;
                        switch (nodeName)
                        {
                        case "StreetAddress":
                        case "City":
                        case "State":
                        case "Country":
                        case "PostalCode":
                            SetMetadataString(metadata, nodeName, n, stripHtml);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
示例#23
0
        private void DisplayMetadata(ShapeMetadata metadata)
        {
            MetadataPanel.DataContext = null;
            DescriptionBox.Navigate("about:blank");

            StringBuilder sb = new StringBuilder();

            if (metadata != null && metadata.HasMetadata())
            {
                MetadataPanel.DataContext = metadata;

                if (!string.IsNullOrEmpty(metadata.Description))
                {
                    DescriptionBox.NavigateToString(metadata.Description);
                }

                foreach (var val in metadata.Properties)
                {
                    sb.AppendLine(val.Key + ": " + val.Value);
                }
            }

            MetadataTbx.Text = sb.ToString();
        }
示例#24
0
        public async Task <IShape> CreateAsync(string shapeType, Func <Task <IShape> > shapeFactory, Action <ShapeCreatingContext> creating, Action <ShapeCreatedContext> created)
        {
            ShapeDescriptor shapeDescriptor;

            (await GetShapeTableAsync()).Descriptors.TryGetValue(shapeType, out shapeDescriptor);

            var creatingContext = new ShapeCreatingContext
            {
                New          = this,
                ShapeFactory = this,
                ShapeType    = shapeType,
                OnCreated    = new List <Func <ShapeCreatedContext, Task> >(),
                CreateAsync  = shapeFactory
            };

            creating?.Invoke(creatingContext);

            // "creating" events may add behaviors and alter base type
            foreach (var ev in _events)
            {
                ev.Creating(creatingContext);
            }

            if (shapeDescriptor != null)
            {
                foreach (var ev in shapeDescriptor.CreatingAsync)
                {
                    await ev(creatingContext);
                }
            }

            // Create the new instance
            var createdContext = new ShapeCreatedContext
            {
                New          = creatingContext.New,
                ShapeFactory = creatingContext.ShapeFactory,
                ShapeType    = creatingContext.ShapeType,
                Shape        = await creatingContext.CreateAsync()
            };

            var shape = createdContext.Shape as IShape;

            if (shape == null)
            {
                throw new InvalidOperationException("Invalid base type for shape: " + createdContext.Shape.GetType().ToString());
            }

            if (shape.Metadata == null)
            {
                shape.Metadata = new ShapeMetadata();
            }

            ShapeMetadata shapeMetadata = shape.Metadata;

            shape.Metadata.Type = shapeType;

            // Merge wrappers if there are any
            if (shapeDescriptor != null && shapeMetadata.Wrappers.Count + shapeDescriptor.Wrappers.Count > 0)
            {
                shapeMetadata.Wrappers.AddRange(shapeDescriptor.Wrappers);
            }

            // "created" events provides default values and new object initialization
            foreach (var ev in _events)
            {
                ev.Created(createdContext);
            }

            if (shapeDescriptor != null)
            {
                foreach (var ev in shapeDescriptor.CreatedAsync)
                {
                    await ev(createdContext);
                }
            }

            if (creatingContext != null)
            {
                foreach (var ev in creatingContext.OnCreated)
                {
                    await ev(createdContext);
                }
            }

            created?.Invoke(createdContext);

            return(createdContext.Shape);
        }
        public IShape Create(string shapeType, INamedEnumerable <object> parameters, Func <dynamic> createShape)
        {
            var             defaultShapeTable = _shapeTableLocator.Value.Lookup(null);
            ShapeDescriptor shapeDescriptor;

            defaultShapeTable.Descriptors.TryGetValue(shapeType, out shapeDescriptor);

            parameters = parameters ?? Arguments.Empty();

            var creatingContext = new ShapeCreatingContext {
                New          = this,
                ShapeFactory = this,
                ShapeType    = shapeType,
                OnCreated    = new List <Action <ShapeCreatedContext> >()
            };

            IEnumerable <object> positional = parameters.Positional.ToList();
            var baseType = positional.FirstOrDefault() as Type;

            if (baseType == null)
            {
                // default to common base class
                creatingContext.Create = createShape ?? (() => new Shape());
            }
            else
            {
                // consume the first argument
                positional             = positional.Skip(1);
                creatingContext.Create = () => Activator.CreateInstance(baseType);
            }

            // "creating" events may add behaviors and alter base type)
            foreach (var ev in _events)
            {
                ev.Value.Creating(creatingContext);
            }
            if (shapeDescriptor != null)
            {
                foreach (var ev in shapeDescriptor.Creating)
                {
                    ev(creatingContext);
                }
            }

            // create the new instance
            var createdContext = new ShapeCreatedContext {
                New       = creatingContext.New,
                ShapeType = creatingContext.ShapeType,
                Shape     = creatingContext.Create()
            };

            if (!(createdContext.Shape is IShape))
            {
                throw new InvalidOperationException("Invalid base type for shape: " + createdContext.Shape.GetType().ToString());
            }

            ShapeMetadata shapeMetadata = createdContext.Shape.Metadata;

            createdContext.Shape.Metadata.Type = shapeType;

            if (shapeDescriptor != null)
            {
                shapeMetadata.Wrappers = shapeMetadata.Wrappers.Concat(shapeDescriptor.Wrappers).ToList();
            }

            // "created" events provides default values and new object initialization
            foreach (var ev in _events)
            {
                ev.Value.Created(createdContext);
            }
            if (shapeDescriptor != null)
            {
                foreach (var ev in shapeDescriptor.Created)
                {
                    ev(createdContext);
                }
            }
            foreach (var ev in creatingContext.OnCreated)
            {
                ev(createdContext);
            }


            // other properties passed with call overlay any defaults, so are after the created events

            // only one non-Type, non-named argument is allowed
            var initializer = positional.SingleOrDefault();

            if (initializer != null)
            {
                foreach (var prop in initializer.GetType().GetProperties())
                {
                    createdContext.Shape[prop.Name] = prop.GetValue(initializer, null);
                }
            }

            foreach (var kv in parameters.Named)
            {
                createdContext.Shape[kv.Key] = kv.Value;
            }

            return(createdContext.Shape);
        }
示例#26
0
        private void ApplyImplementation(BuildShapeContext context, string displayType)
        {
            if (String.IsNullOrEmpty(_differentiator))
            {
                _differentiator = _prefix;
            }

            // Look into specific implementations of placements (like placement.info files)
            var placement = context.FindPlacement((IShape)context.Shape, _differentiator, displayType);

            // If no placement is found, use the default location
            if (placement == null)
            {
                // Look for mapped display type locations
                if (_otherLocations != null)
                {
                    _otherLocations.TryGetValue(displayType, out _defaultLocation);
                }

                placement = new Descriptors.PlacementInfo()
                {
                    Location = _defaultLocation
                };
            }

            // If there are no placement or it's explicitely noop then stop rendering execution
            if (String.IsNullOrEmpty(placement.Location) || placement.Location == "-")
            {
                return;
            }

            // Parse group placement.
            _groupId = placement.GetGroup();

            // If the shape's group doesn't match the currently rendered one, return
            if (!String.Equals(context.GroupId ?? "", _groupId ?? "", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var newShape = _shapeBuilder(context);

            // Ignore it if the driver returned a null shape.
            if (newShape == null)
            {
                return;
            }

            ShapeMetadata newShapeMetadata = newShape.Metadata;

            newShapeMetadata.Prefix          = _prefix;
            newShapeMetadata.DisplayType     = displayType;
            newShapeMetadata.PlacementSource = placement.Source;
            newShapeMetadata.Tab             = placement.GetTab();

            // The _processing callback is used to delay execution of costly initialization
            // that can be prevented by caching
            if (_processing != null)
            {
                newShapeMetadata.OnProcessing(_processing);
            }

            // Apply cache settings
            if (!String.IsNullOrEmpty(_cacheId) && _cache != null)
            {
                _cache(newShapeMetadata.Cache(_cacheId));
            }

            // If a specific shape is provided, remove all previous alternates and wrappers.
            if (!String.IsNullOrEmpty(placement.ShapeType))
            {
                newShapeMetadata.Type = placement.ShapeType;
                newShapeMetadata.Alternates.Clear();
                newShapeMetadata.Wrappers.Clear();
            }

            if (placement.Alternates != null)
            {
                foreach (var alternate in placement.Alternates)
                {
                    newShapeMetadata.Alternates.Add(alternate);
                }
            }

            if (placement.Wrappers != null)
            {
                foreach (var wrapper in placement.Wrappers)
                {
                    newShapeMetadata.Wrappers.Add(wrapper);
                }
            }

            dynamic parentShape = context.Shape;

            if (placement.IsLayoutZone())
            {
                parentShape = context.Layout;
            }

            var position = placement.GetPosition();
            var zones    = placement.GetZones();

            foreach (var zone in zones)
            {
                if (parentShape == null)
                {
                    break;
                }

                var zoneProperty = parentShape.Zones;
                if (zoneProperty != null)
                {
                    // parentShape is a ZoneHolding
                    parentShape = zoneProperty[zone];
                }
                else
                {
                    // try to access it as a member
                    parentShape = parentShape[zone];
                }
            }

            if (String.IsNullOrEmpty(position))
            {
                parentShape.Add(newShape);
            }
            else
            {
                parentShape.Add(newShape, position);
            }
        }
示例#27
0
        private async Task <Geometry> ParseGeometry(XElement node, Dictionary <string, Type> columnInfo, string primaryKeyName)
        {
            XElement n = node.FirstNode as XElement;

            Geometry g = null;
            var      metadata = new ShapeMetadata();
            string   nodeName, tempString;
            double   lat = double.NaN, lon = double.NaN, tempDouble;

            while (n != null)
            {
                nodeName = n.Name.LocalName;

                if (columnInfo.ContainsKey(nodeName) && !metadata.Properties.ContainsKey(nodeName))
                {
                    var type = columnInfo[nodeName];

                    if (type == typeof(string))
                    {
                        tempString = XmlUtilities.GetString(n, false);

                        if (string.Compare(nodeName, primaryKeyName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            metadata.ID = tempString;
                        }

                        metadata.Properties.Add(nodeName, tempString);
                    }
                    else if (type == typeof(long))
                    {
                        metadata.Properties.Add(nodeName, XmlUtilities.GetInt64(n, 0));
                    }
                    else if (type == typeof(double))
                    {
                        tempDouble = XmlUtilities.GetDouble(n, double.NaN);

                        if (!double.IsNaN(tempDouble))
                        {
                            if (string.Compare(nodeName, "Latitude", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                lat = tempDouble;
                            }
                            else if (string.Compare(nodeName, "Longitude", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                lon = tempDouble;
                            }

                            metadata.Properties.Add(nodeName, tempDouble);
                        }
                    }
                    else if (type == typeof(bool))
                    {
                        metadata.Properties.Add(nodeName, XmlUtilities.GetBoolean(n, false));
                    }
                    else if (type == typeof(DateTime))
                    {
                        var time = XmlUtilities.GetDateTime(n);
                        if (time.HasValue)
                        {
                            metadata.Properties.Add(nodeName, time);
                        }
                    }
                    else if (type == typeof(Geometry))
                    {
                        var sGeom = XmlUtilities.GetString(n, false);

                        if (!string.IsNullOrWhiteSpace(sGeom))
                        {
                            g = await new Microsoft.Maps.SpatialToolbox.IO.WellKnownText().Read(sGeom);
                        }
                    }
                }

                n = n.NextNode as XElement;
            }

            if (g == null)
            {
                g = new Point(lat, lon);
            }

            if (metadata.HasMetadata())
            {
                g.Metadata = metadata;
            }

            return(g);
        }
示例#28
0
        private async Task <Geometry> ParseGeometry(List <string> row, List <string> columnNames, Dictionary <string, Type> columnInfo, string primaryKeyName)
        {
            Geometry g        = null;
            var      metadata = new ShapeMetadata();
            string   nodeName;
            double   lat = double.NaN, lon = double.NaN, tempDouble;
            long     tempLong;
            bool     tempBool;
            DateTime tempDate;

            if (row.Count == columnNames.Count)
            {
                for (int i = 0; i < row.Count; i++)
                {
                    nodeName = columnNames[i];

                    if (columnInfo.ContainsKey(nodeName) && !metadata.Properties.ContainsKey(nodeName))
                    {
                        var type = columnInfo[nodeName];

                        if (type == typeof(string))
                        {
                            if (string.Compare(nodeName, primaryKeyName, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                metadata.ID = row[i];
                            }

                            metadata.Properties.Add(nodeName, row[i]);
                        }
                        else if (type == typeof(long))
                        {
                            if (!long.TryParse(row[i], out tempLong))
                            {
                                tempLong = 0;
                            }

                            metadata.Properties.Add(nodeName, tempLong);
                        }
                        else if (type == typeof(double))
                        {
                            if (double.TryParse(row[i], out tempDouble))
                            {
                                if (string.Compare(nodeName, "Latitude", StringComparison.OrdinalIgnoreCase) == 0)
                                {
                                    lat = tempDouble;
                                }
                                else if (string.Compare(nodeName, "Longitude", StringComparison.OrdinalIgnoreCase) == 0)
                                {
                                    lon = tempDouble;
                                }

                                metadata.Properties.Add(nodeName, tempDouble);
                            }
                        }
                        else if (type == typeof(bool))
                        {
                            if (!bool.TryParse(row[i], out tempBool))
                            {
                                tempBool = false;
                            }

                            metadata.Properties.Add(nodeName, tempBool);
                        }
                        else if (type == typeof(DateTime))
                        {
                            if (DateTime.TryParse(row[i], out tempDate))
                            {
                                metadata.Properties.Add(nodeName, tempDate);
                            }
                        }
                        else if (type == typeof(Geometry))
                        {
                            if (!string.IsNullOrWhiteSpace(row[i]))
                            {
                                g = await new Microsoft.Maps.SpatialToolbox.IO.WellKnownText().Read(row[i]);
                            }
                        }
                    }
                }

                if (g == null)
                {
                    g = new Point(lat, lon);
                }

                if (metadata.HasMetadata())
                {
                    g.Metadata = metadata;
                }
            }

            return(g);
        }
示例#29
0
 public ShapeMessage(ShapeMetadata metaData)
 {
     _metaData = metaData;
 }
示例#30
0
        private void ApplyImplementation(BuildShapeContext context, string displayType)
        {
            var placement = context.FindPlacement(_shapeType, _differentiator, _defaultLocation);

            if (String.IsNullOrEmpty(placement.Location) || placement.Location == "-")
            {
                return;
            }

            // Parse group placement.
            var group = placement.GetGroup();

            if (!String.IsNullOrEmpty(group))
            {
                _groupId = group;
            }

            if (!String.Equals(context.GroupId ?? "", _groupId ?? "", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            dynamic parentShape = context.Shape;

            context.ContentPart = ContentPart;

            var newShape = _shapeBuilder(context);

            // Ignore it if the driver returned a null shape.
            if (newShape == null)
            {
                return;
            }

            // Add a ContentPart property to the final shape.
            if (ContentPart != null && newShape.ContentPart == null)
            {
                newShape.ContentPart = ContentPart;
            }

            // Add a ContentField property to the final shape.
            if (ContentField != null && newShape.ContentField == null)
            {
                newShape.ContentField = ContentField;
            }

            ShapeMetadata newShapeMetadata = newShape.Metadata;

            newShapeMetadata.Prefix          = _prefix;
            newShapeMetadata.DisplayType     = displayType;
            newShapeMetadata.PlacementSource = placement.Source;
            newShapeMetadata.Tab             = placement.GetTab();

            // If a specific shape is provided, remove all previous alternates and wrappers.
            if (!String.IsNullOrEmpty(placement.ShapeType))
            {
                newShapeMetadata.Type = placement.ShapeType;
                newShapeMetadata.Alternates.Clear();
                newShapeMetadata.Wrappers.Clear();
            }

            foreach (var alternate in placement.Alternates)
            {
                newShapeMetadata.Alternates.Add(alternate);
            }

            foreach (var wrapper in placement.Wrappers)
            {
                newShapeMetadata.Wrappers.Add(wrapper);
            }

            // Check if the zone name is in reference of Layout, e.g. /AsideSecond.
            if (placement.IsLayoutZone())
            {
                parentShape = context.Layout;
            }

            var position = placement.GetPosition();
            var zone     = placement.GetZone();

            if (String.IsNullOrEmpty(position))
            {
                parentShape.Zones[zone].Add(newShape);
            }
            else
            {
                parentShape.Zones[zone].Add(newShape, position);
            }
        }