public bool Add(string name, string content, DateTime dateTime) { if (!string.IsNullOrEmpty(name) || !string.IsNullOrEmpty(content)) { Entry entry; if (!Entries.TryGetValue(dateTime, out entry)) { Entries.Add(dateTime, new Entry(string.IsNullOrEmpty(name) ? null : name, string.IsNullOrEmpty(content) ? null : content, dateTime)); try { DB.Save(Entries.Values.ToArray()); } catch (Exception e) { return(true); } } { if (entry != null) { entry.Content += string.Format("\n{0}", content); } } return(true); } return(false); }
private void SaveInfo_Click(object sender, EventArgs e) { // if (AgeComboBox.Text != null && NameBox.Text != null && BookBox.Text != null && ThemeComboBox.Text != null && PriceBox.Text != null && CirculationBox.Text != null && MonthComboBox.Text != null) string name = NameBox.Text; string book = BookBox.Text; var age = AgeComboBox.Text.ToString()[0].ToString(); string theme = ThemeComboBox.Text.ToString()[0].ToString(); double price = double.Parse(PriceBox.Text); int amount = int.Parse(CirculationBox.Text); int month = int.Parse(MonthComboBox.Text); List <DataSpace> space = new List <DataSpace>() { new DataSpace { Author = name, Book = book, Age = age, Theme = theme, Price = price, Circulation = amount, MonthOfPublishing = month, } }; var sav = Information.DataSource as List <DataSpace>; sav.AddRange(space); storage.Save(sav); Information.DataSource = storage.Load(); Information.AutoResizeColumns(); }
public IActionResult AddTodo(Todo todo) { if (!ModelState.IsValid) { return(View(todo)); } _storage.Save(todo); return(RedirectToAction("Index")); }
private void CheckStatus(LicenseRegistration details) { var oldExpiration = details.Expiration; SetStatus(details); if (details.Expiration != oldExpiration) { storage.Save(details); } }
static async Task Save(Storage storage, JObject catalogIndex, IEnumerable <JObject> catalogPages) { foreach (JObject catalogPage in catalogPages) { Uri pageUri = new Uri(catalogPage["url"].ToString()); await storage.Save(pageUri, new StringStorageContent(catalogPage.ToString(), "application/json")); } Uri indexUri = new Uri(catalogIndex["url"].ToString()); await storage.Save(indexUri, new StringStorageContent(catalogIndex.ToString(), "application/json")); }
public void Save(string id, Deal deal) { Logger.Saving(deal); Storage.Save(id, Serializer.SerializeDeal(deal)); Cache.Save(id, new Maybe <Deal>(deal)); Logger.Saved(deal); }
public void TrainerTest() { var model = new NeuralNetwork() .AddFullLayer(10) .AddSigmoid() .AddFullLayer(6) .AddSigmoid() .AddFullLayer(3) .AddSoftmax() .UseCrossEntropyLoss() .UseAdam(); var trainer = new Trainer(model, 64, 10) { Mission = "MNIST", LabelCodec = new OneHotCodec(new List <string> { "a", "b", "c" }), }; var doc = new XmlDocument(); Storage.Save(trainer, "trainer.xml"); var test = Storage.Load <Trainer>("trainer.xml"); }
void MainWindow_Closing(object sender, CancelEventArgs e) { Storage.Save(m_rootViewModel.TaskData); HotKeyHelper.UnregisterHotKey(this, c_hotKeyId); UnregisterApplicationRecoveryAndRestart(); }
async Task UpdateMetadata(Storage storage, Action <HashSet <NuGetVersion> > updateAction, CancellationToken cancellationToken) { string relativeAddress = "index.json"; Uri resourceUri = new Uri(storage.BaseAddress, relativeAddress); HashSet <NuGetVersion> versions = GetVersions(await storage.LoadString(resourceUri, cancellationToken)); updateAction(versions); List <NuGetVersion> result = new List <NuGetVersion>(versions); if (result.Any()) { // Store versions (sorted) result.Sort(); await storage.Save(resourceUri, CreateContent(result.Select((v) => v.ToString())), cancellationToken); } else { // Remove versions file if no versions are present if (storage.Exists(relativeAddress)) { await storage.Delete(resourceUri, cancellationToken); } } }
public void CanSave() { string tmpFolder = Path.GetTempPath(); try { var storage = new Storage <TestClass>(tmpFolder, false); var tc = storage.New(); tc.AnInt = 42; tc.ADate = DateTime.Today; tc.ADouble = 3.1415926535; tc.AString = "Quick brown fox"; var tc2 = storage.New(); tc2.AnInt = 21; tc2.ADate = new DateTime(2000, 4, 9, 13, 59, 59); tc2.ADouble = 1.62e-19; tc2.AString = "Cat in the hat"; storage.Save(); Assert.IsTrue(File.Exists(Path.Combine (tmpFolder, "JsonEntityStoreTests.TestClass.json"))); } finally { File.Delete(Path.Combine (tmpFolder, "JsonEntityStoreTests.TestClass.json")); } }
bool IMetaWeblog.UpdatePost(string postid, string username, string password, Post post, bool publish) { ValidateUser(username, password); Post match = Storage.GetAllPosts().FirstOrDefault(p => p.ID == postid); if (match != null) { match.Title = post.Title; match.Excerpt = post.Excerpt; match.Content = post.Content; if (!string.Equals(match.Slug, post.Slug, StringComparison.OrdinalIgnoreCase)) { match.Slug = PostHandler.CreateSlug(post.Slug); } match.Categories = post.Categories; match.IsPublished = publish; Storage.Save(match); } return(match != null); }
void InternalTransportTransportMessageReceived(object sender, TransportMessageReceivedEventArgs e) { if (UnicastBus.HandledSubscriptionMessage(e.Message, Subscribers, null)) { e.Message.ReplyToAddress = ExternalAddress; ExternalMessageSender.Send(e.Message, RemoteServer); Logger.Debug("Received subscription message."); return; } var data = new ProxyData { Id = GenerateId(), ClientAddress = e.Message.ReplyToAddress, CorrelationId = e.Message.IdForCorrelation }; Storage.Save(data); Logger.Debug("Forwarding request to " + RemoteServer + "."); e.Message.IdForCorrelation = data.Id; e.Message.ReplyToAddress = ExternalAddress; ExternalMessageSender.Send(e.Message, RemoteServer); }
public void EntityExited() { if (Storage.currentPlayer != null) { Storage.currentPlayer.unlockMapLevel = (uint)gameConfigCtrl1.GetLevel() + 1; double time = (double)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalSeconds; double value = (numberOfMoves / (time - gameBoardCtrl1.time)) * gameBoardCtrl1.GetBoard().cells.Count; if (value > Storage.currentPlayer.highscore || Storage.currentPlayer.highscore == 0) { Storage.currentPlayer.highscore = value; } numberOfMoves = 0; Storage.Save(); gameConfigCtrl1.SetLevel((int)Storage.currentPlayer.unlockMapLevel); } // Theseus has exited the level. if (Storage.currentPlayer.unlockMapLevel >= Storage.settings.maps.Count) { gameBoardCtrl1.SetBoard(null); // end of maps } else { gameConfigCtrl1.SetLevel((int)Storage.currentPlayer.unlockMapLevel); } }
// DELETE api/Cart public void Delete() { Cart userCart = GetUserCart(); userCart.CartItems.Clear(); Storage.Save(); }
/// <summary> /// Log out from current account /// </summary> private void Logout() { _updater.Stop(); StopIdle(); IsAuthorized = false; // Clear the account settings Storage.SessionId = string.Empty; Storage.SteamLoginSecure = string.Empty; Storage.SteamParental = string.Empty; UserName = ProfileUrl = Level = AvatarUrl = BackgroundUrl = null; FavoriteBadge = null; Storage.IdleMode = 0; Storage.BadgeFilter = Storage.ShowcaseFilter = string.Empty; AllBadges.Clear(); IdleQueueBadges.Clear(); Storage.Save(); foreach (var showcase in AllShowcases) { showcase.IsCompleted = false; showcase.CanCraft = false; showcase.IsOwned = false; } Logger.Info("See you later"); }
public void SaveTest() { int a = 3; Storage.Save(a, "./testsave.xml"); File.Exists("./testsave.xml"); }
private void FormatPosts(string originalFolderPath, string targetFolderPath) { foreach (string file in Directory.GetFiles(originalFolderPath, "*.xml")) { if (!file.EndsWith("dayentry.xml", StringComparison.OrdinalIgnoreCase)) { continue; } XmlDocument docOrig = LoadDocument(file); XmlNamespaceManager nsm = LoadNamespaceManager(docOrig); foreach (XmlNode entry in docOrig.SelectNodes("//Entry", nsm)) { Post post = new Post(); post.Categories = FormatCategories(entry.SelectSingleNode("Categories")).ToArray(); post.Title = entry.SelectSingleNode("Title").InnerText; post.Slug = FormatterHelpers.FormatSlug(post.Title); post.PubDate = DateTime.Parse(entry.SelectSingleNode("//Created").InnerText); post.LastModified = DateTime.Parse(entry.SelectSingleNode("//Modified").InnerText); post.Content = FormatFileReferences(entry.SelectSingleNode("Content").InnerText); post.Author = entry.SelectSingleNode("Author").InnerText; post.IsPublished = bool.Parse(ReadValue(entry.SelectSingleNode("IsPublic"), "true")); string newFile = Path.Combine(targetFolderPath, entry.SelectSingleNode("EntryId").InnerText + ".xml"); Storage.Save(post, newFile); } } }
public override bool HandleInput() { var input = GetPlayerInput(); if (input == Inputs.cancel) { ScreenResult = new ScreenTransitionResult { FromScreen = ScreenType.NewPlayer, ToScreen = ScreenType.MainMenu }; return(false); } if (input == Inputs.tab) { PlayerName = string.Empty; Layout.PlayerName = PlayerName; Layout.RandomName(); return(true); } if (input == Inputs.ok) { // Create the Hero // TODO: Other classes. var heroClass = new Warrior(); var newPlayerName = string.IsNullOrWhiteSpace(PlayerName) ? Layout.DefaultName : PlayerName; var hero = GameContent.Instance.createHero(newPlayerName, heroClass); Storage.Heroes.Add(hero); Storage.Save(); // Start the Game ScreenResult = new ScreenTransitionResult { FromScreen = ScreenType.NewPlayer, ToScreen = ScreenType.InGame, Result = newPlayerName }; return(false); } if (ConvertKeyToNumber(input) != -1) { if ((input.Modifiers & ConsoleModifiers.Shift) != 0) { PlayerName += input.KeyChar.ToString().ToUpper(); } else { PlayerName += input.KeyChar; } } if (input.Key == ConsoleKey.Delete) { if (string.IsNullOrWhiteSpace(PlayerName)) { PlayerName = Layout.DefaultName; } PlayerName = PlayerName.Substring(0, PlayerName.Length - 1); } Layout.PlayerName = PlayerName; return(true); }
public async Task Save() { if (IsMultiplex) { if (Parent == null) { throw new InvalidOperationException("multiplex memory no parent"); } await Parent.Save(); return; } if (_logger.IsEnabled(LogLevel.Trace)) { _logger.LogTrace($"<{Name ?? ""}>{MultiplexPath} save() to {Storage?.ToString() ?? "N/A"}"); } if (Payload == null) { throw new InvalidOperationException("no payload, please call load() first."); } if (Storage == null) { if (_logger.IsEnabled(LogLevel.Trace)) { _logger.LogTrace($"save() no storage, NOOP"); } return; } await Storage.Save(Payload); }
public void TestSave() { var user = _storage.Load("Andrew"); var contacts = new List <Friend> { new Friend { Name = "Tina", Online = true }, new Friend { Name = "Alex", Online = true } }; user.Contacts = contacts; _storage.Save(user); user = _storage.Load("Andrew"); Assert.That(user.Name, Is.EqualTo("Andrew")); var counter = 0; foreach (var contact in user.Contacts) { Assert.That(contact.Name, Is.EqualTo(contacts[counter].Name)); Assert.That(contact.Online, Is.EqualTo(contacts[counter].Online)); ++counter; } Assert.That(user.MessageBySender.Count, Is.EqualTo(0)); }
protected override void OnClick(EventArgs e) { base.OnClick(e); if (Enabled) { if (!_storage.IsSaved) { var sps = new ShowingParameters(); if (!sps.Show()) { return; } _storage.Parameters.ProductName = sps.ProudctName; _storage.Parameters.ProductVersion = sps.ProductVersion; _storage.Parameters.ProductCode = sps.ProcutCode; _storage.Parameters.CustomerName = sps.CustomerName; _storage.Parameters.CustomerCode = sps.CustomerCode; _storage.SaveAs(sps.Path); } else { _storage.Save(); } } }
private static void Delete(HttpContext context, Post post) { if (!context.User.Identity.IsAuthenticated) { throw new HttpException(403, "No access"); } string commentId = context.Request["commentId"]; Comment comment = post.Comments.SingleOrDefault(c => c.ID == commentId); if (comment != null) { post.Comments.Remove(comment); Storage.Save(post); } else { throw new HttpException(404, "Comment could not be found"); } if (context.Request.HttpMethod == "GET") { context.Response.Redirect(post.AbsoluteUrl.ToString() + "#comments", true); } }
private static void Save(HttpContext context, Post post) { string name = context.Request.Form["name"]; string email = context.Request.Form["email"]; string website = context.Request.Form["website"]; string content = context.Request.Form["content"]; Validate(name, email, content); Comment comment = new Comment() { Author = name.Trim(), Email = email.Trim(), Website = GetUrl(website), Ip = context.Request.UserHostAddress, UserAgent = context.Request.UserAgent, IsAdmin = context.User.Identity.IsAuthenticated, Content = HttpUtility.HtmlEncode(content.Trim()).Replace("\n", "<br />"), }; post.Comments.Add(comment); Storage.Save(post); if (!context.User.Identity.IsAuthenticated) { System.Threading.ThreadPool.QueueUserWorkItem((s) => SendEmail(comment, post, context.Request)); } RenderComment(context, comment); }
private void button2_Click(object sender, EventArgs e)//save to file { List <string> MagicList = new List <string>(); MagicList.Add(keyGenereator.MagicWord); Storage.Save(MagicList); }
private void EditPost(string id, string title, string excerpt, string content, bool isPublished, string[] categories) { Post post = Storage.GetAllPosts().FirstOrDefault(p => p.ID == id); if (post != null) { post.Title = title; post.Excerpt = excerpt; post.Content = content; post.Categories = categories; } else { post = new Post() { Title = title, Excerpt = excerpt, Content = content, Slug = CreateSlug(title), Categories = categories }; HttpContext.Current.Response.Write(post.Url); } SaveFilesToDisk(post); post.IsPublished = isPublished; Storage.Save(post); }
public void CanReadZip() { string tmpFolder = Path.GetTempPath(); try { var storage = new Storage <TestClass>(tmpFolder, true); var tc = storage.New(); tc.AnInt = 42; tc.ADate = DateTime.Today; tc.ADouble = 3.1415926535; tc.AString = "Quick brown fox"; var tc2 = storage.New(); tc2.AnInt = 21; tc2.ADate = new DateTime(2000, 4, 9, 13, 59, 59); tc2.ADouble = 1.62e-19; tc2.AString = "Cat in the hat"; storage.Save(); storage = new Storage <TestClass>(tmpFolder, true); Assert.AreEqual(2, storage.Count()); Assert.AreEqual(2, storage.All().Count); Assert.AreEqual(42, storage.All()[0].AnInt); Assert.AreEqual(new DateTime(2000, 4, 9, 13, 59, 59), storage.Last().ADate); } finally { File.Delete(Path.Combine (tmpFolder, "JsonEntityStoreTests.TestClass.json.zip")); } }
public void CanDeleteById() { string tmpFolder = Path.GetTempPath(); try { var storage = new Storage <TestClass>(tmpFolder, false); var tc = storage.New(); tc.AnInt = 42; tc.ADate = DateTime.Today; tc.ADouble = 3.1415926535; tc.AString = "Quick brown fox"; var tc2 = storage.New(); tc2.AnInt = 21; tc2.ADate = new DateTime(2000, 4, 9, 13, 59, 59); tc2.ADouble = 1.62e-19; tc2.AString = "Cat in the hat"; storage.Save(); storage = new Storage <TestClass>(tmpFolder, false); var foundT = storage.Find(2); storage.Delete(1); Assert.AreEqual(1, storage.All().Count); Assert.IsNull(storage.Find(1)); Assert.IsNotNull(storage.Find(2)); } finally { File.Delete(Path.Combine (tmpFolder, "JsonEntityStoreTests.TestClass.json")); } }
public void TestInitialize() { string password = "******"; Cryptography c = new Cryptography(); password = c.Encryption(password); Storage.Save(password, "./passwordload.xml"); }
protected override void OnSave() { _config.GamePath = (string)GetInputValue(GamePathTitle); _config.Verbose = (bool)GetInputValue(VerboseModeTitle); _config.BlockInput = (bool)GetInputValue(BlockInputTitle); Storage.Save(_config, Constants.OwmlConfigFileName); Close(); }
private void SaveButtonClick(object sender, RoutedEventArgs e) { Configuration configuration = new Configuration(GetUrl(), TokenTextBox.Text); Storage.Save(configuration); new MainWindow(configuration, Storage.RestoreViewConfiguration()).Show(); Close(); }
public void Delete() { Storage storage = new Storage(); storage.name = "test_delete"; storage.Delete(); Dictionary<string, object> data = storage.Load(); Assert.AreEqual(0, DataUtil.Length(data)); storage.SetKeyValue("level", 2); storage.Save(); data = storage.Load(); Assert.AreEqual(2, data["level"]); data = storage.Load(); Assert.AreEqual(2, data["level"]); storage.Delete(); data = storage.Load(); Assert.AreEqual(0, DataUtil.Length(data)); storage.Save(); Assert.AreEqual(0, DataUtil.Length(data)); data = storage.Load(); Assert.AreEqual(0, DataUtil.Length(data)); }
public void Test_Save_ReturnsFalseOnLargeObject() { Storage store = new Storage(new EmailSender()); bool result = store.Save(getLargeDataObject()); Assert.IsFalse(result); }