/// <summary>Fills in the form with the information from the given <paramref name="slide" /></summary>
 /// <param name="slide">The slide whose information should be filled in.</param>
 private void LoadSlide(Slide slide)
 {
     this.TitleTextBox.Text = slide.Title;
     this.ContentTextEditor.Text = slide.Content;
     this.ImageUrlControl.Url = slide.ImageLink;
     this.LinkUrlControl.Url = slide.Link;
     this.PagerImageUrlControl.Url = slide.PagerImageLink;
     this.StartDateTextBox.Text = slide.StartDate.ToShortDateString();
     this.EndDateTextBox.Text = slide.EndDate.HasValue ? slide.EndDate.Value.ToShortDateString() : string.Empty;
     this.SortOrderTextBox.Text = slide.SortOrder.ToString(CultureInfo.CurrentCulture);
 }
        /// <summary>process import of multi-instance records.</summary>
        /// <param name="xml">The xml.</param>
        /// <param name="prefix">The prefix (image, or link)</param>
        /// <param name="slide">The slide.</param>
        private static void ProcessImport(XmlNode xml, string prefix, Slide slide)
        {
            var ps = DotNetNuke.Entities.Portals.PortalController.GetCurrentPortalSettings();

            var contentTypeXml = xml.SelectSingleNode(prefix + "contenttype");
            var contentFileNameXml = xml.SelectSingleNode(prefix + "filename");
            var contentFileExtensionXml = xml.SelectSingleNode(prefix + "fileextension");
            var contentFolderPathXml = xml.SelectSingleNode(prefix + "folderpath");
            var contentBase64Xml = xml.SelectSingleNode(prefix + "filedata");
            var contentTabPathXml = xml.SelectSingleNode(prefix + "tabpath");

            // this item appears to be an encoded tabpath.... lets continue
            if (contentTabPathXml != null)
            {
                // todo, when upgrading  DNN reference, switch this to GetTabByTabPath on the TabController
                var tabInfo = ps.DesktopTabs.Cast<TabInfo>().SingleOrDefault(desktopTab => desktopTab.TabPath == contentTabPathXml.InnerText);
                if (tabInfo != null)
                {
                    switch (prefix)
                    {
                        case "image":
                            slide.ImageLink = "TabID=" + tabInfo.TabID.ToString(CultureInfo.InvariantCulture);
                            break;
                        default:
                            slide.Link = "TabID=" + tabInfo.TabID.ToString(CultureInfo.InvariantCulture);
                            break;
                    }
                }
            }

            // this item appears to be an encoded image... lets continue
            if (contentTypeXml != null && contentBase64Xml != null && contentFolderPathXml != null && contentFileNameXml != null && contentFileExtensionXml != null)
            {
                var folderController = new FolderController();
                var fileController = new FileController();

                // for now, just put imported images into the root folder...
                var folder = folderController.GetFolder(ps.PortalId, contentFolderPathXml.InnerText, true);

                if (folder == null)
                {
                    folderController.AddFolder(ps.PortalId, contentFolderPathXml.InnerText);
                    folder = folderController.GetFolder(ps.PortalId, contentFolderPathXml.InnerText, true);
                }

                var file = fileController.GetFile(contentFileNameXml.InnerText, ps.PortalId, folder.FolderID);
                if (file == null)
                {
                    var content = Convert.FromBase64String(contentBase64Xml.InnerText);
                    file = new DotNetNuke.Services.FileSystem.FileInfo
                                   {
                                       PortalId = ps.PortalId,
                                       ContentType = contentTypeXml.InnerText,
                                       FileName = contentFileNameXml.InnerText,
                                       Extension = contentFileExtensionXml.InnerText,
                                       FolderId = folder.FolderID,
                                       Size = content.Length,
                                   };

                    // save the file the dnn filesystem
                    File.WriteAllBytes(ps.HomeDirectoryMapPath + file.FileName, content);

                    // add the file to the dnn database
                    file.FileId = fileController.AddFile(file);
                }

                // update the files content.... just incase, it never hurts.... right?
                ////fileController.UpdateFileContent(file.FileId, content);

                switch (prefix)
                {
                    case "image":
                        slide.ImageLink = "FileID=" + file.FileId.ToString(CultureInfo.InvariantCulture);
                        break;
                    default:
                        slide.Link = "FileID=" + file.FileId.ToString(CultureInfo.InvariantCulture);
                        break;
                }
            }
        }
        /// <summary>Imports the given content into a new module instance</summary>
        /// <param name="moduleId">The new module's ID.</param>
        /// <param name="content">The module's content as XML.</param>
        /// <param name="version">The version.</param>
        /// <param name="userId">The user ID.</param>
        public void ImportModule(int moduleId, string content, string version, int userId)
        {
            // ReSharper disable PossibleNullReferenceException
            // ReSharper disable UseObjectOrCollectionInitializer
            try
            {
                var slides = DotNetNuke.Common.Globals.GetContent(content, "slides");

                foreach (XmlNode slide in slides.SelectNodes("slide"))
                {
                    var newSlide = new Slide();

                    newSlide.Content = slide.SelectSingleNode("content").InnerText;
                    newSlide.Link = slide.SelectSingleNode("link").InnerText;
                    newSlide.ImageLink = slide.SelectSingleNode("imagelink").InnerText;
                    newSlide.StartDate = DateTime.Parse(slide.SelectSingleNode("startdate").InnerText, CultureInfo.InvariantCulture);

                    var endDateXml = slide.SelectSingleNode("enddate");
                    if (endDateXml != null)
                    {
                        newSlide.EndDate = DateTime.Parse(endDateXml.InnerText, CultureInfo.InvariantCulture);
                    }

                    newSlide.PagerImageLink = slide.SelectSingleNode("pagerimagelink").InnerText;
                    newSlide.Title = slide.SelectSingleNode("title").InnerText;
                    newSlide.SortOrder = int.Parse(slide.SelectSingleNode("sortorder").InnerText, CultureInfo.InvariantCulture);
                    newSlide.TrackLink = bool.Parse(slide.SelectSingleNode("tracklink").InnerText);

                    ProcessImport(slide, "image", newSlide);
                    ProcessImport(slide, "link", newSlide);

                    newSlide.Save(moduleId);
                }
            }
            catch (Exception exc)
            {
                Exceptions.LogException(exc);
            }
        }
예제 #4
0
        /// <summary>process import of multi-instance records.</summary>
        /// <param name="xml">The xml.</param>
        /// <param name="prefix">The prefix (image, or link)</param>
        /// <param name="slide">The slide.</param>
        private static void ProcessImport(XmlNode xml, string prefix, Slide slide)
        {
            var ps = DotNetNuke.Entities.Portals.PortalController.GetCurrentPortalSettings();

            var contentTypeXml          = xml.SelectSingleNode(prefix + "contenttype");
            var contentFileNameXml      = xml.SelectSingleNode(prefix + "filename");
            var contentFileExtensionXml = xml.SelectSingleNode(prefix + "fileextension");
            var contentFolderPathXml    = xml.SelectSingleNode(prefix + "folderpath");
            var contentBase64Xml        = xml.SelectSingleNode(prefix + "filedata");
            var contentTabPathXml       = xml.SelectSingleNode(prefix + "tabpath");

            // this item appears to be an encoded tabpath.... lets continue
            if (contentTabPathXml != null)
            {
                // todo, when upgrading  DNN reference, switch this to GetTabByTabPath on the TabController
                var tabInfo = ps.DesktopTabs.Cast <TabInfo>().SingleOrDefault(desktopTab => desktopTab.TabPath == contentTabPathXml.InnerText);
                if (tabInfo != null)
                {
                    switch (prefix)
                    {
                    case "image":
                        slide.ImageLink = "TabID=" + tabInfo.TabID.ToString(CultureInfo.InvariantCulture);
                        break;

                    default:
                        slide.Link = "TabID=" + tabInfo.TabID.ToString(CultureInfo.InvariantCulture);
                        break;
                    }
                }
            }

            // this item appears to be an encoded image... lets continue
            if (contentTypeXml != null && contentBase64Xml != null && contentFolderPathXml != null && contentFileNameXml != null && contentFileExtensionXml != null)
            {
                var folderController = new FolderController();
                var fileController   = new FileController();

                // for now, just put imported images into the root folder...
                var folder = folderController.GetFolder(ps.PortalId, contentFolderPathXml.InnerText, true);

                if (folder == null)
                {
                    folderController.AddFolder(ps.PortalId, contentFolderPathXml.InnerText);
                    folder = folderController.GetFolder(ps.PortalId, contentFolderPathXml.InnerText, true);
                }

                var file = fileController.GetFile(contentFileNameXml.InnerText, ps.PortalId, folder.FolderID);
                if (file == null)
                {
                    var content = Convert.FromBase64String(contentBase64Xml.InnerText);
                    file = new DotNetNuke.Services.FileSystem.FileInfo
                    {
                        PortalId    = ps.PortalId,
                        ContentType = contentTypeXml.InnerText,
                        FileName    = contentFileNameXml.InnerText,
                        Extension   = contentFileExtensionXml.InnerText,
                        FolderId    = folder.FolderID,
                        Size        = content.Length,
                    };

                    // save the file the dnn filesystem
                    File.WriteAllBytes(ps.HomeDirectoryMapPath + file.FileName, content);

                    // add the file to the dnn database
                    file.FileId = fileController.AddFile(file);
                }

                // update the files content.... just incase, it never hurts.... right?
                ////fileController.UpdateFileContent(file.FileId, content);

                switch (prefix)
                {
                case "image":
                    slide.ImageLink = "FileID=" + file.FileId.ToString(CultureInfo.InvariantCulture);
                    break;

                default:
                    slide.Link = "FileID=" + file.FileId.ToString(CultureInfo.InvariantCulture);
                    break;
                }
            }
        }