public void CreateUserAccount_Return3NewGuids() { var deviceInfo1 = new DeviceInfo() { UserName = "******", UserPassword = "******", DeviceName = "PersMobil" }; var deviceInfo2 = new DeviceInfo() { UserName = "******", UserPassword = "******", DeviceName = "KarisMobil" }; var deviceInfo3 = new DeviceInfo() { UserName = "******", UserPassword = "******", DeviceName = "OlasMobil" }; var person1 = new Person() { FirstName = "Per", LastName = "Larsen", Email = "*****@*****.**" }; var person2 = new Person() { FirstName = "Kari", LastName = "Olsen", Email = "*****@*****.**" }; var person3 = new Person() { FirstName = "Ola", LastName = "Normann", Email = "*****@*****.**" }; var dtoCreateUser1 = new DtoCreateUser() { DeviceInfo = deviceInfo1, Person = person1 }; var dtoCreateUser2 = new DtoCreateUser() { DeviceInfo = deviceInfo2, Person = person2 }; var dtoCreateUser3 = new DtoCreateUser() { DeviceInfo = deviceInfo3, Person = person3 }; var newDtoCreateUser1 = new UserBiz().CreateUserAccount(dtoCreateUser1); var newDtoCreateUser2 = new UserBiz().CreateUserAccount(dtoCreateUser2); var newDtoCreateUser3 = new UserBiz().CreateUserAccount(dtoCreateUser3); var log = ActivityLogData.GetLog(); Assert.IsTrue(!string.IsNullOrWhiteSpace(newDtoCreateUser1.DeviceInfo.UserGuid), "dtoCreateUser1.DeviceInfo.UserGuid is empty"); Assert.IsTrue(!string.IsNullOrWhiteSpace(newDtoCreateUser1.Person.UserGuid), "dtoCreateUser1.Person.UserGuid is empty"); Assert.IsTrue(!string.IsNullOrWhiteSpace(newDtoCreateUser2.DeviceInfo.UserGuid), "dtoCreateUser2.DeviceInfo.UserGuid is empty"); Assert.IsTrue(!string.IsNullOrWhiteSpace(newDtoCreateUser2.Person.UserGuid), "dtoCreateUser2.Person.UserGuid is empty"); Assert.IsTrue(!string.IsNullOrWhiteSpace(newDtoCreateUser3.DeviceInfo.UserGuid), "dtoCreateUser3.DeviceInfo.UserGuid is empty"); Assert.IsTrue(!string.IsNullOrWhiteSpace(newDtoCreateUser3.Person.UserGuid), "dtoCreateUser3.Person.UserGuid is empty"); Assert.IsTrue(newDtoCreateUser1.DeviceInfo.UserGuid == newDtoCreateUser1.Person.UserGuid, "Error checking guid in DtoCreateUser1"); Assert.IsTrue(newDtoCreateUser2.DeviceInfo.UserGuid == newDtoCreateUser2.Person.UserGuid, "Error checking guid in DtoCreateUser2"); Assert.IsTrue(newDtoCreateUser3.DeviceInfo.UserGuid == newDtoCreateUser3.Person.UserGuid, "Error checking guid in DtoCreateUser3"); Assert.IsTrue(newDtoCreateUser1.DeviceInfo.UserGuid != newDtoCreateUser2.DeviceInfo.UserGuid, "Error checking guid for 1 & 2"); Assert.IsTrue(newDtoCreateUser1.DeviceInfo.UserGuid != newDtoCreateUser3.DeviceInfo.UserGuid, "Error checking guid for 1 & 3"); Assert.IsTrue(newDtoCreateUser2.DeviceInfo.UserGuid != newDtoCreateUser3.DeviceInfo.UserGuid, "Error checking guid for 2 & 3"); }
public static async Task SaveActivityLogForLoginFailedActionAsync( string userName, string reason) { ActivityLog.ActivityLog activityLog = ActivityLogManager.CreateActivityLog(); activityLog.ForceLog = true; activityLog.UserName = userName; activityLog.EntityName = string.Format("ورود ناموفق-{0}", (object)reason); activityLog.VisibleForEndUser = true; activityLog.EntityID = " "; activityLog.Action = 8; ActivityLog.ActivityLog activityLog1 = activityLog; ActivityLogData activityLogData = new ActivityLogData(); activityLogData.Data = SerializationHelper.SerializeCustom((object)new { UserName = userName, UserToken = activityLog.EntityID, RecordDateTime = DateTime.Now, Action = ActionType.LoginFailed.ToString() }); activityLogData.ObjectState = ObjectState.Added; activityLog1.LogData = activityLogData; await ActivityLogManager.SaveAsync(activityLog); }
public static async Task SaveActivityLogForChangePassActionAsync( int userId, string userName) { ActivityLog.ActivityLog activityLog = ActivityLogManager.CreateActivityLog(); activityLog.ForceLog = true; activityLog.EntityName = "تغییر رمز عبور"; activityLog.UserName = userName; activityLog.VisibleForEndUser = true; activityLog.EntityID = userId.ToString(); activityLog.Action = 9; ActivityLog.ActivityLog activityLog1 = activityLog; ActivityLogData activityLogData = new ActivityLogData(); activityLogData.Data = SerializationHelper.SerializeCustom((object)new { UserName = userName, UserToken = activityLog.EntityID, RecordDateTime = DateTime.Now, Action = ActionType.ChangePassword.ToString() }); activityLogData.ObjectState = ObjectState.Added; activityLog1.LogData = activityLogData; await ActivityLogManager.SaveAsync(activityLog); }
public DeviceInfo GetUserGuid(DeviceInfo deviceInfo) { var newDeviceInfo = deviceInfo; if (!string.IsNullOrWhiteSpace(newDeviceInfo.UserGuid)) { ActivityLogData.Log(newDeviceInfo.UserGuid, "UserBiz.GetUserGuid()", $"UserGuid({newDeviceInfo.UserGuid}) found in received DeviceInfo - Returning if its unique"); if (IsUniqueUserGuid(newDeviceInfo.UserGuid)) { return(newDeviceInfo); } else { LogActivityCreateGuid(newDeviceInfo, $"UserGuid({newDeviceInfo.UserGuid}) not valid - Generating new"); } } var guid = GenerateGuid(); newDeviceInfo.CreatedTime = DateTime.Now; while (!IsUniqueUserGuid(guid)) { guid = GenerateGuid(); } newDeviceInfo.UserGuid = guid; new UserData().StoreDeviceInfo(newDeviceInfo); LogActivityCreateGuid(newDeviceInfo, $"Generated GUID: {newDeviceInfo.UserGuid}"); return(newDeviceInfo); }
public static void SaveActivityLogForLogOffAction(UserContext userContext) { ActivityLog.ActivityLog activityLog1 = ActivityLogManager.CreateActivityLog(); activityLog1.ForceLog = true; activityLog1.EntityName = "خروج"; activityLog1.EntityID = userContext.Token; activityLog1.Action = 7; activityLog1.UserID = userContext.UserId; activityLog1.UserName = userContext.UserName; activityLog1.ClientIP = userContext.ClientIP; activityLog1.VisibleForEndUser = true; ActivityLog.ActivityLog activityLog2 = activityLog1; ActivityLogData activityLogData = new ActivityLogData(); activityLogData.Data = SerializationHelper.SerializeCustom((object)new { UserName = userContext.UserName, UserToken = userContext.Token, RecordDateTime = DateTime.Now, Action = ActionType.Logout.ToString() }); activityLogData.ObjectState = ObjectState.Added; activityLog2.LogData = activityLogData; ActivityLogManager.Save(activityLog1); }
public void GetUserGuid_Return3NewGuids() { var deviceInfo1 = new DeviceInfo() { UserName = "******", UserPassword = "******", DeviceName = "PersMobil" }; var deviceInfo2 = new DeviceInfo() { UserName = "******", UserPassword = "******", DeviceName = "KarisMobil" }; var deviceInfo3 = new DeviceInfo() { UserName = "******", UserPassword = "******", DeviceName = "OlasMobil" }; var actualGuid1 = new UserBiz().GetUserGuid(deviceInfo1); var actualGuid2 = new UserBiz().GetUserGuid(deviceInfo2); var actualGuid3 = new UserBiz().GetUserGuid(deviceInfo3); var log = ActivityLogData.GetLog(); Assert.IsTrue(!string.IsNullOrWhiteSpace(actualGuid1.UserGuid), "ActualGuid1 is empty"); Assert.IsTrue(!string.IsNullOrWhiteSpace(actualGuid2.UserGuid), "ActualGuid2 is empty"); Assert.IsTrue(!string.IsNullOrWhiteSpace(actualGuid3.UserGuid), "ActualGuid3 is empty"); Assert.IsTrue(actualGuid1 != actualGuid2, "actualGuid1 and actualGuid2 are equal"); Assert.IsTrue(actualGuid1 != actualGuid3, "actualGuid1 and actualGuid3 are equal"); Assert.IsTrue(actualGuid2 != actualGuid3, "actualGuid2 and actualGuid3 are equal"); //Assert.IsTrue(log.Count() == 3, $"Missing records in ActivityLog. Expected 3, found {log.Count()}"); }
public Logging(string method, string description = "", string userId = Constants.SYSTEM_USER) { if (string.IsNullOrWhiteSpace(description)) { description = "Call received"; } ActivityLogData.Log(userId, method, description); }
public ActionResult <DeviceInfo> GetNewUserGuid([FromBody] DeviceInfo deviceInfo) { ActivityLogData.Log(Constants.SYSTEM_USER, "ApiController.GetNewUserGuid()", $"Call received"); var userBiz = new UserBiz(); var newDeviceInfo = userBiz.GetUserGuid(deviceInfo); return(Ok(newDeviceInfo)); }
public ActionResult DeleteActivityHistory(long Id) { ActivityLogData activityLog = rsContext.getActivityLog(Id); TempData["infoMessage"] = Resources.Resources.TheActivityHistoryHaveBeenDeletedSuccessfullyForActivity + activityLog.ActivityName + " " + activityLog.date; rsContext.DeleteActivityHistory(Id); return(RedirectToAction("HistoryByActivity")); }
public void StoreDeviceInfo(DeviceInfo deviceInfo) { ActivityLogData.Log(deviceInfo.UserGuid, "UserData.StoreDeviceInfo()", $"Store DeviceInfo"); if (StaticDb.DeviceInfos == null) { StaticDb.DeviceInfos = new List <DeviceInfo>(); } StaticDb.DeviceInfos.Add(deviceInfo); }
public void StorePerson(Person person) { ActivityLogData.Log(person.UserGuid, "UserData.StorePerson()", $"Store Person"); if (StaticDb.Persons == null) { StaticDb.Persons = new List <Person>(); } StaticDb.Persons.Add(person); }
public override Stream ChainStream(Stream stream) { if (LogData == null) { LogData = new ActivityLogData(); } var logData = LogData; logData.transportStream = stream; logData.accessStream = new MemoryStream(); return(logData.accessStream); }
public static ActivityLog getActivityLogFromData(ActivityLogData activityLogData) { ActivityLog al = new ActivityLog(); al.ActivityName = activityLogData.ActivityName; al.date = activityLogData.date; al.expID = activityLogData.expID; al.id = activityLogData.id; al.isMainActivity = activityLogData.isMainActivity; al.RoomId = activityLogData.RoomId; return(al); }
private void LogRequest(ActivityLogData logData) { try { //Create the directory if it doesn't exist var directoryName = Path.GetDirectoryName(fileName); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } using (var fs = new FileStream(fileName, FileMode.Append, FileAccess.Write)) { var sw = new StreamWriter(fs); sw.WriteLine("--------------------------------------------------------------"); sw.WriteLine("- " + logData.methodName + " executed in " + (logData.endTime - logData.startTime).TotalMilliseconds.ToString("#,###,##0") + " ms"); sw.WriteLine("--------------------------------------------------------------"); sw.WriteLine("* Input received at " + logData.startTime.ToString("HH:mm:ss.fff")); sw.WriteLine(); sw.WriteLine("\t" + logData.inputSoap.Replace("\r\n", "\r\n\t")); sw.WriteLine(); if (!logData.endedInError) { sw.WriteLine("* Output sent at " + logData.endTime.ToString("HH:mm:ss.fff")); } else { sw.WriteLine("* Output ended in Error at " + logData.endTime.ToString("HH:mm:ss.fff")); } sw.WriteLine(); sw.WriteLine("\t" + logData.outputSoap.Replace("\r\n", "\r\n\t")); sw.WriteLine(); sw.Flush(); sw.Close(); } } finally { LogData = null; } }
private void LogActivityCreateGuid(DeviceInfo newDeviceInfo, string appendMsg) { string msg = ""; if (!string.IsNullOrWhiteSpace(newDeviceInfo.DeviceName)) { msg = $"{msg} - DeviceName: {newDeviceInfo.DeviceName}"; } if (!string.IsNullOrWhiteSpace(newDeviceInfo.Model)) { msg = $"{msg} - Model: {newDeviceInfo.Model}"; } if (!string.IsNullOrWhiteSpace(newDeviceInfo.UserName)) { msg = $"{msg} - UserName: {newDeviceInfo.UserName}"; } msg = $"{msg} - {appendMsg}"; ActivityLogData.Log(newDeviceInfo.UserGuid, "UserBiz.LogActivityCreateGuid()", msg); }
// GET: Activities/DisplayLog public ActionResult DisplayLog(long Id) { ActivityLogData activityLogData = rsContext.getActivityLog(Id); if (activityLogData is SALogData) { return(RedirectToAction("DisplaySALog", new { ActivityId = activityLogData.id })); } else if (activityLogData is TFQLogData) { return(RedirectToAction("DisplayTFQLog", new { ActivityId = activityLogData.id })); } else if (activityLogData is AmericanLogData) { return(RedirectToAction("DisplayAmericanLog", new { ActivityId = activityLogData.id })); } else if (activityLogData is ExperimentLogData) { return(RedirectToAction("DisplayExperimentLog", new { ActivityId = activityLogData.id })); } return(View()); }
public static void SaveActivityLogForLoginAction(string userName) { ActivityLog.ActivityLog activityLog1 = ActivityLogManager.CreateActivityLog(); activityLog1.ForceLog = true; activityLog1.UserName = userName; activityLog1.EntityName = "ورود"; activityLog1.VisibleForEndUser = true; activityLog1.EntityID = SecurityManager.CurrentUserToken; activityLog1.Action = 6; ActivityLog.ActivityLog activityLog2 = activityLog1; ActivityLogData activityLogData = new ActivityLogData(); activityLogData.Data = SerializationHelper.SerializeCustom((object)new { UserName = userName, UserToken = activityLog1.EntityID, RecordDateTime = DateTime.Now, Action = ActionType.Login.ToString() }); activityLogData.ObjectState = ObjectState.Added; activityLog2.LogData = activityLogData; ActivityLogManager.Save(activityLog1); }
public DtoCreateUser CreateUserAccount(DtoCreateUser dtoCreateUser) { var validate = ValidateCreateUserAccount(dtoCreateUser); if (!validate.Status) { ActivityLogData.Log(Constants.SYSTEM_USER, "UserBiz.CreateUserAccount()", $"Validation failed - {validate.Message}"); throw new Exception(validate.Message); } var newDtoCreateUser = dtoCreateUser; var newDeviceInfo = GetUserGuid(newDtoCreateUser.DeviceInfo); newDtoCreateUser.DeviceInfo = newDeviceInfo; var person = newDtoCreateUser.Person; person.UserGuid = newDeviceInfo.UserGuid; CreatePerson(person); ActivityLogData.Log(newDtoCreateUser.DeviceInfo.UserGuid, "UserBiz.CreateUserAccount()", $"UserGuid({newDtoCreateUser.DeviceInfo.UserGuid}) Created"); return(newDtoCreateUser); }
public int GetLogCount() { return(ActivityLogData.GetLogCount()); }
public override void ProcessMessage(SoapMessage message) { if (LogData == null) { LogData = new ActivityLogData(); } var logData = LogData; if (message is SoapServerMessage) { switch (message.Stage) { case SoapMessageStage.BeforeDeserialize: //Take the data from the transport stream coming in from the client //and copy it into inputSoap log. Then reset the transport to the beginning //copy it to the access stream that the server will use to read the incoming message. logData.startTime = DateTime.Now; logData.inputSoap = GetSoapMessage(logData.transportStream); Copy(logData.transportStream, logData.accessStream); logData.accessStream.Position = 0; break; case SoapMessageStage.AfterDeserialize: //Capture the method name after deserialization and it is now known. (was buried in the incoming soap) logData.methodName = GetMethodName(message); break; case SoapMessageStage.BeforeSerialize: //Do nothing here because we are not modifying the soap break; case SoapMessageStage.AfterSerialize: //Take the serialized soap data captured by the access stream and //write it into the log file. But if an error has occurred write the exception details. logData.endTime = DateTime.Now; logData.accessStream.Position = 0; if (message.Exception != null) { logData.endedInError = true; if (message.Exception.InnerException != null && message.Exception is System.Web.Services.Protocols.SoapException) { logData.outputSoap = GetFullExceptionMessage(message.Exception.InnerException); } else { logData.outputSoap = GetFullExceptionMessage(message.Exception); } } else { logData.outputSoap = GetSoapMessage(logData.accessStream); } //Transfer the soap data as it was created by the service //to the transport stream so it is received the client unmodified. Copy(logData.accessStream, logData.transportStream); LogRequest(logData); break; } } else if (message is SoapClientMessage) { throw new NotSupportedException("This extension must be ran on the server side"); } }
public IEnumerable <ActivityLog> GetActivityLog() { return(ActivityLogData.GetLog()); }