public void TestAccessContentFromBlobCreatedFromJson() { var blob = ArrayTestBlob(); Db.SaveBlob(blob); var blobDict = new List <object> { new Dictionary <string, object>() { { Blob.ContentTypeKey, blob.ContentType }, { Blob.DigestKey, blob.Digest }, { Blob.LengthKey, blob.Length }, { Constants.ObjectTypeProperty, "blob" } } }; var listContainsBlobJson = JsonConvert.SerializeObject(blobDict); using (var md = new MutableDocument("doc1")) { var ma = new MutableArrayObject(listContainsBlobJson); var blobInMa = (MutableDictionaryObject)ma.GetValue(0); var blobInMD = new Blob(blobInMa.ToDictionary()); blobInMD.Content.Should().BeNull(CouchbaseLiteErrorMessage.BlobDbNull); } }
private static MutableArrayObject ConvertList(IList list) { var array = new MutableArrayObject(); array.SetData(list); return(array); }
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 TestGetArray() { var mNestedArray = new MutableArrayObject(); mNestedArray.AddLong(1L); mNestedArray.AddString("Hello"); mNestedArray.AddValue(null); var mArray = new MutableArrayObject(); mArray.AddLong(1L); mArray.AddString("Hello"); mArray.AddValue(null); mArray.AddArray(mNestedArray); using (var mDoc = new MutableDocument("test")) { mDoc.SetArray("array", mArray); using (var doc = Db.Save(mDoc)) { var array = doc.GetArray("array"); array.Should().NotBeNull(); array.GetArray(0).Should().BeNull(); array.GetArray(1).Should().BeNull(); array.GetArray(2).Should().BeNull(); array.GetArray(3).Should().NotBeNull(); var nestedArray = array.GetArray(3); nestedArray.ShouldBeEquivalentTo(mNestedArray); array.ShouldBeEquivalentTo(mArray); } } }
public async Task <bool> DeleteItemAsync(int index) { using (var doc = _db.GetDocument(CoreApp.DocId)) using (var mdoc = doc.ToMutable()) using (MutableArrayObject listItems = mdoc.GetArray(CoreApp.ArrKey)) { listItems.RemoveAt(index); _db.Save(mdoc); } _items.Remove(index); return(await Task.FromResult(true)); }
} // End JSONAPIDocument public void JsonApiArray() { // Init for docs //var this_Db = DataStore.getDbHandle(); var ourdbname = "ournewdb"; if (Database.Exists(ourdbname, "/")) { Database.Delete(ourdbname, "/"); } // tag::tojson-array[] Database dbNew = new Database(ourdbname); // JSON String -- an Array (3 elements. including embedded arrays) var thisJSONstring = "[{'id':'1000','type':'hotel','name':'Hotel Ted','city':'Paris','country':'France','description':'Undefined description for Hotel Ted'},{'id':'1001','type':'hotel','name':'Hotel Fred','city':'London','country':'England','description':'Undefined description for Hotel Fred'}, {'id':'1002','type':'hotel','name':'Hotel Ned','city':'Balmain','country':'Australia','description':'Undefined description for Hotel Ned','features':['Cable TV','Toaster','Microwave']}]".Replace("'", "\""); // Get JSON Array from JSON String JArray myJsonObj = JArray.Parse(thisJSONstring); // Create mutable array using JSON String Array var myArray = new MutableArrayObject(); myArray.SetJSON(thisJSONstring); // <.> // Create a new documenty for each array element for (int i = 0; i < myArray.Count; i++) { var dict = myArray.GetDictionary(i); var docid = myArray[i].Dictionary.GetString("id"); var newdoc = new MutableDocument(docid, dict.ToDictionary()); // <.> dbNew.Save(newdoc); } // Get one of the created docs and iterate through one of the embedded arrays var extendedDoc = dbNew.GetDocument("1002"); var features = extendedDoc.GetArray("features"); // <.> foreach (string feature in features) { System.Console.Write(feature); // <.> //process array item as required } var featuresJSON = extendedDoc.GetArray("features").ToJSON(); // <.> // end::tojson-array[] }
public async Task <bool> UpdateItemAsync(SeasonalItem item) { using (var doc = _db.GetDocument(CoreApp.DocId)) using (var mdoc = doc.ToMutable()) using (MutableArrayObject listItems = mdoc.GetArray(CoreApp.ArrKey)) { var dictObj = listItems.GetDictionary(item.Index); dictObj.SetString("key", item.Name); dictObj.SetInt("value", item.Quantity); var blob = new Blob("image/png", item.ImageByteArray); dictObj.SetBlob("image", blob); _db.Save(mdoc); } return(await Task.FromResult(true)); }
public void TestArrayFragmentSetArrayObject() { var doc = new MutableDocument("doc1"); doc["array"].Value = new List <object>(); var array = new MutableArrayObject(); array.AddString("Jason").AddDouble(5.5).AddBoolean(true); doc["array"].Array.AddArray(array); SaveDocument(doc, d => { d["array"][0][0].String.Should().Be("Jason", "because that is the value that was stored"); d["array"][0][1].Double.Should().Be(5.5, "because that is the value that was stored"); d["array"][0][2].Boolean.Should().Be(true, "because that is the value that was stored"); }); }
public void TestArrayObject() { var now = DateTimeOffset.UtcNow; var nowStr = now.ToString("o"); var ao = new MutableArrayObject(); var blob = new Blob("text/plain", Encoding.UTF8.GetBytes("Winter is coming")); var dict = new MutableDictionaryObject(new Dictionary <string, object> { ["foo"] = "bar" }); ao.AddFloat(1.1f); ao.AddBlob(blob); ao.AddDate(now); ao.AddDictionary(dict); var obj = new Object(); var arr = new MutableArrayObject(new[] { 5, 4, 3, 2, 1 }); ao.InsertValue(0, obj); ao.InsertInt(0, 42); ao.InsertLong(0, Int64.MaxValue); ao.InsertFloat(0, 3.14f); ao.InsertDouble(0, Math.PI); ao.InsertBoolean(0, true); ao.InsertBlob(0, blob); ao.InsertDate(0, now); ao.InsertArray(0, arr); ao.InsertDictionary(0, dict); ao.Should().Equal(dict, arr, nowStr, blob, true, Math.PI, 3.14f, Int64.MaxValue, 42, obj, 1.1f, blob, nowStr, dict); ao.SetLong(0, Int64.MaxValue); ao.SetFloat(1, 3.14f); ao.SetDouble(2, Math.PI); ao.SetBoolean(3, true); ao.SetBlob(4, blob); ao.SetArray(5, arr); ao.SetDictionary(6, dict); ao.SetDate(7, now); ao.Should().Equal(Int64.MaxValue, 3.14f, Math.PI, true, blob, arr, dict, nowStr, 42, obj, 1.1f, blob, nowStr, dict); }
public void TestDictionaryFragmentSetArray() { var doc = new MutableDocument("doc1"); var array = new MutableArrayObject(); array.AddInt(0).AddInt(1).AddInt(2); doc["array"].Value = array; 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].Int.Should().Be(0, "because that is what was stored"); d["array"][1].Int.Should().Be(1, "because that is what was stored"); d["array"][2].Int.Should().Be(2, "because that is what was stored"); d["array"][3].Value.Should().BeNull("because that is an invalid index"); d["array"][3].Exists.Should().BeFalse("because there is no data at the invalid index"); }); }
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); }