Пример #1
0
        /// <summary>
        /// Get publishing targets for any given publication
        /// </summary>
        /// <param name="publicationID"></param>
        /// <returns></returns>
        public static Dictionary <string, List <string> > GetPublishingTargets(List <string> publicationIDs)
        {
            cs_client = CoreServiceProvider.CreateCoreService();
            Dictionary <string, List <string> > resultTargets = new Dictionary <string, List <string> >();
            var pubTargets = cs_client.GetSystemWideList(new PublicationTargetsFilterData());

            foreach (var publicationID in publicationIDs)
            {
                foreach (PublicationTargetData pubTargetdata in pubTargets)
                {
                    List <string>           targetIds    = new List <string>();
                    PublicationTargetData   target       = (PublicationTargetData)cs_client.Read(pubTargetdata.Id, new ReadOptions());
                    LinkToPublicationData[] pubDataItems = target.Publications;
                    foreach (LinkToPublicationData publicationData in pubDataItems)
                    {
                        if (publicationData.IdRef == publicationID)
                        {
                            if (resultTargets.ContainsKey(publicationData.Title))
                            {
                                resultTargets[publicationData.Title].Add(pubTargetdata.Id);
                            }

                            else
                            {
                                targetIds.Add(pubTargetdata.Id);
                                resultTargets.Add(publicationData.Title, targetIds);
                            }
                        }
                    }
                }
            }

            return(resultTargets);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PublicationTarget"/> class.
        /// </summary>
        /// <param name="client"><see cref="T:TcmCoreService.Client" /></param>
        /// <param name="publicationTargetData"><see cref="T:Tridion.ContentManager.CoreService.Client.PublicationTargetData" /></param>
        protected PublicationTarget(Client client, PublicationTargetData publicationTargetData)
            : base(client, publicationTargetData)
        {
            if (publicationTargetData == null)
                throw new ArgumentNullException("publicationTargetData");

            mPublicationTargetData = publicationTargetData;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PublicationTarget"/> class.
        /// </summary>
        /// <param name="client"><see cref="T:TcmCoreService.Client" /></param>
        /// <param name="publicationTargetData"><see cref="T:Tridion.ContentManager.CoreService.Client.PublicationTargetData" /></param>
        protected PublicationTarget(Client client, PublicationTargetData publicationTargetData) : base(client, publicationTargetData)
        {
            if (publicationTargetData == null)
            {
                throw new ArgumentNullException("publicationTargetData");
            }

            mPublicationTargetData = publicationTargetData;
        }
        public static PublicationTargetResult From(PublicationTargetData item)
        {
            var result = new PublicationTargetResult
            {
                Description    = TextEntry.From(item.Description, Resources.LabelDescription),
                TargetLanguage = TextEntry.From(item.TargetLanguage, Resources.LabelTargetLanguage)
            };

            if (item.DefaultCodePage != null)
            {
                string codePage = "System Default";
                if (item.DefaultCodePage > 0)
                {
                    var encoding = Encoding.GetEncodings().FirstOrDefault(e => e.CodePage == item.DefaultCodePage);
                    if (encoding != null)
                    {
                        codePage = encoding.DisplayName;
                    }
                }
                result.DefaultCodePage = TextEntry.From(codePage, Resources.LabelDefaultCodePage);
            }

            if (item.Priority != null)
            {
                string priority = Resources.PriorityMedium;

                switch (item.Priority.Value)
                {
                case PublishPriority.High:
                    priority = Resources.PriorityHigh;
                    break;

                case PublishPriority.Low:
                    priority = Resources.PriorityLow;
                    break;
                }

                result.Priority = TextEntry.From(priority, Resources.LabelPriority);
            }

            var destinations = item.Destinations.Select(
                destination => string.Format(Resources.PublicationTargetDestination, destination.Title, destination.ProtocolSchema.Title)
                ).ToList();

            result.Destinations = TextEntry.From(string.Join(", ", destinations), Resources.LabelDestinations);

            AddCommonProperties(item, result);
            return(result);
        }
        /// <summary>
        /// Reload the <see cref="PublicationTarget" /> with the specified <see cref="T:Tridion.ContentManager.CoreService.Client.PublicationTargetData" />
        /// </summary>
        /// <param name="publicationTargetData"><see cref="T:Tridion.ContentManager.CoreService.Client.PublicationTargetData" /></param>
        protected void Reload(PublicationTargetData publicationTargetData)
        {
            if (publicationTargetData == null)
            {
                throw new ArgumentNullException("publicationTargetData");
            }

            mPublicationTargetData = publicationTargetData;
            base.Reload(publicationTargetData);

            mMinApprovalStatus = null;
            mDestinations      = null;
            mPublications      = null;
            mTargetTypes       = null;
        }
        public static PublicationTargetResult From(PublicationTargetData item)
        {
            var result = new PublicationTargetResult
            {
                Description = TextEntry.From(item.Description, Resources.LabelDescription),
                TargetLanguage = TextEntry.From(item.TargetLanguage, Resources.LabelTargetLanguage)
            };

            if (item.DefaultCodePage != null)
            {
                string codePage = "System Default";
                if (item.DefaultCodePage > 0)
                {
                    var encoding = Encoding.GetEncodings().FirstOrDefault(e => e.CodePage == item.DefaultCodePage);
                    if (encoding != null)
                    {
                        codePage = encoding.DisplayName;
                    }
                }
                result.DefaultCodePage = TextEntry.From(codePage, Resources.LabelDefaultCodePage);
            }

            if (item.Priority != null)
            {
                string priority = Resources.PriorityMedium;

                switch (item.Priority.Value)
                {
                    case PublishPriority.High:
                        priority = Resources.PriorityHigh;
                        break;
                    case PublishPriority.Low:
                        priority = Resources.PriorityLow;
                        break;
                }

                result.Priority = TextEntry.From(priority, Resources.LabelPriority);
            }

            var destinations = item.Destinations.Select(
                    destination => string.Format(Resources.PublicationTargetDestination, destination.Title, destination.ProtocolSchema.Title)
                ).ToList();

            result.Destinations = TextEntry.From(string.Join(", ", destinations), Resources.LabelDestinations);

            AddCommonProperties(item, result);
            return result;
        }
        internal void CreatePublicationTarget(XElement site, WebsiteHelper.TargetLanguage language)
        {
            string targetName   = site.Element("Name").Value;
            string targetTypeId = TcmUri.UriNull;
            string url          = string.Empty;

            if (language == WebsiteHelper.TargetLanguage.Aspnet || language == WebsiteHelper.TargetLanguage.REL)
            {
                url = "http://localhost:" + site.Element("Port").Value + "/httpupload.aspx";
            }
            else if (language == WebsiteHelper.TargetLanguage.Jsp)
            {
                url = "http://localhost:" + site.Element("Port").Value + "/" + site.Element("ContextRoot").Value + "/httpupload";
            }


            TargetTypesFilterData filter = new TargetTypesFilterData();

            //filter.ForRepository.IdRef = Configuration.WebsitePublicationId;
            foreach (XElement node in _client.GetSystemWideListXml(filter).Nodes())
            {
                if (node.Attribute("Title").Value.Equals(targetName))
                {
                    targetTypeId = node.Attribute("ID").Value;
                    break;
                }
            }
            if (targetTypeId.Equals(TcmUri.UriNull))
            {
                TargetTypeData targetType =
                    (TargetTypeData)_client.GetDefaultData(ItemType.TargetType, null);
                targetType.Title       = targetName;
                targetType.Description = targetName;
                targetType             = (TargetTypeData)_client.Save(targetType, _readOptions);
                targetTypeId           = targetType.Id;
            }

            PublicationTargetsFilterData pFilter = new PublicationTargetsFilterData();
            string pTargetId = TcmUri.UriNull;

            foreach (XElement node in _client.GetSystemWideListXml(pFilter).Nodes())
            {
                if (node.Attribute("Title").Value.Equals(targetName))
                {
                    pTargetId = node.Attribute("ID").Value;
                    break;
                }
            }
            if (pTargetId.Equals(TcmUri.UriNull))
            {
                PublicationTargetData pt =
                    (PublicationTargetData)_client.GetDefaultData(ItemType.PublicationTarget, null);
                pt.Title        = targetName;
                pt.Description  = targetName;
                pt.Publications = new[] { new LinkToPublicationData {
                                              IdRef = Configuration.WebsitePublicationId
                                          } };
                pt.TargetTypes = new[] { new LinkToTargetTypeData {
                                             IdRef = targetTypeId
                                         } };

                SchemaData protocolSchema = (SchemaData)_client.Read("/webdav//HTTPS.xsd", _readOptions);

                //_client.GetSystemWideListXml()

                TargetDestinationData destination = new TargetDestinationData
                {
                    ProtocolSchema = new LinkToSchemaData {
                        IdRef = protocolSchema.Id
                    },
                    Title        = targetName,
                    ProtocolData =
                        "<HTTPS xmlns=\"" + protocolSchema.NamespaceUri + "\"><UserName>notused</UserName><Password>notused</Password><URL>" +
                        url + "</URL></HTTPS>"
                };
                pt.Destinations = new[] { destination };
                if (language == WebsiteHelper.TargetLanguage.Aspnet)
                {
                    pt.TargetLanguage = "ASP.NET";
                }
                else
                {
                    pt.TargetLanguage = "JSP";
                }

                _client.Save(pt, null);
            }
        }
        /// <summary>
        /// Reload the <see cref="PublicationTarget" /> with the specified <see cref="T:Tridion.ContentManager.CoreService.Client.PublicationTargetData" />
        /// </summary>
        /// <param name="publicationTargetData"><see cref="T:Tridion.ContentManager.CoreService.Client.PublicationTargetData" /></param>
        protected void Reload(PublicationTargetData publicationTargetData)
        {
            if (publicationTargetData == null)
                throw new ArgumentNullException("publicationTargetData");

            mPublicationTargetData = publicationTargetData;
            base.Reload(publicationTargetData);

            mMinApprovalStatus = null;
            mDestinations = null;
            mPublications = null;
            mTargetTypes = null;
        }