示例#1
0
        /// <summary>
        /// Uploads and saves a file
        /// </summary>
        /// <param name="siteId"></param>
        /// <param name="groupIds"></param>
        /// <param name="userId"></param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="fileFullPath"></param>
        /// <param name="fileContent"></param>
        /// <param name="isEnabled"></param>
        /// <param name="size">if the file is an image and the size is set then the image will be resized</param>
        /// <returns></returns>
        public long Upload(long siteId, long[] groupIds, long userId, string title, string description,
                           string fileFullPath, System.IO.Stream fileStream, bool isEnabled, string size)
        {
            //throw error in case of validation problem
            ValidateToUpdateFile(siteId, userId, groupIds);

            //SAVE THE FILE ------------------------------------------------------
            awFile file = new awFile();

            file.fileId = MiscLibrary.CreateUniqueId();

            string     resourceFileName = GetFileNameOnly(fileFullPath);
            string     extension        = GetFileExension(resourceFileName);
            bool       isVideoFile      = _videoLib.isVideoFile(extension);
            int        contentLength    = (int)fileStream.Length;
            string     filePath         = "";
            bool       saveOnLocal      = isVideoFile || !FileAmazonS3.SaveOnAmazonS3();
            SAVED_FILE savedFileInfo    = new SAVED_FILE();

            //SAVE THE FILE FIRST
            try
            {
                file.contentType = GetContentType(AWAPI_BusinessLibrary.library.ConfigurationLibrary.Config.fileMimeXMLPath, extension);

                filePath      = CreateFilePath(saveOnLocal, siteId, file.fileId, extension);
                savedFileInfo = SaveFile(siteId, saveOnLocal, file.contentType, filePath, fileStream, size.Trim());

                file.isOnLocal     = saveOnLocal;
                file.contentSize   = contentLength;
                file.path          = savedFileInfo.filePath.ToLower();
                file.siteId        = siteId;
                file.title         = String.IsNullOrEmpty(title) ? resourceFileName : title;
                file.description   = description;
                file.link          = GetUrl(file.fileId, savedFileInfo.filePath, "").ToLower();
                file.pubDate       = DateTime.Now;
                file.lastBuildDate = DateTime.Now;
                file.isEnabled     = isEnabled;
                file.userId        = userId;
                file.createDate    = DateTime.Now;

                _context.awFiles.InsertOnSubmit(file);
                _context.SubmitChanges();
            }
            catch (Exception ex)
            {
                DeleteFromStorage(siteId, saveOnLocal, filePath);
                throw ex;
            }

            //add file to groups
            AddFileToGroups(file.fileId, groupIds);

            //IF FILE IS A VIDEO FILE THEN CONVERT IT
            if (isVideoFile)
            {
                IfVideoConvertToFLV(file.fileId);
            }

            return(file.fileId);
        }
示例#2
0
        /// <summary>
        /// Add file with URL address
        /// </summary>
        /// <param name="siteId"></param>
        /// <param name="groupIds"></param>
        /// <param name="userId"></param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="fileUrl"></param>
        /// <param name="isEnabled"></param>
        /// <returns></returns>
        public long Add(long siteId, long fileId, long[] groupIds, long userId, string title, string description,
                        string fileUrl, string thumbUrl, bool isEnabled)
        {
            //Check if all the file groups exist---------------
            var groupList = from g in _context.awFileGroups
                            where groupIds.Contains(g.fileGroupId)
                            select g;

            if (groupList == null || groupList.Count() < groupIds.Length)
            {
                throw new Exception("One or more file groups do not exist");
            }

            //Save the file
            awFile file = new awFile();

            file.fileId = fileId > 0 ? fileId : MiscLibrary.CreateUniqueId();

            string resourceFileName = GetFileNameOnly(fileUrl);
            string extension        = GetFileExension(resourceFileName);

            //SAVE THE FILE FIRST
            try
            {
                file.contentType   = GetContentType(AWAPI_BusinessLibrary.library.ConfigurationLibrary.Config.fileMimeXMLPath, extension);
                file.isOnLocal     = false; //this also can be used for external urls (not only amazon)
                file.contentSize   = 0;
                file.path          = fileUrl.ToLower();
                file.siteId        = siteId;
                file.title         = String.IsNullOrEmpty(title) ? resourceFileName : title;
                file.description   = description;
                file.link          = fileUrl.ToLower();
                file.thumbnail     = thumbUrl.ToLower();
                file.pubDate       = DateTime.Now;
                file.lastBuildDate = DateTime.Now;
                file.isEnabled     = isEnabled;
                file.userId        = userId;
                file.createDate    = DateTime.Now;

                _context.awFiles.InsertOnSubmit(file);
                _context.SubmitChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //add file to groups
            AddFileToGroups(file.fileId, groupIds);
            return(file.fileId);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="siteTagId"></param>
        /// <param name="fieldId"></param>
        /// <param name="userId"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public long UpdateFieldValue(long contentId, long fieldId, long userId, string value, string cultureCode)
        {
            var flds = from f in _context.awContentCustomFieldValues
                       where f.customFieldId.Equals(fieldId) &&
                       f.contentId.Equals(contentId)
                       select f;

            awContentCustomFieldValue fld = _context.awContentCustomFieldValues.
                                            FirstOrDefault(v => v.customFieldId.Equals(fieldId) &&
                                                           v.contentId.Equals(contentId) &&
                                                           v.cultureCode.Equals(cultureCode));

            //if doesn't exist then Add a new one, else udpate the current one
            if (fld == null)
            {
                fld = new awContentCustomFieldValue();
                fld.customFieldValueId = MiscLibrary.CreateUniqueId();
                fld.cultureCode        = cultureCode;
                fld.customFieldId      = fieldId;
                fld.contentId          = contentId;
                fld.fieldValue         = value;
                fld.userId             = userId;
                fld.lastBuildDate      = DateTime.Now;
                fld.createDate         = DateTime.Now;

                _context.awContentCustomFieldValues.InsertOnSubmit(fld);
            }
            else
            {
                fld.fieldValue    = value;
                fld.userId        = userId;
                fld.lastBuildDate = DateTime.Now;
            }

            _context.SubmitChanges();

            return(fld.customFieldValueId);
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileId"></param>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public void AddFileToGroups(long fileId, long[] groupIds)
        {
            //delete file group association
            var tmpList = from fg in _context.awFileInGroups
                          where fg.fileId.Equals(fileId)
                          select fg;

            _context.awFileInGroups.DeleteAllOnSubmit(tmpList);

            foreach (long groupId in groupIds)
            {
                long fileInGroupId = MiscLibrary.CreateUniqueId();

                awFileInGroup file = new awFileInGroup();
                file.fileInGroupId = fileInGroupId;
                file.fileGroupId   = groupId;
                file.fileId        = fileId;
                file.createDate    = DateTime.Now;

                _context.awFileInGroups.InsertOnSubmit(file);
            }
            _context.SubmitChanges();
        }