コード例 #1
0
        public NewUserReturnData CreateUser(String userName)
        {
            SessionAwareCoreServiceClient coreService = Client.GetCoreService();

            try
            {
#if TRIDION2013
                UserData userData = (UserData)coreService.GetDefaultData(ItemType.User, null, new ReadOptions());
#else
                UserData userData = (UserData)coreService.GetDefaultData(ItemType.User, null);
#endif
                userData.Title       = userName;
                userData.Description = userName;

                userData = (UserData)coreService.Create(userData, new ReadOptions());

                _newUserReturnData = new NewUserReturnData();
                _newUserReturnData.UserDescription = userData.Description;
                _newUserReturnData.UserName        = userData.Title;
                _newUserReturnData.UserID          = userData.Id;
                _newUserReturnData.ErrorMessage    = null;
            }
            catch (Exception e)
            {
                _newUserReturnData = new NewUserReturnData();
                _newUserReturnData.UserDescription = "Creation Failed";
                _newUserReturnData.UserName        = userName;
                _newUserReturnData.UserID          = null;
                _newUserReturnData.ErrorMessage    = e.Message;
            }
            return(_newUserReturnData);
        }
コード例 #2
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);
        }
コード例 #3
0
        /// <summary>
        /// Create Keywirds in a given category
        /// </summary>
        /// <param name="model">CategoryModel</param>
        /// <param name="CategoryId">tcm:xx-yy-zz</param>
        /// <returns></returns>
        public static string CreateKeywordsInCategory(CategoryModel model, string CategoryId)
        {
            var result = "true";

            cs_client = CoreServiceProvider.CreateCoreService();

            try
            {
                // open the category that is already created in Tridion
                CategoryData category = (CategoryData)cs_client.Read(CategoryId, null);

                var xmlCategoryKeywords = cs_client.GetListXml(CategoryId, new KeywordsFilterData());
                var keywordAny          = xmlCategoryKeywords.Elements()
                                          .Where(element => element.Attribute("Key").Value == model.Key)
                                          .Select(element => element.Attribute("ID").Value)
                                          .Select(id => (KeywordData)cs_client.Read(id, null)).FirstOrDefault();

                if (keywordAny == null)
                {
                    // create a new keyword
                    KeywordData keyword = (KeywordData)cs_client.GetDefaultData(Tridion.ContentManager.CoreService.Client.ItemType.Keyword, category.Id, new ReadOptions());
                    // set the id to 0 to notify Tridion that it is new
                    keyword.Id          = "tcm:0-0-0";
                    keyword.Title       = model.Title;
                    keyword.Key         = model.Key;
                    keyword.Description = model.Description;
                    keyword.IsAbstract  = false;

                    // create the keyword
                    cs_client.Create(keyword, null);
                    cs_client.Close();
                }
            }
            catch (Exception ex)
            {
                result = "Error: " + ex.Message;
            }
            finally
            {
                cs_client.Close();
            }

            return(result);
        }
コード例 #4
0
        public bool UploadToTridion(string fileName)
        {
            client = PowerTools.Common.CoreService.Client.GetCoreService();
            try
            {
                string mmType = GetMultiMediaType(Path.GetExtension(fileName));
                if (mmType != null)
                {
                    BinaryContentData bcd = new BinaryContentData
                    {
                        UploadFromFile = fileName,
                        MultimediaType = new LinkToMultimediaTypeData {
                            IdRef = mmType
                        },
                        Filename   = Path.GetFileName(fileName),
                        IsExternal = false
                    };

                    ComponentData compData = new ComponentData
                    {
                        LocationInfo = new LocationInfo
                        {
                            OrganizationalItem = new LinkToOrganizationalItemData
                            {
                                IdRef = orgItemUri //Organizational item
                            },
                        },
                        ComponentType = ComponentType.Multimedia,
                        Title         = MakeValidFileName(Path.GetFileNameWithoutExtension(fileName)),

                        Schema = new LinkToSchemaData
                        {
                            IdRef = schemaUri
                        },

                        IsBasedOnMandatorySchema  = false,
                        IsBasedOnTridionWebSchema = true,
                        ApprovalStatus            = new LinkToApprovalStatusData
                        {
                            IdRef = "tcm:0-0-0"
                        },
                        Id            = "tcm:0-0-0",
                        BinaryContent = bcd
                    };

                    ComponentData comp = (ComponentData)client.Create(compData, new ReadOptions());
                    return(true);
                }
            }
            catch (Exception ex)
            {
                string d = ex.Message;
            }
            finally
            {
                if (client != null)
                {
                    client.Close();
                }
            }

            return(false);
        }
コード例 #5
0
        public override void Process(ServiceProcess process, object arguments)
        {
            ImageUploadParameters parameters = (ImageUploadParameters)arguments;

            try
            {
                string directory = parameters.Directory;
                if (!Directory.Exists(directory))
                {
                    process.Failed = true;
                    process.Complete(string.Format(CultureInfo.InvariantCulture, "Directory '{0}' does not exist. No images were uploaded!", directory));
                    return;
                }
                string[] files = Directory.GetFiles(directory);
                int      i     = 0;
                _client = PowerTools.Common.CoreService.Client.GetCoreService();

                //Get all component titles in the target folder
                _componentTitles = getAllComponentTitles(parameters.FolderUri);

                foreach (string file in files)
                {
                    process.SetStatus("Importing image: " + Path.GetFileName(file));
                    process.SetCompletePercentage(++i * 100 / files.Length);

                    FileInfo fileInfo = new FileInfo(file);
                    if (fileInfo.Exists)
                    {
                        string mmType = GetMultiMediaType(fileInfo.Extension);
                        if (mmType != null)
                        {
                            BinaryContentData bcd = new BinaryContentData
                            {
                                UploadFromFile = file,
                                MultimediaType = new LinkToMultimediaTypeData {
                                    IdRef = mmType
                                },
                                Filename   = file,
                                IsExternal = false
                            };

                            ComponentData compData = new ComponentData
                            {
                                LocationInfo = new LocationInfo
                                {
                                    OrganizationalItem = new LinkToOrganizationalItemData
                                    {
                                        IdRef = parameters.FolderUri                                         //Organizational item
                                    },
                                },
                                ComponentType = ComponentType.Multimedia,
                                Title         = MakeValidFileName(fileInfo.Name),

                                Schema = new LinkToSchemaData
                                {
                                    IdRef = parameters.SchemaUri                                     //schemaData.IdRef
                                },

                                IsBasedOnMandatorySchema  = false,
                                IsBasedOnTridionWebSchema = true,
                                ApprovalStatus            = new LinkToApprovalStatusData
                                {
                                    IdRef = "tcm:0-0-0"
                                },
                                Id            = "tcm:0-0-0",
                                BinaryContent = bcd
                            };

                            ComponentData comp = (ComponentData)_client.Create(compData, new ReadOptions());
                        }
                    }
                }

                process.Complete();
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
コード例 #6
0
        public bool UploadToTridion(string fileName)
        {
            client = PowerTools.Common.CoreService.Client.GetCoreService();
            try
            {
                string mmType = GetMultiMediaType(Path.GetExtension(fileName));
                if (mmType != null)
                {

                    BinaryContentData bcd = new BinaryContentData
                    {
                        UploadFromFile = fileName,
                        MultimediaType = new LinkToMultimediaTypeData { IdRef = mmType },
                        Filename = Path.GetFileName(fileName),
                        IsExternal = false
                    };

                    ComponentData compData = new ComponentData
                    {
                        LocationInfo = new LocationInfo
                        {
                            OrganizationalItem = new LinkToOrganizationalItemData
                            {
                                IdRef = orgItemUri //Organizational item
                            },
                        },
                        ComponentType = ComponentType.Multimedia,
                        Title = MakeValidFileName(Path.GetFileNameWithoutExtension(fileName)),

                        Schema = new LinkToSchemaData
                        {
                            IdRef = schemaUri 
                        },

                        IsBasedOnMandatorySchema = false,
                        IsBasedOnTridionWebSchema = true,
                        ApprovalStatus = new LinkToApprovalStatusData
                        {
                            IdRef = "tcm:0-0-0"
                        },
                        Id = "tcm:0-0-0",
                        BinaryContent = bcd
                    };

                    ComponentData comp = (ComponentData)client.Create(compData, new ReadOptions());
                    return true;
                }
            }
            catch (Exception ex)
            {
                string d = ex.Message;
            }
            finally
            {
                if (client != null)
                {
                    client.Close();
                }
            }

            return false;
        }
コード例 #7
0
        private string ImportSingleItem(IEclUri eclUri)
        {
            string id = "tcm:0-0-0";
            IContentLibraryMultimediaItem eclItem = (IContentLibraryMultimediaItem)_eclContentLibraryContext.GetItem(eclUri);
            string       extension = eclItem.Filename.Substring(eclItem.Filename.LastIndexOf('.') + 1);
            MemoryStream ms        = null;
            string       tempPath;

            try
            {
                // create some template attributes
                IList <ITemplateAttribute> attributes = CreateTemplateAttributes(eclItem);

                // determine if item has content or is available online
                string publishedPath = eclItem.GetDirectLinkToPublished(attributes);
                if (string.IsNullOrEmpty(publishedPath))
                {
                    // we can directly get the content
                    IContentResult content = eclItem.GetContent(attributes);
                    ms = new MemoryStream();
                    content.Stream.CopyTo(ms);
                    ms.Position = 0;
                }
                else
                {
                    // read the content from the publish path
                    using (WebClient webClient = new WebClient())
                    {
                        byte[] thumbnailData = webClient.DownloadData(publishedPath);
                        ms = new MemoryStream(thumbnailData, false);
                    }
                }

                // upload binary (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI)
                using (StreamUploadClient suClient = new StreamUploadClient("streamUpload_netTcp_2012"))
                {
                    tempPath = suClient.UploadBinaryContent(eclItem.Filename, ms);
                }
            }
            finally
            {
                if (ms != null)
                {
                    ms.Dispose();
                }
            }

            // create tcm item
            var mmComponent = new ComponentData
            {
                Id     = id,
                Title  = eclItem.Title,
                Schema = new LinkToSchemaData {
                    IdRef = _schemaUri
                },
                LocationInfo = new LocationInfo {
                    OrganizationalItem = new LinkToOrganizationalItemData {
                        IdRef = _folderUri
                    }
                }
            };

            // put binary data in tcm item (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI)
            using (SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2012"))
            {
                // impersonate with current user
                client.Impersonate(_username);

                // set metadata
                var schemaFields = client.ReadSchemaFields(_schemaUri, true, new ReadOptions());
                if (schemaFields.MetadataFields.Any())
                {
                    var fields = Fields.ForMetadataOf(schemaFields, mmComponent);
                    if (!string.IsNullOrEmpty(eclItem.MetadataXml))
                    {
                        XNamespace ns       = GetNamespace(eclItem.MetadataXml);
                        XDocument  metadata = XDocument.Parse(eclItem.MetadataXml);
                        var        children = metadata.Element(ns + "Metadata").Descendants();
                        for (int i = 0; i < children.Count(); i++)
                        {
                            fields.AddFieldElement(new ItemFieldDefinitionData {
                                Name = "data"
                            });
                            var embeddedFields = fields["data"].GetSubFields(i);
                            embeddedFields.AddFieldElement(new ItemFieldDefinitionData {
                                Name = "key"
                            });
                            embeddedFields.AddFieldElement(new ItemFieldDefinitionData {
                                Name = "value"
                            });
                            embeddedFields["key"].Value   = children.ElementAt(i).Name.LocalName;
                            embeddedFields["value"].Value = children.ElementAt(i).Value;
                        }
                    }
                    mmComponent.Metadata = fields.ToString();
                }

                // find multimedia type
                var list           = client.GetSystemWideList(new MultimediaTypesFilterData());
                var multimediaType = list.OfType <MultimediaTypeData>().Single(mt => mt.FileExtensions.Contains(extension));

                // set BinaryContent of a component
                mmComponent.BinaryContent = new BinaryContentData
                {
                    UploadFromFile = tempPath,
                    Filename       = eclItem.Filename,
                    MultimediaType = new LinkToMultimediaTypeData {
                        IdRef = multimediaType.Id
                    }
                };

                // create (and save) component
                ComponentData data = (ComponentData)client.Create(mmComponent, new ReadOptions());
                id = data.Id;
            }

            //string result = string.Format("created {0}, from {1}, in {2}, using {3}, for {4}", id, eclUri, _folderUri, _schemaUri, _username);
            return(id);
        }
コード例 #8
0
        private string ImportSingleItem(IEclUri eclUri)
        {
            string id = "tcm:0-0-0";
            IContentLibraryMultimediaItem eclItem = (IContentLibraryMultimediaItem)_eclContentLibraryContext.GetItem(eclUri);
            string extension = eclItem.Filename.Substring(eclItem.Filename.LastIndexOf('.') + 1);
            MemoryStream ms = null;
            string tempPath;
            try
            {
                // create some template attributes
                IList<ITemplateAttribute> attributes = CreateTemplateAttributes(eclItem);

                // determine if item has content or is available online
                string publishedPath = eclItem.GetDirectLinkToPublished(attributes);
                if (string.IsNullOrEmpty(publishedPath))
                {
                    // we can directly get the content 
                    IContentResult content = eclItem.GetContent(attributes);
                    ms = new MemoryStream();
                    content.Stream.CopyTo(ms);
                    ms.Position = 0;
                }
                else
                {
                    // read the content from the publish path
                    using (WebClient webClient = new WebClient())
                    {
                        byte[] thumbnailData = webClient.DownloadData(publishedPath);
                        ms = new MemoryStream(thumbnailData, false);
                    }
                }

                // upload binary (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI) 
                using (StreamUploadClient suClient = new StreamUploadClient("streamUpload_netTcp_2012"))
                {
                    tempPath = suClient.UploadBinaryContent(eclItem.Filename, ms);
                }
            }
            finally
            {
                if (ms != null)
                {
                    ms.Dispose();
                }
            }

            // create tcm item
            var mmComponent = new ComponentData
            {
                Id = id,
                Title = eclItem.Title,
                Schema = new LinkToSchemaData { IdRef = _schemaUri },
                LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = _folderUri } }
            };

            // put binary data in tcm item (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI) 
            using (SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2012"))
            {
                // impersonate with current user
                client.Impersonate(_username);

                // set metadata
                var schemaFields = client.ReadSchemaFields(_schemaUri, true, new ReadOptions());
                if (schemaFields.MetadataFields.Any())
                {
                    var fields = Fields.ForMetadataOf(schemaFields, mmComponent);
                    if (!string.IsNullOrEmpty(eclItem.MetadataXml))
                    {
                        XNamespace ns = GetNamespace(eclItem.MetadataXml);
                        XDocument metadata = XDocument.Parse(eclItem.MetadataXml);
                        var children = metadata.Element(ns + "Metadata").Descendants();
                        for (int i = 0; i < children.Count(); i++)
                        {
                            fields.AddFieldElement(new ItemFieldDefinitionData { Name = "data" });
                            var embeddedFields = fields["data"].GetSubFields(i);
                            embeddedFields.AddFieldElement(new ItemFieldDefinitionData { Name = "key" });
                            embeddedFields.AddFieldElement(new ItemFieldDefinitionData { Name = "value" });
                            embeddedFields["key"].Value = children.ElementAt(i).Name.LocalName;
                            embeddedFields["value"].Value = children.ElementAt(i).Value;
                        }
                    }
                    mmComponent.Metadata = fields.ToString();
                }

                // find multimedia type
                var list = client.GetSystemWideList(new MultimediaTypesFilterData());
                var multimediaType = list.OfType<MultimediaTypeData>().Single(mt => mt.FileExtensions.Contains(extension));

                // set BinaryContent of a component
                mmComponent.BinaryContent = new BinaryContentData
                {
                    UploadFromFile = tempPath,
                    Filename = eclItem.Filename,
                    MultimediaType = new LinkToMultimediaTypeData { IdRef = multimediaType.Id }
                };

                // create (and save) component
                ComponentData data = (ComponentData)client.Create(mmComponent, new ReadOptions());
                id = data.Id;
            }

            //string result = string.Format("created {0}, from {1}, in {2}, using {3}, for {4}", id, eclUri, _folderUri, _schemaUri, _username);
            return id;
        }
コード例 #9
0
		public override void Process(ServiceProcess process, object arguments)
		{
			ImageUploadParameters parameters = (ImageUploadParameters)arguments;

			try
			{
                string directory = parameters.Directory;
                if (!Directory.Exists(directory))
                {
                    process.Failed = true;
                    process.Complete(string.Format(CultureInfo.InvariantCulture, "Directory '{0}' does not exist. No images were uploaded!", directory));
                    return;
                }
                string[] files = Directory.GetFiles(directory);
				int i = 0;
                _client = PowerTools.Common.CoreService.Client.GetCoreService();

                //Get all component titles in the target folder           
                _componentTitles = getAllComponentTitles(parameters.FolderUri);

				foreach (string file in files)
				{
					process.SetStatus("Importing image: " + Path.GetFileName(file));
					process.SetCompletePercentage(++i * 100 / files.Length);
					
					FileInfo fileInfo = new FileInfo(file);
					if (fileInfo.Exists)
					{
						string mmType = GetMultiMediaType(fileInfo.Extension);
						if (mmType != null)
						{
							BinaryContentData bcd = new BinaryContentData
							{
								UploadFromFile = file,
								MultimediaType = new LinkToMultimediaTypeData { IdRef = mmType },
								Filename = file,
								IsExternal = false
							};

							ComponentData compData = new ComponentData
							{
								LocationInfo = new LocationInfo
								{
									OrganizationalItem = new LinkToOrganizationalItemData
									{
										IdRef = parameters.FolderUri //Organizational item
									},
								},
								ComponentType = ComponentType.Multimedia,
								Title = MakeValidFileName(fileInfo.Name),

								Schema = new LinkToSchemaData
								{
									IdRef = parameters.SchemaUri //schemaData.IdRef
								},

								IsBasedOnMandatorySchema = false,
								IsBasedOnTridionWebSchema = true,
								ApprovalStatus = new LinkToApprovalStatusData
								{
									IdRef = "tcm:0-0-0"
								},
								Id = "tcm:0-0-0",
								BinaryContent = bcd
							};

							ComponentData comp = (ComponentData)_client.Create(compData, new ReadOptions());
						}
					}
				}

				process.Complete();
			}
			finally
			{
				if (_client != null)
				{
					_client.Close();
				}
			}
		}