Exemple #1
0
        /// <summary>
        /// 修改文件响应事件
        /// </summary>
        /// <param name="strFilePath">文件全路径</param>
        /// <param name="strFileName">文件名</param>
        private static void sdn_ChangedFile(string strFilePath, string strFileName)
        {
            try
            {
                log.Info("Changed a file response event.");
                //交警支队 现有光匝为rename后文件同步完成
                if (strFileName.StartsWith("index"))                                    //如果是索引文件,把索引文件插入队列
                {
                    string  strJosn  = File.ReadAllText(strFilePath, Encoding.UTF8);    //采用UTF-8编码解析得到的json数据
                    JObject jobject  = (JObject)JsonConvert.DeserializeObject(strJosn); //得到索引文件中的json格式数据
                    string  strQueue = jobject["queueno"].ToString();                   //得到全局唯一的 批次号

                    baseQueue.QueueItem item = new baseQueue.QueueItem();
                    //item.FileList =;
                    item.dtTime     = DateTime.Now;
                    item.excState   = 0;
                    item.iDirection = (uint)iDirection;
                    item.msgState   = 0;
                    item.queType    = jobject["itype"].ToString();
                    string strQueueNo = strQueue;
                    item.queueNo     = strQueueNo;          //得到文件名中的批次号
                    item.snowflakeId = GetSonwflake() + ""; //得到唯一的雪花算法
                    item.syncState   = 0;
                    int iSyncTimes = Convert.ToInt32(jobject["synctimes"]);
                    item.syncTimes    = (uint)iSyncTimes; //同步次数
                    item.strIndexFile = strFilePath;
                    readList.Add(strQueueNo, item);       //添加到对应队列
                }
                else if (strFileName.StartsWith("sql"))   //sql文件
                {
                    if (!Directory.Exists(readPath))
                    {//如果写入文件夹不存在 创建该文件夹
                        Directory.CreateDirectory(readPath);
                    }
                    File.Move(strFilePath, $"{readPath}\\{strFileName}", true); //移动文件 如果有重名则覆盖
                                                                                // File.Delete(strFilePath);//删除ftp文件夹内文件
                }
                else //其他文件
                {
                }
            }
            catch (Exception ex)
            {
                log.Error("sdn_ChangedFile:" + ex.Message);
            }
        }
Exemple #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="strQueueNo"></param>
 /// <param name="item"></param>
 private static void addQueueInsert(string strQueueNo, baseQueue.QueueItem item)
 {
     try
     {
         if (insertList.Find(strQueueNo) != null)
         {
             insertList[strQueueNo] = item;
         }
         else
         {
             insertList.Add(strQueueNo, item);
         }
     }
     catch (Exception ex)
     {
         log.Error(ex.Message);
     }
 }