Пример #1
0
        public bool Step()
        {
            string[]    files = new GetLogFiles().readlist(_dataDirectory);
            int         FileCount = files.Length; int iCount = 0;
            List <Task> tsArr = new List <Task>();
            FileInfo    fi    = null;

            using (var progress = new ProgressBar())
            {
                try
                {
                    logger.Info("Extraction Processing...");

                    LimitedConcurrencyLevelTaskScheduler lcts = new LimitedConcurrencyLevelTaskScheduler(_maxThread);
                    TaskFactory factory = new TaskFactory(lcts);

                    foreach (string file in files)
                    {
                        fi = new FileInfo(file);

                        string filename = fi.Name.Substring(0, fi.Name.Length - 4);
                        if (filename.Length >= 7)
                        {
                            filename = filename.Substring(0, 7);
                        }

                        //ExportToFile(file, _bFilter);
                        Task ts = factory.StartNew(() =>
                        {
                            try
                            {
                                ExportToFile(file, _pointType);
                                Interlocked.Increment(ref iCount);
                                progress.Report((double)iCount / FileCount);
                            }
                            catch (Exception ex)
                            {
                                logger.Error("Error: Failed in " + file + ". " + ex.Message);
                            }
                        });

                        tsArr.Add(ts);
                    }
                    //else { Interlocked.Increment(ref iCount); progress.Report((double)iCount / FileCount); }

                    Task AllTasks = Task.WhenAll(tsArr.ToArray());
                    return(AllTasks.ContinueWith <bool>((a) =>//当所有task完成后,执行这个回调
                    {
                        //Common.Execute("copy  " + _outTempDirectory + @"\*.csv " + _outFile, 0);
                        _sw.Close();
                        return true;
                    }).Result);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    return(false);
                }
            }
        }
Пример #2
0
        public bool Step()
        {
            bool bFlag = true;

            string[]    files = new GetLogFiles().readlist(_dataDirectory);
            int         FileCount = files.Length; int iCount = 0;
            List <Task> tsArr = new List <Task>();
            FileInfo    fi    = null;

            using (var progress = new ProgressBar())
            {
                try
                {
                    if (_lpFile != null)
                    {
                        LoadlpFile();
                    }

                    logger.Info("Conversion Processing...");

                    LimitedConcurrencyLevelTaskScheduler lcts = new LimitedConcurrencyLevelTaskScheduler(_maxThread);
                    TaskFactory factory = new TaskFactory(lcts);

                    foreach (string file in files)
                    {
                        fi    = new FileInfo(file);
                        bFlag = true;

                        string filename = fi.Name.Substring(0, fi.Name.Length - 4);
                        if (filename.Length >= 7)
                        {
                            filename = filename.Substring(0, 7);
                        }
                        if (_lpFile != null)
                        {
                            if (_lpDics.Contains(filename) == false)
                            {
                                bFlag = false;
                            }
                        }

                        if (bFlag)
                        {
                            //ExportToFile(file, _bFilter);
                            Task ts = factory.StartNew(() =>
                            {
                                try
                                {
                                    ExportToFile(file, _bFilter);
                                    Interlocked.Increment(ref iCount);
                                    progress.Report((double)iCount / FileCount);
                                }
                                catch (Exception ex)
                                {
                                    logger.Error("Error: Failed in " + file + ". " + ex.Message);
                                }
                            });

                            tsArr.Add(ts);
                        }
                        else
                        {
                            Interlocked.Increment(ref iCount); progress.Report((double)iCount / FileCount);
                        }
                    }

                    Task AllTasks = Task.WhenAll(tsArr.ToArray());
                    return(AllTasks.ContinueWith <bool>((a) =>//当所有task完成后,执行这个回调
                    {
                        return true;
                    }).Result);
                    //return true;
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    return(false);
                }
            }
            //return false;
        }