/// <summary>
        ///     Remove temp associated with this file.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="isAddTemp"></param>
        /// <param name="isPrivate"></param>
        /// <param name="additionalRootPath"></param>
        /// <param name="rootPath"></param>
        public void RemoveTempImage(IUploadableFile file, bool isAddTemp = true, bool isPrivate  = false,
                                    string additionalRootPath            = null, string rootPath = null)
        {
            var fileName = GetOrganizeName(file, true, isAddTemp);

            if (rootPath == null)
            {
                rootPath = RootPath;
            }
            if (additionalRootPath == null)
            {
                additionalRootPath = AdditionalRoots;
            }

            rootPath += additionalRootPath;

            var path1  = rootPath + fileName;
            var source = path1.Replace("~", appPath).Replace('/', '\\');

            try {
                File.Delete(source);
            } catch (Exception ex) {
                Starter.HanldeError.HandleBy(ex);
            }
        }
        public static string GetOrganizeName(IUploadableFile file, bool includeExtention = false, bool asTemp = false,
                                             string tempString = "_temp")
        {
            var ext = "";

            if (!asTemp)
            {
                tempString = "";
            }
            if (includeExtention)
            {
                ext = "." + file.Extension;
            }
            return(file.UploadGuid + "-" + file.Sequence + tempString + ext);
        }
        /// <summary>
        /// </summary>
        /// <param name="category"></param>
        /// <param name="sourceFileName">like "Justuploaded"</param>
        /// <param name="processedFileName"></param>
        /// <param name="isSourceAddTemp">if true then sourceFileName(removing ext) += FileAdditionalTemp</param>
        /// <param name="ext"></param>
        /// <param name="additionalRootPath">
        ///     Advertise/ should contain slash. But it should be define at the class creation time.
        ///     Best way to set it in class constructor.
        /// </param>
        /// <param name="rootPath"></param>
        public void ProcessImage(IUploadableFile file, IImageCategory category, string sourceFileName = null,
                                 string processedFileName  = null, bool isSourceAddTemp = true, bool isPrivate = false,
                                 string additionalRootPath = null, string rootPath      = null)
        {
            if (file != null && category != null)
            {
                if (rootPath == null)
                {
                    rootPath = RootPath;
                }

                if (isPrivate)
                {
                    rootPath += "Private/";
                }

                if (additionalRootPath == null)
                {
                    additionalRootPath = AdditionalRoots;
                }


                rootPath         += additionalRootPath;
                sourceFileName    = GetOrganizeName(file, true, isSourceAddTemp); //soruce as temp
                processedFileName = GetOrganizeName(file, true, false);           // target
                var path1   = rootPath + sourceFileName;
                var path2   = rootPath + processedFileName;
                var source  = VirtualPathtoAbsoluteServerPath(path1);
                var target  = VirtualPathtoAbsoluteServerPath(path2);
                var setting = "height=" + category.Height + "&width=" + category.Width + "&mode=stretch&format=" +
                              file.Extension;
                if (File.Exists(target))
                {
                    File.Delete(target);
                }
                try {
                    ImageBuilder.Current.Build(source, target, new ResizeSettings(setting));
                } catch (Exception ex) {
                    Starter.HanldeError.HandleBy(ex);
                }
            }
            else
            {
                throw new Exception("Data missing while upload.");
            }
        }
 public HighlightGamesController(ApplicationDbContext context, UserManager <ApplicationUser> userManager, IUploadableFile upload) : base(context, userManager)
 {
     _upload     = upload;
     imageFolder = "highlights";
 }
        /// <summary>
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="addtionalRootPath"></param>
        /// <param name="file"></param>
        /// <param name="isPrivate"></param>
        /// <param name="asTemp"></param>
        /// <param name="tempString"></param>
        /// <param name="rootPath"></param>
        /// <returns></returns>
        public static string UploadedImageSrc(this HtmlHelper helper, string addtionalRootPath, IUploadableFile file,
                                              bool isPrivate  = false, bool asTemp = false, string tempString = "_temp",
                                              string rootPath = "~/Uploads/Images/")
        {
            if (isPrivate)
            {
                rootPath += "Private/";
            }
            rootPath += addtionalRootPath;
            if (!asTemp)
            {
                tempString = "";
            }
            var fileName = file.UploadGuid + "-" + file.Sequence + tempString + "." + file.Extension;

            var path = string.Format("{0}{1}", rootPath, fileName);

            return(AppVar.Url + VirtualPathUtility.ToAbsolute(path));
            //return (markup);
        }
Beispiel #6
0
        public object PostBlobCall(string apiCall, object targetObject, object parent, object data, IUploadableFile file)
        {
            if (apiCall == null)
            {
                throw new ArgumentNullException(nameof(apiCall));
            }
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            var sp = new ServerCallParameters();

            sp.Api = apiCall;
            return(PostBlobCall(sp, targetObject, parent, data, new[] { file }));
        }
 public LeaguesController(ApplicationDbContext context, UserManager <ApplicationUser> userManager, IUploadableFile upload) : base(context, userManager)
 {
     _upload    = upload;
     logoFolder = "leagues";
 }
Beispiel #8
0
 public TeamsController(ApplicationDbContext context, UserManager <ApplicationUser> userManager, IUploadableFile upload) : base(context, userManager)
 {
     _upload     = upload;
     teamsFolder = "teams";
 }