Example #1
0
        public HttpResponseMessage UpdateImages(List<ImageLocInfo> images)
        {
            string imgType = "STORY";
            try
            {
                foreach (ImageLocInfo image in images)
                {
                    ImageInfo upImage = DbController.Instance.GetImage(image.ImageId);
                    upImage.TextPosition = image.TextPosition;
                    DbController.Instance.UpdateImage(upImage);

                    ImageLangInfo imageLang = new ImageLangInfo();
                    imageLang.ImageId = image.ImageId;
                    imageLang.Language = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
                    imageLang.LongDescription = image.LongDescription;
                    imageLang.ShortDescription = image.ShortDescription;
                    DbController.Instance.DeleteImageLang(imageLang);
                    DbController.Instance.InsertImageLang(imageLang);

                    ForeignImageInfo foreignImage = new ForeignImageInfo() { ForeignId = image.ForeignId, ForeignToken = imgType, ImageId = image.ImageId, ViewOrder = image.ViewOrder};
                    DbController.Instance.UpdateForeignImage(foreignImage);
                }
                return Request.CreateResponse(HttpStatusCode.OK, true);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
            }
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ImportModule implements the IPortable ImportModule Interface
        /// </summary>
        /// <param name="ModuleID">The Id of the module to be imported</param>
        /// <param name="Content">The content to be imported</param>
        /// <param name="Version">The version of the module to be imported</param>
        /// <param name="UserId">The Id of the user performing the import</param>
        /// -----------------------------------------------------------------------------
        public void ImportModule(int ModuleID, string Content, string Version, int UserID)
        {
            int? partModuleId = null, partPortalId = null;
            
            ModuleInfo module = ModuleController.Instance.GetModule(ModuleID, PortalSettings.Current.ActiveTab.TabID, true);
            switch ((string)module.ModuleSettings["Partitioning"])
            {
                case "1":
                    partModuleId = ModuleID;
                    break;
                case "2":
                    partPortalId = PortalSettings.Current.PortalId;
                    break;

            }
            
            XmlNode xmlroot = Globals.GetContent(Content, "BBImageStories");

            // Save Templates
            string templateRoot = PortalSettings.Current.HomeDirectoryMapPath + "..\\..\\DesktopModules\\" + module.DesktopModule.FolderName + "\\";

            XmlNode xmlListTemplate = xmlroot.SelectSingleNode("ListTemplate");
            string contentListTemplate = xmlListTemplate.SelectSingleNode("Content").InnerText;
            string contentListName = xmlListTemplate.SelectSingleNode("Name").InnerText;
            string listTemplateFile = templateRoot + "js\\List\\" + contentListName;
            File.WriteAllText(listTemplateFile, contentListTemplate);
            ModuleController.Instance.UpdateModuleSetting(ModuleID, "List", contentListName.ToLower());

            XmlNode xmlViewTemplate = xmlroot.SelectSingleNode("ViewTemplate");
            string contentViewTemplate = xmlViewTemplate.SelectSingleNode("Content").InnerText;
            string contentViewName = xmlViewTemplate.SelectSingleNode("Name").InnerText;
            string viewTemplateFile = templateRoot + "js\\View\\" + contentViewName;
            File.WriteAllText(viewTemplateFile, contentViewTemplate);
            ModuleController.Instance.UpdateModuleSetting(ModuleID, "View", contentViewName.ToLower());

            XmlNode xmlImageWidth = xmlroot.SelectSingleNode("ImageWidth");
            if (xmlImageWidth != null)
                ModuleController.Instance.UpdateModuleSetting(ModuleID, "Width", xmlImageWidth.InnerText);

            //XmlNode xmlPartitioning = xmlroot.SelectSingleNode("Partitioning");
            //if (xmlPartitioning != null)
            //    ModuleController.Instance.UpdateModuleSetting(ModuleID, "Partitioning", xmlPartitioning.InnerText);

            foreach (XmlNode xmlStory in xmlroot.SelectNodes("Story"))
            {
                // Insert Story
                string strModuleId = xmlStory.SelectSingleNode("ModuleId").InnerText;
                string strPortalId = xmlStory.SelectSingleNode("PortalId").InnerText;
                string strStartDate = xmlStory.SelectSingleNode("StartDate").InnerText;
                string strEndDate = xmlStory.SelectSingleNode("EndDate").InnerText;
                StoryInfo story = new StoryInfo()
                                  {
                                      ModuleId = partModuleId,
                                      PortalId = partPortalId,
                                      StartDate = (strStartDate != "null") ? (DateTime?) Convert.ToDateTime(strStartDate, CultureInfo.InvariantCulture) : null,
                                      EndDate = (strEndDate != "null") ? (DateTime?) Convert.ToDateTime(strEndDate, CultureInfo.InvariantCulture) : null,
                                      LastPublishedDate = null,
                                      CreatedByUserID = UserID,
                                      CreatedOnDate = DateTime.Now,
                                      LastModifiedByUserID = UserID,
                                      LastModifiedOnDate = DateTime.Now
                                  };
                int storyId = DbController.Instance.InsertStory(story, ModuleID, PortalSettings.Current.ActiveTab.TabID);

                // Insert Story Language Info
                XmlNode xmlStoryLangs = xmlStory.SelectSingleNode("StoryLangs");
                foreach (XmlNode xmlStoryLang in xmlStoryLangs.SelectNodes("StoryLang"))
                {
                    string strLanguage = xmlStoryLang.SelectSingleNode("Language").InnerText;
                    string strTitle = xmlStoryLang.SelectSingleNode("Title").InnerText;
                    string strStory = xmlStoryLang.SelectSingleNode("Story").InnerText;
                    StoryLangInfo storyLang = new StoryLangInfo()
                                              {
                                                  StoryId = storyId,
                                                  Language = strLanguage,
                                                  Title = strTitle,
                                                  Story = strStory
                                              };
                    DbController.Instance.InsertStoryLang(storyLang, PortalSettings.Current.ActiveTab.TabID);
                }

                // Insert Images
                string imageDir = "Images/BBImageStory/" + storyId.ToString();

                IFolderInfo folder;
                if (!FolderManager.Instance.FolderExists(PortalSettings.Current.PortalId, imageDir))
                    folder = FolderManager.Instance.AddFolder(PortalSettings.Current.PortalId, imageDir);
                else
                    folder = FolderManager.Instance.GetFolder(PortalSettings.Current.PortalId, imageDir);

                XmlNode xmlImages = xmlStory.SelectSingleNode("Images");
                foreach (XmlNode xmlImage in xmlImages.SelectNodes("Image"))
                {
                    string strViewOrder = xmlImage.SelectSingleNode("ViewOrder").InnerText;
                    string strImageData = xmlImage.SelectSingleNode("ImageData").InnerText;
                    string strFileName = xmlImage.SelectSingleNode("FileName").InnerText;
                    MemoryStream imageStream = HexStringToStream(strImageData);
                    if (!FileManager.Instance.FileExists(folder, strFileName))
                    {
                        // Add File to directory
                        IFileInfo ifile = FileManager.Instance.AddFile(folder, strFileName, imageStream, true);

                        // Insert Image reference into Image Table
                        ImageInfo image = new ImageInfo() {FileId = ifile.FileId};
                        int imageId = DbController.Instance.InsertImage(image);

                        // Combine image and story in crosstable
                        ForeignImageInfo foreignImage = new ForeignImageInfo() {ForeignId = storyId, ForeignToken = "STORY", ImageId = imageId, ViewOrder = Convert.ToInt32(strViewOrder)};
                        DbController.Instance.InsertForeignImage(foreignImage);

                        XmlNode xmlImageLangs = xmlImage.SelectSingleNode("ImageLangs");
                        foreach (XmlNode xmlImageLang in xmlImageLangs.SelectNodes("ImageLang"))
                        {
                            string strLanguage = xmlImageLang.SelectSingleNode("Language").InnerText;
                            string strShortDescription = xmlImageLang.SelectSingleNode("ShortDescription").InnerText;
                            string strLongDescription = xmlImageLang.SelectSingleNode("LongDescription").InnerText;
                            ImageLangInfo imageLang = new ImageLangInfo()
                                                      {
                                                          ImageId = imageId,
                                                          Language = strLanguage,
                                                          ShortDescription = strShortDescription,
                                                          LongDescription = strLongDescription
                                                      };
                            DbController.Instance.InsertImageLang(imageLang);

                        }
                    }
                }
            }
        }
Example #3
0
 public void UpdateImageLang(ImageLangInfo imageLang)
 {
     using (IDataContext context = DataContext.Instance())
     {
         string sqlCmd = "UPDATE {databaseOwner}[{objectQualifier}" + Prefix + "ImageLang] SET ShortDescription = @2,LongDescription = @3 WHERE ImageId = @0 AND Language = @1";
         context.Execute(CommandType.Text, sqlCmd, imageLang.ImageId, imageLang.Language, imageLang.ShortDescription, imageLang.LongDescription);
     }
 }
Example #4
0
 public void DeleteImageLang(ImageLangInfo imageLang)
 {
     using (IDataContext context = DataContext.Instance())
     {
         string sqlCmd = "DELETE FROM {databaseOwner}[{objectQualifier}" + Prefix + "ImageLang] WHERE ImageId = @0 AND Language = @1";
         context.Execute(CommandType.Text, sqlCmd, imageLang.ImageId, imageLang.Language);
     }
 }
Example #5
0
 public void InsertImageLang(ImageLangInfo imageLang)
 {
     using (IDataContext context = DataContext.Instance())
     {
         string sqlCmd = "INSERT INTO {databaseOwner}[{objectQualifier}" + Prefix + "ImageLang] (ImageId,Language,ShortDescription,LongDescription) VALUES (@0,@1,@2,@3)";
         context.Execute(CommandType.Text, sqlCmd, imageLang.ImageId, imageLang.Language, imageLang.ShortDescription, imageLang.LongDescription);
     }
 }
Example #6
0
        public HttpResponseMessage UploadImage()
        {
            try
            {
                var httpRequest = HttpContext.Current.Request;
                int storyId = Convert.ToInt32(httpRequest["storyId"]);
                if (httpRequest.Files.Count > 0)
                {
                    string imageDir = "Images/BBImageStory/" + storyId.ToString();

                    IFolderInfo folder;
                    if (!FolderManager.Instance.FolderExists(ActiveModule.PortalID, imageDir))
                        folder = FolderManager.Instance.AddFolder(ActiveModule.PortalID, imageDir);
                    else
                        folder = FolderManager.Instance.GetFolder(ActiveModule.PortalID, imageDir);


                    // Save uploaded files to upload directory
                    for (int i = 0; i < httpRequest.Files.Count; i++)
                    {
                        var file = httpRequest.Files[i];

                        if (!FileManager.Instance.FileExists(folder, file.FileName))
                        {
                            // Add File to directory
                            IFileInfo ifile = FileManager.Instance.AddFile(folder, file.FileName, file.InputStream, true);

                            // Insert Image reference into Image Table
                            ImageInfo image = new ImageInfo() { FileId = ifile.FileId };
                            int imageId = DbController.Instance.InsertImage(image);

                            // Create empty language info for image
                            ImageLangInfo imageLang = new ImageLangInfo() { ImageId = imageId, Language = System.Threading.Thread.CurrentThread.CurrentCulture.Name, LongDescription = "", ShortDescription = "" };
                            DbController.Instance.InsertImageLang(imageLang);

                            // Combine image and story in crosstable
                            ForeignImageInfo foreignImage = new ForeignImageInfo() { ForeignId = storyId, ForeignToken = "STORY", ImageId = imageId, ViewOrder = 0 };
                            DbController.Instance.InsertForeignImage(foreignImage);
                        }
                    }

                    var retval = new HttpResponseMessage(HttpStatusCode.OK);
                    retval.Content = new StringContent("File transfer completed", System.Text.Encoding.UTF8, "text/plain");
                    return retval;
                }
                return Request.CreateResponse(HttpStatusCode.BadRequest);

            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
            }
        }