/// <summary> /// Sets up bot instance /// </summary> public void Setup() { // Set logging level LogLevels logLevel; Enum.TryParse <LogLevels>(CoreSettings.Get("LogLevel", "Production"), out logLevel); Log.Level = logLevel; // Load instance Bot = new Instance(CoreSettings.Get("Name", defaultName)); userName = NetworkSettings.Get("Username"); password = NetworkSettings.Get("Password"); World = NetworkSettings.Get("World"); Owner = userName; // Connect to network ConnectToUniverse(); Log.Info("Network", "Connected to universe"); // Set up subsystems SetupDatabase(); SetupWeb(); SetupCommands(); SetupEvents(); LoadServices(); // Set up services ConnectToWorld(); PerformMigrations(); InitServices(); Log.Info("Network", "Connected to {0}", World); CoreSettings.Set("Version", MigrationVersion); Bot.ConsoleBroadcast(ChatEffect.None, ColorInfo, "", "Services is now online; say !help for information"); }
private void PeriodicLikeDecrease() { Random r = new Random(); while (true) //TODO use cancelation token { try { //see if it is time to make a decrease DateTime lastDecrease = CoreSettings.Get("LastLikeDecreaseIteration") == null?DateTime.MinValue:DateTime.Parse(CoreSettings.Get("ListLikeDecreaseIteration")); Logger.Instance.Debug($"Lase decrease was at {lastDecrease}"); var span = DateTime.Now - lastDecrease; Logger.Instance.Debug($"Time spent from last like decrease iteration is {span.TotalDays} days"); if (span.TotalDays < 100 && span.TotalDays > 1) { //need to do decrease CoreSettings.Set("LastLikeDecreaseIteration", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), true); //Logger.Instance.Debug($"doing like decrease iteration"); //var count = SourceAffinities.DecreasAllLikes(); //Logger.Instance.Debug($"Decreased likes in {count} records"); Logger.Instance.Debug($"date is db set now to {CoreSettings.Get("LastLikeDecreaseIteration")} and now it is {DateTime.Now}"); } } catch (System.Exception e) { Logger.Instance.Error($"Preriodic like decrease error ! {e.ToString()}"); } int sleepTime = r.Next(1000, 2000); //random number of secconds Thread.Sleep(sleepTime * 1000); } }
public void SetupDatabase() { var database = CoreSettings.Get("Database", "VPServices.db"); Connection = new SQLiteConnection(database, true); Connection.BusyTimeout = TimeSpan.MaxValue; Log.Info("Database", "Set up {0} as database", database); }
private object GetFeedDecorationSetting() { //if (_activity.IsPrimary) // || _activity.RawActivity.object_type != "action_activity") // return new string[0]; var ret = new { char_length = CoreSettings.Get("advancedactivity.feed.char.length", "50"), font_size = CoreSettings.Get("advancedactivity.feed.font.size", "20"), font_color = CoreSettings.Get("advancedactivity.feed.font.color", "#000"), font_style = CoreSettings.Get("advancedactivity.feed.font.style", "normal") }; return(ret); // JsonConvert.SerializeObject(ret); }
public void TestMethod6() { // Remove test setting before test start CoreSettings.Clear("zumzumzum"); // Get test setting, expect null because it doesn't exist var rc = CoreSettings.Get("zumzumzum"); Assert.IsNull(rc); // Get test setting with default value, expect that value rc = CoreSettings.Get("zumzumzum", "888"); Assert.AreEqual(rc, "888"); // Set test setting to value "777" without allowing add new, // Expect 0 affected rows var affectedRows = CoreSettings.Set("zumzumzum", "777"); Assert.AreEqual(affectedRows, 0); // Get the test setting, expect null because we didn't actually add it rc = CoreSettings.Get("zumzumzum"); Assert.IsNull(rc); // Set the test setting, this time allow adding a new record // Expect affected rows to be 1 (new row added) affectedRows = CoreSettings.Set("zumzumzum", "777", true); Assert.AreEqual(affectedRows, 1); // Get the test setting, expect value "777" because we did add the row rc = CoreSettings.Get("zumzumzum"); Assert.AreEqual(rc, "777"); // Remove the test setting, expect affected rows to be 1 because we know // it exists affectedRows = CoreSettings.Clear("zumzumzum"); Assert.AreEqual(affectedRows, 1); }
public static string Get(string url) { try { string apiUrl = string.Format(_apiUrlTemplate, System.Web.HttpUtility.HtmlEncode(url), CoreSettings.Get("core.iframely.secretIframelyKey")); var httpClient = new HttpClient { // BaseAddress = new Uri(apiUrl) }; httpClient.DefaultRequestHeaders .Accept .Add(new MediaTypeWithQualityHeaderValue("application/json")); return(httpClient.GetAsync(apiUrl).Result.Content.ReadAsStringAsync().Result); } catch (Exception e) { return(null); } }
public void TestMethod5() { var rc = CoreSettings.Get("aaf.allowed.buysell.content.0"); Assert.AreEqual(rc, "user"); }