static void Main(string[] args) { try { Program parkingLot = new Program(); if (args.Length == 1) { string filePath = args[0]; IInputFileReader fileReader = new InputFileReader(); IValidateFileType validateFileType = new ValidateFileType(); IExecuteFromFile fileExecutor = new ExecuteFromFile(parkingLot._provider, validateFileType, fileReader); string messages = fileExecutor.Execute(filePath); Console.WriteLine(messages); } else if (args.Length > 1) { Console.WriteLine("Takes only one argument"); } else { string result = string.Empty; bool isLive = true; while (isLive) { string userInputCommand = Console.ReadLine(); if (userInputCommand.Equals("exit")) { isLive = false; } else { ICommandExecutor executor = parkingLot._provider.InitExecutor(userInputCommand); if (executor != null) { result = executor.ExecuteCommand(userInputCommand); } else { result = "Invalid Command"; } Console.WriteLine(result); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public JsonResult UploadFile() { try { HttpPostedFileBase file = Request.Files[0]; string fileName = string.Empty; string path = string.Empty; byte[] data = null; if (file != null && file.ContentLength > 0) { Stream s; s = file.InputStream; fileName = Path.GetFileName(file.FileName); bool flag = ValidateFileType.IsAllowedFileType(fileName, s); if (flag) { var extension = fileName.Split('.'); fileName = "upload" + "Name" + "." + extension[1]; //string newFolder = Path.Combine(Server.MapPath("~/Uploads/"), "00001"); //System.IO.Directory.CreateDirectory(newFolder); path = Path.Combine(Server.MapPath("~/Uploads/"), fileName); file.SaveAs(path); return(Json(path, JsonRequestBehavior.AllowGet)); } else { return(Json("error", JsonRequestBehavior.AllowGet)); } } return(Json(path, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json("OOPS!!Something went wrong while uploading file, your Error code: ", JsonRequestBehavior.AllowGet)); } }
public string FileUpload(DomFile obj) { string Result = ""; try { if (!string.IsNullOrEmpty(obj.Agent_Code) && !string.IsNullOrEmpty(obj.Policy_No) && !string.IsNullOrEmpty(obj.FileName)) { //string zipPath = @"E:\AIA\test1.zip"; byte[] FileBytes = Convert.FromBase64String(obj.Filedata); //System.IO.File.ReadAllBytes(zipPath); // string Path = ConfigurationManager.AppSettings["DocumentUploadPath"]; //@"E:\AIA\uploaddocsmobility"; //bool IsfolderExist = CheckImageExist(obj.Department_Code); //if (IsfolderExist == false) //{ // var directoryInfo1 = new DirectoryInfo(Path); // directoryInfo1.CreateSubdirectory(obj.Department_Code); //} //Path = Path + @"\" + obj.Department_Code; bool IsfolderExist = CheckImageExist(obj.Agent_Code); if (IsfolderExist == false) { var directoryInfo1 = new DirectoryInfo(Path); directoryInfo1.CreateSubdirectory(obj.Agent_Code); } Path = Path + "//" + obj.Agent_Code; IsfolderExist = CheckImageExist(obj.Agent_Code + @"\" + obj.Policy_No); if (IsfolderExist == false) { var directoryInfo1 = new DirectoryInfo(Path); directoryInfo1.CreateSubdirectory(obj.Policy_No); } Path = Path + @"\" + obj.Policy_No; string zipPath1 = ConfigurationManager.AppSettings["DocumentUploadZipPath"]; Random rnd = new Random(); obj.FileName = rnd.Next(1, 9999) + obj.FileName; bool isExist = System.IO.File.Exists(zipPath1 + obj.FileName); FileStream fs = new FileStream(zipPath1 + obj.FileName, FileMode.Append); if (FileBytes.Count() > 0) { fs.Write(FileBytes, 0, FileBytes.Length); } fs.Close(); #region File validations using (ZipFile zip = ZipFile.Read(zipPath1 + obj.FileName)) { foreach (ZipEntry e in zip) { try { using (var stream = e.OpenReader()) { if (!ValidateFileType.IsAllowedFileType(e.FileName, (Stream)stream)) { Result = "Please Provide Valid File Format"; return(Result); } } } catch (Exception ex) { } } } #endregion #region Convert to PDF List <DocumentUploadFile> LstDocumentUpload = new List <DocumentUploadFile>(); UtilityController objUtilityController = new UtilityController(); using (ZipFile zip = ZipFile.Read(zipPath1 + obj.FileName)) { foreach (ZipEntry e in zip) { try { using (var stream = e.OpenReader()) { DocumentUploadFile objUpload = new DocumentUploadFile(); MemoryStream ms = new MemoryStream(); e.Extract(ms); byte[] bytes = new byte[ms.Length]; bytes = objUtilityController.PdfGeneration(ms.ToArray()); System.IO.File.WriteAllBytes(Path + "//" + e.FileName.Substring(0, e.FileName.IndexOf(".")) + ".pdf", bytes); objUpload.FileName = e.FileName.Split('.')[0].Split('_')[0]; objUpload.FileData = bytes; LstDocumentUpload.Add(objUpload); } //DocumentUploadFile objUpload = new DocumentUploadFile(); //objUpload.FilePath = obj.FileName;.spli //objUpload.ItemType = RequestDoc[i].ItemType; //objUpload.MemberType = RequestDoc[i].MemberType; //objUpload.FileData = fileData; } catch (Exception ex) { } } } byte[] ConcatFiles; var directryPath = ConfigurationManager.AppSettings["FileUpload"] + "\\" + obj.Agent_Code + "\\" + obj.Policy_No + "\\LDMS"; if (!Directory.Exists(directryPath)) { Directory.CreateDirectory(directryPath); } foreach (var fName in LstDocumentUpload.Select(a => a.FileName).Distinct().ToList()) { ConcatFiles = CrossCutting.DataTypeConvExtention.ConcatPdf(LstDocumentUpload.Where(a => a.FileName == fName).Select(a => a.FileData).ToList()); //System.IO.File.WriteAllBytes(ConfigurationManager.AppSettings["LDMSFileUpload"] + "\\" + obj.Agent_Code + "\\" + obj.Policy_No + "\\" + fName + ".pdf", ConcatFiles); System.IO.File.WriteAllBytes(directryPath + "\\" + fName + ".pdf", ConcatFiles); } #endregion //ZipFile fileToExtract = ZipFile.Read(zipPath1 + obj.FileName); //fileToExtract.ExtractAll(Path, ExtractExistingFileAction.DoNotOverwrite); Result = Path; } else { Result = "Kindly provide Department code, Agent Code, Document Name and policy number to proceed..!"; } } catch (Exception ex) { log4net.GlobalContext.Properties["ErrorCode"] = Codes.GetErrorCode(); Logger.Error(ex); Result = "Failure"; } return(Result); }