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 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)); }
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); }