Пример #1
0
        public async Task Save(IFileListEntry uploadFile, string savePath)
        {
            using var ms = await uploadFile.ReadAllAsync();

            using var saveFile = File.OpenWrite(Path.Combine(_uploadsDirectory, savePath));
            saveFile.Write(ms.ToArray());
            saveFile.Close();
        }
Пример #2
0
        public async Task <Resume> ParseResumeFromXmlAsync(IFileListEntry[] files)
        {
            IFileListEntry ResumeFile  = files.FirstOrDefault();
            XmlSerializer  serializer  = new XmlSerializer(typeof(Resume));
            Resume         result      = new Resume {
            };
            XmlReaderSettings settings = new XmlReaderSettings
            {
                IgnoreWhitespace = true
            };

            using (XmlReader reader = XmlReader.Create(await ResumeFile.ReadAllAsync(), settings))
            {
                result = (Resume)serializer.Deserialize(reader);
                reader.Close();
            }
            return(result);

            ////MemoryStream s = await ResumeFile.ReadAllAsync();
            //Console.WriteLine(ResumeFile.Data);
            //string testData = @"<cv>
            //                    <personal-data>
            //                    </personal-data>
            //                    <course-data>
            //                    <cn>F**K YOUSEF</cn>
            //                    <cd>696969</cd>
            //                    </course-data>
            //                    </cv>";
            //using (TextReader reader = new StringReader(testData))
            //{
            //    result = (Resume)serializer.Deserialize(ResumeFile.Data);
            //}
            //return result;

            //XDocument doc = XDocument.Parse(str);
            //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);
            //byte[] bytes;
            //bytes = System.Text.Encoding.ASCII.GetBytes(str);
            //request.ContentType = "text/xml; encoding='utf-8'";
            //request.ContentLength = bytes.Length;
            //request.Method = "POST";
            //Stream requestStream = request.GetRequestStream();
            //requestStream.Write(bytes, 0, bytes.Length);
            //requestStream.Close();
            //HttpWebResponse response;
            //response = (HttpWebResponse)request.GetResponse();
            //if (response.StatusCode == HttpStatusCode.OK)
            //{
            //    Stream responseStream = response.GetResponseStream();
            //    string responseStr = new StreamReader(responseStream).ReadToEnd();
            //    return responseStr;
            //}
            //return null;
        }
Пример #3
0
 private async Task ImportPaymentsVippsFile(TandemBookingContext db, IFileListEntry file)
 {
     if (file.Name.EndsWith(".xml.zip", StringComparison.OrdinalIgnoreCase))
     {
         using (var archive = new ZipArchive(await file.ReadAllAsync(), ZipArchiveMode.Read))
         {
             using (var strm = archive.Entries.First().Open())
             {
                 ImportPaymentsVippsStream(db, strm);
             }
         }
     }
     else
     {
         ErrorMessage += $"File {file.Name} is of unexpected type. ";
     }
 }
Пример #4
0
        private async Task <DocumentModel> UploadFile(IFileListEntry file)
        {
            if (file != null)
            {
                byte[]       result;
                MemoryStream sourceStream = await file.ReadAllAsync((int)file.Size);

                result = new byte[file.Data.Length];
                await sourceStream.ReadAsync(result, 0, (int)file.Data.Length);

                DocumentModel doc = new DocumentModel()
                {
                    FileName    = file.Name,
                    Data        = result,
                    ContentType = file.Type
                };

                return(doc);
            }
            return(null);
        }
        public async Task <byte[]> HandleFile(IFileListEntry entry)
        {
            if (entry == null)
            {
                throw new InvalidOperationException("No file");
            }

            if (entry.Size == 0)
            {
                throw new InvalidOperationException("Empty file");
            }

            if (entry.Size > MaxFileSize)
            {
                throw new InvalidOperationException($"File size ({entry.Size}) exceeds max allowed ({MaxFileSize})");
            }

            if (entry.Type != FileType)
            {
                throw new InvalidOperationException($"Unexpected file type {entry.Type}; ({FileType} expected)");
            }

            byte[] data = null;

            using (var ms = await entry.ReadAllAsync(1048576))
                data = ms.ToArray();

            if (data == null || data.Length == 0)
            {
                throw new InvalidOperationException("No Data");
            }

            DataValidation?.Invoke(data);

            return(data);
        }