public void AddLastAccess(string name, DateTime ipv4, DateTime azurev4) { name = name.ToLowerInvariant().Trim(); lock (LockObj) { LastAccess a; if (lastaccesses.ContainsKey(name)) { a = lastaccesses[name]; } else { a = new LastAccess(); a.Name = name; lastaccesses.Add(name, a); } if (a.LastAccess_IPv4 < ipv4) { a.LastAccess_IPv4 = ipv4; } if (a.LastAccess_Azure < azurev4) { a.LastAccess_Azure = azurev4; } } }
public int DoUpdateLastAccess(DateTime currDate) { int result = 0; int accessId = 1; LastAccess lastAccess = new LastAccess(accessId, currDate); try { using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ToString(); connection.Open(); NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Connection = connection; cmd.CommandText = "Update LastAccess Set accessDate=@accessDate where accessid=@accessid"; cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new NpgsqlParameter("@accessid", lastAccess.AccessId)); cmd.Parameters.Add(new NpgsqlParameter("@accessDate", lastAccess.AccessDate)); result = cmd.ExecuteNonQuery(); cmd.Dispose(); connection.Close(); } } catch (Exception ex) { Console.WriteLine(ex); } return(result); }
public LastAccess DoRetrieveLastAccess() { try { using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ToString(); connection.Open(); NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Connection = connection; cmd.CommandText = "Select * from LastAccess WHERE accessid=1"; cmd.CommandType = CommandType.Text; NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); cmd.Dispose(); connection.Close(); int accessId = int.Parse(dt.Rows[0]["accessid"].ToString()); DateTime accessDate = DateTime.Parse(dt.Rows[0]["accessDate"].ToString()); LastAccess lastAccess = new LastAccess(accessId, accessDate); return(lastAccess); } } catch (Exception ex) { Console.WriteLine(ex); } return(null); }
public int DoCreateLastAccessRecord(DateTime currDate) { int result = 0; LastAccess lastAccess = new LastAccess(currDate); try { using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ToString(); connection.Open(); NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Connection = connection; cmd.CommandText = "Insert into LastAccess(accessDate) values(@accessDate)"; cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new NpgsqlParameter("@accessDate", lastAccess.AccessDate)); result = cmd.ExecuteNonQuery(); cmd.Dispose(); connection.Close(); } } catch (Exception ex) { Console.WriteLine(ex); } return(result); }
protected void btnResetLimit_Click(object sender, EventArgs e) { DateTime currDate = DateTime.Now; LastAccessBLL lastAccessBLL = new LastAccessBLL(); LastAccess lastAccess = lastAccessBLL.DoRetrieveLastAccess(); if (currDate.ToString("yyyy-MM-dd").Equals(lastAccess.AccessDate.ToString("yyyy-MM-dd"))) { lblResetFailed.Text = "Reset is unsuccessful. Last reset date is the same as current date"; } else { int result = lastAccessBLL.DoUpdateLastAccess(currDate); if (result > 0) { lastAccessBLL.DoUpdateOrderCounter(); } else { lblResetFailed.Text = "Reset is unsuccessful"; } lblResetSuccess.Text = "Reset is successful"; txtLastUpdate.Text = currDate.ToString("dd-MM-yyyy"); } panelResetLimit.Visible = true; }
// sets the Customer up to a array used to show data in the listview as a listviewitem public string[] GetListViewItemRange() { string[] arr = new string[11] { CustomerNumber.ToString(), FirstName, LastName, EmailAddress.Print(), AccountBalance.ToString(), CustAdresse.PostCode.ToString(), CustAdresse.City, CustAdresse.Street, CustAdresse.StreetNr.ToString(), LastAccess.ToShortDateString(), "" }; return(arr); }
public string ConvertToString() { return (Attributes.ToString() + "|" + CreationTime.ToString() + "|" + DirectoryName.ToString() + "|" + FileName.ToString() + "|" + LastAccess.ToString() + "|" + LastWrite.ToString() + "|" + Security.ToString() + "|" + Size.ToString()); }
internal void SaveTo(System.IO.BinaryWriter writer) { writer.Write(LastAccess.ToBinary()); writer.Write(BodyLength); writer.Write(ETag); writer.Write(LastModified); writer.Write(Expires.ToBinary()); writer.Write(Age); writer.Write(MaxAge); writer.Write(Date.ToBinary()); writer.Write(MustRevalidate); writer.Write(Received.ToBinary()); }
internal void SaveTo(BinaryWriter stream) { stream.Write(Version); stream.Write(Name ?? string.Empty); stream.Write(Value ?? string.Empty); stream.Write(Date.ToBinary()); stream.Write(LastAccess.ToBinary()); stream.Write(Expires.ToBinary()); stream.Write(MaxAge); stream.Write(IsSession); stream.Write(Domain ?? string.Empty); stream.Write(Path ?? string.Empty); stream.Write(IsSecure); stream.Write(IsHttpOnly); }
protected void Page_Load(object sender, EventArgs e) { if (Session["isLogin"] == null) { Response.Redirect("Login.aspx"); } panelResetLimit.Visible = false; adminViewStats.Visible = false; staffViewStats.Visible = false; gv_FoodItemStats.Visible = false; gv_CustMostOrder.Visible = false; UserAccount user = (UserAccount)Session["UserAccountObj"]; lblUserName.Text = user.Username.ToUpper(); lblUserRole.Text = user.UserRole.ToUpper(); if (user.UserRole.Equals("Manager")) { panelResetLimit.Visible = true; LastAccessBLL lastAccessBLL = new LastAccessBLL(); int result = lastAccessBLL.DoCheckLastAccessExists(); if (result <= 0) { int createResult = lastAccessBLL.DoCreateLastAccessRecord(DateTime.Now); txtLastUpdate.Text = "-"; btnResetLimit.Enabled = false; } else { LastAccess lastAccess = lastAccessBLL.DoRetrieveLastAccess(); txtLastUpdate.Text = lastAccess.AccessDate.ToString("dd-MM-yyyy"); } } }
public override string ToString() { return(CustomerNumber + ", " + FirstName + ", " + LastName + ", " + EmailAddress.Print() + ", " + CustAdresse.ToString() + ", " + LastAccess.ToShortDateString() + ", " + AccountBalance); }
public string PrintCustomerCrypt() { return(Crypto.EncodeLine(new string[] { CustomerNumber.ToString(), FirstName, LastName, EmailAddress.Print(), CustAdresse.ToCSVString(), LastAccess.ToShortDateString(), AccountBalance.ToString() })); }
public string PrintCustomerForView() { return(CustomerNumber + "," + FirstName + "," + LastName + "," + EmailAddress.Print() + "," + AccountBalance + "," + LastAccess.ToShortDateString() + "," + CustAdresse.ToCSVString()); }
public int CompareTo(HTTPCacheFileInfo other) { return(LastAccess.CompareTo(other.LastAccess)); }
async Task main_thread(CancellationToken cancel) { await Task.Yield(); DateTime next_full_update = new DateTime(0); DateTime next_diff_update = new DateTime(0); DateTime last_update = new DateTime(0); bool full_ok = false; write_log(string.Format("DBTHREAD: main thread loop inited.")); while (cancel.IsCancellationRequested == false) { DateTime now = DateTime.Now; if (now >= next_full_update) { write_log(string.Format("DBTHREAD: full update started.")); next_full_update = now + Util.GenRandInterval(interval_full_update); try { await using var db = await OpenDbAsync(cancel); db.CommandTimeoutSecs = SqlTimeoutSecs; var table = await db.EasySelectAsync <Hosts2Table>(@" SELECT HOST_ID, HOST_NAME, HOST_LAST_IPV4, HOST_LAST_IPV6, HOST_UPDATE_DATE, HOST_AZURE_IP FROM HOSTS where HOST_LOGIN_DATE >= @BEGIN_DATE or HOST_NUM_ACCESS != 0 ", new { BEGIN_DATE = DateTime.Now.AddMonths(-1), }, cancel : cancel); //HOSTS2TableAdapter ta = new HOSTS2TableAdapter(); //SetSqlTimeout(ta, SqlTimeout); //DDNS.HOSTS2DataTable table = ta.GetData2(DateTime.Now.AddMonths(-1)); Dictionary <string, Host> hosts_tmp = new Dictionary <string, Host>(); write_log(string.Format("DBTHREAD: full db query: {0} records.", table.Count())); DateTime max_update_dt = new DateTime(0); foreach (var r in table) { Host h = new Host(); h.Name = r.HOST_NAME.ToLowerInvariant(); h.IPv4 = r.HOST_LAST_IPV4; h.IPv6 = r.HOST_LAST_IPV6; h.AzureIPv4 = r.HOST_AZURE_IP; if (max_update_dt < r.HOST_UPDATE_DATE) { max_update_dt = r.HOST_UPDATE_DATE; } if (hosts_tmp.ContainsKey(h.Name) == false) { hosts_tmp.Add(h.Name, h); } } lock (LockObj) { this.hosts = hosts_tmp; } last_update = now; if (max_update_dt.Ticks != 0 && max_update_dt < last_update) { last_update = max_update_dt; } full_ok = true; this.LastDbReadTime.Set(DateTime.Now); this.IsEmpty = false; } catch (Exception ex) { Console.WriteLine(ex.ToString()); write_log(string.Format("DBTHREAD: DBERROR (Full Update): {0}", ex.Message)); next_full_update = now + Util.GenRandInterval(interval_full_update_on_error); } //write_log(string.Format("DBTHREAD: next_full_update = {0}", next_full_update)); } if (now >= next_diff_update && full_ok) { next_diff_update = now + Util.GenRandInterval(interval_diff_update); try { //write_log(string.Format("DBTHREAD: diff update started, diffs since {0}.", last_update - interval_clock_margin)); await using var db = await OpenDbAsync(cancel); db.CommandTimeoutSecs = SqlTimeoutSecs; var table = await db.EasySelectAsync <Hosts2Table>(@" SELECT HOST_AZURE_IP, HOST_ID, HOST_LAST_IPV4, HOST_LAST_IPV6, HOST_NAME, HOST_UPDATE_DATE FROM HOSTS WITH (NOLOCK) WHERE (HOST_UPDATE_DATE >= @DT)", new { DT = last_update - interval_clock_margin, }, cancel : cancel); // HOSTS2TableAdapter ta = new HOSTS2TableAdapter(); //SetSqlTimeout(ta, SqlTimeout); //DDNS.HOSTS2DataTable table = ta.GetDataByUpdateDate(last_update - interval_clock_margin); var ban_table = await db.EasySelectAsync <BanTable>(@" SELECT BAN_ID, BAN_KEY, BAN_REDIRECT_TO FROM BAN"); //BANTableAdapter ban_ta = new BANTableAdapter(); //SetSqlTimeout(ban_ta, SqlTimeout); //DDNS.BANDataTable ban_table = ban_ta.GetData(); write_log(string.Format("DBTHREAD: diff db query: {0} records. ban: {1} records.", table.Count(), ban_table.Count())); DateTime max_update_dt = new DateTime(0); lock (LockObj) { foreach (var r in table) { Host h = new Host(); h.Name = r.HOST_NAME.ToLowerInvariant(); h.IPv4 = r.HOST_LAST_IPV4; h.IPv6 = r.HOST_LAST_IPV6; h.AzureIPv4 = r.HOST_AZURE_IP; if (max_update_dt < r.HOST_UPDATE_DATE) { max_update_dt = r.HOST_UPDATE_DATE; } if (this.hosts.ContainsKey(h.Name) == false) { this.hosts.Add(h.Name, h); } else { this.hosts[h.Name] = h; } } this.ban_list.Clear(); foreach (var r in ban_table) { try { if (IPUtil.IsStrIPv4(r.BAN_REDIRECT_TO.Trim())) { string key = r.BAN_KEY; Str.NormalizeString(ref key); key = key.ToLowerInvariant(); if (ban_list.ContainsKey(key) == false) { ban_list.Add(key, new Ban() { Key = r.BAN_KEY.Trim(), RedirectTo = r.BAN_REDIRECT_TO.Trim(), }); } } } catch { } } } last_update = now; if (max_update_dt.Ticks != 0 && max_update_dt < last_update) { last_update = max_update_dt; } this.LastDbReadTime.Set(DateTime.Now); } catch (Exception ex) { write_log(string.Format("DBTHREAD: DBERROR (Diff Update): {0}", ex.Message)); } //write_log(string.Format("DBTHREAD: next_diff_update = {0}", next_diff_update)); // write last access try { await using var db = await OpenDbAsync(cancel); //HOSTSTableAdapter ta = new HOSTSTableAdapter(); //SetSqlTimeout(ta, SqlTimeout); db.CommandTimeoutSecs = SqlTimeoutSecs; Dictionary <string, LastAccess> a2 = null !; lock (LockObj) { a2 = lastaccesses; lastaccesses = new Dictionary <string, LastAccess>(); } int num_v4 = 0, num_azure = 0; foreach (string name in a2.Keys) { LastAccess a = a2[name]; if (a.LastAccess_IPv4.Ticks != 0) { //ta.WriteLastAccess(a.LastAccess_IPv4, a.Name); await db.EasyExecuteAsync(@" UPDATE HOSTS SET HOST_ACCESS_DATE = @NOW, HOST_NUM_ACCESS = HOST_NUM_ACCESS + 1 WHERE HOST_NAME = @NAME", new { NOW = a.LastAccess_IPv4, NAME = a.Name, } ); num_v4++; } if (a.LastAccess_Azure.Ticks != 0) { //ta.WriteAzureLastAccess(a.LastAccess_Azure, a.Name); await db.EasyExecuteAsync(@" UPDATE HOSTS SET HOST_AZURE_ACCESS_DATE = @NOW, HOST_AZURE_NUM_ACCESS = HOST_AZURE_NUM_ACCESS + 1 WHERE HOST_NAME = @NAME", new { NOW = a.LastAccess_Azure, NAME = a.Name, } ); num_azure++; } } if (num_v4 != 0 || num_azure != 0) { write_log(string.Format("DBTHREAD: Last Access Updated, IPv4={0}, Azure={1}", num_v4, num_azure)); } this.LastDbWriteTime.Set(DateTime.Now); } catch (Exception ex) { write_log(string.Format("DBTHREAD: DBERROR (Update LastAccess): {0}", ex.Message)); } } //halt_event.Wait(100); await cancel._WaitUntilCanceledAsync(100); } write_log(string.Format("DBTHREAD: main thread loop stopped.")); }
public void GetInfo(TSPlayer receiver) { receiver.SendInfoMessage("属地 {0} - 领主: {1} | 创建: {2} | 修改: {3}", Id, string.IsNullOrWhiteSpace(Owner) ? "无" : Owner, GetTime.ToString("g"), LastAccess.ToString("g")); }
public TimeSpan TimeSincePreviousAccess() { return(LastAccess.Subtract(_PreviousAccess)); }
public bool Equals(RegisteredContent other) { return(LastAccess.Equals(other.LastAccess) && LastModified.Equals(other.LastModified) && Attributes == other.Attributes && Length == other.Length); }
/// <summary> /// Sort items in descending order by LastAccess, so that the oldest item is sorted into last position. /// </summary> /// <param name="other">Other item to compare this item to.</param> /// <returns>-1 if this CacheItem was last accessed more recently than the other item, i.e. has a larger value for LastAccess. /// 0 if both items are of equal age. /// 1 if this CacheItem was last accessed before the other item.</returns> public int CompareTo(CacheItem other) { return(-LastAccess.CompareTo(other.LastAccess)); }
public int CompareTo(Cookie other) { return(LastAccess.CompareTo(other.LastAccess)); }