private MutableDocument CreateDocument(string tag) { var doc = new MutableDocument(); doc.SetString("tag", tag); doc.SetString("firstName", "Daniel"); doc.SetString("lastName", "Tiger"); var address = new MutableDictionaryObject(); address.SetString("street", "1 Main street"); address.SetString("city", "Mountain View"); address.SetString("state", "CA"); doc.SetDictionary("address", address); var phones = new MutableArrayObject(); phones.AddString("650-123-0001") .AddString("650-123-0001"); doc.SetArray("phones", phones); doc.SetDate("updated", DateTimeOffset.UtcNow); return(doc); }
public void TestGetDictionary() { var mNestedDict = new MutableDictionaryObject(); mNestedDict.SetLong("key1", 1L); mNestedDict.SetString("key2", "Hello"); mNestedDict.SetValue("key3", null); var mDict = new MutableDictionaryObject(); mDict.SetLong("key1", 1L); mDict.SetString("key2", "Hello"); mDict.SetValue("key3", null); mDict.SetDictionary("nestedDict", mNestedDict); using (var mDoc = new MutableDocument("test")) { mDoc.SetDictionary("dict", mDict); using (var doc = Db.Save(mDoc)) { var dict = doc.GetDictionary("dict"); dict.Should().NotBeNull(); dict.GetDictionary("not-exists").Should().BeNull(); var nestedDict = dict.GetDictionary("nestedDict"); nestedDict.Should().NotBeNull(); nestedDict.ToDictionary().ShouldBeEquivalentTo(mNestedDict.ToDictionary()); } } }
public void TestRemoveDictionary() { var doc = new MutableDocument("doc1"); var profile1 = new MutableDictionaryObject(); profile1.SetString("name", "Scott Tiger"); doc.SetDictionary("profile", profile1); doc.GetDictionary("profile").ShouldBeEquivalentTo(profile1, "because that was what was inserted"); doc.Contains("profile").Should().BeTrue("because a value exists for that key"); doc.Remove("profile"); doc.GetValue("profile").Should().BeNull("beacuse the value for 'profile' was removed"); doc.Contains("profile").Should().BeFalse("because the value was removed"); profile1.SetInt("age", 20); profile1.GetString("name").Should().Be("Scott Tiger", "because the dictionary object should be unaffected"); profile1.GetInt("age").Should().Be(20, "because the dictionary should still be editable"); doc.GetValue("profile").Should() .BeNull("because changes to the dictionary should not have any affect anymore"); var savedDoc = Db.Save(doc); savedDoc.GetValue("profile").Should().BeNull("beacuse the value for 'profile' was removed"); savedDoc.Contains("profile").Should().BeFalse("because the value was removed"); }
public void TestReplaceDictionary() { var doc = new MutableDocument("doc1"); var profile1 = new MutableDictionaryObject(); profile1.SetString("name", "Scott Tiger"); doc.SetDictionary("profile", profile1); doc.GetDictionary("profile").ShouldBeEquivalentTo(profile1, "because that is what was set"); var profile2 = new MutableDictionaryObject(); profile2.SetString("name", "Daniel Tiger"); doc.SetDictionary("profile", profile2); doc.GetDictionary("profile").ShouldBeEquivalentTo(profile2, "because that is what was set"); profile1.SetInt("age", 20); profile1.GetString("name").Should().Be("Scott Tiger", "because profile1 should be detached now"); profile1.GetInt("age").Should().Be(20, "because profile1 should be detached now"); profile2.GetString("name").Should().Be("Daniel Tiger", "because profile2 should be unchanged"); profile2.GetValue("age").Should().BeNull("because profile2 should be unchanged"); Db.Save(doc); var gotDoc = Db.GetDocument("doc1"); gotDoc.GetDictionary("profile") .Should() .NotBeSameAs(profile2, "because a new MutableDocument should return a new instance"); var savedProfile2 = gotDoc.GetDictionary("profile"); savedProfile2.GetString("name").Should().Be("Daniel Tiger", "because that is what was saved"); }
public void TestSetNull() { using (var mDoc = new MutableDocument("test")) { var mDict = new MutableDictionaryObject(); mDict.SetValue("obj-null", null); mDict.SetString("string-null", null); mDict.SetArray("array-null", null); mDict.SetDictionary("dict-null", null); mDoc.SetDictionary("dict", mDict); SaveDocument(mDoc, doc => { doc.Count.Should().Be(1); doc.Contains("dict").Should().BeTrue(); var d = doc.GetDictionary("dict"); d.Should().NotBeNull(); d.Count.Should().Be(4); d.Contains("obj-null").Should().BeTrue(); d.Contains("string-null").Should().BeTrue(); d.Contains("array-null").Should().BeTrue(); d.Contains("dict-null").Should().BeTrue(); d.GetValue("obj-null").Should().BeNull();; d.GetValue("string-null").Should().BeNull();; d.GetValue("array-null").Should().BeNull();; d.GetValue("dict-null").Should().BeNull(); }); } }
public void TestDictionaryFragmentSetDictionary() { var doc = new MutableDocument("doc1"); var dict = new MutableDictionaryObject(); dict.SetString("name", "Jason") .SetValue("address", new Dictionary <string, object> { ["street"] = "1 Main Street", ["phones"] = new Dictionary <string, object> { ["mobile"] = "650-123-4567" } }); doc["dict"].Value = dict; SaveDocument(doc, d => { d["dict"]["name"].String.Should().Be("Jason", "because that is what was stored"); d["dict"]["address"]["street"] .String .Should() .Be("1 Main Street", "because that is what was stored"); d["dict"]["address"]["phones"]["mobile"] .String .Should() .Be("650-123-4567", "because that is what was stored"); }); }
public MutableDictionaryObject DocumentInitialize() { MutableDictionaryObject dico = new MutableDictionaryObject(); dico.SetString("table", Table); if (Num != null) { dico.SetLong("num", Num ?? 0); } dico.SetString("libelle", Libelle); dico.SetString("localite", Localite); dico.SetString("depCode", DepCode); dico.SetLong("petNumero", PetNumero); dico.SetString("etat", Etat); return(dico); }
public MutableDictionaryObject DocumentInitialize() { MutableDictionaryObject dico = new MutableDictionaryObject(); dico.SetString("table", Table); if (Num != null) { dico.SetLong("num", Num ?? 0); } dico.SetLong("pgrNum", PgrNum); dico.SetString("code", Code); dico.SetDouble("surface", Surface); dico.SetDouble("surfacePlancher", SurfacePlancher); dico.SetString("facade", Facade); dico.SetString("letCode", LetCode); dico.SetString("etat", Etat); dico.SetDouble("prixVenteConseille", PrixVenteConseille ?? 0); return(dico); }
public async Task <bool> AddItemAsync(SeasonalItem item) { using (var doc = _db.GetDocument(CoreApp.DocId)) using (var mdoc = doc.ToMutable()) using (MutableArrayObject listItems = mdoc.GetArray(CoreApp.ArrKey)) { var dictObj = new MutableDictionaryObject(); dictObj.SetString("key", item.Name); dictObj.SetInt("value", item.Quantity); var blob = new Blob("image/png", item.ImageByteArray); dictObj.SetBlob("image", blob); listItems.AddDictionary(dictObj); _db.Save(mdoc); _items.Add(_items.Count + 1, item); } return(await Task.FromResult(true)); }
public void TestSetNestedDictionaries() { var doc = new MutableDocument("doc1"); var level1 = new MutableDictionaryObject(); level1.SetString("name", "n1"); doc.SetDictionary("level1", level1); var level2 = new MutableDictionaryObject(); level2.SetString("name", "n2"); level1.SetDictionary("level2", level2); var level3 = new MutableDictionaryObject(); level3.SetString("name", "n3"); level2.SetDictionary("level3", level3); doc.GetDictionary("level1").ShouldBeEquivalentTo(level1, "because that is what was inserted"); level1.GetDictionary("level2").ShouldBeEquivalentTo(level2, "because that is what was inserted"); level2.GetDictionary("level3").ShouldBeEquivalentTo(level3, "because that is what was inserted"); var dict = new Dictionary <string, object> { ["level1"] = new Dictionary <string, object> { ["name"] = "n1", ["level2"] = new Dictionary <string, object> { ["name"] = "n2", ["level3"] = new Dictionary <string, object> { ["name"] = "n3" } } } }; doc.ToDictionary().ShouldBeEquivalentTo(dict, "because otherwise the document's contents are incorrect"); Db.Save(doc); var gotDoc = Db.GetDocument("doc1"); gotDoc.GetDictionary("level1").Should().NotBeSameAs(level1); gotDoc.ToDictionary().ShouldBeEquivalentTo(dict); }
public void TestReplaceDictionaryDifferentType() { var doc = new MutableDocument("doc1"); var profile1 = new MutableDictionaryObject(); profile1.SetString("name", "Scott Tiger"); doc.SetDictionary("profile", profile1); doc.GetDictionary("profile").ShouldBeEquivalentTo(profile1, "because that is what was set"); doc.SetString("profile", "Daniel Tiger"); doc.GetString("profile").Should().Be("Daniel Tiger", "because that is what was set"); profile1.SetInt("age", 20); profile1.GetString("name").Should().Be("Scott Tiger", "because profile1 should be detached now"); profile1.GetInt("age").Should().Be(20, "because profile1 should be detached now"); doc.GetString("profile").Should().Be("Daniel Tiger", "because profile1 should not affect the new value"); Db.Save(doc); var gotDoc = Db.GetDocument("doc1"); gotDoc.GetString("profile").Should().Be("Daniel Tiger", "because that is what was saved"); }
public void TestArrayFragmentSetDictionary() { var doc = new MutableDocument("doc1"); var dict = new MutableDictionaryObject(); dict.SetString("name", "Jason") .SetValue("address", new Dictionary <string, object> { ["street"] = "1 Main Street", ["phones"] = new Dictionary <string, object> { ["mobile"] = "650-123-4567" } }); doc["array"].Value = new[] { dict }; SaveDocument(doc, d => { d["array"][-1].Value.Should().BeNull("because that is an invalid index"); d["array"][-1].Exists.Should().BeFalse("because there is no data at the invalid index"); d["array"][0].Exists.Should().BeTrue("because data exists at this index"); d["array"][1].Value.Should().BeNull("because that is an invalid index"); d["array"][1].Exists.Should().BeFalse("because there is no data at the invalid index"); d["array"][0]["name"].String.Should().Be("Jason", "because that is what was stored"); d["array"][0]["address"]["street"] .String .Should() .Be("1 Main Street", "because that is what was stored"); d["array"][0]["address"]["phones"]["mobile"] .String .Should() .Be("650-123-4567", "because that is what was stored"); }); }
private void Button_Click(object sender, RoutedEventArgs e) { #region Data Control if (!String.IsNullOrEmpty(OperationTextBox.Text) && OperationComboBox.SelectedIndex == -1) { MessageBox.Show("Select a Operation value.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!String.IsNullOrEmpty(MaintenanceTextBox.Text) && MaintenanceComboBox.SelectedIndex == -1) { MessageBox.Show("Select a Maintenance value.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!String.IsNullOrEmpty(TechAssistanceTextBox.Text) && TechAssistanceComboBox.SelectedIndex == -1) { MessageBox.Show("Select a Tech Assistance value.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!String.IsNullOrEmpty(TechPubTextBox.Text) && TechPubComboBox.SelectedIndex == -1) { MessageBox.Show("Select a Tech Pub value.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!String.IsNullOrEmpty(LogisticsTextBox.Text) && LogisticsComboBox.SelectedIndex == -1) { MessageBox.Show("Select a Logistics value.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!String.IsNullOrEmpty(CSCTextBox.Text) && CSCComboBox.SelectedIndex == -1) { MessageBox.Show("Select a CSC value.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!String.IsNullOrEmpty(CommunicationTextBox.Text) && CommunicationComboBox.SelectedIndex == -1) { MessageBox.Show("Select a CSC value.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!String.IsNullOrEmpty(CommercialSupportTextBox.Text) && CommercialSupportComboBox.SelectedIndex == -1) { MessageBox.Show("Select a Commercial Support value.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!String.IsNullOrEmpty(CostOfOperationTextBox.Text) && CostOfOperationComboBox.SelectedIndex == -1) { MessageBox.Show("Select a Cost Of Operation value.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!String.IsNullOrEmpty(WarrentyAdministrationTextBox.Text) && WarrentyAdministrationComboBox.SelectedIndex == -1) { MessageBox.Show("Select a Administration value.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!String.IsNullOrEmpty(OEMServiceTextBox.Text) && OEMServiceComboBox.SelectedIndex == -1) { MessageBox.Show("Select a OEM Service value.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!String.IsNullOrEmpty(VendorManagementTextBox.Text) && VendorManagementComboBox.SelectedIndex == -1) { MessageBox.Show("Select a Vendor Management value.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (CustomerComboBox.SelectedIndex == -1) { MessageBox.Show("Select a Customer for this Report.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } #endregion string id = null; using (var mutableDoc = new MutableDocument()) { if (!string.IsNullOrWhiteSpace(GlobalCommentTextBox.Text)) { mutableDoc.SetString("commentaireGenerale", GlobalCommentTextBox.Text.Trim().ToLower()); } mutableDoc.SetString("customer", CustomerComboBox.Text.Trim().ToLower()); mutableDoc.SetString("type", "report"); mutableDoc.SetString("mois", DateTime.Now.ToString("MMMMMMMMMMMMM").ToLower()); var rubriques = new MutableArrayObject(); mutableDoc.SetArray("rubriques", rubriques); if (OperationComboBox.SelectedIndex != -1) { var operation = new MutableDictionaryObject(); operation.SetString("nom", "operation") .SetInt("note", Int32.Parse(((ComboBoxItem)OperationComboBox.SelectedItem).Content.ToString())); if (!String.IsNullOrEmpty(OperationTextBox.Text)) { operation.SetString("commentaire", OperationTextBox.Text.ToLower().TrimEnd().TrimStart()); } rubriques.AddDictionary(operation); } if (MaintenanceComboBox.SelectedIndex != -1) { var maintenance = new MutableDictionaryObject(); maintenance.SetString("nom", "maintenance") .SetInt("note", Int32.Parse(((ComboBoxItem)MaintenanceComboBox.SelectedItem).Content.ToString())); if (!String.IsNullOrEmpty(MaintenanceTextBox.Text)) { maintenance.SetString("commentaire", MaintenanceTextBox.Text.ToLower().TrimEnd().TrimStart()); } rubriques.AddDictionary(maintenance); } if (TechAssistanceComboBox.SelectedIndex != -1) { var techAssistance = new MutableDictionaryObject(); techAssistance.SetString("nom", "techAssistance") .SetInt("note", Int32.Parse(((ComboBoxItem)TechAssistanceComboBox.SelectedItem).Content.ToString())); if (!String.IsNullOrEmpty(TechAssistanceTextBox.Text)) { techAssistance.SetString("commentaire", TechAssistanceTextBox.Text.ToLower().TrimEnd().TrimStart()); } rubriques.AddDictionary(techAssistance); } if (TechPubComboBox.SelectedIndex != -1) { var techPub = new MutableDictionaryObject(); techPub.SetString("nom", "techPub") .SetInt("note", Int32.Parse(((ComboBoxItem)TechPubComboBox.SelectedItem).Content.ToString())); if (!String.IsNullOrEmpty(TechPubTextBox.Text)) { techPub.SetString("commentaire", TechPubTextBox.Text.ToLower().TrimEnd().TrimStart()); } rubriques.AddDictionary(techPub); } if (LogisticsComboBox.SelectedIndex != -1) { var logistics = new MutableDictionaryObject(); logistics.SetString("nom", "logistics") .SetInt("note", Int32.Parse(((ComboBoxItem)LogisticsComboBox.SelectedItem).Content.ToString())); if (!String.IsNullOrEmpty(LogisticsTextBox.Text)) { logistics.SetString("commentaire", LogisticsTextBox.Text.ToLower().TrimEnd().TrimStart()); } rubriques.AddDictionary(logistics); } if (CSCComboBox.SelectedIndex != -1) { var csc = new MutableDictionaryObject(); csc.SetString("nom", "csc") .SetInt("note", Int32.Parse(((ComboBoxItem)CSCComboBox.SelectedItem).Content.ToString())); if (!String.IsNullOrEmpty(CSCTextBox.Text)) { csc.SetString("commentaire", CSCTextBox.Text.ToLower().TrimEnd().TrimStart()); } rubriques.AddDictionary(csc); } if (CommunicationComboBox.SelectedIndex != -1) { var communication = new MutableDictionaryObject(); communication.SetString("nom", "communication") .SetInt("note", Int32.Parse(((ComboBoxItem)CommunicationComboBox.SelectedItem).Content.ToString())); if (!String.IsNullOrEmpty(CommunicationTextBox.Text)) { communication.SetString("commentaire", CommunicationTextBox.Text.ToLower().TrimEnd().TrimStart()); } rubriques.AddDictionary(communication); } if (CommercialSupportComboBox.SelectedIndex != -1) { var commercialSupport = new MutableDictionaryObject(); commercialSupport.SetString("nom", "commercialSupport") .SetInt("note", Int32.Parse(((ComboBoxItem)CommercialSupportComboBox.SelectedItem).Content.ToString())); if (!String.IsNullOrEmpty(CommercialSupportTextBox.Text)) { commercialSupport.SetString("commentaire", CommercialSupportTextBox.Text.ToLower().TrimEnd().TrimStart()); } rubriques.AddDictionary(commercialSupport); } if (CostOfOperationComboBox.SelectedIndex != -1) { var CostOfOperation = new MutableDictionaryObject(); CostOfOperation.SetString("nom", "costOfOperation") .SetInt("note", Int32.Parse(((ComboBoxItem)CostOfOperationComboBox.SelectedItem).Content.ToString())); if (!String.IsNullOrEmpty(CostOfOperationTextBox.Text)) { CostOfOperation.SetString("commentaire", CostOfOperationTextBox.Text.ToLower().TrimEnd().TrimStart()); } rubriques.AddDictionary(CostOfOperation); } if (WarrentyAdministrationComboBox.SelectedIndex != -1) { var WarrentyAdministration = new MutableDictionaryObject(); WarrentyAdministration.SetString("nom", "warrentyAdministration") .SetInt("note", Int32.Parse(((ComboBoxItem)WarrentyAdministrationComboBox.SelectedItem).Content.ToString())); if (!String.IsNullOrEmpty(WarrentyAdministrationTextBox.Text)) { WarrentyAdministration.SetString("commentaire", WarrentyAdministrationTextBox.Text.ToLower().TrimEnd().TrimStart()); } rubriques.AddDictionary(WarrentyAdministration); } if (OEMServiceComboBox.SelectedIndex != -1) { var oemService = new MutableDictionaryObject(); oemService.SetString("nom", "oemService") .SetInt("note", Int32.Parse(((ComboBoxItem)OEMServiceComboBox.SelectedItem).Content.ToString())); if (!String.IsNullOrEmpty(OEMServiceTextBox.Text)) { oemService.SetString("commentaire", OEMServiceTextBox.Text.ToLower().TrimEnd().TrimStart()); } rubriques.AddDictionary(oemService); } if (VendorManagementComboBox.SelectedIndex != -1) { var vendorManagement = new MutableDictionaryObject(); vendorManagement.SetString("nom", "vendorManagement") .SetInt("note", Int32.Parse(((ComboBoxItem)VendorManagementComboBox.SelectedItem).Content.ToString())); if (!String.IsNullOrEmpty(VendorManagementTextBox.Text)) { vendorManagement.SetString("commentaire", VendorManagementTextBox.Text.ToLower().TrimEnd().TrimStart()); } rubriques.AddDictionary(vendorManagement); } Database.Save(mutableDoc); id = mutableDoc.Id; } Console.WriteLine("Document saved with : " + id); Logger.Info("Document saved with : " + id); MessageBox.Show("Report saved with : " + id, "Report Saved", MessageBoxButton.OK, MessageBoxImage.Information); }
public MutableDictionaryObject DocumentInitialize() { MutableDictionaryObject dico = new MutableDictionaryObject(); dico.SetString("table", Table); if (DateNaissance != DateTime.MinValue) { dico.SetDate("dateNaissance", DateNaissance); } dico.SetString("email", Email); dico.SetString("lieuNaissance", LieuNaissance); dico.SetString("lieuTravail", LieuTravail); dico.SetString("nationalite", Nationalite); dico.SetString("nom", Nom); dico.SetString("portable", Portable); dico.SetString("prenom", Prenom); dico.SetString("profession", Profession); dico.SetDouble("salaireNetMensuel", SalaireNetMensuel ?? 0); dico.SetString("telPro", TelPro); dico.SetString("titreSejour", TitreSejour); dico.SetString("profession", Profession); dico.SetString("civCode", CivCode); dico.SetString("civLibelle", CivLibelle); return(dico); }