Beispiel #1
0
        public async Task <JsonResult> GetEditableContent(long id)
        {
            if (CurrentUserId == 0)
            {
                await TryAuthenticateFromHttpContext(_communityService, _notificationService);
            }

            var contentInputViewModel = new ContentInputViewModel();
            var contentDetails        = _contentService.GetContentDetailsForEdit(id, CurrentUserId);

            // Set value from ContentDetials to ContentInputViewModel.
            contentInputViewModel.SetValuesFrom(contentDetails);

            // Set Thumbnail URL.
            contentInputViewModel.ThumbnailLink = contentInputViewModel.ThumbnailID != Guid.Empty ?
                                                  Url.Action("Thumbnail", "File", new { id = contentInputViewModel.ThumbnailID }) :
                                                  Url.Content("~/content/images/default" + Enum.GetName(typeof(ContentTypes), contentDetails.ContentData.ContentType) + "thumbnail.png");

            return(new JsonResult {
                Data = contentInputViewModel, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Beispiel #2
0
        public async Task <string> BuildPublicTourXml(bool webclient)
        {
            var adminCommunityId = 596915;
            var adminId          = 184331;
            var tourDetailList   = await _communityService.GetCommunityContents(adminCommunityId, adminId);

            var tourContentList = new List <ContentInputViewModel>();

            foreach (var item in tourDetailList)
            {
                var contentInputViewModel = new ContentInputViewModel();
                contentInputViewModel.SetValuesFrom(item);
                tourContentList.Add(contentInputViewModel);
            }
            var children = await _communityService.GetChildCommunities(adminCommunityId, adminId);

            var folders = new List <CommunityViewModel>();

            foreach (var child in children)
            {
                var communityViewModel = new CommunityViewModel();
                Mapper.Map(child, communityViewModel);
                folders.Add(communityViewModel);
            }
            using (var sw = new StringWriter())
            {
                using (var xmlWriter = new XmlTextWriter(sw))
                {
                    xmlWriter.Formatting = Formatting.Indented;
                    xmlWriter.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
                    xmlWriter.WriteStartElement("Folder");
                    foreach (var folder in folders)
                    {
                        var tourIds = folder.Description != null?folder.Description.Split(',') : new string[0];

                        var toursInFolder = false;
                        foreach (var tourId in tourIds)
                        {
                            try
                            {
                                var id          = Convert.ToInt32(tourId);
                                var tourDetails = tourDetailList.Find(details => details.ID == id);
                                if (tourDetails == null || tourDetails.IsDeleted)
                                {
                                    continue;
                                }
                                var tourContents = tourContentList.Find(model => model.ID == id);
                                var json         = tourDetails.Citation.Replace("json://", "");
                                var extData      = JsonConvert.DeserializeObject <dynamic>(json);
                                if (webclient && (extData.webclient == null || extData.webclient != true))
                                {
                                    continue;
                                }
                                Newtonsoft.Json.Linq.JArray related = extData.related;
                                var relatedTours = string.Empty;
                                if (webclient)
                                {
                                    foreach (Guid guid in related)
                                    {
                                        var relatedTour    = tourContentList.Find(t => t.ContentDataID == guid);
                                        var relatedJson    = relatedTour.Citation.Replace("json://", "");
                                        var relatedExtData = JsonConvert.DeserializeObject <dynamic>(relatedJson);
                                        // only include related tours that are also webclient friendly
                                        if (relatedExtData.webclient == null || relatedExtData.webclient != true)
                                        {
                                            continue;
                                        }
                                        if (relatedTours.Length > 0)
                                        {
                                            relatedTours += ";";
                                        }
                                        relatedTours += guid.ToString();
                                    }
                                }
                                else
                                {
                                    relatedTours = string.Join(";", related);
                                }
                                // write folder xml ONLY after first viable tour obj is found
                                if (!toursInFolder)
                                {
                                    xmlWriter.WriteStartElement("Folder");
                                    xmlWriter.WriteAttributeString("Name", folder.Name);
                                    xmlWriter.WriteAttributeString("Group", "Tour");
                                    xmlWriter.WriteAttributeString("Thumbnail", "");
                                    toursInFolder = true;
                                }
                                xmlWriter.WriteStartElement("Tour");
                                xmlWriter.WriteAttributeString("Title", tourDetails.Name.Replace("&", "&amp;"));
                                xmlWriter.WriteAttributeString("ID", tourContents.ContentDataID.ToString());
                                xmlWriter.WriteAttributeString("Description",
                                                               tourDetails.Description.Replace("&", "&amp;"));
                                xmlWriter.WriteAttributeString("Classification",
                                                               extData["classification"] != null ? extData["classification"].ToString() : "Other");
                                xmlWriter.WriteAttributeString("AuthorEmail",
                                                               extData.authorEmail != null ? extData.authorEmail.ToString() : "");
                                xmlWriter.WriteAttributeString("Author",
                                                               extData.author != null ? extData.author.ToString().Replace("&", "&amp;") : "");
                                xmlWriter.WriteAttributeString("AverageRating",
                                                               tourDetails.AverageRating.ToString(CultureInfo.InvariantCulture));
                                xmlWriter.WriteAttributeString("LengthInSecs", tourContents.TourLength);
                                xmlWriter.WriteAttributeString("OrganizationUrl",
                                                               extData.organizationUrl != null
                                        ? extData.organizationUrl.ToString().Replace("&", "&amp;")
                                        : "");
                                xmlWriter.WriteAttributeString("OrganizationName",
                                                               extData.organization != null
                                        ? extData.organization.ToString().Replace("&", "&amp;")
                                        : "");
                                xmlWriter.WriteAttributeString("ITHList",
                                                               extData.ithList != null
                                        ? extData.ithList.ToString()
                                        : extData.taxonomy != null ? extData.taxonomy.ToString() : "");
                                xmlWriter.WriteAttributeString("AstroObjectsList", string.Empty);
                                xmlWriter.WriteAttributeString("Keywords",
                                                               tourDetails.Tags.Replace(',', ';').Replace(" ", ""));
                                xmlWriter.WriteAttributeString("RelatedTours", relatedTours);
                                xmlWriter.WriteEndElement();
                            }
                            catch (NullReferenceException)
                            {
                                //ignore - deleted tour
                            }
                        }
                        if (toursInFolder)
                        {
                            xmlWriter.WriteEndElement();
                        }
                    }

                    xmlWriter.WriteEndElement();

                    xmlWriter.Close();
                }
                sw.Close();
                var xml            = sw.ToString();
                var storageAccount =
                    Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(
                        ConfigReader <string> .GetSetting("WWTWebBlobs"));

                var blobClient         = storageAccount.CreateCloudBlobClient();
                var cloudBlobContainer = blobClient.GetContainerReference("tours");
                var toursBlob          = cloudBlobContainer.GetBlobReferenceFromServer(webclient? "webclienttours.wtml" : "alltours.wtml");
                var bytes = new byte[xml.Length * sizeof(char)];
                Buffer.BlockCopy(xml.ToCharArray(), 0, bytes, 0, bytes.Length);
                toursBlob.UploadFromByteArray(bytes, 0, bytes.Length);
                return(toursBlob.StorageUri.PrimaryUri.AbsoluteUri);
            }
        }