示例#1
0
        private void GatherSchemaDataFields(SchemaData schemaData)
        {
            string prefix = "/";

            if (schemaData.SchemaUrl != null)
            {
                string id = schemaData.SchemaUrl.GetFragment();
                if (id != null)
                {
                    // Make sure it was found and the object is a Schema
                    if (this.file.FindObject(id) is Schema schema)
                    {
                        foreach (SimpleField field in schema.Fields)
                        {
                            this.GatherSimpleFieldFields(field, schema);
                        }

                        this.PopulateSimpleFieldNameMap(schema);
                        prefix = schema.Name + prefix;
                    }
                }
            }

            foreach (SimpleData data in schemaData.SimpleData)
            {
                this.GatherSimpleDataFields(data, prefix);
            }
        }
示例#2
0
 void ProcessSchema()
 {
     _listView.Items.Clear();
     if (_feature.ExtendedData != null)
     {
         if (_feature.ExtendedData.SchemaData != null)
         {
             SchemaData schemaData = _feature.ExtendedData.SchemaData.FirstOrDefault();
             if (schemaData != null)
             {
                 string originalName = _feature.ExtendedData.SchemaData.First().SchemaUrl.OriginalString;
                 if (originalName.StartsWith("#"))
                 {
                     originalName = originalName.Substring(1);
                 }
                 schemaData.SimpleData.ToList().ForEach(d =>
                 {
                     _listView.Items.Add(new KmlSchemaWithValueDto()
                     {
                         Name  = d.Name,
                         Value = d.Text
                     });
                 });
             }
         }
     }
 }
示例#3
0
        /// <summary>
        /// Create bundle from given schema
        /// </summary>
        /// <param name="schemaID"></param>
        /// <param name="folderId"></param>
        /// <returns></returns>
        public static VirtualFolderData CreateBundle(string schemaID, string folderId)
        {
            cs_client = CoreServiceProvider.CreateCoreService();
            SchemaData bundleSchema = (SchemaData)cs_client.Read(schemaID, new ReadOptions());

            SchemaData virtualFolderTypeSchema =
                cs_client.GetVirtualFolderTypeSchema(@"http://www.sdltridion.com/ContentManager/Bundle");

            VirtualFolderData bundle = new VirtualFolderData()
            {
                Id             = "tcm:0-0-0",
                Title          = "Test Bundle Title",
                Description    = "Test Bundle Description",
                MetadataSchema = new LinkToSchemaData()
                {
                    IdRef = bundleSchema.Id
                },
                TypeSchema = new LinkToSchemaData()
                {
                    IdRef = virtualFolderTypeSchema.Id
                },
                LocationInfo = new LocationInfo()
                {
                    OrganizationalItem = new LinkToOrganizationalItemData()
                    {
                        IdRef = folderId
                    }
                }
            };

            bundle = (VirtualFolderData)cs_client.Create(bundle, new ReadOptions());
            return(bundle);
        }
示例#4
0
        private IList <SchemaData> GetConvertibleSchemas(IEnumerable <XElement> rawList)
        {
            List <SchemaData> list = new List <SchemaData>();

            foreach (var item in rawList)
            {
                try
                {
                    SchemaData schema = (SchemaData)Client.Read(item.Attribute("ID").Value, new ReadOptions());
                    if (schema.Purpose == SchemaPurpose.Embedded)
                    {
                        list.Insert(0, schema);// embedded schemas are always needed by other schemas, it saves us some rounds of parsing if we insert them at the top of the list
                        continue;
                    }
                    if (schema.Purpose == SchemaPurpose.Component || schema.Purpose == SchemaPurpose.Multimedia)
                    {
                        list.Add(schema);
                    }
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("R6"))
                    {
                        log.Error($"cannot process schema {item.Attribute("Title").Value} because it contains elements which were introduced in Tridion 9.0; please call this script with the parameter --tridion9");
                        throw e; // TODO: handle gracefully
                    }
                    else
                    {
                        throw e;
                    }
                }
            }
            return(list);
        }
示例#5
0
        public static void Initialize()
        {
            WindowStateInfo.DefaultIcon = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Icon\\DbSharp.ico"));
            AValue.ConfigData           = ConfigData.LoadConfigData();

            var l = AValue.ConfigData.RecentSchemaFiles.Where(el => String.IsNullOrEmpty(el.FilePath)).ToList();

            foreach (var item in l)
            {
                AValue.ConfigData.RecentSchemaFiles.Remove(item);
            }
            AValue.ConfigData.ChangeCultureInfo();

            if (String.IsNullOrEmpty(AValue.ConfigData.SchemaFilePath) == false)
            {
                try
                {
                    String xml = File.ReadAllText(AValue.ConfigData.SchemaFilePath);
                    AValue.LoadSchemaData(xml);
                }
                catch (FileNotFoundException)
                {
                    AValue.ConfigData.SchemaFilePath = "";
                }
            }
            if (AValue.SchemaData == null)
            {
                AValue.SchemaData = new SchemaData();
            }
            AValue.CreateErrorLogFolder();
            Application.Current.DispatcherUnhandledException += DispatcherUnhandledException;
        }
示例#6
0
        private Schema getSchemaData(string id)
        {
            SchemaData       item         = null;
            SchemaFieldsData schemaFields = null;

            try
            {
                using (var coreService = Client.GetCoreService())
                {
                    item         = coreService.Read(id, new ReadOptions()) as SchemaData;
                    schemaFields = coreService.ReadSchemaFields(id, true, new ReadOptions());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }



            Schema schema = new Schema();

            schema.Title           = item.Title;
            schema.Description     = item.Description;
            schema.RootElementName = item.RootElementName;
            schema.NamespaceUri    = item.NamespaceUri;
            schema.LocationInfo    = item.LocationInfo.Path;
            schema.SchemaType      = item.Purpose.Value.ToString();

            schema.Fields         = getFieldsDescription(schemaFields.Fields);
            schema.MetadataFields = getFieldsDescription(schemaFields.MetadataFields);

            return(schema);
        }
示例#7
0
        public void UserExceptionTest()
        {
            try
            {
                var filters = new QueryFilterCollection();
                filters.QueryFilters.Add(new QueryFilter()
                {
                    FieldName         = "RandomName",
                    GroupOperator     = EGroupOperator.And,
                    SearchingOperator = EFilterOperator.Contains,
                    SearchingValue    = 2
                });

                var sort = new SortingName[]
                {
                    new SortingName()
                    {
                        ItemName = "OtherRandomName",
                        Order    = "DESC"
                    }
                };

                var parameters = base.GetDataParameters(ItemName, EQueryType.GridView, 0, 0, filters, sort);

                var result = base.Execute(() => SchemaData.GetDataAsync(parameters).Result, (t) => this.GetResultString(t), this.GetType());
            }
            catch (AggregateException ex)
            {
                if (!(ex.InnerException is ALexException))
                {
                    throw ex;
                }
            }
        }
示例#8
0
        public List <string> GenerateInfoForAllSchema()
        {
            List <string> allSchema = new List <string>();

            TcmUri uri = new TcmUri(bbFolderURI);

            SessionAwareCoreServiceClient client = GetCoreServiceClient();

            RepositoryItemsFilterData filter = new RepositoryItemsFilterData();


            filter.ItemTypes   = new[] { Tridion.ContentManager.CoreService.Client.ItemType.Schema };
            filter.Recursive   = true;
            filter.BaseColumns = Tridion.ContentManager.CoreService.Client.ListBaseColumns.Id;

            IdentifiableObjectData[] schemas = client.GetList(bbFolderURI, filter);

            foreach (SchemaData schema in schemas)
            {
                SchemaData sch = (SchemaData)client.Read(schema.Id, null);
                ParseSchema(sch);
                allSchema.Add(formattedSchemaInfo);
            }

            return(allSchema);
        }
示例#9
0
        public static string GenerateComponent(ICoreServiceFrameworkContext coreService, string xml, string schemaID, helper.SchemaType schemaType, string folderUri, string ext_Id, string ext_Name)
        {
            try
            {
                string          Title        = string.Empty;
                string          Tcmuri       = string.Empty;
                string          ReturnTcmuri = string.Empty;
                SearchQueryData filter       = new SearchQueryData();
                filter.FullTextQuery = "title";
                filter.ItemTypes     = new ItemType[] { ItemType.Component };

                BasedOnSchemaData basedSchema = new BasedOnSchemaData();
                basedSchema.Schema = new LinkToSchemaData()
                {
                    IdRef = schemaID
                };
                basedSchema.Field      = "title";
                basedSchema.FieldValue = ext_Id;


                filter.BasedOnSchemas = new BasedOnSchemaData[] { basedSchema };
                XElement results = coreService.Client.GetSearchResultsXml(filter);
                for (IEnumerator <XElement> e = results.Descendants().GetEnumerator(); e.MoveNext();)
                {
                    Title  = e.Current.Attribute(XName.Get("Title")).Value;
                    Tcmuri = e.Current.FirstAttribute.Value != null ? e.Current.FirstAttribute.Value : null;
                }
                Title = Title != string.Empty ? Title : ext_Name;
                ComponentData componentData = GetNewComponent(folderUri, schemaID, schemaType, Title);

                componentData.ComponentType = ComponentType.Normal;
                SchemaData sd = coreService.Client.Read(schemaID, null) as SchemaData;

                var content = XElement.Parse(xml);
                var xmlns   = UpdateNodesWithDefaultNamespace(content.ToString(), "xmlns=" + "\"" + @"" + sd.NamespaceUri.ToString() + @"""");

                componentData.Content = xmlns.ToString().Replace("Article", "Content");
                TridionObjectInfo tridionObjectInfo = helper.GetTridionObject(coreService, ItemType.Component, folderUri, Title);
                if (tridionObjectInfo.TcmUri != null)
                {
                    componentData.Id = tridionObjectInfo.TcmUri;
                    var data = (ComponentData)coreService.Client.Read(tridionObjectInfo.TcmUri, new ReadOptions());
                    componentData = (ComponentData)coreService.Client.Update(componentData, new ReadOptions());

                    ReturnTcmuri = componentData.Id.ToString();
                }
                else
                {
                    componentData = (ComponentData)coreService.Client.Create(componentData, new ReadOptions());

                    ReturnTcmuri = componentData.Id.ToString();
                }
                return(ReturnTcmuri);
            }
            catch (Exception ex)
            {
                return("");
            }
        }
示例#10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Schema"/> class.
        /// </summary>
        /// <param name="client"><see cref="T:TcmCoreService.Client" /></param>
        /// <param name="schemaData"><see cref="T:Tridion.ContentManager.CoreService.Client.SchemaData" /></param>
        protected Schema(Client client, SchemaData schemaData)
            : base(client, schemaData)
        {
            if (schemaData == null)
                throw new ArgumentNullException("schemaData");

            mSchemaData = schemaData;
        }
        public string GetContent(string sourceTable, DataRow sourceDataRow, SchemaData targetSchema, List<ItemFieldDefinitionData> targetComponentFields, List<ItemFieldDefinitionData> targetMetadataFields, string targetFolderUri, List<ResultInfo> results)
        {
            XNamespace ns = targetSchema.NamespaceUri;
            XElement resElement = new XElement(ns + targetSchema.RootElementName);

            //article header field
            XElement heading = new XElement(ns + "headline", sourceDataRow["Summary"]);
            resElement.Add(heading);

            //article image field - create multimedia component
            string imagePath = sourceDataRow["ImageUrl"] == null ? null : "C:\\web" + sourceDataRow["ImageUrl"].ToString().Replace("/", "\\");

            XElement metadata = new XElement(ns + "Metadata");
            metadata.Add(new XElement(ns + "altText", sourceDataRow["Summary"]));

            //create multimedia component
            ResultInfo imageResult = Functions.SaveMultimediaComponentFromBinary(imagePath, null, metadata.ToString(), targetFolderUri, "Image");
            if (imageResult.Status == Status.Success || imageResult.Status == Status.None)
            {
                //create component link
                ComponentData multimediaComponent = Functions.GetComponent(imageResult.TcmId);
                XElement imageLink = Functions.GetComponentLink(multimediaComponent.Id, multimediaComponent.Title, "image");
                resElement.Add(imageLink);
            }
            //add operation status to dialog
            results.Add(imageResult);

            //article body field - create paragraphs collection
            string body = sourceDataRow["Body"].ToString();
            MatchCollection matches = Regex.Matches(body, @"<p>\s*(.+?)\s*</p>");
            if (matches.Count > 0)
            {
                foreach (Match match in matches)
                {
                    string value = match.Value;
                    value = Regex.Replace(value, "<p[^>]*>", string.Empty);
                    value = Regex.Replace(value, "</p>", string.Empty);

                    XElement articleBody = new XElement(ns + "articleBody");
                    XElement content = new XElement(ns + "content", value);
                    articleBody.Add(content);
                    resElement.Add(articleBody);
                }
            }
            else
            {
                //single paragraph
                XElement articleBody = new XElement(ns + "articleBody");
                XElement content = new XElement(ns + "content", body);
                articleBody.Add(content);
                resElement.Add(articleBody);
            }

            string resText = resElement.ToString();
            resText = resText.Replace(" xmlns=\"\"", string.Empty);

            return resText;
        }
示例#12
0
 public DeleteObjectCommand(String outputDirectoryPath, SchemaData schemaData, String connectionString)
     : base(schemaData, connectionString)
 {
     this.OutputDirectoryPath   = outputDirectoryPath;
     this.DeleteExistedFiles    = false;
     this.TableNames            = new List <string>();
     this.StoredProcedures      = new List <string>();
     this.UserDefinedTableTypes = new List <string>();
 }
示例#13
0
        public UserType(SchemaData data)
        {
            Name        = "User";
            Description = "A user?";

            Field(u => u.Id).Description("Id of the user");
            Field(u => u.Name, nullable: false).Description("Name of the user");
            Field(u => u.Email, nullable: false).Description("Contact details of the user");
        }
示例#14
0
        protected override dynamic GetThreeRecodsResult(DataParameters queryParameters)
        {
            var result = SchemaData.GetDataAsync(queryParameters).Result;

            Assert.True(result.Result[1].Count == 4);
            Assert.True(result.Result[2]["MultiSelectSampleId"] != 0);

            return(result);
        }
示例#15
0
 public static void LoadSchemaData(String xmlText)
 {
     if (String.IsNullOrWhiteSpace(xmlText) == true)
     {
         AValue.SchemaData = new SchemaData();
         return;
     }
     AValue.SchemaData = AppEnvironment.Settings.XmlSerializer.Deserialize <SchemaData>(xmlText);
 }
示例#16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Schema"/> class.
        /// </summary>
        /// <param name="client"><see cref="T:TcmCoreService.Client" /></param>
        /// <param name="schemaData"><see cref="T:Tridion.ContentManager.CoreService.Client.SchemaData" /></param>
        protected Schema(Client client, SchemaData schemaData) : base(client, schemaData)
        {
            if (schemaData == null)
            {
                throw new ArgumentNullException("schemaData");
            }

            mSchemaData = schemaData;
        }
示例#17
0
        public IEnumerable <SchemaData> FindSchema(string schemaId)
        {
            log.Info("Called FindSchema with schemaId " + schemaId);
            SchemaData         mainSchema = Client.Read(schemaId, new ReadOptions()) as SchemaData;
            IList <SchemaData> allSchemas = new List <SchemaData> {
                mainSchema
            };

            AddUsedSchemas(mainSchema, allSchemas);
            return(allSchemas);
        }
示例#18
0
        public ImportObjectCommandService(SchemaData schemaData
                                          , String connectionString
                                          , IEnumerable <String> tableNames
                                          , IEnumerable <String> storedProcedureNames
                                          , IEnumerable <String> userDefinedTableTypeNames)
        {
            this._SchemaData      = schemaData;
            this.ConnectionString = connectionString;
            this._TableNames.AddRange(tableNames);
            this._StoredProcedureNames.AddRange(storedProcedureNames);
            this._UserDefinedTableTypeNames.AddRange(userDefinedTableTypeNames);

            this.InitializeProperty();
        }
示例#19
0
        public static SchemaResult From(SchemaData item, string currentUserId)
        {
            var result = new SchemaResult
            {
                Description = TextEntry.From(item.Description, Resources.LabelDescription),
                Namespace = TextEntry.From(item.NamespaceUri, Resources.LabelNamespace),
                RootElementName = TextEntry.From(item.RootElementName, Resources.LabelRootElementName)
            };

            AddFieldsSummary(item, result);
            AddCommonProperties(item, result);
            AddPropertiesForRepositoryLocalObject(item, result, currentUserId);
            return result;
        }
示例#20
0
        private static void ProcessSchema(SchemaData schema)
        {
            var components = schema.GetAllUsages <ComponentData>();

            foreach (var component in components)
            {
                var usingComponents = component.GetAllUsages <ComponentData>(filterPredicate: x => new TcmUri(x.Schema.IdRef).ItemId != 18521 && new TcmUri(x.Schema.IdRef).ItemId != 18147);

                if (usingComponents.Count > 0)
                {
                    Logger.Warn("Found {0} components using Component {1} based on Schema {2}: {3}", usingComponents.Count, component.Id, schema.Title, string.Join(", ", usingComponents.Select(x => x.Id + " - " + x.Title)));
                }
            }
        }
        public static SchemaResult From(SchemaData item, string currentUserId)
        {
            var result = new SchemaResult
            {
                Description     = TextEntry.From(item.Description, Resources.LabelDescription),
                Namespace       = TextEntry.From(item.NamespaceUri, Resources.LabelNamespace),
                RootElementName = TextEntry.From(item.RootElementName, Resources.LabelRootElementName)
            };

            AddFieldsSummary(item, result);
            AddCommonProperties(item, result);
            AddPropertiesForRepositoryLocalObject(item, result, currentUserId);
            return(result);
        }
示例#22
0
        /// <summary>
        /// Reload the <see cref="Schema" /> with the specified <see cref="T:Tridion.ContentManager.CoreService.Client.SchemaData" />
        /// </summary>
        /// <param name="schemaData"><see cref="T:Tridion.ContentManager.CoreService.Client.SchemaData" /></param>
        protected void Reload(SchemaData schemaData)
        {
            if (schemaData == null)
            {
                throw new ArgumentNullException("schemaData");
            }

            mSchemaData = schemaData;
            base.Reload(schemaData);

            mAllowedMultimediaTypes = null;
            mComponentProcess       = null;
            mBundleProcess          = null;
        }
示例#23
0
        public static ImportItem CreateSchema(SchemaData schemaData)
        {
            var importItem = new ImportItem()
            {
                ItemType        = ItemType.Schema,
                Name            = schemaData.Title,
                Namespace       = schemaData.NamespaceUri,
                Content         = schemaData.Xsd,
                RootElementName = schemaData.RootElementName,
                SchemaPurpose   = schemaData.Purpose.Value,
                SourceId        = schemaData.Id
            };

            return(importItem);
        }
示例#24
0
 public override void GetTableReference()
 {
     var dataParameters   = base.GetDataParameters("BasicColumnType", EQueryType.GridView, 10, 1);
     var sourceParameters = new SourceParameters()
     {
         FieldItemName        = "RecordsGrid",
         ItemName             = "MultiSelectSamplesView",
         QueryType            = EQueryType.EditView,
         AdditionalParameters = new System.Collections.Generic.Dictionary <string, object>()
         {
             { "MultiSelectSampleId", 1 }
         },
     };
     var result = base.Execute(() => SchemaData.GetTableSourceAsync(sourceParameters, dataParameters).Result, (t) => this.GetResultString(t), this.GetType());
 }
示例#25
0
 private void GetInitialCatalogData()
 {
     try
     {
         SetConnectionInfo(true);
         SchemaData schemaData = new SchemaData();
         var        result     = schemaData.GetInitialCatalogData();
         cbInitialCatalog.DisplayMember = "SCHEMA_Field02";
         cbInitialCatalog.ValueMember   = "SCHEMA_Field01";
         cbInitialCatalog.DataSource    = result.ToList();
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("取得資料庫名稱時發生錯誤. SysInfo={0}", ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#26
0
        public override void GetSource()
        {
            var parameters = new SourceParameters()
            {
                FieldItemName        = "CheckboxSelection",
                ItemName             = base.ItemName,
                QueryType            = EQueryType.EditView,
                AdditionalParameters = new System.Collections.Generic.Dictionary <string, object>()
                {
                    { "MultiSelectSampleId", 1 }
                },
            };
            var result = base.Execute(() => SchemaData.GetDataSourceAsync(parameters).Result, (t) => this.GetResultString(t), this.GetType());

            Assert.True(result.Result.Count > 0);
            Assert.True(result.Result[0].Value != 0);
        }
        private void btnGetTable_Click(object sender, EventArgs e)
        {
            SchemaData schemaData = new SchemaData();
            var        result     = schemaData.GetTableData();

            SetLog("讀取 Schema..");
            treeView1.Nodes[0].Text = frmORMappingWindow.ConnectionInfo.Initial_Catalog;
            SetLog(string.Format("讀取資料庫 {0}..", frmORMappingWindow.ConnectionInfo.Initial_Catalog));
            treeView1.Nodes[0].Nodes.Clear();
            foreach (var schema in result)
            {
                TreeNode node = new TreeNode(schema.SCHEMA_Field03);
                treeView1.Nodes[0].Nodes.Add(node);
            }
            SetLog("讀取資料表完成.");
            treeView1.ExpandAll();
        }
示例#28
0
        /// <summary>
        /// Gets a list of all component templates used by this schema
        /// </summary>
        /// <param name="schemaId">The schema ID</param>
        /// <returns><![CDATA[An IEnumerabe<XNode> list of component templates]]></returns>
        private IEnumerable <XNode> GetUsingComponentTemplates(ComponentData component)
        {
            SchemaData componentSchema = GetComponentSchema(component.Schema.IdRef);

            LogMessage("The component's schema ID is " + componentSchema.Id);
            UsingItemsFilterData usingFilter = new UsingItemsFilterData();

            usingFilter.ItemTypes        = new[] { ItemType.ComponentTemplate };
            usingFilter.IncludedVersions = VersionCondition.OnlyLatestVersions;

            //LinkToRepositoryData contextRepository = new LinkToRepositoryData()
            //{
            //    IdRef = TestContext.Properties["TemplatePublicationId"].ToString()
            //};
            //usingFilter.InRepository = contextRepository;

            return(Client.GetListXml(componentSchema.Id, usingFilter).Nodes());
        }
示例#29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="folderID"></param>
        /// <param name="recursive"></param>
        /// <param name="srcSchemaID"></param>
        /// <param name="destSchemaID"></param>
        public static string UpdateSchemaForComponent(string folderID, bool recursive, string srcSchemaID, string destSchemaID, bool isMultiMediaComp)
        {
            cs_client = CoreServiceProvider.CreateCoreService();
            StringBuilder        sb          = new StringBuilder();
            FolderData           folder      = cs_client.Read(folderID, null) as FolderData;
            SchemaData           schema      = cs_client.Read(destSchemaID, null) as SchemaData;
            XNamespace           ns          = schema.NamespaceUri;
            XElement             items       = cs_client.GetListXml(folder.Id, SetComponenetFilterCriterias(isMultiMediaComp));
            List <ComponentData> failedItems = new List <ComponentData>();

            foreach (XElement item in items.Elements())
            {
                ComponentData component = cs_client.Read(item.Attribute("ID").Value, null) as ComponentData;

                if (!component.Schema.IdRef.Equals(srcSchemaID))
                {
                    // If the component is not of the schmea that we want to change from, do nothing...
                    return("");
                }

                if (component.Schema.IdRef.Equals(schema.Id))
                {
                    // If the component already has this schema, don't do anything.
                    return("");
                }

                component = cs_client.TryCheckOut(component.Id, new ReadOptions()) as ComponentData;


                if (component.IsEditable.Value)
                {
                    component.Schema.IdRef = destSchemaID;
                    component.Metadata     = new XElement(ns + "Metadata").ToString();
                    cs_client.Save(component, null);
                    cs_client.CheckIn(component.Id, null);
                }
                else
                {
                    sb.AppendLine("Schema Can not be updated for: " + component.Id);
                    sb.AppendLine("");
                }
            }
            return(sb.ToString());
        }
示例#30
0
        private void AddUsedSchemas(SchemaData mainSchema, IList <SchemaData> allSchemas)
        {
            log.Info($"Called AddUsedSchemas to find dependent schemas for {mainSchema.Title} - total number of schemas found so far: {allSchemas.Count()}");
            UsedItemsFilterData filter = new UsedItemsFilterData
            {
                ItemTypes = new ItemType[] { ItemType.Category }
            };
            XElement list           = Client.GetListXml(mainSchema.Id, filter);
            var      usedCategories = list.Descendants();

            if (usedCategories.Count() > 0)
            {
                foreach (var elmt in usedCategories)
                {
                    CategoryData cat = (CategoryData)Client.Read(elmt.Attribute("ID").Value, new ReadOptions());
                    if (cat.KeywordMetadataSchema != null && cat.KeywordMetadataSchema.IdRef != "tcm:0-0-0")
                    {
                        if (!allSchemas.Select(s => s.Id).Contains(cat.KeywordMetadataSchema.IdRef))
                        {
                            SchemaData s = Client.Read(cat.KeywordMetadataSchema.IdRef, new ReadOptions()) as SchemaData;
                            allSchemas.Add(s);
                            AddUsedSchemas(s, allSchemas);
                        }
                    }
                }
            }
            filter = new UsedItemsFilterData
            {
                ItemTypes = new ItemType[] { ItemType.Schema }
            };
            list = Client.GetListXml(mainSchema.Id, filter);
            var unprocessedSchemas = list.Descendants().Where(i => !(allSchemas.Select(s => s.Id).Contains(i.Attribute("ID").Value)));

            if (unprocessedSchemas.Count() > 0)
            {
                IEnumerable <SchemaData> usedSchemas = GetConvertibleSchemas(unprocessedSchemas);
                //allSchemas = allSchemas.Union(usedSchemas).ToList();
                allSchemas.AddRange(usedSchemas.Where(p => !allSchemas.Any(p2 => p2.Id == p.Id)));
                foreach (SchemaData usedSchema in usedSchemas)
                {
                    AddUsedSchemas(usedSchema, allSchemas);
                }
            }
        }
        private void btnGetTables_Click(object sender, EventArgs e)
        {
            SchemaData schemaData = new SchemaData();

            try
            {
                RefreshTreeView(schemaData);
                btnNext.Enabled = true;
                ConnectionServices.CleanErrorMsg();
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("讀取資料表時發生錯誤. SysInfo={0}", ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnNext.Enabled = false;
                ConnectionServices.Error(ex);
                ConnectionServices.ShowConnectWindow();
                RefreshTreeView(schemaData);
            }
        }
示例#32
0
        public DeleteObjectCommandService(String outputDirectoryPath
                                          , SchemaData schemaData
                                          , String connectionString
                                          , IEnumerable <String> tableNames
                                          , IEnumerable <String> storedProcedureNames
                                          , IEnumerable <String> userDefinedTableTypeNames)

        {
            this._SchemaData = schemaData;
            var sc = this._SchemaData;

            var cm = new DeleteObjectCommand(outputDirectoryPath, sc, connectionString);

            cm.TableNames.AddRange(tableNames);
            cm.StoredProcedures.AddRange(storedProcedureNames);
            cm.UserDefinedTableTypes.AddRange(userDefinedTableTypeNames);

            this.Commands.Add(cm);
        }
示例#33
0
        public SchemaTestBase(string logPath) : base(logPath)
        {
            var factory = new SqlQueryBuilderTestFactory();

            var db      = factory.CreateDbContext(null);
            var options = factory.GetQueryBuilderOptions();

            var context = new SchemaContext(options, db);

            SchemaData           = new SchemaData(context);
            SchemaConfigurations = new SchemaConfigurations(context);

            // Loads this in order to improve the test performance.
            // If I don't do this the first load last up to 300ms the first time.
            var parameters = this.GetDataParameters("BasicColumnType", EQueryType.DetailListView, 1, 0);

            SchemaConfigurations.GetEditConfigAsync(parameters).Wait();
            SchemaData.GetDataAsync(parameters).Wait();
        }
        public ModelBuilder(SchemaData schema, ModelBase model)
        {
            XDocument doc = XDocument.Parse(schema.Xsd);
            model.Name = schema.Title;

            if (model is EmbeddedModel)
            {
                XElement complexType = doc.Root.Descendants(Constants.XSD_NAMESPACE + "complexType")
                    .FirstOrDefault(x => x.Attribute("name") != null && x.Attribute("name").Value == schema.RootElementName);
                new FieldsBuilder(complexType, model.Fields);
            }
            else
            {
                XElement content = doc.Root.Descendants(Constants.XSD_NAMESPACE + "element")
                    .FirstOrDefault(x => x.Attribute("name") != null && x.Attribute("name").Value == "Content");
                new FieldsBuilder(content, model.Fields);

                XElement metadata = doc.Root.Descendants(Constants.XSD_NAMESPACE + "element")
                    .FirstOrDefault(x => x.Attribute("name") != null && x.Attribute("name").Value == "Metadata");
                new FieldsBuilder(metadata, model.MetadataFields);
            }
        }
示例#35
0
        private static void AddFieldsSummary(SchemaData schema, SchemaResult result)
        {
            try
            {
                XDocument doc = XDocument.Parse(schema.Xsd);
                const string nameAttr = "name";

                if (!string.IsNullOrWhiteSpace(schema.RootElementName))
                {
                    var rootElement = doc.Descendants(schemaFields).FirstOrDefault(e => e.Attribute(nameAttr) != null && e.Attribute(nameAttr).Value == schema.RootElementName);
                    result.FieldsSummary = TextEntry.From(GetFieldSummary(rootElement, Resources.None), Resources.LabelFieldsSummary);
                }

                bool expectFields = (schema.Purpose == SchemaPurpose.Metadata ||
                                     schema.Purpose == SchemaPurpose.Multimedia ||
                                     schema.Purpose == SchemaPurpose.Bundle);

                var metadataRoot = doc.Descendants(schemaFields).FirstOrDefault(e => e.Attribute(nameAttr) != null && e.Attribute(nameAttr).Value == "Metadata");
                result.MetadataFieldsSummary = TextEntry.From(GetFieldSummary(metadataRoot, expectFields ? Resources.None : null), Resources.LabelMetadataFieldsSummary);
            }
            catch (System.Xml.XmlException)
            {
            }
        }
        public string GetFixedContent(SchemaData sourceSchema, List<ItemFieldDefinitionData> sourceComponentFields, List<ItemFieldDefinitionData> sourceMetadataFields, string sourceComponentXml, string sourceMetadataXml, string sourceUri, SchemaData targetSchema, List<ItemFieldDefinitionData> targetComponentFields, List<ItemFieldDefinitionData> targetMetadataFields, string targetFolderUri, List<ResultInfo> results)
        {
            XDocument sourceDoc = XDocument.Parse(sourceMetadataXml);
            XElement root = sourceDoc.Root;
            if (root == null)
                return string.Empty;

            XNamespace sourceNs = sourceSchema.NamespaceUri;

            XNamespace ns = targetSchema.NamespaceUri;
            XElement resElement = new XElement(ns + targetSchema.RootElementName);

            // just copy from source to target
            XElement xTitle = root.Elements(sourceNs + "title").FirstOrDefault();
            if (xTitle != null)
            {
                resElement.Add(xTitle);
            }

            // just copy from source to target
            XElement xDescription = root.Elements(sourceNs + "description").FirstOrDefault();
            if (xDescription != null)
            {
                resElement.Add(xDescription);
            }

            // just copy from source to target
            XElement xKeywords = root.Elements(sourceNs + "keywords").FirstOrDefault();
            if (xKeywords != null)
            {
                resElement.Add(xKeywords);
            }

            // just copy from source to target
            XElement xOpenGraph = root.Elements(sourceNs + "openGraph").FirstOrDefault();
            if (xOpenGraph != null)
            {
                resElement.Add(xOpenGraph);
            }

            // find which checkboxes are checked
            bool showInTopNavigation = sourceDoc.Root.GetByXPath("Metadata/navigationOptions/ShowInTopNavigation", sourceNs) != null;
            bool showInFooterNavigation = sourceDoc.Root.GetByXPath("Metadata/navigationOptions/ShowInFooterNavigation", sourceNs) != null;
            bool showInBreadcrumbs = sourceDoc.Root.GetByXPath("Metadata/navigationOptions/ShowInBreadcrumbs", sourceNs) != null;
            bool showInLeftSideNavigation = sourceDoc.Root.GetByXPath("Metadata/navigationOptions/ShowInLeftSideNavigation", sourceNs) != null;
            bool showInSiteMapNavigation = sourceDoc.Root.GetByXPath("Metadata/navigationOptions/ShowInSiteMapNavigation", sourceNs) != null;
            bool showInMobileNavigation = sourceDoc.Root.GetByXPath("Metadata/navigationOptions/ShowInMobileNavigation", sourceNs) != null;

            if (showInTopNavigation || showInFooterNavigation || showInBreadcrumbs || showInLeftSideNavigation || showInSiteMapNavigation || showInMobileNavigation)
            {
                //find keywors that are used in target component
                string publicationId = Functions.GetPublicationTcmId(targetFolderUri);
                string categoryId = Functions.GetCategoriesByPublication(publicationId).First(x => x.Title == "Navigation").TcmId;
                List<ItemInfo> keywords = Functions.GetKeywordsByCategory(categoryId);

                // create field with selected Top keyword
                if (showInTopNavigation)
                {
                    ItemInfo keyword = keywords.First(x => x.Title == "Top");

                    XElement navigationOption = new XElement(ns + "navigationOption");
                    navigationOption.Add(Functions.GetKeywordLink(keyword.TcmId, keyword.Title, "Navigation"));
                    resElement.Add(navigationOption);
                }

                // create field with selected Footer keyword
                if (showInFooterNavigation)
                {
                    ItemInfo keyword = keywords.First(x => x.Title == "Footer");

                    XElement navigationOption = new XElement(ns + "navigationOption");
                    navigationOption.Add(Functions.GetKeywordLink(keyword.TcmId, keyword.Title, "Navigation"));
                    resElement.Add(navigationOption);
                }

                // create field with selected Breadcrumbs keyword
                if (showInBreadcrumbs)
                {
                    ItemInfo keyword = keywords.First(x => x.Title == "Breadcrumbs");

                    XElement navigationOption = new XElement(ns + "navigationOption");
                    navigationOption.Add(Functions.GetKeywordLink(keyword.TcmId, keyword.Title, "Navigation"));
                    resElement.Add(navigationOption);
                }

                // create field with selected LeftSide keyword
                if (showInLeftSideNavigation)
                {
                    ItemInfo keyword = keywords.First(x => x.Title == "LeftSide");

                    XElement navigationOption = new XElement(ns + "navigationOption");
                    navigationOption.Add(Functions.GetKeywordLink(keyword.TcmId, keyword.Title, "Navigation"));
                    resElement.Add(navigationOption);
                }

                // create field with selected SiteMap keyword
                if (showInSiteMapNavigation)
                {
                    ItemInfo keyword = keywords.First(x => x.Title == "SiteMap");

                    XElement navigationOption = new XElement(ns + "navigationOption");
                    navigationOption.Add(Functions.GetKeywordLink(keyword.TcmId, keyword.Title, "Navigation"));
                    resElement.Add(navigationOption);
                }

                // create field with selected Mobile keyword
                if (showInMobileNavigation)
                {
                    ItemInfo keyword = keywords.First(x => x.Title == "Mobile");

                    XElement navigationOption = new XElement(ns + "navigationOption");
                    navigationOption.Add(Functions.GetKeywordLink(keyword.TcmId, keyword.Title, "Navigation"));
                    resElement.Add(navigationOption);
                }
            }

            string resText = resElement.ToString();
            resText = resText.Replace(" xmlns=\"\"", string.Empty);
            resText = resText.Replace(String.Format(" xmlns=\"{0}\"", sourceNs), string.Empty);

            return resText;
        }
示例#37
0
        /// <summary>
        /// Reload the <see cref="Schema" /> with the specified <see cref="T:Tridion.ContentManager.CoreService.Client.SchemaData" />
        /// </summary>
        /// <param name="schemaData"><see cref="T:Tridion.ContentManager.CoreService.Client.SchemaData" /></param>
        protected void Reload(SchemaData schemaData)
        {
            if (schemaData == null)
                throw new ArgumentNullException("schemaData");

            mSchemaData = schemaData;
            base.Reload(schemaData);

            mAllowedMultimediaTypes = null;
            mComponentProcess = null;
            mBundleProcess = null;
        }
示例#38
0
        private ViewModel CoreCreateModel(SchemaData schema, SessionAwareCoreServiceClient client)
        {
            Console.WriteLine("\nTitle:" + schema.Title + ", Schema Purpose: " + schema.Purpose);
            IList<FieldProperty> modelProperties = new List<FieldProperty>();
            ViewModel model = new ViewModel();
            switch (schema.Purpose)
            {
                case SchemaPurpose.Embedded:
                    model.BaseClass = typeof(ViewModelBase);
                    model.ModelType = ModelType.EmbeddedSchemaFields;
                    break;
                case SchemaPurpose.Component:
                    model.BaseClass = typeof(ViewModelBase);
                    model.ModelType = ModelType.ComponentPresentation;
                    break;
                case SchemaPurpose.Metadata:
                    return null;
                case SchemaPurpose.Multimedia:
                    model.BaseClass = typeof(ViewModelBase);
                    model.ModelType = ModelType.MultimediaComponent;
                    break;
                case SchemaPurpose.Protocol:
                    return null;
                case SchemaPurpose.TemplateParameters:
                    return null;
                case SchemaPurpose.UnknownByClient:
                    return null;
                case SchemaPurpose.VirtualFolderType:
                    return null;
                case SchemaPurpose.Bundle:
                    return null;
                default:
                    break;
            }

            SchemaFieldsData fields = client.ReadSchemaFields(schema.Id, false, expandedOptions);

            if (fields.Fields != null)
            {
                ProcessFields(fields.Fields, false, ref modelProperties);
            }
            if (fields.MetadataFields != null)
            {
                ProcessFields(fields.MetadataFields, true, ref modelProperties);
            }
            model.Name = schema.Title.ResolveModelName();
            model.SchemaName = schema.Title;
            model.FieldProperties = modelProperties;
            model.ContainingFolder = schema.LocationInfo.OrganizationalItem.Title.ResolveModelName();
            return model;
        }