/// <summary> /// Logs warning to the database /// </summary> /// <param name="sender"></param> /// <param name="warningMessage"></param> /// <param name="memberName"></param> public static void LogWarning(object sender, string warningMessage, [CallerMemberName] string memberName = "") { int?userID = User != null ? User.id : (int?)null; LogService.AddLog(new LogToAdd(userID, LogMessageType.WARNING, $"{sender.GetType()}.{memberName}", warningMessage)); Debug.WriteLine($"WARNING: {sender.GetType()}.{memberName}"); }
public static void SftpSynchronize() { try { LogService.AddLog(LogMode.FileLog, LogEvent.Debug, new Exception("初始化连接Sftp...")); SFTPHelper sftp = new SFTPHelper(Config.Sftp_Server, Config.Sftp_Port, Config.Sftp_UserName, Config.Sftp_Password); LogService.AddLog(LogMode.FileLog, LogEvent.Debug, new Exception("开始获取Sftp服务器文件列表...")); List <string> files = sftp.GetFileList(Config.Sftp_FileDirectory, "zip"); LogService.AddLog(LogMode.FileLog, LogEvent.Debug, new Exception(string.Format("SFTP服务器共有{0}个文件", files.Count))); int index = 1; foreach (var file in files) { LogService.AddLog(LogMode.FileLog, LogEvent.Debug, new Exception(string.Format("开始下载SFTP第{0}个文件{1}", index, file))); string sftpFilePath = Config.Sftp_FileDirectory + "/" + file; string loaclFilePath = Path.Combine(Config.Local_FileDirectory, file); if (File.Exists(loaclFilePath)) { File.Delete(loaclFilePath); } sftp.Get(sftpFilePath, loaclFilePath); LogService.AddLog(LogMode.FileLog, LogEvent.Debug, new Exception(string.Format("结束下载SFTP第{0}个文件{1}", index, file))); index++; } } catch (Exception ex) { LogService.AddLog(LogMode.FileLog, LogEvent.Error, ex); } }
protected void BtnPost_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(Title1.Text) && !String.IsNullOrEmpty(Details.Text)) { var db = new ApplicationDbContext(); db.Posts.Add(new Post() { Title = Title1.Text, Details = Details.Text }); db.SaveChanges(); var userId = User.Identity.GetUserId(); var email = User.Identity.GetUserName(); // var logService = new LogService(); // LogService.GetLogs(userId); var userLog = new DALUserLog.UserLog { UserId = userId, Action = "Created", Details = "A New Post Created", Email = email, SendingDate = DateTime.UtcNow }; LogService.AddLog(userLog); Response.Redirect("/Posts/PostsList"); } ModelState.AddModelError("", "Please Fill All Fields"); }
/// <summary> /// Logs error to the database /// </summary> /// <param name="sender"></param> /// <param name="errorMessage"></param> /// <param name="memberName"></param> public static void LogError(object sender, string errorMessage, [CallerMemberName] string memberName = "") { int?userID = User != null ? User.id : (int?)null; LogService.AddLog(new LogToAdd(userID, LogMessageType.ERROR, $"{sender.GetType()}.{memberName}", errorMessage)); Debug.WriteLine($"ERROR: {sender.GetType()}.{memberName}"); }
/// <summary> /// Logs information to the database /// </summary> /// <param name="sender"></param> /// <param name="infoMessage"></param> /// <param name="memberName"></param> public static void LogInfo(object sender, string infoMessage, [CallerMemberName] string memberName = "") { int?userID = User != null ? User.id : (int?)null; LogService.AddLog(new LogToAdd(userID, LogMessageType.INFO, $"{sender.GetType()}.{memberName}", infoMessage)); Debug.WriteLine($"INFO: {sender.GetType()}.{memberName}"); }
public void Test_AddLog() { Log log = (Log)_logList[0]; _logDalMock.Setup(s => s.AddLog(log)); _logService.AddLog(log); _logDalMock.Verify(s => s.AddLog(log), Times.Once); }
public IHttpActionResult PostLog(Log log) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _logService.AddLog(log); return(CreatedAtRoute("DefaultApi", new { id = log.LogId }, log)); }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { LogAdd newLog = new LogAdd { // This is a internal service log. The API logs from others will not be run throuhg the Core logger Component = _name, LogLevel = logLevel.ToString(), LogMessage = formatter(state, exception) }; _logService.AddLog(newLog); }
protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e) { var userId = User.Identity.GetUserId(); var email = User.Identity.GetUserName(); var userLog = new DALUserLog.UserLog { UserId = userId, Action = "Deleted", Details = "Post deleted ", Email = email, SendingDate = DateTime.UtcNow }; LogService.AddLog(userLog); }
public static void Synchronize() { while (true) { string time = DateTime.Now.ToString("HH:mm:ss"); if (time == Config.ExecutionTime) { LogService.AddLog(LogMode.FileLog, LogEvent.Debug, new Exception("开始执行获取sftp服务器文件...")); SftpSynchronize(); LogService.AddLog(LogMode.FileLog, LogEvent.Debug, new Exception("执行结束获取sftp服务器文件。")); LogService.AddLog(LogMode.FileLog, LogEvent.Debug, new Exception("开始执行删除过期文件(默认7天)...")); SynGetFileDay(); LogService.AddLog(LogMode.FileLog, LogEvent.Debug, new Exception("执行结束删除过期文件(默认7天)...")); } Thread.Sleep(1000); } }
public IActionResult Doubling(int?input) { service.AddLog("/doubling", input.ToString()); if (input == null) { return(Json(new { error = "Please provide an input!" })); } else { return(Json(new { received = input, result = input * 2 })); } }
public void AddLog__log_db_save_method_returns_mocked_data() { _dbLoggerMock = new Mock <IDbLogger>(); _fileLoggerMock = new Mock <IFileLogger>(); _logService = new LogService(_dbLoggerMock.Object, _fileLoggerMock.Object, dataContext); var returnLog = new Log() { Logger = typeof(LogTest).ToString(), Message = "q1" }; _dbLoggerMock.Setup(m => m.Add(It.IsAny <string>(), It.IsAny <object>())) .Returns(returnLog); Log dbRecord = _logService.AddLog("Test", typeof(LogTest)); Assert.AreEqual(returnLog, dbRecord); }
public async Task Test_AddLog_ShouldAddLog() { var context = GetContext(); var repo = new DbRepository <Log>(context); var logService = new LogService(repo); var log = new Log { Id = 122, UserId = "a", ResourceId = 1, LogType = LogType.AddedAComment }; int result = await logService.AddLog(log); Assert.Single(context.Log); }
public void AddLog__log_file_save_method_returns_mocked_data() { _dbLoggerMock = new Mock <IDbLogger>(); _fileLoggerMock = new Mock <IFileLogger>(); _logService = new LogService(_dbLoggerMock.Object, _fileLoggerMock.Object, dataContext); var mockedLog = new Log() { Logger = typeof(LogTest).ToString(), Message = "q2" }; _dbLoggerMock.Setup(m => m.Add(It.IsAny <string>(), It.IsAny <object>())) .Throws <SystemException>(); _fileLoggerMock.Setup(m => m.Add(It.IsAny <string>(), It.IsAny <object>())) .Returns(mockedLog); Log log = _logService.AddLog("Test", typeof(LogTest)); Assert.AreEqual(mockedLog, log); }
public async System.Threading.Tasks.Task Test5Async() { var userChoiceServiceMock = new Mock <IUserChoiceService>(); List <Log> log = new List <Log>(); for (int i = 0; i < 10; i++) { Log tmpLog3 = new Log(); tmpLog3.FoodName = i.ToString(); int[] p3 = { i, i, i, i, i, i }; tmpLog3.WeightChangeList = new List <int>(p3); log.Add(tmpLog3); } userChoiceServiceMock.Setup(w => w.ReadJsonAsync()).ReturnsAsync(log); var mockUserChoiceService = userChoiceServiceMock.Object; LogService logService = new LogService(mockUserChoiceService); await logService.InitAsync(); Assert.AreEqual(logService.GetLogs(), log); Log tmpLog = new Log(); tmpLog.FoodName = "10"; int[] p = { 10, 10, 10, 10, 10, 10 }; tmpLog.WeightChangeList = new List <int>(p); log.Add(tmpLog); logService.AddLog(tmpLog); Assert.AreEqual(logService.GetLogs(), log); Log tmpLog1 = new Log(); tmpLog1.FoodName = "11"; int[] p1 = { 11, 11, 11, 11, 11, 11 }; tmpLog.WeightChangeList = new List <int>(p1); log.Add(tmpLog); logService.SetLogs(log); Assert.AreEqual(logService.GetLogs(), log); //logService.SetLogs(); }
public static void SynGetFileDay() { DirectoryInfo directoryInfo = new DirectoryInfo(Config.Local_FileDirectory); FileInfo[] files = directoryInfo.GetFiles("*.zip"); try { foreach (var file in files) { if (file.CreationTime.AddDays(Config.DelHistoryImportfiles) < DateTime.Now) { LogService.AddLog(LogMode.FileLog, LogEvent.Debug, new Exception(string.Format("开始删除文件{0}", file))); file.Delete(); LogService.AddLog(LogMode.FileLog, LogEvent.Debug, new Exception(string.Format("结束删除文件{0}", file))); } } } catch (Exception ex) { LogService.AddLog(LogMode.FileLog, LogEvent.Error, ex); } }
public IActionResult Post([FromBody] LogAdd logAdd) { Log newLog = _logService.AddLog(logAdd); return(new OkObjectResult(newLog)); }
public async Task AddLog(int CompanyId = 0, string WebSite = null, string LinkedinOfTradingName = null, QualifyCompanyModel qualifyCompany = null, int count = 0, string LinkedinOfUser = null, string ActionMesage = null) { if (WebSite != null) { LogDTO logDTO = new LogDTO { Action = "Перешел на сайт " + WebSite, UserId = TempService.CurrentUser.Id }; await LogService.AddLog(logDTO); //Thread.Sleep(3000); } else if (WebSite == null && CompanyId != 0) { LogDTO logDTO = new LogDTO { Action = "Просмотрел компанию " + TempService.AllCompanies.Where(p => p.Id == SelectedId).FirstOrDefault().TradingName, UserId = TempService.CurrentUser.Id }; await LogService.AddLog(logDTO); } else if (LinkedinOfTradingName != null) { LogDTO logDTO = new LogDTO { Action = "Просмотрел аккаунт LinkedIn компании " + LinkedinOfTradingName, UserId = TempService.CurrentUser.Id }; await LogService.AddLog(logDTO); } else if (qualifyCompany != null) { LogDTO logDTO; if (qualifyCompany.IsQualify) { logDTO = new LogDTO { Action = "Изменил статус компании " + qualifyCompany.CompanyTradingName + " на Квалифицированный", UserId = TempService.CurrentUser.Id }; } else { logDTO = new LogDTO { Action = "Изменил статус компании " + qualifyCompany.CompanyTradingName + " на НЕ квалифицированный", UserId = TempService.CurrentUser.Id }; } await LogService.AddLog(logDTO); } else if (count != 0) { LogDTO logDTO = new LogDTO { Action = "Добавил " + count + " контактов в lemmlist", UserId = TempService.CurrentUser.Id }; await LogService.AddLog(logDTO); } else if (LinkedinOfUser != null) { LogDTO logDTO = new LogDTO { Action = "Просмотрел аккаунт LinkedIn пользователя " + LinkedinOfUser, UserId = TempService.CurrentUser.Id }; await LogService.AddLog(logDTO); } else if (ActionMesage != null) { LogDTO logDTO = new LogDTO { Action = ActionMesage, UserId = TempService.CurrentUser.Id }; await LogService.AddLog(logDTO); } await TempService.UpdateLogs(); await RenderUpdate(); }
/* * public void Retrain() * { * FileAccess fileAccessTheta0 = new FileAccess("Theta0.csv"); * FileAccess fileAccessTheta1 = new FileAccess("Theta1.csv"); * Theta = new string[HiddenLayerLength + 1]; * * Theta[0] = fileAccessTheta0.ReadFile(); * Theta[1] = fileAccessTheta1.ReadFile(); * * var t = new Thread(() => Service("127.0.0.1", 6000 + NumberOfSlaves, 0)); * t.Start(); * t.Join(); * } */ public void Service(int slaveNumber) { CommunicationsServer communicationServer = new CommunicationsServer(Configuration) { PipelineId = PipelineId }; communicationServer.SendCommunicationServerParameters(); var response = communicationServer.GetCommunicationResonse(); bool P2pSuccess = false; MiddleLayer middleLayer = null; if (response.P2P) { IPEndPoint remoteEndPoint = communicationServer.GetIpEndPoint(response.EndPoint); IPEndPoint localEndPoint = communicationServer.server.client.Client.LocalEndPoint as IPEndPoint; communicationServer.server.Close(); try { TcpHole tcpHole = new TcpHole(); TcpClient tcpClient = tcpHole.PunchHole(localEndPoint, remoteEndPoint); if (!tcpHole.Success) { throw new Exception("Hole Punching Failed"); } CommunicationTcp communicationTcp = new CommunicationTcp(tcpClient); middleLayer = new MiddleLayer() { CommunicationModule = new CommunicationModule() { CommunicationTcp = communicationTcp, P2P = true } }; P2pSuccess = true; }catch (Exception E) { if (E.Message != "Hole Punching Failed") { throw; } } } if (!P2pSuccess) { CommunicationRabbitMq communicationM2s = new CommunicationRabbitMq(queueName: PipelineId + "_" + response.QueueNumber + "m2s", Configuration: Configuration); CommunicationRabbitMq communicationS2m = new CommunicationRabbitMq(queueName: PipelineId + "_" + response.QueueNumber + "s2m", Configuration: Configuration); communicationS2m.StartConsumer(); middleLayer = new MiddleLayer() { CommunicationModule = new CommunicationModule() { CommunicationRabbitMqM2S = communicationM2s, CommunicationRabbitMqS2M = communicationS2m, P2P = false } }; } var slaveParameters = BuildSlaveParameters(slaveNumber); middleLayer.SendInitialData(slaveParameters, X_value[slaveNumber], y_value[slaveNumber], Theta); int thetaSize = 0; bool isLog = true; while (isLog) { string data = middleLayer.CommunicationModule.ReceiveData(); try { LogService.AddLog(JsonConvert.DeserializeObject <List <Log> >(data), slaveNumber); } catch { try { if (middleLayer.CommunicationModule.P2P) { thetaSize = int.Parse(data); ThetaSlaves[slaveNumber] = middleLayer.BuildTheta(middleLayer.ReceiveTheta(thetaSize), HiddenLayerLength); } else { ThetaSlaves[slaveNumber] = middleLayer.BuildTheta(data, HiddenLayerLength); } isLog = false; } catch (Exception e) { throw; } } } middleLayer.CommunicationModule.Close(); }