Ejemplo n.º 1
0
        public SchemaFieldsData ReadSchemaFields(string schemaId, bool expandEmbeddedFields = true, ReadOptions readOptions = null)
        {
            SchemaFieldsData data = null;

            CoreService().Using(client =>
            {
                try
                {
                    if (readOptions == null)
                    {
                        readOptions = new ReadOptions {
                            LoadFlags = LoadFlags.Expanded
                        }
                    }
                    ;
                    data = client.ReadSchemaFields(schemaId, expandEmbeddedFields, readOptions);
                }
                catch (Exception e)
                {
                    throw;
                }
            });

            return(data);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public string getSchemaByTcm(string tcmuri)
        {
            string xmljson = "XML";

            try
            {
                string output = string.Empty;
                coreService = CoreServiceFactory.GetCoreServiceContext(new Uri(ConfigurationManager.AppSettings["CoreServiceURL"].ToString()), new NetworkCredential(ConfigurationManager.AppSettings["UserName"].ToString(), ConfigurationManager.AppSettings["Password"].ToString(), ConfigurationManager.AppSettings["Domain"].ToString()));

                SchemaFieldsData schemaFieldsData = coreService.Client.ReadSchemaFields("tcm:" + tcmuri, false, null);
                if (xmljson.ToString().ToLower() == "json")
                {
                    output = JsonConvert.SerializeObject(schemaFieldsData);
                }
                else
                {
                    output = JsonConvert.SerializeObject(schemaFieldsData);
                    XmlDocument doc = new XmlDocument();

                    using (var reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(output), XmlDictionaryReaderQuotas.Max))
                    {
                        XElement xml = XElement.Load(reader);
                        doc.LoadXml(xml.ToString());
                    }
                    output = doc.InnerXml.ToString();
                }
                return(output);// xmljson.ToString().ToLower() == "json" ? ConvertTojson.ConvertXmlToJson(schemasXml.ToString()) : schemasXml.ToString();
            }
            catch (Exception ex)
            {
                return(ex.Message.ToString());
            }
        }
Ejemplo n.º 4
0
        public SchemaFieldsData ReadSchemaFields(string schemaId, bool expandEmbeddedFields = true, ReadOptions readOptions = null)
        {
            if (_client == null)
            {
                return(default(SchemaFieldsData));
            }

            SchemaFieldsData data = null;


            try
            {
                if (readOptions == null)
                {
                    readOptions = new ReadOptions {
                        LoadFlags = LoadFlags.Expanded
                    }
                }
                ;
                data = _client.ReadSchemaFields(schemaId, expandEmbeddedFields, readOptions);
            }
            catch (Exception e)
            {
                Log.Error("ReadSchemaFields", e);
                throw;
            }


            return(data);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the metadata schema fields.
        /// </summary>
        /// <param name="client">Tridion client object.</param>
        /// <param name="tcmSchema">The TCM schema.</param>
        /// <returns></returns>
        public static List <ItemFieldDefinitionData> GetSchemaMetadataFields(IAlchemyCoreServiceClient client, string tcmSchema)
        {
            SchemaFieldsData schemaFieldsData = client.ReadSchemaFields(tcmSchema, true, null);

            if (schemaFieldsData == null || schemaFieldsData.MetadataFields == null)
            {
                return(null);
            }

            return(schemaFieldsData.MetadataFields.ToList());
        }
Ejemplo n.º 6
0
 public static Fields GetComponentSchemaFields(ICoreServiceFrameworkContext coreService, string schemaID, EnumType.FieldType fieldType)
 {
     try
     {
         SchemaFieldsData schemaFieldData = coreService.Client.ReadSchemaFields(schemaID, true, new ReadOptions());
         return(fieldType == EnumType.FieldType.Component ? Fields.ForContentOf(schemaFieldData)
                                                              : Fields.ForMetadataOf(schemaFieldData));
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 7
0
    private TcmFields parent;      // the parent fields (so we're an embedded schema), where we can find the data

    public TcmFields(SchemaFieldsData _data, ItemFieldDefinitionData[] _definitions, string _content = null, string _rootElementName = null)
    {
        data        = _data;
        definitions = _definitions;
        var content = new XmlDocument();

        if (!string.IsNullOrEmpty(_content))
        {
            content.LoadXml(_content);
        }
        else
        {
            content.AppendChild(content.CreateElement(string.IsNullOrEmpty(_rootElementName) ? _data.RootElementName : _rootElementName, _data.NamespaceUri));
        }
        root             = content.DocumentElement;
        namespaceManager = new XmlNamespaceManager(content.NameTable);
        namespaceManager.AddNamespace("custom", _data.NamespaceUri);
    }
Ejemplo n.º 8
0
        private readonly Fields _parent;         // the parent fields (so we're an embedded schema), where we can find the data

        public Fields(SchemaFieldsData data, ItemFieldDefinitionData[] definitions, string content = null, string rootElementName = null)
        {
            _data        = data;
            _definitions = definitions;
            var doc = new XmlDocument();

            if (!string.IsNullOrEmpty(content))
            {
                doc.LoadXml(content);
            }
            else
            {
                doc.AppendChild(doc.CreateElement(string.IsNullOrEmpty(rootElementName) ? data.RootElementName : rootElementName, data.NamespaceUri));
            }
            _root             = doc.DocumentElement;
            _namespaceManager = new XmlNamespaceManager(doc.NameTable);
            _namespaceManager.AddNamespace("custom", data.NamespaceUri);
        }
Ejemplo n.º 9
0
        public static List <Lead> getLeadList(ICoreServiceFrameworkContext coreService)
        {
            SchemaFieldsData     schemaFieldData = coreService.Client.ReadSchemaFields(ConfigurationManager.AppSettings["SchemaID"].ToString(), true, new ReadOptions());
            UsingItemsFilterData f = new UsingItemsFilterData {
                ItemTypes = new[] { ItemType.Component }
            };

            IdentifiableObjectData[] items = coreService.Client.GetList(ConfigurationManager.AppSettings["SchemaID"].ToString(), f);
            List <Lead> newLeadList        = new List <Lead>();
            XmlDocument Xdoc = new XmlDocument();

            foreach (var item in items)
            {
                Lead          _lead     = new Lead();
                ComponentData component = (ComponentData)coreService.Client.Read(item.Id, new ReadOptions());
                Xdoc.LoadXml(component.Content);
                _lead = DataTransformation.Deserialize <Lead>(Xdoc);
                newLeadList.Add(_lead);
                //Do something
            }
            return(newLeadList);
        }
Ejemplo n.º 10
0
 public static void process(List <News> DataFromExchange)
 {
     try
     {
         coreService = CoreServiceFactory.GetCoreServiceContext(new Uri(ConfigurationSettings.AppSettings["CoreServiceURL"].ToString()), new NetworkCredential(ConfigurationSettings.AppSettings["UserName"].ToString(), ConfigurationSettings.AppSettings["Password"].ToString(), ConfigurationSettings.AppSettings["Domain"].ToString()));
         SchemaFieldsData schemaFieldData = coreService.Client.ReadSchemaFields(ConfigurationSettings.AppSettings["SchemaID"].ToString(), true, new ReadOptions());
         foreach (News p in DataFromExchange)
         {
             string serializeXml = "";
             bool   bln          = helper.helper.Serialize <News>(p, ref serializeXml);
             string xml          = serializeXml;
             var    tcmuri       = TridionComponent.GenerateComponent(coreService, xml, helper.helper.SetPublication(ConfigurationSettings.AppSettings["FolderLocation"].ToString(), ConfigurationSettings.AppSettings["SchemaID"].ToString()), helper.helper.SchemaType.Component, ConfigurationSettings.AppSettings["FolderLocation"].ToString(), p.title, p.title);
             if (p.IsPublish.ToLower() == "true")
             {
                 TridionComponent.Publish(tcmuri, ConfigurationSettings.AppSettings["PublicationTargetIDs"].ToString(), coreService);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        //public static T GetMany<T>(string id, ReadOptions readOptions = null) where T : IdentifiableObjectData
        //{
        //    object obj = null;
        //    CreateCoreServiceClient().Using(client =>
        //    {
        //        try
        //        {
        //            if (readOptions == null) readOptions = new ReadOptions { LoadFlags = LoadFlags.Expanded };
        //            obj = client.Read(id, readOptions);
        //        }
        //        catch (Exception e)
        //        {
        //            obj = null;
        //        }
        //    });
        //    return obj as T;
        //}
        public static SchemaFieldsData GetSchemaFields(string id, bool expandEmbeddedFields = true, ReadOptions readOptions = null)
        {
            SchemaFieldsData obj = null;

            CreateCoreServiceClient().Using(client =>
            {
                try
                {
                    if (readOptions == null)
                    {
                        readOptions = new ReadOptions {
                            LoadFlags = LoadFlags.Expanded
                        }
                    }
                    ;
                    obj = client.ReadSchemaFields(id, expandEmbeddedFields, readOptions);
                }
                catch (Exception e)
                {
                    obj = null;
                }
            });
            return(obj);
        }
Ejemplo n.º 12
0
 public static Fields ForContentOf(SchemaFieldsData data)
 {
     return(new Fields(data, data.Fields));
 }
Ejemplo n.º 13
0
 public static TcmFields ContentFields(this ComponentData component, SchemaFieldsData schema)
 {
     return(TcmFields.ForContentOf(schema, component));
 }
Ejemplo n.º 14
0
 public static TcmFields ForMetadataOf(SchemaFieldsData _data, RepositoryLocalObjectData _item)
 {
     return(new TcmFields(_data, _data.MetadataFields, _item.Metadata, "Metadata"));
 }
Ejemplo n.º 15
0
 public static TcmFields ForContentOf(SchemaFieldsData _data, ComponentData _component)
 {
     return(new TcmFields(_data, _data.Fields, _component.Content));
 }
Ejemplo n.º 16
0
 public static TcmFields ForContentOf(SchemaFieldsData _data)
 {
     return(new TcmFields(_data, _data.Fields));
 }
Ejemplo n.º 17
0
 public static TcmFields MetadataFields(this ComponentData component, SchemaFieldsData schema)
 {
     return(TcmFields.ForMetadataOf(schema, component));
 }
Ejemplo n.º 18
0
 public static Fields ForContentOf(SchemaFieldsData data, ComponentData component)
 {
     return(new Fields(data, data.Fields, component.Content));
 }
 public static Fields ForMetadataOf(SchemaFieldsData _data)
 {
     return(new Fields(_data, _data.MetadataFields));
 }
Ejemplo n.º 20
0
 public static Fields ForMetadataOf(SchemaFieldsData data, RepositoryLocalObjectData item)
 {
     return(new Fields(data, data.MetadataFields, item.Metadata, "Metadata"));
 }