Beispiel #1
0
 /// <summary>
 /// 是不是在处理队列
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 private bool IsOnDealing(DealDataBase data)
 {
     lock (dealingQueueLocker)
     {
         return(DealingQueue.ContainsKey(data.TaskInfoFilePath));
     }
 }
        protected bool MoveData(DealDataBase data)
        {
            bool   res      = false;
            string targPath = null;

            switch (data.DealResult)
            {
            case FileHandleStatus.Success:
                targPath = CompleteDir;
                break;

            case FileHandleStatus.Fail:
                targPath = ErrorDir;
                break;

            default:
                break;
            }
            try
            {
                if (data.MoveFile(targPath))
                {
                    res = true;
                }
            }
            catch (Exception ex)
            {
                ILog.log.Error($"数据移动失败:{ex.ToString()}");
            }

            return(res);
        }
Beispiel #3
0
        protected void OnDataGreated(object sender, EventArgs e)
        {
            try
            {
                DealDataBase data = LoadData(sender, e);
                if (data == null || IsInWaitingList(data))
                {
                    return;
                }

                lock (dealingQueueLocker)
                {
                    if (IsOnDealing(data))
                    {
                        return;
                    }
                }
                //加入等待队列
                EnQueueWaiting(data);
                //if(!data.IS)
            }
            catch (Exception ex)
            {
                ILog.log.Error($"扫描文件出错:{ex.ToString()}");
            }
        }
Beispiel #4
0
 protected void EnQueueWaiting(DealDataBase data)
 {
     if (IsInWaitingList(data))
     {
         return;
     }
     WaitingQueue.Enqueue(data);
 }
Beispiel #5
0
 protected bool EnQueueDealing(DealDataBase data)
 {
     lock (dealingQueueLocker)
     {
         if (DealingQueue.ContainsKey(data.TaskInfoFilePath))
         {
             return(false);
         }
         DealingQueue.Add(data.TaskInfoFilePath, data);
         return(true);
     }
 }
Beispiel #6
0
        //protected void OnDataGreated(object sender,EventArgs e)
        //{
        //    try
        //    {
        //        DealDataBase data = LoadData(sender, e);
        //        if(data == null || IsInWaitingList(data))
        //        {
        //            return;
        //        }

        //        lock(dealingQueueLocker)
        //        {
        //            if(IsOnDealing(data))
        //            {
        //                return;
        //            }
        //        }
        //        EnQueueWaiting(data);
        //        //if(!data.IS)
        //    }
        //    catch(Exception ex)
        //    {
        //        ILog.log.Error($"扫描文件出错:{ex.ToString()}");
        //    }
        //}

        //protected void FileScan()
        //{
        //    do
        //    {
        //        try
        //        {
        //            foreach(KeyValuePair<object,EventArgs> eventHandler in GetDatas())
        //            {
        //                OnDataGreated(eventHandler.Key, eventHandler.Value);

        //                while (WaitingQueue.Count > 100)
        //                {
        //                    Thread.Sleep(1000);
        //                }
        //            }


        //        }
        //        catch(Exception ex)
        //        {
        //            ILog.log.Error($"扫描文件出错:{ex.ToString()}");
        //        }
        //        finally
        //        {
        //            Thread.Sleep(1000);
        //        }
        //    } while (true);
        //}
        #endregion


        /// <summary>
        /// 这里在等待队列里面拿出数据
        /// </summary>
        /// <returns></returns>
        protected DealDataBase DeQueueWaiting()
        {
            if (!WaitingQueue.Any())
            {
                return(null);
            }
            DealDataBase res   = null;
            int          total = 0;

            while (!WaitingQueue.TryDequeue(out res))
            {
                if (total % (30 * 100) == 0)
                {
                    ILog.log.Error($"从等待队列拿出数据失败");
                }
                Thread.Sleep(1000);
                total += 100;
            }
            return(res);
        }
Beispiel #7
0
        protected DealDataBase LoadData(Object sender, EventArgs arg)
        {
            DealDataBase        res = null;
            FileSystemEventArgs e   = arg as FileSystemEventArgs;

            if (e == null)
            {
                return(res);
            }

            if (e.ChangeType != WatcherChangeTypes.Created)
            {
                return(res);
            }

            try
            {
                if (!IsFile(e.FullPath))
                {
                    return(res);
                }
                string        destDir = Decompression(e.FullPath, this.configData.InputPath);
                DirectoryInfo root    = new DirectoryInfo(destDir);
                //FileInfo taskfi = new FileInfo(e.FullPath);
                if (IsInWaitingList(root))
                {
                    return(res);
                }
                //这里开始解压 返回文件夹的名

                res = new DealingFileBase();
            }
            catch (Exception ex)
            {
                ILog.log.Error($"{ex.ToString()}");
                res = null;
            }
            return(res);
        }
Beispiel #8
0
        /// <summary>
        /// 这里是api 处理得线程
        /// </summary>
        protected void DealApi()
        {
            int total = 0;

            while (true)
            {
                while (!WaitingQueue.Any())
                {
                    Thread.Sleep(1000);

                    DealDataBase data = DeQueueWaiting();

                    try
                    {
                        if (data == null)
                        {
                            ILog.log.Error($"获取数据失败");
                            continue;
                        }

                        if (IsOnDealing(data))
                        {
                            continue;
                        }

                        if (!EnQueueDealing(data))
                        {
                            continue;
                        }

                        //ILog.log.Debug($"来了一个数据:任务id--{data.Taskinfo.taskid}任务数据{data.Jsdata}准备进行请求api");
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }
        /// <summary>
        /// 这里删除的是文件夹
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        protected bool DeleteData(DealDataBase data)
        {
            bool flag = false;

            return(flag);
        }
Beispiel #10
0
 protected bool IsInWaitingList(DealDataBase data)
 {
     return(WaitingQueue.Any((x) => { return x.TaskInfoFilePath == data.TaskInfoFilePath; }));
 }