예제 #1
0
        static void Main()
        {
            SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2013");

            ContentManager cm = new ContentManager(client);
            List<Source> sources = cm.GetSources();
            foreach (var source in sources)
            {
                List<Article> articles = cm.GetArticlesForSource(source);
                foreach (Article article in articles)
                {
                    string id = article.Id.ToString().Replace("tcm:4", "tcm:5");
                    if(!client.IsPublished(id, "tcm:0-2-65537", true))
                        cm.Publish(new []{id}, "tcm:0-2-65537");
                }
            }
        }
예제 #2
0
        public SocialPageData Execute(string pageUri)
        {
            SessionAwareCoreServiceClient client = null;
            SocialPageData socialPageData        = new SocialPageData();

            try
            {
                client = Client.GetCoreService();

                string liveTargetUri = Configuration.GetConfigString("livetargeturi");
                string liveUrl       = Configuration.GetConfigString("liveurl");

                PageData            pageData = (PageData)client.Read(pageUri, new ReadOptions());
                PublishLocationInfo pubInfo  = (PublishLocationInfo)pageData.LocationInfo;

                socialPageData.Title       = pageData.Title;
                socialPageData.Uri         = pageUri;
                socialPageData.Url         = liveUrl + pubInfo.PublishLocationUrl;
                socialPageData.IsPublished = client.IsPublished(pageUri, liveTargetUri, true);
                socialPageData.UseShortUrl = bool.Parse(Configuration.GetConfigString("shorturl"));

                string shortUrl = string.Empty;

                if (socialPageData.UseShortUrl)
                {
                    ApplicationData appData = client.ReadApplicationData(pageUri, SHORT_URL_APP_ID);

                    if (appData != null)
                    {
                        Byte[] data = appData.Data;
                        shortUrl = Encoding.Unicode.GetString(data);
                    }

                    if (shortUrl.Equals(string.Empty))
                    {
                        Bitly  service = new Bitly(socialPageData.Url);
                        string shorter = service.ShortenUrl(service.UrlToShorten, service.BitlyLogin, service.BitlyAPIKey);
                        shortUrl = Bitly.ParseXmlResponse(shorter, false);

                        Byte[] byteData = Encoding.Unicode.GetBytes(shortUrl);
                        appData = new ApplicationData
                        {
                            ApplicationId = SHORT_URL_APP_ID,
                            Data          = byteData,
                            TypeId        = shortUrl.GetType().ToString()
                        };

                        client.SaveApplicationData(pageUri, new[] { appData });
                    }
                }

                socialPageData.ShortUrl = shortUrl;
            }
            catch (Exception ex)
            {
                socialPageData.HasError  = true;
                socialPageData.ErrorInfo = ex;
            }
            finally
            {
                if (client != null)
                {
                    if (client.State == CommunicationState.Faulted)
                    {
                        client.Abort();
                    }
                    else
                    {
                        client.Close();
                    }
                }
            }

            return(socialPageData);
        }
 internal bool IsPublished(string id, string targetPurpose)
 {
     return(_client.IsPublished(id, targetPurpose, true));
 }