Пример #1
0
        public IStorageFile GetResizedFileUrl(string fileStoreKey, string path, string fileName, int width, int height)
        {
            string resizedFileName = fileName + "-" + width.ToString() + "x" + height.ToString() + ".";
            string resizedPath     = Path.Combine(path, "ResizeImages");

            System.Drawing.Imaging.ImageFormat format;
            string extension = GlobalSettings.GetExtension(fileName).ToLower();

            if (extension == "png" || extension == "gif")
            {
                format           = System.Drawing.Imaging.ImageFormat.Png;
                resizedFileName += "png";
            }
            else
            {
                format           = System.Drawing.Imaging.ImageFormat.Jpeg;
                resizedFileName += "jpg";
            }
            FileStorageProvider fileProvider = new FileStorageProvider(fileStoreKey);
            IStorageFile        file         = fileProvider.GetFile(resizedPath, resizedFileName);

            if (file == null)
            {
                IStorageFile originalFile = null;

                if (fileProvider != null)
                {
                    originalFile = fileProvider.GetFile(path, fileName);
                }

                if (originalFile != null)
                {
                    using (Stream sourceStream = originalFile.OpenReadStream())
                    {
                        using (Stream imageStream = GlobalSettings.ResizeImage(sourceStream, height, width, format))
                        {
                            file = fileProvider.AddUpdateFile(resizedPath, resizedFileName, imageStream);
                            imageStream.Close();
                        }
                        sourceStream.Close();
                    }
                }
            }
            return(file);
        }
Пример #2
0
        public static void EditFile(CompanyQualification qualification, Stream contentStream)
        {
            string name = GlobalSettings.EnsureHtmlEncoded(qualification.QualificationName) + ".rar";

            if (contentStream == null)
            {
                IStorageFile file = FileStorageProvider.Instance(CompanyQualifications.FileStoreKey)
                                    .GetFile(CompanyQualifications.MakePath(qualification.CompanyID), GlobalSettings.EnsureHtmlEncoded(qualification.QualificationFile) + ".rar");
                contentStream = file.OpenReadStream();
            }
            //事件触发
            FileStorageProvider fs = new FileStorageProvider(FileStoreKey);

            fs.AddUpdateFile(MakePath(qualification.CompanyID), name, contentStream);

            qualification.QualificationFile = MakePath(qualification.CompanyID);
            CommonDataProvider.Instance.UpdateQualification(qualification);

            HHCache.Instance.Remove(CacheKeyManager.GetQualificationKey(qualification.QualificationID));

            //事件触发
        }