Ejemplo n.º 1
0
        internal override string Execute(string[] parameters)
        {
            int userID;

            if (!Helper.TryGetUserID(_session, out userID))
            {
                return(String.Empty);
            }

            int             folderID;
            List <string[]> rawContentInfo;

            if (error != "1")
            {
                return(error);
            }

            BLClient   client = null;
            List <int> addedIDs;

            try
            {
                client = new BLClient();

                addedIDs = client.AddAssetContent(userID, folderID, contentIDList);
            }
            catch (Exception ex)
            {
                return(ErrorWrapper.SendError(ex.Message));
            }
            finally
            {
                client.Dispose();
            }

            return(Flatten(addedIDs));
        }
Ejemplo n.º 2
0
        private void UploadAndSaveToDB(out long totalUploadSize)
        {
            int userID;

            totalUploadSize = 0;

            if (!Helper.TryGetUserID(Session, out userID))
            {
                return;
            }

            List <AssetContent> assetContents = new List <AssetContent>();

            int fileCount = Int32.Parse(Request.Form["FileCount"]);

            UploadForm uploadForm = new UploadForm(_inviteToOverrideFieldText)
            {
                Title       = Request.Form["TitleOvr"].Trim(),
                Creator     = Request.Form["CreatorOvr"].Trim(),
                Description = Request.Form["DescriptionOvr"].Trim(),
                Url         = Request.Form["URLOvr"].Trim()
            };

            uploadForm.SetDateIfNotEmpty(Request.Form["DateOvr"].Trim());
            uploadForm.SetDisplayDuration(Request.Form["DisplayDurationOvr"].Trim(), _minDisplayDuration, _maxDisplayDuration);

            //Iterate through uploaded data and save the original file and thumbnail
            for (int i = 1; i <= fileCount; i++)
            {
                HttpPostedFile postedFile   = Request.Files["SourceFile_" + i];
                UploadedFile   uploadedFile = _uploadedFileFactory.CreateUploadedFile(uploadForm, _fileDurationDetectorFactory, Path.GetExtension(postedFile.FileName).ToLower());

                uploadedFile.RawContentPath            = _rawContentPath;
                uploadedFile.ThumbnailAssetContentPath = _thumbnailAssetContentPath;
                uploadedFile.UploadedStream            = postedFile.InputStream;
                uploadedFile.OriginalFileName          = postedFile.FileName;
                uploadedFile.SetDateIfUserHasNotProvidedOne(Request.Params["SourceFileCreatedDateTime_" + i]);

                uploadedFile.Thumbnail1Stream = Request.Files["Thumbnail1_" + i].InputStream;
                uploadedFile.Thumbnail2Stream = Request.Files["Thumbnail2_" + i].InputStream;

                uploadedFile.SaveThumbnail();
                uploadedFile.SaveContent();
                uploadedFile.SetDisplayDuration();

                totalUploadSize += uploadedFile.ContentLength;

                assetContents.Add(new AssetContent(uploadedFile.Title,
                                                   uploadedFile.Folder + "\\" + uploadedFile.GuidFilenameWithExtension,
                                                   uploadedFile.GuidFilenameWithoutExtension,
                                                   uploadedFile.Extension,
                                                   uploadedFile.Folder + "/" + uploadedFile.GuidFilenameWithoutExtension + ".jpg",
                                                   uploadedFile.Folder + "\\" + uploadedFile.GuidFilenameWithoutExtension + ".jpg",
                                                   uploadedFile.Folder,
                                                   uploadedFile.GuidFilenameWithoutExtension + ".jpg",
                                                   uploadForm.Description,
                                                   uploadForm.Creator,
                                                   uploadedFile.Date,
                                                   uploadForm.Url,
                                                   uploadedFile.DisplayDuration,
                                                   uploadedFile.ContentLength,
                                                   uploadedFile.PreviewType));
            }

            BLClient client = null;
            bool     bDurationsAmended;

            try
            {
                client = new BLClient();

                bDurationsAmended = client.AddAssetContent(userID, int.Parse(Request.Form["AssetContentFolderID"]), assetContents);
            }
            finally
            {
                client.Dispose();
            }

            Session.Add("DurationsAmended", bDurationsAmended);
        }
Ejemplo n.º 3
0
        private void UploadAndSaveToDB(out long totalUploadSize)
        {
            string rawContentPath = System.Configuration.ConfigurationSettings.AppSettings["assetContentPath"];
            string thumbnailAssetContentRelativePath = System.Configuration.ConfigurationSettings.AppSettings["thumbnailAssetContentRelativePath"];
            string thumbnailAssetContentPath         = System.Configuration.ConfigurationSettings.AppSettings["thumbnailAssetContentPath"];

            int userID;

            totalUploadSize = 0;

            if (!Helper.TryGetUserID(Session, out userID))
            {
                return;
            }

            List <AssetContent> assetContents = new List <AssetContent>();

            int fileCount = Int32.Parse(Request.Form["FileCount"]);

            string title           = Request.Form["TitleOvr"].Trim();
            string creator         = Request.Form["CreatorOvr"].Trim();
            string description     = Request.Form["DescriptionOvr"].Trim();
            string date            = Request.Form["DateOvr"].Trim();
            string url             = Request.Form["URLOvr"].Trim();
            string displayDuration = Request.Form["DisplayDurationOvr"].Trim();

            bool bUseTitleOvr           = !string.IsNullOrEmpty(title) && title != _inviteToOverrideValues;
            bool bUseCreatorOvr         = !string.IsNullOrEmpty(creator) && creator != _inviteToOverrideValues;
            bool bUseDescriptionOvr     = !string.IsNullOrEmpty(description) && description != _inviteToOverrideValues;
            bool bUseDateOvr            = !string.IsNullOrEmpty(date) && date != _inviteToOverrideValues;
            bool bUseURLOvr             = !string.IsNullOrEmpty(url) && url != _inviteToOverrideValues;
            bool bUseDisplayDurationOvr = !string.IsNullOrEmpty(displayDuration) && displayDuration != _inviteToOverrideValues;

            title           = bUseTitleOvr ? title : null;
            creator         = bUseCreatorOvr ? creator : null;
            description     = bUseDescriptionOvr ? description : null;
            date            = bUseDateOvr ? date : null;
            url             = bUseURLOvr ? url : null;
            displayDuration = bUseDisplayDurationOvr ? displayDuration : null;

            DateTime?userGivenDate    = null;
            float    fDisplayDuration = -1F;

            if (bUseDateOvr)
            {
                Helper.NullableDateTryParse(date, out userGivenDate);
            }

            // TODO: pending future development to accept videos, always try to parse user's given display duration
            if (!float.TryParse(displayDuration, out fDisplayDuration) || fDisplayDuration < _minDisplayDuration || fDisplayDuration > _maxDisplayDuration)
            {
                fDisplayDuration = -1F;
            }

            //Iterate through uploaded data and save the original file and thumbnail
            for (int i = 1; i <= fileCount; i++)
            {
                string      newFilename;
                string      newFilenameWithoutExtension;
                string      newFolder;
                PreviewType previewType;

                if (!bUseDateOvr)
                {
                    userGivenDate = ToDotNetFormat(Request.Params["SourceFileCreatedDateTime_" + i]);
                }

                int contentLength = -1;

                //Get source file and save it to disk.
                HttpPostedFile sourceFile = Request.Files["SourceFile_" + i];
                string         fileName   = System.IO.Path.GetFileName(sourceFile.FileName);
                string         extension  = System.IO.Path.GetExtension(sourceFile.FileName).ToLower();

                bool bIsImage = GetIsFileImage(extension);
                bool bIsVideo = GetIsFileVideo(extension);

                if (!bUseTitleOvr)
                {
                    title = Path.GetFileNameWithoutExtension(fileName);
                }

                FilenameMakerLib.FilenameFromGUID.MakeFilenameAndFolder(fileName, out newFilename,
                                                                        out newFilenameWithoutExtension, out newFolder);

                string pathWithoutFilename = rawContentPath + newFolder;

                if (!Directory.Exists(pathWithoutFilename))
                {
                    Directory.CreateDirectory(pathWithoutFilename);
                }

                //Get first thumbnail  and save it to disk.
                HttpPostedFile thumbnail1File = Request.Files["Thumbnail1_" + i];

                string thumbnailFullPhysicalPathWithoutFilename = thumbnailAssetContentPath + newFolder;

                if (!Directory.Exists(thumbnailFullPhysicalPathWithoutFilename))
                {
                    Directory.CreateDirectory(thumbnailFullPhysicalPathWithoutFilename);
                }

                string thumbnailFullPath = thumbnailFullPhysicalPathWithoutFilename + "\\" + newFilenameWithoutExtension + ".jpg";

                if (bIsImage)
                {
                    thumbnail1File.SaveAs(thumbnailFullPath);
                }
                else if (bIsVideo)
                {
                    CopyDefaultThumbnailForType(extension, thumbnailAssetContentPath, thumbnailFullPath);
                }
                else
                {
                    File.Copy(thumbnailAssetContentPath + "flash-swf.jpg", thumbnailFullPath);
                }

                // get resized file and save
                HttpPostedFile thumbnail2File = Request.Files["Thumbnail2_" + i];

                if (bIsImage)
                {
                    thumbnail2File.SaveAs(pathWithoutFilename + "\\" + newFilename);

                    contentLength = thumbnail2File.ContentLength;
                }
                else
                {
                    sourceFile.SaveAs(pathWithoutFilename + "\\" + newFilename);

                    contentLength = sourceFile.ContentLength;
                }

                totalUploadSize += contentLength;

                previewType = GetPreviewType(bIsImage, bIsVideo);

                assetContents.Add(new AssetContent(title,
                                                   newFolder + "\\" + newFilename,
                                                   newFilenameWithoutExtension,
                                                   extension,
                                                   newFolder + "/" + newFilenameWithoutExtension + ".jpg",
                                                   newFolder + "\\" + newFilenameWithoutExtension + ".jpg",
                                                   newFolder,
                                                   newFilenameWithoutExtension + ".jpg",
                                                   description,
                                                   creator,
                                                   userGivenDate,
                                                   url,
                                                   fDisplayDuration,
                                                   contentLength,
                                                   previewType));
            }

            BLClient client            = null;
            bool     bDurationsAmended = false;

            try
            {
                client = new BLClient();

                bDurationsAmended = client.AddAssetContent(userID, int.Parse(Request.Form["AssetContentFolderID"]), assetContents);
            }
            finally
            {
                client.Dispose();
            }

            Session.Add("DurationsAmended", bDurationsAmended);
        }