Esempio n. 1
0
        private MultiPartParser ParseFile(System.IO.Stream Stream)
        {
            SICTLogger.WriteInfo(UploadBusiness.CLASS_NAME, "ParseFile ", "Start");
            MultiPartParser Parser = null;

            try
            {
                Parser = new MultiPartParser(Stream);
                if (!Parser.Success)
                {
                    SICTLogger.WriteError(UploadBusiness.CLASS_NAME, "ParseFile ", "Unable to parse the file");
                    Parser = null;
                }
                else
                {
                    SICTLogger.WriteVerbose(UploadBusiness.CLASS_NAME, "ParseFile ", "Successfully parsed file - Filename is - " + Parser.Filename);
                }
            }
            catch (System.Exception Ex)
            {
                SICTLogger.WriteException(UploadBusiness.CLASS_NAME, "ParseFile ", Ex);
            }
            SICTLogger.WriteInfo(UploadBusiness.CLASS_NAME, "ParseFile ", "End");
            return(Parser);
        }
Esempio n. 2
0
        public ReturnValue UploadFile(System.IO.Stream FileStream, string Instance)
        {
            ReturnValue  ReturnValue     = new ReturnValue();
            BusinessUtil ObjBusinessUtil = new BusinessUtil();

            SICTLogger.WriteInfo(UploadBusiness.CLASS_NAME, "UploadFile", "Start ");
            try
            {
                MultiPartParser Parser         = this.ParseFile(FileStream);
                string          UploadFilePath = string.Empty;
                ObjBusinessUtil.GetUploadFilePath(ref UploadFilePath, System.IO.Path.GetFileNameWithoutExtension(Parser.Filename), System.IO.Path.GetExtension(Parser.Filename));
                using (System.IO.FileStream FileToupload = new System.IO.FileStream(UploadFilePath, System.IO.FileMode.Create))
                {
                    FileToupload.Write(Parser.FileContents, 0, Parser.FileContents.Length);
                }
                bool IsFileValid = this.ValidateFile(UploadFilePath);
                if (IsFileValid)
                {
                    Task.Factory.StartNew(delegate
                    {
                        this.BulkInsert(UploadFilePath, Instance);
                    });
                    ReturnValue.ReturnCode    = 1;
                    ReturnValue.ReturnMessage = "Upload Successful";
                }
                else
                {
                    ReturnValue.ReturnCode    = 5;
                    ReturnValue.ReturnMessage = "Invalid File ";
                }
                FileStream.Close();
            }
            catch (System.Exception Ex)
            {
                ReturnValue.ReturnCode    = -1;
                ReturnValue.ReturnMessage = "Error in Function ";
                SICTLogger.WriteException(UploadBusiness.CLASS_NAME, "UploadFile", Ex);
            }
            SICTLogger.WriteInfo(UploadBusiness.CLASS_NAME, "UploadFile", "UploadFileEnd");
            return(ReturnValue);
        }