/// <summary> /// Starts recording. /// </summary> public void Start() { if (_isRecording) { Log.Debug("Already recording"); return; } //Prevent recording before completing calibration if (!Settings.CalibrationDone) { throw new InvalidOperationException("Cannot start recording before completing accelerometer calibration"); } _sessionInfo = new SessionInfo(Settings.LastVehicleType, Settings.LastAnchorageType, Settings.LastNumberOfPeople); _isRecording = true; if (Settings.OfflineMode) { UserLog.Add(LogStrings.RecordingOffline); Log.Debug("Started offline recording"); } else { UserLog.Add(LogStrings.RecordingStarted); Log.Debug("Started recording"); } }
/// <summary> /// Executes flush operation on a collection of data pieces asynchronously. /// </summary> private async Task FlushCoreAsync(ICollection <DataPiece> data) { var filename = FileNaming.GenerateDataQueueFilename(); string filepath = Path.Combine(FileNaming.DataQueuePath, filename); Log.Debug("Flushing collector with {0} data pieces to {1}", data.Count, filename); try { using (var fileStream = await FileOperations.CreateNewFile(filepath)) { using (var textWrite = new StreamWriter(fileStream, Encoding.UTF8)) { var serializer = JsonSerializer.Create(); await Task.Run(() => { serializer.Serialize(textWrite, data, typeof(ICollection <DataPiece>)); //Early flush on background thread textWrite.Flush(); fileStream.Flush(); }); } } } catch (Exception ex) { Log.Error(ex, "Failed flushing data collector to file {0}", filepath); UserLog.Add(UserLog.Icon.Error, LogStrings.FileWriteError); } UserLog.Add(UserLog.Icon.None, LogStrings.FileWriteSuccess); OnFileGenerated(filepath); }
private void HandleInternalEngineError(object sender, InternalEngineErrorEventArgs e) { Log.Error(null, "Internal engine error"); UserLog.Add(UserLog.Icon.Error, LogStrings.InternalEngineError); InternalEngineErrorReported.Raise(this); StopRecordingCommand.Execute(null); }
/// <summary> /// 用户日志写入 /// </summary> protected void Log(UserLog log) { if (log.SiteID == 0 || log.UserID == 0 || string.IsNullOrEmpty(log.Content)) { return; } log.CreateAt = DateTime.Now; log.IP = IPAgent.IP; using (DbExecutor db = NewExecutor()) { log.Add(db); } }
/// <summary> /// Complete session and flush out data to database. /// </summary> public void CompleteSession() { if (_dumpWriter != null) { _dumpWriter.Flush(); } if (_ppeCount == 0) { Log.Debug("Completing session of 0 data pieces, ignoring"); return; } Log.Debug("Completing statistic collection session"); try { // TODO: perform in background // TODO: accumulate on DB record if record already stored (updates instead of insert) using (var db = DatabaseUtility.OpenConnection()) { var record = new StatisticRecord { TrackId = _previous.TrackId, Start = _tsStart, End = _tsEnd, MaxPpe = _ppeMax, AvgPpe = (_ppeAccumulator / _ppeCount), Bins = _ppeBins, DistanceTraveled = _distance, DataPieceCount = _ppeCount, ElapsedTime = _elapsed }; db.Insert(record); } } catch (Exception ex) { Log.Error(ex, "Failed to store statistics"); } Log.Event("Recording.newStats", new Dictionary <string, string>() { { "distance", _distance.ToString(CultureInfo.InvariantCulture) }, { "dataPieces", _ppeCount.ToString(CultureInfo.InvariantCulture) }, { "elapsedMinutes", _elapsed.TotalMinutes.ToString(CultureInfo.InvariantCulture) } }); UserLog.Add(LogStrings.StatsRecorded, _distance, _ppeCount); Reset(); }
/// <summary> /// Stops recording. /// </summary> public void Stop() { if (!_isRecording) { Log.Debug("Already stopped"); return; } _isRecording = false; _lastMeasurementCollection = null; _statsCollector.CompleteSession(); UserLog.Add(LogStrings.RecordingStopped); Log.Debug("Stopped recording"); }
private void HandleLocationSensorStatusChanged(object sender, LocationSensorStatusChangedEventArgs e) { if (e.PreviousStatus == LocationSensorStatus.Fixing && e.CurrentStatus == LocationSensorStatus.Working) { UserLog.Add(UserLog.Icon.None, LogStrings.GpsFix); } else if (e.PreviousStatus == LocationSensorStatus.Working && e.CurrentStatus == LocationSensorStatus.Fixing) { UserLog.Add(UserLog.Icon.None, LogStrings.GpsFixLost); } else if (e.CurrentStatus == LocationSensorStatus.Disabled) { UserLog.Add(UserLog.Icon.None, LogStrings.GpsDisabled); } OnPropertyChanged(() => LocationSensorStatus); SensorStatusUpdated.Raise(this); }
private void HandleLocationSensorError(object sender, LocationErrorEventArgs e) { switch (e.Error) { case LocationErrorType.RemainedStationary: Log.Debug("GPS stationary for too long: stopping recording"); UserLog.Add(UserLog.Icon.Warning, LogStrings.RecordingSuspendedStationary); break; case LocationErrorType.SpeedTooLow: Log.Debug("User moving too slowly: stopping recording"); UserLog.Add(UserLog.Icon.Warning, LogStrings.RecordingSuspendedSpeed); break; } RecordingSuspended.Raise(this, e); StopRecordingCommand.Execute(null); }
private static async Task FullInstallation() { // Remove previous (unversioned) versions of the database, if any if (await FileOperations.CheckFile(FileNaming.DatabasePath)) { UserLog.Add(LogStrings.DatabaseMigrationReset); Log.Debug("Deleting old database: bye bye existing data"); Log.Event("Database.reset"); var token = await FileOperations.GetToken(FileNaming.DatabasePath); await token.Delete(); } // Database creation using (var db = OpenConnection()) { db.CreateTable <TrackUploadRecord>(); db.CreateTable <StatisticRecord>(); } Log.Event("Database.create"); }
/// <summary> /// Complete session and flush out data to database. /// </summary> public void CompleteSession() { if (_ppeCount == 0) { Log.Debug("Completing session of 0 data pieces, ignoring"); return; } Log.Debug("Completing statistic collection session"); Flush(); Log.Event("Recording.newStats", new Dictionary <string, string>() { { "distance", _record.DistanceTraveled.ToString(CultureInfo.InvariantCulture) }, { "dataPieces", _ppeCount.ToString(CultureInfo.InvariantCulture) }, { "elapsedMinutes", _record.ElapsedTime.TotalMinutes.ToString(CultureInfo.InvariantCulture) } }); UserLog.Add(LogStrings.StatsRecorded, _record.DistanceTraveled, _ppeCount); Reset(); }
void IUserEventObserver.Whisper(ChatItem chatItem) { UserLog.Add($"Whisper({chatItem.UserId}, {chatItem.Message})"); }
void IUserEventObserver.Invite(string invitorUserId, string roomName) { UserLog.Add($"Invite({invitorUserId}, {roomName})"); }
protected void Page_Load(object sender, EventArgs e) { string safekey = Request["safekey"]; getXML(); string StrSql = "select * from " + tabName + " where " + colName + "='" + safekey + "'"; DataTable dt = RunDataTableSQL(StrSql, null); string url1 = Request.ApplicationPath + "/AdminSpace/Index.aspx?d=" + DateTime.Now.ToBinary(); string url2 = Request.ApplicationPath + "/MySpace/MySpace.aspx?d=" + DateTime.Now.ToBinary(); string url3 = Request.ApplicationPath + "/MySpace/MySpace.aspx?d=" + DateTime.Now.ToBinary(); string url4 = ""; string userNo = ""; string identity = ""; string LoginName = ""; string Password = ""; if (dt != null && dt.Rows.Count > 0) { string errcode = dt.Rows[0]["errcode"].ToString(); switch (errcode) { case "1": Response.Write("为用户名密码错误"); break; case "2": Response.Write("请将卡号密码输入完整"); break; case "3": Response.Write("卡号密码必须为数字"); break; case "4": Response.Write("卡号长度应为12位,密码的长度应为6位"); break; case "5": Response.Write("卡号不存在"); break; case "10": Response.Write("身份证号不正确"); break; } string yktkh = dt.Rows[0]["yktkhusername"].ToString(); if (yktkh.Length > 5) { identity = yktkh.Substring(0, 1); if (identity == "0") { identity = "3"; userNo = yktkh.Substring(tea_start, tea_length); } else { identity = "2"; userNo = yktkh.Substring(stu_start, stu_length); } } DataTable dt2 = dtLoginNamAndPassword(userNo, identity); if (dt2 != null && dt2.Rows.Count > 0) { LoginName = dt2.Rows[0][0].ToString(); Password = dt2.Rows[0][1].ToString(); } UserBL userBl = new UserBL(); UserInfo userInfo = userBl.CheckUser(LoginName, Password); if (userInfo != null && userInfo.IsRestrict == false) { Session.Add(Utilities.UserProfile, userInfo); // 身份(0超级管理员,1普通管理员,2学生,3教师,4系统外用户) Hashtable hsOnline = Application["OnlineUsers"] as Hashtable; if (hsOnline == null) { hsOnline = new Hashtable(); Application["OnlineUsers"] = hsOnline; } if (hsOnline[userInfo.UserID] == null) { hsOnline.Add(userInfo.UserID, DateTime.Now); Application["OnlineUsers"] = hsOnline; } string url = ""; if (userInfo.Identity <= 1) { url = url1; } if (userInfo.Identity == 2) { url = url2; /*Begin:201010290953guokaiju * Type:add * By:管理员给学生发消息无反应... */ Able.ACC.BusinessRules.MySpace.Message.G2SGetAdminMessage(userInfo.UserID); //End:201010290953guokaiju } if (userInfo.Identity == 3) { url = url3; /*Begin:201010290953guokaiju * Type:add * By:管理员给教师发消息无反应... */ Able.ACC.BusinessRules.MySpace.Message.G2SGetAdminMessage(userInfo.UserID); //End:201010290953guokaiju } if (userInfo.Identity == 4) { url4 = Request.ApplicationPath + "/Template/View.aspx?action=view&courseType=0&courseId=" + userInfo.fCCPWebSiteID; } Session["WebURL"] = url; string strLastTime = userInfo.LastLoginTime.Replace('-', '/'); #region 添加日志 string logContent = string.Format("【fUserID】{0}【fLoginName】{1}【fUserName】{2}【fIdentity】{3}", userInfo.UserID, userInfo.LoginName, userInfo.UserName, userInfo.Identity); LogAction logAction = LogAction.登录; UserLog.Add(logAction, LogOperateObjName.其他, userInfo.UserID, logContent, false); #endregion string UserName = userInfo.UserName; string UserURL = url; StringBuilder sb = new StringBuilder(); sb.Append("<User>"); sb.Append("<Name>"); sb.Append(UserName); sb.Append("</Name><Url>"); sb.Append(UserURL); sb.Append("</Url></User>"); Session["USER_STATE"] = sb.ToString(); } else { Session["USER_STATE"] = "<User/>"; if (userInfo != null && userInfo.IsRestrict == true) { Response.Write("用户被锁 请联系管理员"); Response.StatusCode = 403; } else { Response.Write("用户名或密码错误"); Response.StatusCode = 403; } } } Response.Redirect("CA1.aspx"); }
protected void Page_Load(object sender, EventArgs e) { UserInfo userInfo = new UserInfo(); UserBL userBl = new UserBL(); if (Able.Acc.Plugin.Module.IsHNDX) { HNDXLoginTicket ticket = this.Session[HNDXLoginTicket.SessionKey] as HNDXLoginTicket; bool flag = HNDXLoginTicket.Authenticate(ticket.LoginId, ticket.Ticket); if (flag) { userInfo = Able.Acc.Plugin.UserDA.LoginByLoginName(ticket.LoginId); } } else { String userId = (String)Session["identityCard"]; if (userId == null) { //DotNetCASClientServiceValidate client = new DotNetCASClientServiceValidate(); //userId = client.Authenticate(Request, Response, false); if (userId != "failed") { Session["identityCard"] = userId; } // failed } userInfo = userBl.AuthenticateByUserIdentityCard(userId); } string url1 = Request.ApplicationPath + "/AdminSpace/Index.aspx?d=" + DateTime.Now.ToBinary(); string url2 = Request.ApplicationPath + "/MySpace/MySpace.aspx?d=" + DateTime.Now.ToBinary(); string url3 = Request.ApplicationPath + "/MySpace/MySpace.aspx?d=" + DateTime.Now.ToBinary(); string url4 = ""; if (userInfo != null && userInfo.IsRestrict == false) { Session.Add(Utilities.UserProfile, userInfo); // 身份(0超级管理员,1普通管理员,2学生,3教师,4系统外用户) Hashtable hsOnline = Application["OnlineUsers"] as Hashtable; if (hsOnline == null) { hsOnline = new Hashtable(); Application["OnlineUsers"] = hsOnline; } if (hsOnline[userInfo.UserID] == null) { hsOnline.Add(userInfo.UserID, DateTime.Now); Application["OnlineUsers"] = hsOnline; } string url = ""; if (userInfo.Identity <= 1) { url = url1; } if (userInfo.Identity == 2) { url = url2; /*Begin:201010290953guokaiju * Type:add * By:管理员给学生发消息无反应... */ Able.ACC.BusinessRules.MySpace.Message.G2SGetAdminMessage(userInfo.UserID); //End:201010290953guokaiju } if (userInfo.Identity == 3) { url = url3; /*Begin:201010290953guokaiju * Type:add * By:管理员给教师发消息无反应... */ Able.ACC.BusinessRules.MySpace.Message.G2SGetAdminMessage(userInfo.UserID); //End:201010290953guokaiju } if (userInfo.Identity == 4) { url4 = Request.ApplicationPath + "/Template/View.aspx?action=view&courseType=0&courseId=" + userInfo.fCCPWebSiteID; } Session["WebURL"] = url; string strLastTime = userInfo.LastLoginTime.Replace('-', '/'); #region 添加日志 string logContent = string.Format("【fUserID】{0}【fLoginName】{1}【fUserName】{2}【fIdentity】{3}", userInfo.UserID, userInfo.LoginName, userInfo.UserName, userInfo.Identity); LogAction logAction = LogAction.登录; UserLog.Add(logAction, LogOperateObjName.其他, userInfo.UserID, logContent, false); #endregion string UserName = userInfo.UserName; string UserURL = url; StringBuilder sb = new StringBuilder(); sb.Append("<User>"); sb.Append("<Name>"); sb.Append(UserName); sb.Append("</Name><Url>"); sb.Append(UserURL); sb.Append("</Url></User>"); Session["USER_STATE"] = sb.ToString(); } else { Session["USER_STATE"] = "<User/>"; if (userInfo != null && userInfo.IsRestrict == true) { Response.Write("用户被锁 请联系管理员"); Response.StatusCode = 403; } else { Response.Write("用户名或密码错误"); Response.StatusCode = 403; } } Response.Redirect("CA1.aspx"); }