Exemplo n.º 1
0
        void LogToService(LogDetails logDetails)
        {
            LogServiceClient client = null;

            try
            {
                client = new LogServiceClient(WebConfigurationManager.AppSettings[Constants.FINLOGSERVICE_ENDPOINT]);
                client.Open();
                client.CreateLogEntry(logDetails);
            }
            finally
            {
                if (client.State != System.ServiceModel.CommunicationState.Closed)
                {
                    try
                    {
                        client.Close();
                    }
                    catch
                    {
                    }
                }
                client = null;
            }
        }
 private void TrySendLogToAdministratorPanel(string log)
 {
     try
     {
         var adminPanel = new LogServiceClient("LOG");
         adminPanel.RecieveLog(_networkNode.GetId().Id, log);
         adminPanel.Close();
     }
     catch (Exception ex)
     {
         EventLogHelper.WriteErrorToEventLog(ex);
     }
 }
Exemplo n.º 3
0
 public void Dispose()
 {
     _operationContextScope.Dispose();
     _client.Close();
 }
Exemplo n.º 4
0
 private async void QueryLogExec()
 {
     LogService.LogServiceClient lc = new LogServiceClient();
     this.count = int.Parse(System.Configuration.ConfigurationManager.AppSettings["logCount"]);
     try
     {
         lc.Open();
         //TODO Set the method async, set UI waiting.
         var queryTask = lc.QueryLogQueryTakeAsync(this.QueryLogArgs, 0, count, this.IsWithKeepLine);
         this.QueryLogList = (await queryTask).OrderByDescending(l => l.OptionDate).ToList();
     }
     catch (Exception ex)
     {
         Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>(ex.Message), "querySysLogError");
     }
     finally
     {
         lc.Close();
     }
     //TODO Set UI to be free.
 }
Exemplo n.º 5
0
        public Task FliterBlackNote(bool SyncWhiteNotes, bool SyncBlackNotes)
        {
            return Task.Run(() =>
            {
                lock (this)
                {
                    FliterServiceClient fClient = new FliterServiceClient();

                    LogServiceClient lClient = new LogServiceClient();
                    try
                    {
                        lClient.Open();
                        fClient.Open();
                        if (SyncBlackNotes)
                        {
                            //定时同步黑名单
                            this.BlackList = fClient.GetBlackNoteList().ToList();
                        }
                        if (SyncWhiteNotes)
                        {
                            //定时同步白名单
                            this.WhiteList = fClient.GetWhiteNoteList().ToList();
                        }

                        //获取日志
                        NewLogList = lClient.LastQueryLogQuery(this.LastId, false);
                        if (NewLogList.Count() > 0)
                        {
                            this.LastId = NewLogList.Max(n => n.Id);
                        }

                        //添加至对应的列表中
                        this.TodayLogList.AddRange(NewLogList);
                        this.LastHundreLogList.AddRange(NewLogList);

                        //删除过期黑名单
                        foreach (var n in BlackList)
                        {
                            if (n.Reason == "当日查询过多!" && DateTime.Now.Subtract(n.CreateDate).TotalDays > 1)
                            {
                                fClient.DelBlackNote(n);
                                continue;
                            }
                            if (n.Reason == "短时间内频繁查询。" && DateTime.Now.Subtract(n.CreateDate).TotalSeconds > this.shortTimeSpan)
                            {
                                fClient.DelBlackNote(n);
                            }
                        }

                        //删除本地日志中的过期项
                        //if (this.LastHundreLogList.Count() > 100)
                        //{
                        //    this.LastHundreLogList.RemoveRange(0, this.LastHundreLogList.Count() - 100);
                        //}
                        this.LastHundreLogList.RemoveAll(n => DateTime.Now.Subtract(n.OptionDate).TotalSeconds > this.shortTimeSpan);
                        this.TodayLogList.RemoveAll(n => DateTime.Now.Subtract(n.OptionDate).TotalDays > 1);
                        //while (this.TodayLogList.Count() > 0 && DateTime.Now.Subtract(this.TodayLogList[0].OptionDate).TotalDays > 1)
                        //{
                        //    this.TodayLogList.RemoveAt(0);
                        //}
                        BlackList.RemoveAll(n => n.Reason == "当日查询过多!" && DateTime.Now.Subtract(n.CreateDate).TotalDays > 1);
                        BlackList.RemoveAll(n => n.Reason == "短时间内频繁查询。" && DateTime.Now.Subtract(n.CreateDate).TotalSeconds > this.shortTimeSpan);

                        //筛选黑名单
                        var todayDic = GetCountDic(TodayLogList);
                        var lastDic = GetCountDic(LastHundreLogList);

                        //检测是否在白名单内
                        foreach (var k in todayDic.Keys)
                        {
                            if (this.WhiteList.Any(n => n.Feature == k.Feature && n.Mold == k.Mold))
                            {
                                //todayDic.Remove(k);
                                todayDic[k] = 0;
                            }
                        }
                        foreach (var k in lastDic.Keys)
                        {
                            if (this.WhiteList.Any(n => n.Feature == k.Feature && n.Mold == k.Mold))
                            {
                                //lastDic.Remove(k);
                                lastDic[k] = 0;
                            }
                        }
                        //添加至黑名单中(封装新的方法)
                        foreach (var note in todayDic)
                        {
                            if (note.Value > this.timesForOneDay)
                            {
                                // AddToBlackNote(note.Key);
                                var newNote = new BlackNote
                                {
                                    CreateDate = DateTime.Now,
                                    Feature = note.Key.Feature,
                                    Mold = note.Key.Mold,
                                    Flg = true,
                                    Reason = "当日查询过多!",
                                };
                                if (fClient.AddBlackNote(newNote) == 1)
                                {
                                    this.BlackList.Add(newNote);
                                }
                            }

                        }
                        foreach (var note in lastDic)
                        {
                            if (note.Value > this.shortTimeQueryTimes)
                            {
                                var newNote = new BlackNote
                                {
                                    CreateDate = DateTime.Now,
                                    Reason = "短时间内频繁查询。",
                                    Flg = true,
                                    Feature = note.Key.Feature,
                                    Mold = note.Key.Mold,
                                    UpdateDate = DateTime.Now,
                                    Id = 0
                                };
                                var ret = fClient.AddBlackNote(newNote);
                                if (ret == 1)
                                //if (fClient.AddBlackNote(newNote) == 1)
                                {
                                    this.BlackList.Add(newNote);
                                }
                            }
                        }
                        lClient.Close();
                        fClient.Close();
                    }
                    catch (Exception ex)
                    {
                        Messenger.Default.Send<DialogMessage>(new DialogMessage(string.Format("An error was happend on {0}:\r\n{1}", "add black note", ex.Message), null), "showMsg");
                    }
                    finally
                    {
                        lClient.Abort();
                        fClient.Abort();
                    }
                }
            }
             );
        }