Esempio n. 1
0
        private DocumentCompositeNode BuildCompositeNode(IType type)
        {
            DocumentCompositeNode node = this.documentContext.CreateNode((ITypeId)type);

            ++this.complexDepth;
            bool recursionLimitReached = this.complexDepth > DesignDataGenerator.maxComplexDepth && !this.IsCollectionRecent;
            MemberAccessTypes  allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(this.documentContext.TypeResolver, type);
            SortedSet <string> sortedSet             = new SortedSet <string>();

            foreach (IProperty property in ITypeExtensions.GetProperties(type, allowableMemberAccess, true))
            {
                if (!sortedSet.Contains(property.Name))
                {
                    sortedSet.Add(property.Name);
                    if (DesignDataGenerator.IsPropertyWritable(property, this.documentContext.TypeResolver))
                    {
                        DocumentNode documentNode = this.BuildNode(property.PropertyType, true, recursionLimitReached);
                        if (documentNode != null)
                        {
                            node.Properties[(IPropertyId)property] = documentNode;
                        }
                    }
                }
            }
            if (type.ItemType != null && (this.IsTypeXamlFriendly(type.ItemType) || this.CanBuildSimpleNode(type.ItemType)))
            {
                this.stack.Add(DesignDataGenerator.NodeType.Collection);
                this.BuildCollectionNode(type, node);
                this.stack.RemoveAt(this.stack.Count - 1);
            }
            --this.complexDepth;
            return(node);
        }
Esempio n. 2
0
        public static void UpdateDesignValues(DocumentNode node, IProperty property, ISampleTypeConfiguration valueGenerator)
        {
            DocumentCompositeNode documentCompositeNode = node as DocumentCompositeNode;

            if (documentCompositeNode == null)
            {
                return;
            }
            if (property.DeclaringType.IsAssignableFrom((ITypeId)documentCompositeNode.Type))
            {
                documentCompositeNode.Properties[(IPropertyId)property] = documentCompositeNode.Context.CreateNode(property.PropertyType.RuntimeType, valueGenerator.Value);
            }
            foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)documentCompositeNode.Properties)
            {
                DesignDataGenerator.UpdateDesignValues(keyValuePair.Value, property, valueGenerator);
            }
            if (!documentCompositeNode.SupportsChildren)
            {
                return;
            }
            for (int index = 0; index < documentCompositeNode.Children.Count; ++index)
            {
                DesignDataGenerator.UpdateDesignValues(documentCompositeNode.Children[index], property, valueGenerator);
            }
        }
Esempio n. 3
0
 public void SetValue(ConfigurationPlaceholder control, object value)
 {
     if (control != ConfigurationPlaceholder.RandomLatinWordCount && control != ConfigurationPlaceholder.RandomLatinWordLength && control != ConfigurationPlaceholder.StringFormat)
     {
         return;
     }
     this.stringConfigurator.SetConfigurationValue(control, value);
     using (TemporaryCursor.SetWaitCursor())
         DesignDataGenerator.UpdateDesignValues(this.designDataFile, this.property, (ISampleTypeConfiguration)this.stringConfigurator);
 }
Esempio n. 4
0
        public static bool IsPropertyWritable(IProperty property, ITypeResolver typeResolver)
        {
            if (property == null)
            {
                return(false);
            }
            MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(typeResolver, property.DeclaringType);

            return(DesignDataGenerator.IsPropertyWritable(property, allowableMemberAccess));
        }
Esempio n. 5
0
        public static IProjectItem CreateDesignDataFile(Type type, string dataSourceName, IProjectContext projectContext, bool isDesignTimeCreatable)
        {
            string path1   = Path.Combine(Path.GetDirectoryName(projectContext.ProjectPath), DataSetContext.SampleData.DataRootFolder);
            string str     = dataSourceName ?? type.Name;
            string path2_1 = str + ".xaml";
            string path2   = Path.Combine(path1, path2_1);
            int    num     = 1;

            while (File.Exists(path2))
            {
                string path2_2 = str + num.ToString((IFormatProvider)CultureInfo.InvariantCulture) + ".xaml";
                path2 = Path.Combine(path1, path2_2);
                ++num;
            }
            string          path3           = Path.GetTempFileName() + ".xaml";
            IProjectContext projectContext1 = projectContext;

            if (!isDesignTimeCreatable)
            {
                projectContext1 = (IProjectContext)(projectContext as TypeReflectingProjectContext) ?? (IProjectContext) new TypeReflectingProjectContext(projectContext);
            }
            DocumentContext documentContext = new DocumentContext(projectContext1, (IDocumentLocator) new DocumentLocator(path2), false);
            IType           type1           = documentContext.TypeResolver.GetType(type);
            DocumentNode    node            = new DesignDataGenerator(type1, (IDocumentContext)documentContext).Build();

            try
            {
                using (StreamWriter text = File.CreateText(path3))
                {
                    using (XamlDocument xamlDocument = new XamlDocument((IDocumentContext)documentContext, (ITypeId)type1, (ITextBuffer) new SimpleTextBuffer(), DocumentEncodingHelper.DefaultEncoding, (IXamlSerializerFilter) new DefaultXamlSerializerFilter()))
                        new XamlSerializer((IDocumentRoot)xamlDocument, (IXamlSerializerFilter) new DefaultXamlSerializerFilter()).Serialize(node, (TextWriter)text);
                }
                BuildTaskInfo        buildTaskInfo = new BuildTaskInfo(DocumentContextHelper.DesignDataBuildTask, (IDictionary <string, string>) new Dictionary <string, string>());
                DocumentCreationInfo creationInfo  = new DocumentCreationInfo()
                {
                    BuildTaskInfo   = buildTaskInfo,
                    TargetFolder    = path1,
                    TargetPath      = path2,
                    SourcePath      = path3,
                    CreationOptions = CreationOptions.SilentlyOverwrite | CreationOptions.SilentlyOverwriteReadOnly | CreationOptions.DoNotSelectCreatedItems | CreationOptions.DoNotSetDefaultImportPath
                };
                return(((IProject)projectContext.GetService(typeof(IProject))).AddItem(creationInfo));
            }
            finally
            {
                try
                {
                    File.Delete(path3);
                }
                catch
                {
                }
            }
        }
Esempio n. 6
0
        public static IProperty WritablePropertyFromSchemaItem(DataSchemaItem dataSchemaItem)
        {
            IProperty      property       = (IProperty)null;
            DataSchemaNode dataSchemaNode = dataSchemaItem.DataSchemaNode;

            if (dataSchemaNode.Parent != null && dataSchemaNode.IsProperty)
            {
                DataSchemaNode parent = dataSchemaNode.Parent;
                property = (IProperty)dataSchemaItem.DataSourceNode.DocumentNode.TypeResolver.GetType(parent.Type).GetMember(MemberType.Property, dataSchemaNode.PathName, MemberAccessTypes.All);
                if (!DesignDataGenerator.IsPropertyWritable(property, (ITypeResolver)dataSchemaItem.ViewModel.ProjectContext))
                {
                    property = (IProperty)null;
                }
            }
            return(property);
        }
Esempio n. 7
0
        public static bool UpdateDesignValues(IProjectItem designDataFile, IProperty property, ISampleTypeConfiguration valueGenerator)
        {
            designDataFile.OpenView(false);
            SceneDocument sceneDocument = designDataFile.Document as SceneDocument;

            if (sceneDocument == null || sceneDocument.DocumentRoot == null || sceneDocument.DocumentRoot.RootNode == null)
            {
                return(false);
            }
            using (SceneEditTransaction editTransaction = sceneDocument.CreateEditTransaction(StringTable.UpdateDesignValuesUndo))
            {
                DesignDataGenerator.UpdateDesignValues(sceneDocument.DocumentRoot.RootNode, property, valueGenerator);
                editTransaction.Commit();
            }
            return(true);
        }