Exemple #1
0
        public object ConvertToWpf(IDocumentContext sourceDocumentContext, object obj)
        {
            if (PlatformConverter.IsPlatformValue(obj, this.StandaloneWpfDocumentContext))
            {
                return(obj);
            }
            if (obj != null)
            {
                ITypeId typeId = (ITypeId)sourceDocumentContext.TypeResolver.GetType(obj.GetType());
                if (PlatformTypes.Style.IsAssignableFrom(typeId) || PlatformTypes.FrameworkTemplate.IsAssignableFrom(typeId))
                {
                    return(Activator.CreateInstance(PlatformTypeHelper.ConvertTypeId(typeId, this.StandaloneWpfDocumentContext.TypeResolver.PlatformMetadata).RuntimeType));
                }
                if (PlatformTypes.CompositeTransform.IsAssignableFrom(typeId))
                {
                    IPlatform platform = PlatformConverter.GetPlatform(sourceDocumentContext);
                    if (platform != null)
                    {
                        Transform transform = (Transform)platform.GeometryHelper.ConvertTransformToWpf(obj);
                        if (transform != null)
                        {
                            return((object)transform);
                        }
                    }
                }
            }
            object     obj1       = this.ConvertInternal(obj, sourceDocumentContext, this.StandaloneWpfDocumentContext, PlatformConverter.ConvertToType.InstanceValue);
            FontFamily fontFamily = obj1 as FontFamily;

            if (fontFamily != null && fontFamily.Source == PlatformConverter.portableUserInterfaceString)
            {
                return((object)PlatformConverter.PortableUserInterfaceFont);
            }
            return(obj1);
        }
Exemple #2
0
        private DocumentNode ConvertSubtree(DocumentNode node, IDocumentContext sourcePlatformDocumentContext, IDocumentContext targetPlatformDocumentContext)
        {
            DocumentPrimitiveNode documentPrimitiveNode = node as DocumentPrimitiveNode;
            DocumentCompositeNode documentCompositeNode = node as DocumentCompositeNode;

            if (documentPrimitiveNode != null)
            {
                ITypeId typeId        = (ITypeId)PlatformTypeHelper.ConvertTypeId((ITypeId)documentPrimitiveNode.Type, targetPlatformDocumentContext.TypeResolver.PlatformMetadata);
                object  valueAsObject = DocumentPrimitiveNode.GetValueAsObject((DocumentNode)documentPrimitiveNode);
                if (valueAsObject != null)
                {
                    return((DocumentNode) new DocumentPrimitiveNode(targetPlatformDocumentContext, typeId, this.ConvertInternal(valueAsObject, sourcePlatformDocumentContext, targetPlatformDocumentContext, PlatformConverter.ConvertToType.InstanceValue)));
                }
                IDocumentNodeValue documentNodeValue = DocumentPrimitiveNode.GetValueAsMember((DocumentNode)documentPrimitiveNode) != null || documentPrimitiveNode.Value == null ? (IDocumentNodeValue)null : documentPrimitiveNode.Value.Clone(targetPlatformDocumentContext);
                return((DocumentNode) new DocumentPrimitiveNode(targetPlatformDocumentContext, typeId, documentNodeValue));
            }
            if (documentCompositeNode != null)
            {
                if (PlatformTypes.CompositeTransform.IsAssignableFrom((ITypeId)documentCompositeNode.Type))
                {
                    IPlatform platform = PlatformConverter.GetPlatform(sourcePlatformDocumentContext);
                    if (platform != null)
                    {
                        TransformGroup transformGroup = platform.GeometryHelper.ConvertTransformToWpf((object)documentCompositeNode);
                        if (PlatformConverter.IsPlatformValue((object)transformGroup, targetPlatformDocumentContext))
                        {
                            return(targetPlatformDocumentContext.CreateNode(typeof(TransformGroup), (object)transformGroup));
                        }
                    }
                }
                ITypeId typeId = (ITypeId)PlatformTypeHelper.ConvertTypeId((ITypeId)documentCompositeNode.Type, targetPlatformDocumentContext.TypeResolver.PlatformMetadata);
                if (!documentCompositeNode.TypeResolver.PlatformMetadata.IsNullType(typeId))
                {
                    DocumentCompositeNode node1 = targetPlatformDocumentContext.CreateNode(typeId);
                    foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)documentCompositeNode.Properties)
                    {
                        IProperty property = this.ConvertPropertyKey(keyValuePair.Key, targetPlatformDocumentContext.TypeResolver.PlatformMetadata);
                        if (property != null)
                        {
                            DocumentNode node2 = keyValuePair.Value;
                            if (!PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)node2.Type) && !PlatformTypes.Style.IsAssignableFrom((ITypeId)node2.Type))
                            {
                                DocumentNode node3 = this.ConvertSubtree(node2, sourcePlatformDocumentContext, targetPlatformDocumentContext);
                                if (node3 != null && (PlatformTypeHelper.GetPropertyType(property).IsAssignableFrom(node3.TargetType) || DocumentNodeUtilities.IsMarkupExtension(node3)))
                                {
                                    node1.Properties[(IPropertyId)property] = node3;
                                }
                            }
                        }
                    }
                    if (documentCompositeNode.SupportsChildren)
                    {
                        for (int index = 0; index < documentCompositeNode.Children.Count; ++index)
                        {
                            DocumentNode node2 = documentCompositeNode.Children[index];
                            node1.Children.Add(this.ConvertSubtree(node2, sourcePlatformDocumentContext, targetPlatformDocumentContext));
                        }
                    }
                    return((DocumentNode)node1);
                }
            }
            return((DocumentNode)null);
        }
Exemple #3
0
        private object ConvertInternal(object value, IDocumentContext sourcePlatformDocumentContext, IDocumentContext targetPlatformDocumentContext, PlatformConverter.ConvertToType convertType)
        {
            if (value == null)
            {
                return((object)null);
            }
            if (value == PlatformConverter.PortableUserInterfaceFont)
            {
                value = (object)new FontFamily(PlatformConverter.portableUserInterfaceString);
            }
            if (PlatformConverter.IsPlatformValue(value, targetPlatformDocumentContext))
            {
                if (convertType == PlatformConverter.ConvertToType.DocumentNode)
                {
                    return((object)targetPlatformDocumentContext.CreateNode(value.GetType(), value));
                }
                return(value);
            }
            Type type1 = value.GetType();

            if (convertType == PlatformConverter.ConvertToType.InstanceValue && PlatformConverter.CanUseFastConversion(type1))
            {
                return(this.ConvertInternalFast(value, sourcePlatformDocumentContext.TypeResolver, targetPlatformDocumentContext.TypeResolver));
            }
            SceneDocument activeDocument = this.designerContext.ActiveDocument;

            ((PurePlatformProjectContext)this.StandaloneWpfDocumentContext.TypeResolver).SetActualProjectContext(activeDocument != null ? activeDocument.ProjectContext : (IProjectContext)null);
            DocumentNode documentNode1 = value as DocumentNode;
            DocumentNode node;

            using (((IProjectContext)sourcePlatformDocumentContext.TypeResolver).Platform.DocumentNodeBuilderFactory.ForceBuildAnimatedValue)
                node = documentNode1 ?? sourcePlatformDocumentContext.CreateNode(value.GetType(), value);
            if (node == null)
            {
                return((object)null);
            }
            object obj          = (object)null;
            IType  type2        = node.Type;
            IType  platformType = ((IPlatformTypes)targetPlatformDocumentContext.TypeResolver.PlatformMetadata).GetPlatformType(type2.FullName);

            if (node is DocumentPrimitiveNode)
            {
                if (convertType == PlatformConverter.ConvertToType.DocumentNode)
                {
                    return((object)this.ConvertSubtree(node, sourcePlatformDocumentContext, targetPlatformDocumentContext));
                }
                if (platformType == null || type2.TypeConverter == null || platformType.TypeConverter == null)
                {
                    return((object)null);
                }
                DocumentPrimitiveNode documentPrimitiveNode1 = value as DocumentPrimitiveNode;
                string text;
                if (documentPrimitiveNode1 != null)
                {
                    text = documentPrimitiveNode1.GetValue <string>();
                }
                else
                {
                    DocumentPrimitiveNode documentPrimitiveNode2 = node as DocumentPrimitiveNode;
                    text = documentPrimitiveNode2 == null || !(documentPrimitiveNode2.Value is DocumentNodeStringValue) ? type2.TypeConverter.ConvertToString((ITypeDescriptorContext)null, CultureInfo.InvariantCulture, value) : documentPrimitiveNode2.GetValue <string>();
                }
                try
                {
                    obj = platformType.TypeConverter.ConvertFromString((ITypeDescriptorContext)null, CultureInfo.InvariantCulture, text);
                }
                catch
                {
                }
            }
            else
            {
                DocumentNode documentNode2 = this.ConvertSubtree(node, sourcePlatformDocumentContext, targetPlatformDocumentContext);
                if (convertType == PlatformConverter.ConvertToType.DocumentNode)
                {
                    return((object)documentNode2);
                }
                if (documentNode2 != null)
                {
                    DocumentNodePath documentNodePath = new DocumentNodePath(documentNode2, documentNode2);
                    using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(targetPlatformDocumentContext, this.designerContext))
                    {
                        instanceBuilderContext.ViewNodeManager.RootNodePath = documentNodePath;
                        instanceBuilderContext.ViewNodeManager.Instantiate(instanceBuilderContext.ViewNodeManager.Root);
                        using (instanceBuilderContext.DisablePostponedResourceEvaluation())
                            obj = instanceBuilderContext.ViewNodeManager.ValidRootInstance;
                        instanceBuilderContext.ViewNodeManager.RootNodePath = (DocumentNodePath)null;
                    }
                }
            }
            if (obj == null && platformType != null && (!platformType.SupportsNullValues && platformType.RuntimeType != (Type)null))
            {
                obj = InstanceBuilderOperations.InstantiateType(platformType.RuntimeType, true);
            }
            return(obj);
        }