Beispiel #1
0
        private void Process(bool multithread, string connectionID)
        {
            // Prepare
            var _Cancel = new CancellationTokenSource();

            Session["_Cancel"] = _Cancel;
            var FileName = Session["FileName"]?.ToString();
            var Parser   = _Facade.Parser;

            if (Parser.FileAlreadyParsed(FileName))
            {
                ProgressHub.SendMessage(connectionID, "File already parsed!");
                return;
            }
            // Fire and forget
            Task <bool> .Run(() =>
            {
                var progress = new Progress <int>();
                try
                {
                    var ProgressBarMaximum    = Parser.RowsInAnketa(FileName).Result;
                    progress.ProgressChanged += (sender, args) =>
                    {
                        ProgressHub.SendProgress(connectionID, args, ProgressBarMaximum);
                    };
                    if (!multithread)
                    {
                        Parser.Parse_SigleAsync(FileName, progress, _Cancel).Wait();
                    }
                    else
                    {
                        Parser.Parse_MultipleAsync(FileName, progress, _Cancel).Wait();
                    }
                }
                catch (Exception ex)
                {
                    ProgressHub.SendMessage(connectionID, ex.InnerException.Message);
                }
                int fileId = _Facade.Keeper.GetFile(Path.GetFileName(FileName)).ID;
                ProgressHub.ParsingCompleted(connectionID, fileId);
                return(true);
            });
        }