Esempio n. 1
0
        /// <summary>
        ///     Download the zip file
        /// </summary>
        /// <returns></returns>
        public ActionResult GetZipFile()
        {
            var service = new AIRService();
            var zipPathList = (List<string>) Session[AIRResources.ZipPathList];

            if (zipPathList.Count == 0)
            {
                return null;
            }

            if (zipPathList.Count == 1)
            {
                return File(zipPathList[0], @"application/octet-stream","Zip.zip");
            }

            var foldername = Session[AIRResources.SessionGuid].ToString();
            var folderPath = Path.Combine(Server.MapPath("~/App_Data"), foldername);

            var zipFile = service.CreateZipFile(zipPathList,folderPath,foldername);
            return File(zipFile, @"application/octet-stream", "Zip.zip");
        }
Esempio n. 2
0
        /// <summary>
        ///     Save the file on the server
        /// </summary>
        /// <param name="UploadDefault"></param>
        /// <returns></returns>
        public ActionResult SaveDefault(IEnumerable<HttpPostedFileBase> UploadDefault)
        {
            var listPath = new List<string>();

            var foldername = Session[AIRResources.SessionGuid].ToString();
            var folderPath = Path.Combine(Server.MapPath("~/App_Data"), foldername);

            if (Directory.Exists(folderPath))
            {
               // Directory.Delete(folderPath, true);
            }
            else
            {
                Directory.CreateDirectory(folderPath);
            }

            try
            {

                var fileName = string.Empty;
                var filenameWOExtension = string.Empty;
                // Technicaly, there is only one file
                foreach (var file in UploadDefault)

                {
                     fileName = Path.GetFileName(file.FileName);
                    filenameWOExtension = Path.GetFileNameWithoutExtension(fileName);
                    if (string.IsNullOrEmpty(fileName))
                    {
                        continue;
                    }

                    var destinationPath = Path.Combine(folderPath, fileName);

                    file.SaveAs(destinationPath);

                    if (System.IO.File.Exists(destinationPath))
                    {
                        listPath.Add(destinationPath);
                    }
                }

                var presetListToDo = new List<PresetSize>();

                if ((bool) Session[AIRResources.iOs])
                {
                    presetListToDo.AddRange(GetSizeListFromJson(Enums.PresetEnum.iOS));
                }
                if ((bool) Session[AIRResources.Android])
                {
                    presetListToDo.AddRange(GetSizeListFromJson(Enums.PresetEnum.Android));
                }
                if ((bool) Session[AIRResources.Windows])
                {
                    presetListToDo.AddRange(GetSizeListFromJson(Enums.PresetEnum.WindowsPhone));
                }

                var service = new AIRService();

                // TODO Choose the file format
                var formatList = new List<string>
                {
                    "png"
                };
                var pictureContainerList = service.ConvertBatch(listPath, presetListToDo, formatList);

                var zipFilePath = service.CreateZipFile(pictureContainerList, folderPath, filenameWOExtension);

                // We put the file in the Session List
                var listSessionFilePath = Session[AIRResources.ZipPathList] as List<string>;
                if (listSessionFilePath != null)
                {
                    listSessionFilePath.Add(zipFilePath);
                }

                return Json("Ok");
            }
            finally
            {
                // Delete
                foreach (var path in listPath)
                {
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                }
            }
        }