コード例 #1
0
        private static void SaveTaxonomy(Database db)
        {
            List <Dtos.Taxonomy> tags = new List <Dtos.Taxonomy>();

            foreach (var sourceTag in db.TaxonomyItems)
            {
                Dtos.Taxonomy destinationTag = new Dtos.Taxonomy()
                {
                    Id        = sourceTag.Id,
                    Name      = sourceTag.Name,
                    CreatedBy = sourceTag.CreatedBy.Value,
                    UpdatedBy = sourceTag.UpdatedBy.Value,
                    Revision  = sourceTag.Revision.Value
                };

                destinationTag.Created = DateReader.GetDateFromSitecoreFieldValue(sourceTag.Created.Value);
                destinationTag.Updated = DateReader.GetDateFromSitecoreFieldValue(sourceTag.Updated.Value);

                destinationTag.TagName = sourceTag.TagName?.Value;

                tags.Add(destinationTag);
            }

            using (var httpClient = new HttpClient())
            {
                var uri           = new Uri("https://saasxm.xcentium.com/sitecore/api/ssc/blogapi/blogimporter/0/savetags");
                var jsonRequest   = JsonConvert.SerializeObject(tags);
                var stringContent = new StringContent(jsonRequest, Encoding.UTF8, "application/json");
                var response      = httpClient.PostAsync(uri, stringContent).Result;
                if (!response.IsSuccessStatusCode)
                {
                    Console.WriteLine("Received response failure when saving Tags.");
                }
            }
        }
コード例 #2
0
        private static void SaveBlogs(Database db)
        {
            List <Dtos.Blog> blogs = new List <Dtos.Blog>();

            foreach (var sourceBlog in db.BlogPosts)
            {
                Dtos.Blog destinationBlog = new Dtos.Blog()
                {
                    Id        = sourceBlog.Id,
                    Name      = sourceBlog.Name,
                    CreatedBy = sourceBlog.CreatedBy.Value,
                    UpdatedBy = sourceBlog.UpdatedBy.Value,
                    Revision  = sourceBlog.Revision.Value
                };

                destinationBlog.Created = DateReader.GetDateFromSitecoreFieldValue(sourceBlog.Created.Value);
                destinationBlog.Updated = DateReader.GetDateFromSitecoreFieldValue(sourceBlog.Updated.Value);

                destinationBlog.Title   = sourceBlog.Title?.Value;
                destinationBlog.Image   = sourceBlog.Image?.Value;
                destinationBlog.Summary = sourceBlog.Summary?.Value;
                destinationBlog.Body    = sourceBlog.Body?.Value;
                destinationBlog.Author  = sourceBlog.Author?.Value;

                destinationBlog.PublishingDate =
                    DateReader.GetDateFromSitecoreFieldValue(sourceBlog.PublishingDate?.Value);

                destinationBlog.Tags              = sourceBlog.Tags?.Value;
                destinationBlog.BrowserTitle      = sourceBlog.BrowserTitle?.Value;
                destinationBlog.MetaDescription   = sourceBlog.MetaDescription?.Value;
                destinationBlog.MetaKeywords      = sourceBlog.MetaKeywords?.Value;
                destinationBlog.SearchTitle       = sourceBlog.SearchTitle?.Value;
                destinationBlog.SearchDescription = sourceBlog.SearchDescription?.Value;
                destinationBlog.SearchImage       = sourceBlog.SearchImage?.Value;

                blogs.Add(destinationBlog);
            }

            using (var httpClient = new HttpClient())
            {
                var uri           = new Uri("https://saasxm.xcentium.com/sitecore/api/ssc/blogapi/blogimporter/0/saveblogs");
                var jsonRequest   = JsonConvert.SerializeObject(blogs);
                var stringContent = new StringContent(jsonRequest, Encoding.UTF8, "application/json");
                var response      = httpClient.PostAsync(uri, stringContent).Result;
                if (!response.IsSuccessStatusCode)
                {
                    Console.WriteLine("Received response failure when saving Blogs.");
                }
            }
        }
コード例 #3
0
        private static void SaveAuthors(Database db)
        {
            List <Dtos.Author> authors =
                new List <Dtos.Author>();

            foreach (var sourceAuthor in db.Authors)
            {
                Dtos.Author destinationAuthor =
                    new Dtos.Author
                {
                    Id        = sourceAuthor.Id,
                    Name      = sourceAuthor.Name,
                    CreatedBy = sourceAuthor.CreatedBy.Value,
                    UpdatedBy = sourceAuthor.UpdatedBy.Value,
                    Revision  = sourceAuthor.Revision.Value
                };

                destinationAuthor.Created = DateReader.GetDateFromSitecoreFieldValue(sourceAuthor.Created.Value);
                destinationAuthor.Updated = DateReader.GetDateFromSitecoreFieldValue(sourceAuthor.Updated.Value);

                destinationAuthor.FullName     = sourceAuthor.FullName?.Value;
                destinationAuthor.Title        = sourceAuthor.Title?.Value;
                destinationAuthor.Location     = sourceAuthor.Location?.Value;
                destinationAuthor.Bio          = sourceAuthor.Bio?.Value;
                destinationAuthor.ProfileImage = sourceAuthor.ProfileImage?.Value;
                destinationAuthor.EmailAddress = sourceAuthor.EmailAddress?.Value;
                destinationAuthor.Creator      = sourceAuthor.Creator?.Value;

                authors.Add(destinationAuthor);
            }

            using (var httpClient = new HttpClient())
            {
                var uri           = new Uri("https://saasxm.xcentium.com/sitecore/api/ssc/blogapi/blogimporter/0/saveauthors");
                var jsonRequest   = JsonConvert.SerializeObject(authors);
                var stringContent = new StringContent(jsonRequest, Encoding.UTF8, "application/json");
                var response      = httpClient.PostAsync(uri, stringContent).Result;
                if (!response.IsSuccessStatusCode)
                {
                    Console.WriteLine("Received response failure when saving Authors.");
                }
            }
        }
コード例 #4
0
        private static void SaveMediaItems(Database db)
        {
            List <Dtos.Image> images = new List <Dtos.Image>();

            foreach (var sourceImage in db.Images)
            {
                Dtos.Image destinationImage = null;
                if (sourceImage is Jpeg)
                {
                    var destinationJpeg = new Dtos.Jpeg()
                    {
                        Id        = sourceImage.Id,
                        Name      = sourceImage.Name,
                        CreatedBy = sourceImage.CreatedBy.Value,
                        UpdatedBy = sourceImage.UpdatedBy.Value,
                        Revision  = sourceImage.Revision.Value
                    };
                    var sourceJpeg = sourceImage as Jpeg;

                    destinationJpeg.Artist           = sourceJpeg.Artist?.Value;
                    destinationJpeg.Copyright        = sourceJpeg.Copyright?.Value;
                    destinationJpeg.ImageDescription = sourceJpeg.ImageDescription?.Value;
                    destinationJpeg.Make             = sourceJpeg.Make?.Value;
                    destinationJpeg.Model            = sourceJpeg.Model?.Value;
                    destinationJpeg.Software         = sourceJpeg.Software?.Value;

                    destinationImage = destinationJpeg;
                }
                else
                {
                    destinationImage = new Dtos.Image()
                    {
                        Id        = sourceImage.Id,
                        Name      = sourceImage.Name,
                        CreatedBy = sourceImage.CreatedBy.Value,
                        UpdatedBy = sourceImage.UpdatedBy.Value,
                        Revision  = sourceImage.Revision.Value
                    };
                }

                destinationImage.Created = DateReader.GetDateFromSitecoreFieldValue(sourceImage.Created.Value);
                destinationImage.Updated = DateReader.GetDateFromSitecoreFieldValue(sourceImage.Updated.Value);

                destinationImage.Alt        = sourceImage.Alt?.Value;
                destinationImage.Width      = sourceImage.Width?.Value;
                destinationImage.Height     = sourceImage.Height?.Value;
                destinationImage.Dimensions = sourceImage.Dimensions?.Value;
                destinationImage.MimeType   = sourceImage.MimeType?.Value;

                destinationImage.Path = sourceImage.Path;

                Blob blob = db.Blobs.Single(b => "{" + b.Name.ToUpper() + "}" == sourceImage.Blob.Value);
                destinationImage.Blob     = blob.Data;
                destinationImage.FileName = sourceImage.Name + "." + sourceImage.Extension?.Value;

                destinationImage.IsAuthor = db.Authors.Any(a => a.ProfileImageMediaID == sourceImage.Id);

                images.Add(destinationImage);
            }

            using (var httpClient = new HttpClient())
            {
                var uri           = new Uri("https://saasxm.xcentium.com/sitecore/api/ssc/blogapi/blogimporter/0/savemediaitems");
                var jsonRequest   = JsonConvert.SerializeObject(images);
                var stringContent = new StringContent(jsonRequest, Encoding.UTF8, "application/json");
                var task          = Task.Run(async() =>
                {
                    HttpResponseMessage msg = await httpClient.PostAsync(uri, stringContent);
                    if (!msg.IsSuccessStatusCode)
                    {
                        Console.WriteLine($"Received response failure when saving Media Items. {msg.Content.ToString()}");
                    }
                });
                task.Wait(new TimeSpan(0, 30, 0));
            }
        }