Exemplo n.º 1
0
    public static async Task <FileObject> CreateFileAsync(GitFileSystem fileSystem, FileParameters fileParams, CancellationToken cancel = default)
    {
        if (fileParams.Access.Bit(FileAccess.Write))
        {
            throw new FileException(fileParams.Path, "The git filesystem is read-only.");
        }
        if (fileParams.Mode != FileMode.Open)
        {
            throw new FileException(fileParams.Path, "The git filesystem is read-only.");
        }

        cancel.ThrowIfCancellationRequested();

        Blob blob = fileSystem.Commit.GetFile(fileParams.Path);

        Stream stream = blob.GetContentStream();
        IRandomAccess <byte> randomAccess = new SeekableStreamBasedRandomAccess(stream, true);

        try
        {
            GitFileObject f = new GitFileObject(fileSystem, fileParams, randomAccess);

            await Task.CompletedTask;

            return(f);
        }
        catch
        {
            randomAccess._DisposeSafe();
            stream._DisposeSafe();
            throw;
        }
    }
Exemplo n.º 2
0
 public PolyPhaseSorting(SortingParameters sortingParameters, FileParameters fileParameters)
 {
     CreateSortingObjects(sortingParameters, fileParameters);
     distributionTask = new Task(distribute);
     stepTask         = new Task(step);
     mergeTask        = new Task(merge);
 }
Exemplo n.º 3
0
        public void sortAlreadySortedfile()
        {
            var testFilePath           = "D:\\FileToSort.txt";
            var unsortedFileLinesArray = new string[] { "1", "2", "3", "4", "5" };
            var sortedFileContent      = string.Join(Environment.NewLine, unsortedFileLinesArray) + Environment.NewLine;

            File.WriteAllText(testFilePath, string.Join(Environment.NewLine, unsortedFileLinesArray) + Environment.NewLine);
            var sortingParameters = new SortingParameters()
            {
                NumberOfTemporaryFiles = 2
            };
            var fileParameters = new FileParameters()
            {
                BlockSize = 4, SourceFileName = testFilePath,
                TemporaryBufferFileDirectory = "D:\\", Separator = " "
            };
            var sorter = new PolyPhaseSorting(sortingParameters, fileParameters);

            sorter.Distribution.Distribute();
            sorter.Merger.Merge();
            sorter.RestoreOriginalFileName();
            var actualFileContent = File.ReadAllText(testFilePath);

            Assert.AreEqual(sortedFileContent, actualFileContent);
            Console.WriteLine("Statistics:\nRead accesses:\t{0}\nWrite acesses:\t{1}\nSteps:\t{2}",
                              sorter.ReadAccesses, sorter.WriteAccesses, sorter.Steps);

            File.Delete(testFilePath);
        }
Exemplo n.º 4
0
        public void test()
        {
            var testFilePath      = "D:\\TestFile.txt";
            var sortingParameters = new SortingParameters()
            {
                NumberOfTemporaryFiles = 2
            };
            var fileParameters = new FileParameters()
            {
                BlockSize = 8, SourceFileName = testFilePath,
                TemporaryBufferFileDirectory = "D:\\", Separator = " "
            };
            var sorter = new PolyPhaseSorting(sortingParameters, fileParameters);

            sorter.Distribution.Distribute();
            sorter.Merger.Merge();
            sorter.RestoreOriginalFileName();
            var actualFileContent = File.ReadAllText(testFilePath);

            Assert.IsTrue(true);
            Console.WriteLine("Statistics:\nRead accesses:\t{0}\nWrite acesses:\t{1}\nSteps:\t{2}",
                              sorter.ReadAccesses, sorter.WriteAccesses, sorter.Steps);

            File.Delete(testFilePath);
        }
Exemplo n.º 5
0
    protected override async Task <FileObject> CreateFileImplAsync(FileParameters option, CancellationToken cancel = default)
    {
        string fileName = this.PathParser.GetFileName(option.Path);

        if (fileName.IndexOf(Params.SplitStr) != -1)
        {
            throw new ApplicationException($"The original filename '{fileName}' contains '{Params.SplitStr}'.");
        }

        await using (CreatePerTaskCancellationToken(out CancellationToken operationCancel, cancel))
        {
            using (await AsyncLockObj.LockWithAwait(operationCancel))
            {
                cancel.ThrowIfCancellationRequested();

                bool isSimplePhysicalFileExists = await UnderlayFileSystem.IsFileExistsAsync(option.Path);

                if (isSimplePhysicalFileExists)
                {
                    // If there is a simple physical file, open it.
                    return(await UnderlayFileSystem.CreateFileAsync(option, cancel));
                }

                ParsedPath[] relatedFiles = await GetPhysicalFileStateInternal(option.Path, operationCancel);

                return(await LargeFileObject.CreateFileAsync(this, option, relatedFiles, operationCancel));
            }
        }
    }
Exemplo n.º 6
0
        public async Task LoadFile(FileParameters fileParameters)
        {
            var response = await httpService.Post(url, fileParameters);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
        }
Exemplo n.º 7
0
 protected override async Task <FileObject> CreateFileImplAsync(FileParameters option, CancellationToken cancel = default)
 {
     return(await this.AddFileAsync(option,
                                    async (newFilename, newFileOption, c) =>
     {
         return new VfsRamFile(this, newFilename);
     },
                                    cancel));
 }
        public async Task <IActionResult> Index(int id)
        {
            var temp = await _fileProxy.Get(id);

            var file = new FileParameters {
                Image = Convert.ToBase64String(temp)
            };

            return(View(file));
        }
Exemplo n.º 9
0
        /// <summary>
        /// 将当前文件写入控制器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_upload_Click(object sender, EventArgs e)
        {
            FileParameters fp = new FileParameters()
            {
                fileName        = this.lb_fileName.Text,
                fileNameControl = Encoding.UTF8.GetBytes(Path.GetFileName(lb_fileName.Text.Trim())),
                fileType        = 1
            };

            gCodeService.GCode_fileUpload(fp);
            gCodeService.GCode_fileSet(fp);
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Index(int id)
        {
            var user = (TokenUser)HttpContext.Items["User"];

            var temp = await _fileProxy.Get(user.Token, id);

            var file = new FileParameters {
                Image = Convert.ToBase64String(temp)
            };

            return(View(file));
        }
Exemplo n.º 11
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (FileParameters != null ? FileParameters.GetCollectionHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Parameters != null ? Parameters.GetCollectionHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ReleaseName != null ? ReleaseName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ValueFiles != null ? ValueFiles.GetCollectionHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Values != null ? Values.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Version != null ? Version.GetHashCode() : 0);
         return(hashCode);
     }
 }
Exemplo n.º 12
0
        public GCode_Test_Automatic()
        {
            InitializeComponent();
            //ReadTextFile(@"f:GCode.txt");
            ReadTextFile(gCodeService.GCode_fileName());
            this.lb_fileName.Text = gCodeService.GCode_fileName();
            FileParameters fp = new FileParameters()
            {
                fileName        = this.lb_fileName.Text,
                fileNameControl = Encoding.UTF8.GetBytes(Path.GetFileName(lb_fileName.Text.Trim())),
                fileType        = 1
            };

            gCodeService.GCode_fileSet(fp);
        }
Exemplo n.º 13
0
 public MultiFile(String[] segmentPath, long[] segmentSize, FileParameters parameters)
 {
     this.parameters = parameters;
     segment         = new MultiFileSegment[segmentPath.Length];
     for (int i = 0; i < segment.Length; i++)
     {
         MultiFileSegment seg = new MultiFileSegment();
         seg.f      = new OSFile(segmentPath[i], parameters);
         seg.size   = segmentSize[i];
         fixedSize += seg.size;
         segment[i] = seg;
     }
     fixedSize -= segment[segment.Length - 1].size;
     segment[segment.Length - 1].size = long.MaxValue;
 }
        protected override async Task <FileObject> CreateFileImplAsync(FileParameters option, CancellationToken cancel = default)
        {
            Utf8BomFileObject fileObj = new Utf8BomFileObject(this, option);

            try
            {
                await fileObj._InternalCreateFileAsync(cancel);

                return(fileObj);
            }
            catch
            {
                fileObj._DisposeSafe();
                throw;
            }
        }
Exemplo n.º 15
0
        public MultiFile(String filePath, FileParameters parameters)
        {
#if WINRT_NET_FRAMEWORK
            System.Threading.Tasks.Task <Stream> t = ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(filePath);
            t.Wait();
            StreamReader reader = new StreamReader(t.Result);
#else
            StreamReader reader = new StreamReader(filePath);
#endif
            this.parameters = parameters;
            segment         = new MultiFileSegment[0];
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                int sepPos;
                MultiFileSegment seg = new MultiFileSegment();
                string           path;
                if (line.StartsWith("\""))
                {
                    sepPos = line.IndexOf('"', 1);
                    path   = line.Substring(1, sepPos - 1);
                }
                else
                {
                    sepPos = line.IndexOf(' ');
                    path   = sepPos < 0 ? line : line.Substring(0, sepPos);
                }
                if (sepPos >= 0 && sepPos + 1 < line.Length)
                {
                    String fileLength = line.Substring(sepPos + 1).Trim();
                    if (fileLength.Length > 0)
                    {
                        seg.size = long.Parse(fileLength) * 1024; // kilobytes
                    }
                }
                fixedSize += seg.size;
                seg.f      = new OSFile(path, parameters);
                MultiFileSegment[] newSegment = new MultiFileSegment[segment.Length + 1];
                Array.Copy(segment, 0, newSegment, 0, segment.Length);
                newSegment[segment.Length] = seg;
                segment = newSegment;
            }

            fixedSize -= segment[segment.Length - 1].size;
            segment[segment.Length - 1].size = long.MaxValue;
        }
Exemplo n.º 16
0
        private void createNewSorter()
        {
            TextBox_FileToSort.Text = filePath;
            linesIfChoosenFile      = Utilities.getNumberOfLinesInFile(filePath);
            var fileParameters = new FileParameters()
            {
                BlockSize      = int.Parse(TextBox_BlockSize.Text), Separator = " ",
                SourceFileName = filePath,
                TemporaryBufferFileDirectory = TextBox_BufferLocation.Text
            };
            var sortingParameters = new SortingParameters()
            {
                NumberOfTemporaryFiles = int.Parse(TextBox_NumberOfTemporaryBuffers.Text)
            };

            Sorter = new PolyPhaseSorting(sortingParameters, fileParameters);
            Sorter.Distribution.Distribute();
        }
Exemplo n.º 17
0
        public async Task <ActionResult <string> > SaveData(FileParameters fileParams)
        {
            if (fileParams == null)
            {
                return(BadRequest());
            }
            try
            {
                ConnectParameters   connector  = Common.GetConnectParameters(connectionString, container, fileParams.DataConnector);
                CloudStorageAccount account    = CloudStorageAccount.Parse(connectionString);
                CloudFileClient     fileClient = account.CreateCloudFileClient();
                CloudFileShare      share      = fileClient.GetShareReference(fileParams.FileShare);
                if (share.Exists())
                {
                    CloudFileDirectory rootDir = share.GetRootDirectoryReference();
                    CloudFile          file    = rootDir.GetFileReference(fileParams.FileName);
                    if (file.Exists())
                    {
                        string    fileText = file.DownloadTextAsync().Result;
                        LASLoader ls       = new LASLoader(_env);
                        ls.LoadLASFile(connector, fileText);
                        //DbUtilities dbConn = new DbUtilities();
                        //dbConn.OpenConnection(connector);
                        //dbConn.SQLExecute(sql);
                        //dbConn.CloseConnection();
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }

            return(Ok($"OK"));
        }
Exemplo n.º 18
0
        public void TestStaticRoomFileLifecycle()
        {
            var roomId        = RoomList != null && RoomList.Any() ? RoomList.First() : Room;
            var newParameters = textFileContent;

            var newResponse = ChatworkClient.PostRoomFile(Token, roomId, newParameters);

            AssertPostFileResponse(newResponse);

            var fileId     = newResponse.Data.FileId;
            var parameters = new FileParameters
            {
                CreateDownloadUrl = true,
            };

            var response = ChatworkClient.GetRoomFile(Token, roomId, fileId, parameters);

            AssertGetFileResponse(response, fileId);
        }
Exemplo n.º 19
0
        public async void TestRoomFileLifecycleAsync()
        {
            var roomId        = RoomList != null && RoomList.Any() ? RoomList.First() : Room;
            var newParameters = textFileContent;

            var newResponse = await Client.PostRoomFileAsync(roomId, newParameters)
                              .ConfigureAwait(false);

            AssertPostFileResponse(newResponse);

            var fileId     = newResponse.Data.FileId;
            var parameters = new FileParameters
            {
                CreateDownloadUrl = true,
            };

            var response = await Client.GetRoomFileAsync(roomId, fileId, parameters)
                           .ConfigureAwait(false);

            AssertGetFileResponse(response, fileId);
        }
        public async Task <IActionResult> DownloadReportFile([FromBody] FileParameters fileParameters)
        {
            var fileName = fileParameters.Date + ".csv";

            string uRI = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/";

            uRI += fileName;

            string path2 = Path.Combine(_host.ContentRootPath, reportFolder);

            if (!Directory.Exists(path2))
            {
                Directory.CreateDirectory(path2);
            }

            try
            {
                WebClient webClient = new WebClient();
                webClient.DownloadFile(new Uri(uRI), Path.Combine(path2, fileName));

                return(StatusCode(200));
            }

            catch (WebException ex)
            {
                string algo = "";
                return(StatusCode(404, ex.Message));
            }
            catch (ArgumentNullException ex)
            {
                string algo = "";
                return(StatusCode(500, ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
                return(StatusCode(500, ex.Message));
            }
        }
Exemplo n.º 21
0
        public void TestStaticRoomFileLifecycleAsyncCallback()
        {
            var roomId = RoomList != null && RoomList.Any() ? RoomList.First() : Room;

            TestStaticPostRoomFileAsyncCallback(roomId, TestStaticGetRoomFileAsyncCallback);

            // [POST] /rooms/{room_id}/files.
            void TestStaticPostRoomFileAsyncCallback(long roomId, Action <long, long> next)
            {
                var parameters = textFileContent;

                ChatworkClient.PostRoomFileAsync(
                    Token,
                    response =>
                {
                    AssertPostFileResponse(response);
                    next.Invoke(roomId, response.Data.FileId);
                },
                    roomId,
                    parameters);
            }

            // [GET] /rooms/{room_id}/files/{file_id}.
            void TestStaticGetRoomFileAsyncCallback(long roomId, long fileId)
            {
                var parameters = new FileParameters
                {
                    CreateDownloadUrl = true,
                };

                ChatworkClient.GetRoomFileAsync(
                    Token,
                    response => AssertGetFileResponse(response, fileId),
                    roomId,
                    fileId,
                    parameters);
            }
        }
Exemplo n.º 22
0
        public void DownloadFile([FromBody] FileParameters fileParameters)
        {
            var fileName = fileParameters.Date + ".csv";

            string uRI = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/";

            uRI += fileName;

            string reportFolderPath = Path.Combine(_host.ContentRootPath, reportFolder);

            if (!Directory.Exists(reportFolderPath))
            {
                Directory.CreateDirectory(reportFolderPath);
            }

            try
            {
                WebClient webClient = new WebClient();
                webClient.DownloadFileAsync(new Uri(uRI), Path.Combine(reportFolderPath, fileName));
            }

            //catch (WebException ex)
            //{
            //    //string algo = "";
            //    //return StatusCode(404, ex.Message);
            //}
            //catch (ArgumentNullException ex)
            //{
            //    string algo = "";
            //    return StatusCode(500, ex.Message);
            //}
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
                //return StatusCode(500, ex.Message);
                throw;
            }
        }
Exemplo n.º 23
0
        public IEnumerable <CSSEGISandDataDailyReport> GetCovid19File([FromBody] FileParameters parameters)
        {
            CSSEGISandDataDailyReport[] records = Array.Empty <CSSEGISandDataDailyReport>();
            try
            {
                HttpWebRequest  req  = (HttpWebRequest)WebRequest.Create(parameters.Url);
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

                StreamReader sr = new StreamReader(resp.GetResponseStream());
                using var stream = new StringReader(sr.ReadToEnd());

                var engine = new FileHelperEngine <CSSEGISandDataDailyReport>();

                engine.BeforeReadRecord += Engine_BeforeReadRecord;

                records = engine.ReadStream(stream);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString()); // with stack trace
            }
            return(records);
        }
        public void ReadReportFile([FromBody] FileParameters fileParameters)
        {
            var fileName = fileParameters.Url + fileParameters.Date + ".csv";

            CSSEGISandDataDailyReport[] records = Array.Empty <CSSEGISandDataDailyReport>();
            try
            {
                HttpWebRequest  req  = (HttpWebRequest)WebRequest.Create(fileName);
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

                StreamReader sr = new StreamReader(resp.GetResponseStream());
                using var stream = new StringReader(sr.ReadToEnd());

                var engine = new FileHelperEngine <CSSEGISandDataDailyReport>();

                records = engine.ReadStream(stream);
            }
            catch (Exception ex)
            {
                var message = ex.Message;
                Console.WriteLine(ex.ToString()); // with stack trace
            }
        }
Exemplo n.º 25
0
        internal OSFile(String filePath, FileParameters parameters)
        {
            this.parameters = parameters;
#if WINRT_NET_FRAMEWORK
            System.Threading.Tasks.Task <StorageFile> tf = ApplicationData.Current.LocalFolder.CreateFileAsync(filePath, parameters.truncate ? CreationCollisionOption.ReplaceExisting : CreationCollisionOption.OpenIfExists).AsTask <StorageFile>();
            tf.Wait();
            System.Threading.Tasks.Task <IRandomAccessStream> ts = tf.Result.OpenAsync(parameters.readOnly ? FileAccessMode.Read : FileAccessMode.ReadWrite).AsTask <IRandomAccessStream>();
            file     = ts.Result;
            fileSize = (long)file.Size;
#elif SILVERLIGHT
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
            if (parameters.initialQuota != 0)
            {
                // Get the storage file for the application
                if (isf.Quota < parameters.initialQuota)
                {
                    isf.IncreaseQuotaTo(parameters.initialQuota);
                }
            }
            // Open/Create the file for writing
            file = new IsolatedStorageFileStream(filePath,
                                                 parameters.truncate ? FileMode.Create : FileMode.OpenOrCreate, parameters.readOnly ? FileAccess.Read : FileAccess.ReadWrite,
                                                 isf);
            fileSize = file.Length;
#else
            file = new FileStream(filePath, parameters.truncate ? FileMode.Create : FileMode.OpenOrCreate,
                                  parameters.readOnly ? FileAccess.Read : FileAccess.ReadWrite,
                                  parameters.readOnly ? FileShare.Read : FileShare.ReadWrite,
                                  parameters.fileBufferSize
#if !COMPACT_NET_FRAMEWORK && !SILVERLIGHT
                                  , FileOptions.RandomAccess
#endif
                                  );
            fileSize = file.Length;
#endif
            currPos = 0;
        }
Exemplo n.º 26
0
 protected GitFileObject(GitFileSystem fileSystem, FileParameters fileParams, IRandomAccess <byte> baseRandomAccess) : base(fileSystem, fileParams, baseRandomAccess)
 {
 }
Exemplo n.º 27
0
 public Rc4File(String filePath, FileParameters parameters, String key) 
 : base(filePath, parameters)
 {
     length = base.Length & ~(Page.pageSize-1);
     setKey(key);
 }
Exemplo n.º 28
0
 protected override Task <FileObject> CreateFileImplAsync(FileParameters option, CancellationToken cancel = default)
 => GitFileObject.CreateFileAsync(this, option, cancel);
Exemplo n.º 29
0
 public abstract Task <FileObject> OpenAsync(FileParameters option, string fullPath, CancellationToken cancel = default);
Exemplo n.º 30
0
        public FileImpl(VfsRandomAccessFile file, IRandomAccess <byte> randomAccessBase, string fullPath, FileSystem fileSystem, FileParameters fileParams)
            : base(new ConcurrentRandomAccess <byte>(randomAccessBase), fileSystem, fileParams)
        {
            this.File = file;
            this.File.AddHandleRef();

            try
            {
                this.FullPath = fullPath;
            }
            catch
            {
                this.File.ReleaseHandleRef();
                throw;
            }
        }
Exemplo n.º 31
0
    protected async Task <FileObject> AddFileAsync(FileParameters option, CreateFileCallback createFileCallback, CancellationToken cancel = default, bool noOpen = false)
    {
        using (VfsPathParserContext ctx = await ParsePathInternalAsync(option.Path, cancel))
        {
            if (ctx.Exception == null)
            {
                if (ctx.LastEntity is VfsFile file)
                {
                    // Already exists
                    if (option.Mode == FileMode.CreateNew)
                    {
                        throw new VfsException(option.Path, $"The file already exists.");
                    }

                    if (noOpen == false)
                    {
                        return(await file.OpenAsync(option, ctx.NormalizedPath, cancel));
                    }
                    else
                    {
                        return(null !);
                    }
                }
                else
                {
                    // There is existing another type object
                    throw new VfsException(option.Path, $"There are existing object at the speficied path.");
                }
            }

            if (ctx.Exception is VfsNotFoundException && ctx.RemainingPathElements.Count == 1 && ctx.LastEntity is VfsDirectory && option.Mode != FileMode.Open)
            {
                // Create new RAM file
                VfsDirectory lastDir = (VfsDirectory)ctx.LastEntity;

                string fileName = ctx.RemainingPathElements.Peek();

                var newFile = await createFileCallback(fileName, option, cancel);

                string fullPath = PathParser.Combine(ctx.NormalizedPath, fileName);

                try
                {
                    await lastDir.AddFileAsync(newFile);
                }
                catch
                {
                    await newFile.ReleaseLinkAsync(true);

                    throw;
                }

                if (noOpen == false)
                {
                    return(await newFile.OpenAsync(option, fullPath, cancel));
                }
                else
                {
                    return(null !);
                }
            }
            else
            {
                throw ctx.Exception;
            }
        }
    }