protected void Page_Load(object sender, EventArgs e) { if (SystemManager.IsDesignMode || SystemManager.IsPreviewMode) { txtPodcastListing.Text = "XML Generation Widget - only executes in non editing mode." + "<br />" + "• For DocumentLibraryName, create a library and sub folders in Documents & Files and use the format \"Podcasts/2017\"" + "<br />" + "• For itunes_category use the format \"Business/Business News, Business/Careers, News & Politics\""; return; } string thisPageUrl = SiteMapBase.GetActualCurrentNode().Url; // default title settings if (String.IsNullOrEmpty(ChannelTitle)) { ChannelTitle = "Accountancy Ireland"; } if (String.IsNullOrEmpty(ImageTitle)) { ImageTitle = "Accountancy Ireland"; } // --- var xml = new StringBuilder(); xml.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); xml.AppendLine("<rss xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:itunes=\"http://www.itunes.com/dtds/podcast-1.0.dtd\" version=\"2.0\">"); xml.AppendLine(" <channel>"); xml.AppendLine(" <title>" + ChannelTitle + "</title>"); xml.AppendLine(" <link>" + HttpUtility.HtmlEncode(GetAbsoluteUrl(Link)) + "</link>"); xml.AppendLine(" <image>"); { xml.AppendLine(" <url>" + HttpUtility.HtmlEncode(GetAbsoluteUrl(itunes_image)) + "</url>"); xml.AppendLine(" <title>" + ImageTitle + "</title>"); xml.AppendLine(" <link>" + HttpUtility.HtmlEncode(GetAbsoluteUrl(Link)) + "</link>"); } xml.AppendLine(" </image>"); xml.AppendLine(" <description>" + HttpUtility.HtmlEncode(Description) + "</description>"); xml.AppendLine(" <language>en-gb</language>"); xml.AppendLine(" <copyright>" + HttpUtility.HtmlEncode(Copyright) + "</copyright>"); xml.AppendLine(" <webMaster>" + HttpUtility.HtmlEncode(WebMaster) + "</webMaster>"); xml.AppendLine(" <managingEditor>" + HttpUtility.HtmlEncode(ManagingEditor) + "</managingEditor>"); xml.AppendLine(" <atom:link href=\"" + HttpUtility.HtmlEncode(GetAbsoluteUrl(thisPageUrl)) + "\" rel=\"self\" type=\"application/rss+xml\"/>"); xml.AppendLine(" <lastBuildDate>" + HttpUtility.HtmlEncode(LastBuildDate) + "</lastBuildDate>"); xml.AppendLine(" <pubDate>" + HttpUtility.HtmlEncode(PublicationDate) + "</pubDate>"); xml.AppendLine(" <itunes:author>" + HttpUtility.HtmlEncode(itunes_author) + "</itunes:author>"); xml.AppendLine(" <itunes:summary>" + HttpUtility.HtmlEncode(itunes_summary) + "</itunes:summary>"); xml.AppendLine(" <itunes:subtitle>" + HttpUtility.HtmlEncode(itunes_subtitle) + "</itunes:subtitle>"); xml.AppendLine(" <itunes:owner>"); { xml.AppendLine(" <itunes:name>" + HttpUtility.HtmlEncode(itunes_name) + "</itunes:name>"); xml.AppendLine(" <itunes:email>" + HttpUtility.HtmlEncode(itunes_email) + "</itunes:email>"); } xml.AppendLine(" </itunes:owner>"); xml.AppendLine(" <itunes:explicit>" + HttpUtility.HtmlEncode(itunes_explicit) + "</itunes:explicit>"); xml.AppendLine(" <itunes:keywords>" + HttpUtility.HtmlEncode(itunes_keywords) + "</itunes:keywords>"); xml.AppendLine(" <itunes:image href=\"" + HttpUtility.HtmlEncode(GetAbsoluteUrl(itunes_image)) + "\"/>"); IReadOnlyCollection <IReadOnlyCollection <string> > categoryPaths = itunes_category .Split(',') .Select( categoryPath => categoryPath .Split('/') .Select(categoryNode => HttpUtility.HtmlEncode(categoryNode.Trim())) .ToArray() ) .ToArray(); foreach (IGrouping <string, IReadOnlyCollection <string> > topLevelCategory in categoryPaths.GroupBy(categoryNodes => categoryNodes.First())) { int depth = 4; xml.AppendLine(new string(' ', depth) + "<itunes:category text=\"" + topLevelCategory.Key + "\">"); depth += 2; IEnumerable <IEnumerable <string> > childCategoryPathsExcludingTopLevelNode = topLevelCategory.Select(pathIncludingTopLevelNode => pathIncludingTopLevelNode.Skip(1)); foreach (IEnumerable <string> childCategoryNodes in childCategoryPathsExcludingTopLevelNode) { foreach (string categoryNode in childCategoryNodes) { xml.AppendLine(new string(' ', depth) + "<itunes:category text=\"" + categoryNode + "\">"); depth += 2; } foreach (string categoryNode in childCategoryNodes) { depth -= 2; xml.AppendLine(new string(' ', depth) + "</itunes:category>"); } } depth -= 2; xml.AppendLine(new string(' ', depth) + "</itunes:category>"); } // lets get all documents under DocumentLibraryName var librariesManager = LibrariesManager.GetManager(); IFolder folderOrNull = null; string[] folderNames = DocumentLibraryName.Split('/'); using (IEnumerator <string> folderNameEnumerator = folderNames.Cast <string>().GetEnumerator()) { if (folderNameEnumerator.MoveNext()) { folderOrNull = librariesManager .GetDocumentLibraries() .FirstOrDefault(library => library.Title.Equals(folderNameEnumerator.Current)); while (folderOrNull != null && folderNameEnumerator.MoveNext()) { folderOrNull = librariesManager .GetChildFolders(folderOrNull) .FirstOrDefault(childFolder => childFolder.Title.Equals(folderNameEnumerator.Current)); } } } if (folderOrNull != null) { //Note Bugs in Sitefinity: item.Status is always Live and item.UIStatus is always Draft Document[] documents = librariesManager .GetChildItems(folderOrNull) .ToArray() .Select(item => item as Document) .Where(item => item != null && item.IsPublished()) .GroupBy(item => item.Title.ToString()) .Select(group => group.FirstOrDefault()) .OrderBy(document => document.Ordinal) .ToArray(); foreach (Document document in documents) { var duration = document.GetValue("itunes_duration"); var subtitle = document.GetValue("itunes_subtitle"); string urlWithoutQueryString = document.Url.Substring(0, document.Url.IndexOf("?")); //https://stackoverflow.com/questions/284775/how-do-i-parse-and-convert-datetime-s-to-the-rfc-822-date-time-format const string rfc822Format = "r"; xml.AppendLine(" <item>"); xml.AppendLine(" <guid>" + HttpUtility.HtmlEncode(urlWithoutQueryString) + "</guid>"); xml.AppendLine(" <title>" + HttpUtility.HtmlEncode(document.Title) + "</title>"); xml.AppendLine(" <description>" + HttpUtility.HtmlEncode(document.Description) + "</description>"); xml.AppendLine(" <itunes:summary>" + HttpUtility.HtmlEncode(document.Description) + "</itunes:summary>"); xml.AppendLine(" <itunes:subtitle>" + HttpUtility.HtmlEncode(subtitle) + "</itunes:subtitle>"); xml.AppendLine(" <enclosure url=\"" + HttpUtility.HtmlEncode(urlWithoutQueryString) + "\" length=\"" + document.TotalSize + "\" type=\"audio/mpeg\"/>"); xml.AppendLine(" <itunes:duration>" + HttpUtility.HtmlEncode(duration) + "</itunes:duration>"); xml.AppendLine(" <pubDate>" + document.PublicationDate.ToString(rfc822Format) + "</pubDate>"); xml.AppendLine(" </item>"); } } // ----- xml.AppendLine(" </channel>"); xml.AppendLine("</rss>"); Response.Clear(); Response.ContentType = "text/xml"; Response.Write(xml.ToString()); Response.End(); }
/// <summary> /// Executes the workflow activity. /// </summary> /// <param name="executionContext">The execution context.</param> protected override void Execute(CodeActivityContext executionContext) { // Create the tracing service ITracingService tracingService = executionContext.GetExtension <ITracingService>(); if (tracingService == null) { throw new InvalidPluginExecutionException("Failed to retrieve tracing service."); } tracingService.Trace("Entered CreateDocumentLocation.Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}", executionContext.ActivityInstanceId, executionContext.WorkflowInstanceId); // Create the context IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); if (context == null) { throw new InvalidPluginExecutionException("Failed to retrieve workflow context."); } tracingService.Trace("CreateDocumentLocation.Execute(), Correlation Id: {0}, Initiating User: {1}", context.CorrelationId, context.InitiatingUserId); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); IOrganizationService privService = serviceFactory.CreateOrganizationService(null); try { var url = RecordUrl.Get <string>(executionContext); var recordRef = new DynamicUrlParser(url).ToEntityReference(privService); string config = GetSecureConfigValue(privService, "PrivSharePointUser");; string[] user = config.Split(';'); // Create a new sharepoint service using the given priv sharepoint user credentials SPService spService = new SPService(user[0], user[1]); var docLocation = new DocumentLocationHelper(privService, spService); // Get the site passed into the workflow activity var siteId = Site.Get(executionContext); var site = (SharePointSite)service.Retrieve(SharePointSite.EntityLogicalName, siteId.Id, new ColumnSet("sharepointsiteid", "absoluteurl")); if (site != null) { // Set the name of the folder recordRef.Name = RecordFolderName.Get <string>(executionContext); var newLocation = docLocation.CreateDocumentLocation(site, DocumentLibraryName.Get(executionContext), recordRef); DocumentLocation.Set(executionContext, newLocation.ToEntityReference()); DocumentFolder.Set(executionContext, newLocation.AbsoluteURL); } else { DocumentLocation.Set(executionContext, null); } } catch (FaultException <OrganizationServiceFault> e) { tracingService.Trace("Exception: {0}", e.ToString()); // Handle the exception. throw; } tracingService.Trace("Exiting CreateDocumentLocation.Execute(), Correlation Id: {0}", context.CorrelationId); }