/// <summary> /// 信用记录 /// </summary> private void GetCreditsRank() { score = Scoresets.GetValidScoreName(); foreach (string key in creditsrankstats.Keys) { statvars[key] = creditsrankstats[key].ToString(); } if (!statvars.ContainsKey("lastupdate") || (DateTime.Now - DateTime.Parse(statvars["lastupdate"])).TotalMinutes > statscachelife) { statvars.Clear(); statvars["lastupdate"] = Utils.GetDateTime(); Stats.UpdateStatVars("creditsrank", "lastupdate", statvars["lastupdate"]); } ShortUserInfo[] credits; ShortUserInfo[][] extendedcredits; if (statvars.ContainsKey("credits")) { credits = (ShortUserInfo[])SerializationHelper.DeSerialize(typeof(ShortUserInfo[]), statvars["credits"]); } else { credits = Stats.GetUserArray("credits"); Stats.UpdateStatVars("creditsrank", "credits", SerializationHelper.Serialize(credits)); } if (statvars.ContainsKey("extendedcredits")) { extendedcredits = (ShortUserInfo[][])SerializationHelper.DeSerialize(typeof(ShortUserInfo[][]), statvars["extendedcredits"]); } else { extendedcredits = Stats.GetExtsRankUserArray(); Stats.UpdateStatVars("creditsrank", "extendedcredits", SerializationHelper.Serialize(extendedcredits)); } int maxrows = credits.Length; for (int i = 1; i < 8; i++) { maxrows = Math.Max(extendedcredits[i].Length, maxrows); } creditsrank = Stats.GetUserRankHtml(credits, "credits", maxrows); extcreditsrank1 = Stats.GetUserRankHtml(extendedcredits[0], "extcredits1", maxrows); extcreditsrank2 = Stats.GetUserRankHtml(extendedcredits[1], "extcredits2", maxrows); extcreditsrank3 = Stats.GetUserRankHtml(extendedcredits[2], "extcredits3", maxrows); extcreditsrank4 = Stats.GetUserRankHtml(extendedcredits[3], "extcredits4", maxrows); extcreditsrank5 = Stats.GetUserRankHtml(extendedcredits[4], "extcredits5", maxrows); extcreditsrank6 = Stats.GetUserRankHtml(extendedcredits[5], "extcredits6", maxrows); extcreditsrank7 = Stats.GetUserRankHtml(extendedcredits[6], "extcredits7", maxrows); extcreditsrank8 = Stats.GetUserRankHtml(extendedcredits[7], "extcredits8", maxrows); lastupdate = statvars["lastupdate"]; nextupdate = DateTime.Parse(statvars["lastupdate"]).AddMinutes(statscachelife).ToString("yyyy-MM-dd HH:mm:ss"); }
private void mitLoad_Click(object sender, System.EventArgs e) { OpenFileDialog of = new OpenFileDialog(); of.InitialDirectory = Application.ExecutablePath; if (of.ShowDialog() == DialogResult.OK) { SerializationHelper.DeSerialize(gtv, of.FileName); } }
/// <summary> /// 获取反序列化后的配置信息 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="configFile">xml文件</param> /// <returns></returns> public static T XmlDeSerialize <T>(string configFile) where T : class { T template = null; try { template = SerializationHelper.DeSerialize(typeof(T), HttpContext.Current.Server.MapPath(configFile)) as T; } catch { } return(template); }
protected override async Task <T> Parse <T>(string uri, string root) { try { using (Stream stream = await Download(uri)) return(stream == null ? default(T) : SerializationHelper <T> .DeSerialize(stream, root)); } catch (Exception ex) { throw new Exception($"XMLFredClient encountered an error. URI is {uri}, type is {typeof(T).FullName}, root is {root}. See the inner exception for more detail.", ex); } }
/// <summary> /// 在线时间 /// </summary> private void GetOnlinetime() { if (config.Oltimespan == 0) { totalonlinerank = "<li>未开启在线时长统计</li>"; thismonthonlinerank = "<li></li>"; return; } foreach (string key in onlinesstats.Keys) { statvars[key] = onlinesstats[key].ToString(); } if (!statvars.ContainsKey("lastupdate") || (DateTime.Now - DateTime.Parse(statvars["lastupdate"])).TotalMinutes > statscachelife) { statvars.Clear(); statvars["lastupdate"] = Utils.GetDateTime(); Stats.UpdateStatVars("onlines", "lastupdate", statvars["lastupdate"]); } ShortUserInfo[] total; if (statvars.ContainsKey("total")) { total = (ShortUserInfo[])SerializationHelper.DeSerialize(typeof(ShortUserInfo[]), statvars["total"]); } else { total = Stats.GetUserOnlinetime("total"); Stats.UpdateStatVars("onlines", "total", SerializationHelper.Serialize(total)); } ShortUserInfo[] thismonth; if (statvars.ContainsKey("thismonth")) { thismonth = (ShortUserInfo[])SerializationHelper.DeSerialize(typeof(ShortUserInfo[]), statvars["thismonth"]); } else { thismonth = Stats.GetUserOnlinetime("thismonth"); Stats.UpdateStatVars("onlines", "thismonth", SerializationHelper.Serialize(thismonth)); } int maxrows = Math.Max(total.Length, thismonth.Length); totalonlinerank = Stats.GetUserRankHtml(total, "onlinetime", maxrows); thismonthonlinerank = Stats.GetUserRankHtml(thismonth, "onlinetime", maxrows); lastupdate = statvars["lastupdate"]; nextupdate = DateTime.Parse(statvars["lastupdate"]).AddMinutes(statscachelife).ToString("yyyy-MM-dd HH:mm:ss"); }
private void LoadData() { if (!Directory.Exists(_savesPath)) { return; } var wallpapers = SerializationHelper.DeSerialize <IEnumerable <Wallpaper> >(_wallpapersSavePath, typeof(MatrixTransform)); if (wallpapers != null) { foreach (var wallpaper in wallpapers) { _wallpaperController.Wallpapers.Add(wallpaper); } } var phrases = SerializationHelper.DeSerialize <IEnumerable <PhrasesGroup> >(_phrasesSavePath, typeof(MatrixTransform)); if (phrases != null) { foreach (var phrase in phrases) { _wallpaperController.PhrasesGroups.Add(phrase); } } var settings = SerializationHelper.DeSerialize <GeneralSettingsData>(_generalSettingsSavePath, typeof(MatrixTransform)); if (settings != null) { //I take FileInfo instance from DisplaySettings because when i'll try to set //soundsComboBox.SelectedItem to deserialized value, it just setup the null //(because FileInfo is the reference type) if (settings.SelectedSound != null) { _selectedSound = DisplaySettings.SoundFiles.FirstOrDefault( i => settings.SelectedSound.FullName == i.FullName); } Wallpaper.GeneralDefaultFont = settings.GeneralFontSettings; Wallpaper.GeneralDefaultStyle = settings.GeneralWallpaperStyle; _wallpaperController.UpdateFrequency = settings.UpdateFrequency; _wallpaperController.DefaultSignature = settings.DefaultSignature; _wallpaperController.WallpaperUpdateOrder = settings.WallpaperUpdateOrder; _wallpaperController.PhraseUpdateOrder = settings.PhraseUpdateOrder; } }
private void mitPasteUnder_Click(object sender, System.EventArgs e) { SerializationHelper.DeSerialize(gtv, Clipboard.GetDataObject().GetData("demoSerialisation") as Stream, gtv.SelectedNode); }
/// <summary> /// 板块排行 /// </summary> private void GetForumsRank() { foreach (string key in forumsrankstats.Keys) { statvars[key] = forumsrankstats[key].ToString(); } if (!statvars.ContainsKey("lastupdate") || (DateTime.Now - DateTime.Parse(statvars["lastupdate"])).TotalMinutes > statscachelife) { statvars.Clear(); statvars["lastupdate"] = Utils.GetDateTime(); Stats.UpdateStatVars("forumsrank", "lastupdate", statvars["lastupdate"]); } List <ForumInfo> topics; List <ForumInfo> posts; List <ForumInfo> thismonth; List <ForumInfo> today; if (statvars.ContainsKey("topics")) { topics = (List <ForumInfo>)SerializationHelper.DeSerialize(typeof(List <ForumInfo>), statvars["topics"]); } else { topics = Stats.GetForumArray("topics"); Stats.UpdateStatVars("forumsrank", "topics", SerializationHelper.Serialize(topics)); } if (statvars.ContainsKey("posts")) { posts = (List <ForumInfo>)SerializationHelper.DeSerialize(typeof(List <ForumInfo>), statvars["posts"]); } else { posts = Stats.GetForumArray("posts"); Stats.UpdateStatVars("forumsrank", "posts", SerializationHelper.Serialize(posts)); } if (statvars.ContainsKey("thismonth")) { thismonth = (List <ForumInfo>)SerializationHelper.DeSerialize(typeof(List <ForumInfo>), statvars["thismonth"]); } else { thismonth = Stats.GetForumArray("thismonth"); Stats.UpdateStatVars("forumsrank", "thismonth", SerializationHelper.Serialize(thismonth)); } if (statvars.ContainsKey("today")) { today = (List <ForumInfo>)SerializationHelper.DeSerialize(typeof(List <ForumInfo>), statvars["today"]); } else { today = Stats.GetForumArray("today"); Stats.UpdateStatVars("forumsrank", "today", SerializationHelper.Serialize(today)); } int maxrows = topics.Count; maxrows = Math.Max(posts.Count, maxrows); maxrows = Math.Max(thismonth.Count, maxrows); maxrows = Math.Max(today.Count, maxrows); topicsforumsrank = Stats.GetForumsRankHtml(topics, "topics", maxrows); postsforumsrank = Stats.GetForumsRankHtml(posts, "posts", maxrows); thismonthforumsrank = Stats.GetForumsRankHtml(thismonth, "thismonth", maxrows); todayforumsrank = Stats.GetForumsRankHtml(today, "today", maxrows); lastupdate = statvars["lastupdate"]; nextupdate = DateTime.Parse(statvars["lastupdate"]).AddMinutes(statscachelife).ToString("yyyy-MM-dd HH:mm:ss"); }
/// <summary> /// 发帖排行 /// </summary> private void GetPostsRank() { foreach (string key in postsrankstats.Keys) { statvars[key] = postsrankstats[key].ToString(); } if (!statvars.ContainsKey("lastupdate") || (DateTime.Now - DateTime.Parse(statvars["lastupdate"])).TotalMinutes > statscachelife) { statvars.Clear(); statvars["lastupdate"] = Utils.GetDateTime(); Stats.UpdateStatVars("postsrank", "lastupdate", statvars["lastupdate"]); } ShortUserInfo[] posts; ShortUserInfo[] digestposts; ShortUserInfo[] thismonth; ShortUserInfo[] today; if (statvars.ContainsKey("posts")) { posts = (ShortUserInfo[])SerializationHelper.DeSerialize(typeof(ShortUserInfo[]), statvars["posts"]); } else { posts = Stats.GetUserArray("posts"); Stats.UpdateStatVars("postsrank", "posts", SerializationHelper.Serialize(posts)); } if (statvars.ContainsKey("digestposts")) { digestposts = (ShortUserInfo[])SerializationHelper.DeSerialize(typeof(ShortUserInfo[]), statvars["digestposts"]); } else { digestposts = Stats.GetUserArray("digestposts"); Stats.UpdateStatVars("postsrank", "digestposts", SerializationHelper.Serialize(digestposts)); } if (statvars.ContainsKey("thismonth")) { thismonth = (ShortUserInfo[])SerializationHelper.DeSerialize(typeof(ShortUserInfo[]), statvars["thismonth"]); } else { thismonth = Stats.GetUserArray("thismonth"); Stats.UpdateStatVars("postsrank", "thismonth", SerializationHelper.Serialize(thismonth)); } if (statvars.ContainsKey("today")) { today = (ShortUserInfo[])SerializationHelper.DeSerialize(typeof(ShortUserInfo[]), statvars["today"]); } else { today = Stats.GetUserArray("today"); Stats.UpdateStatVars("postsrank", "today", SerializationHelper.Serialize(today)); } int maxrows = posts.Length; maxrows = Math.Max(digestposts.Length, maxrows); maxrows = Math.Max(thismonth.Length, maxrows); maxrows = Math.Max(today.Length, maxrows); postsrank = Stats.GetUserRankHtml(posts, "posts", maxrows); digestpostsrank = Stats.GetUserRankHtml(digestposts, "digestposts", maxrows); thismonthpostsrank = Stats.GetUserRankHtml(thismonth, "thismonth", maxrows); todaypostsrank = Stats.GetUserRankHtml(today, "today", maxrows); lastupdate = statvars["lastupdate"]; nextupdate = DateTime.Parse(statvars["lastupdate"]).AddMinutes(statscachelife).ToString("yyyy-MM-dd HH:mm:ss"); }
/// <summary> /// 基本状况 /// </summary> private void Default() { lastmember = Statistics.GetStatisticsRowItem("lastusername"); foreach (string key in mainstats.Keys) { statvars[key] = mainstats[key].ToString(); } if (!statvars.ContainsKey("lastupdate") || (DateTime.Now - DateTime.Parse(statvars["lastupdate"])).TotalMinutes > statscachelife) { statvars.Clear(); statvars["lastupdate"] = Utils.GetDateTime(); Stats.UpdateStatVars("main", "lastupdate", statvars["lastupdate"]); } forums = Stats.GetForumCount(); topics = Stats.GetTopicCount(); posts = Stats.GetPostCount(); members = Stats.GetMemberCount(); //运行时间 从第一帖到现在 if (statvars.ContainsKey("runtime")) { runtime = Utils.StrToInt(statvars["runtime"], 0); } else { runtime = (DateTime.Now - Convert.ToDateTime(monthpostsstats["starttime"])).Days; Stats.UpdateStatVars("main", "runtime", runtime.ToString()); } //今日新增帖数 if (statvars.ContainsKey("postsaddtoday")) { postsaddtoday = statvars["postsaddtoday"]; } else { postsaddtoday = Stats.GetTodayPostCount().ToString(); Stats.UpdateStatVars("main", "postsaddtoday", postsaddtoday); } //今日新增会员数 if (statvars.ContainsKey("membersaddtoday")) { membersaddtoday = statvars["membersaddtoday"]; } else { membersaddtoday = Stats.GetTodayNewMemberCount().ToString(); Stats.UpdateStatVars("main", "membersaddtoday", membersaddtoday); } //管理人员数 if (statvars.ContainsKey("admins")) { admins = statvars["admins"]; } else { admins = Stats.GetAdminCount().ToString(); Stats.UpdateStatVars("main", "admins", admins); } //未发帖会员数 if (statvars.ContainsKey("memnonpost")) { memnonpost = Utils.StrToInt(statvars["memnonpost"], 0); } else { memnonpost = Stats.GetNonPostMemCount(); Stats.UpdateStatVars("main", "memnonpost", memnonpost.ToString()); } //热门论坛 if (statvars.ContainsKey("hotforum")) { hotforum = (ForumInfo)SerializationHelper.DeSerialize(typeof(ForumInfo), statvars["hotforum"]); } else { hotforum = Stats.GetHotForum(); Stats.UpdateStatVars("main", "hotforum", SerializationHelper.Serialize(hotforum)); } //今日最佳会员及其今日帖数 if (statvars.ContainsKey("bestmem") && statvars.ContainsKey("bestmemposts")) { bestmem = statvars["bestmem"]; bestmemposts = Utils.StrToInt(statvars["bestmemposts"], 0); } else { Stats.GetBestMember(out bestmem, out bestmemposts); Stats.UpdateStatVars("main", "bestmem", bestmem); Stats.UpdateStatVars("main", "bestmemposts", bestmemposts.ToString()); } mempost = members - memnonpost; mempostavg = (double)Math.Round((double)posts / (double)members, 2); topicreplyavg = (double)Math.Round((double)(posts - topics) / (double)topics, 2); mempostpercent = (double)Math.Round((double)(mempost * 100) / (double)members, 2); postsaddavg = (double)Math.Round((double)posts / (double)runtime, 2); membersaddavg = members / runtime; int visitors = Utils.StrToInt(totalstats["members"], 0) + Utils.StrToInt(totalstats["guests"], 0); totalstats["visitors"] = visitors; pageviewavg = (double)Math.Round((double)Utils.StrToInt(totalstats["hits"], 0) / (double)(visitors == 0 ? 1 : visitors), 2); activeindex = ((Math.Round(membersaddavg / (double)(members == 0 ? 1 : members), 2) + Math.Round(postsaddavg / (double)(posts == 0 ? 1 : posts), 2)) * 1500.00 + topicreplyavg * 10.00 + mempostavg + Math.Round(mempostpercent / 10.00, 2) + pageviewavg).ToString(); if (statstatus) { monthofstatsbar = Stats.GetStatsDataHtml("month", monthstats, maxmonth); } else { monthpostsofstatsbar = Stats.GetStatsDataHtml("monthposts", monthpostsstats, maxmonthposts); daypostsofstatsbar = Stats.GetStatsDataHtml("dayposts", daypostsstats, maxdayposts); } lastupdate = statvars["lastupdate"]; nextupdate = DateTime.Parse(statvars["lastupdate"]).AddMinutes(statscachelife).ToString("yyyy-MM-dd HH:mm:ss"); }