예제 #1
0
        public async Task LoadData()
        {
            var b = IsLocalFile();

            if (b)
            {
                await LoadLocalFile();

                return;
            }
            //is a file on internet
            using (var wc = new WebClient())
            {
                StartReadFile?.Invoke(this, EventArgs.Empty);
                var allText = await wc.DownloadStringTaskAsync(FileToRead);
                await ProcessText(allText);

                EndReadFile?.Invoke(this, EventArgs.Empty);
            }
        }
예제 #2
0
        async Task LoadLocalFile()
        {
            ContinueRead = true;
            StartReadFile?.Invoke(this, EventArgs.Empty);
            using (var stream = File.Open(FileToRead, FileMode.OpenOrCreate, FileAccess.Read))
            {
                using (var reader = new StreamReader(stream, FileEnconding))
                {
                    if (this.ReadAllFirstTime)
                    {
                        var allText = await reader.ReadToEndAsync();
                        await ProcessText(allText);
                    }
                    else
                    {
                        string line;
                        while (ContinueRead && ((line = await reader.ReadLineAsync()) != null))
                        {
                            try
                            {
                                //maybe process async?!
                                await ProcessText(line);
                            }
                            catch (Exception ex)
                            {
                                string s = ex.Message;
                                //@class.Log(LogLevel.Error,0,"end send data ERROR receiver file from storage"+s,ex,null);
                                throw;
                            }
                        }
                    }
                }


                EndReadFile?.Invoke(this, EventArgs.Empty);
            }
        }