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");
            });
        }
Пример #2
0
        private MutableDocument CreateDocumentWithTag(string id, string tag)
        {
            var doc = new MutableDocument(id);

            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-0002");
            doc.SetArray("phones", phones);

            doc.SetDate("updated", DateTimeOffset.UtcNow);

            return(doc);
        }
Пример #3
0
        private static MutableDictionaryObject ConvertDictionary(IDictionary <string, object> dictionary)
        {
            var subdocument = new MutableDictionaryObject();

            subdocument.SetData(dictionary);
            return(subdocument);
        }
Пример #4
0
        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);
        }
Пример #5
0
        public void TestMutableDictWithJsonString()
        {
            var dic     = PopulateDictData();
            var dicJson = JsonConvert.SerializeObject(dic, jsonSerializerSettings);
            var md      = new MutableDictionaryObject(dicJson);

            ValidateValuesInMutableDictFromJson(dic, md);
        }
Пример #6
0
        public void TestDictionaryWithULong()
        {
            using (var doc = new MutableDocument("test_ulong")) {
                var dict = new MutableDictionaryObject();
                dict.SetValue("high_value", UInt64.MaxValue);
                doc.SetDictionary("nested", dict);
                Db.Save(doc);
            }

            using (var doc = Db.GetDocument("test_ulong")) {
                doc["nested"]["high_value"].Value.Should().Be(UInt64.MaxValue);
            }
        }
        public DesignFlightBookingViewModel()
        {
            var data = new MutableDictionaryObject()
                       .SetString("destinationairport", "BBB")
                       .SetString("sourceairport", "AAA")
                       .SetString("date", DateTime.Now.ToString())
                       .SetDouble("price", 999.99)
                       .SetString("name", "Airplane Airlines")
                       .SetString("flight", "AB123");



            BookingsList.Add(new BookingCellModel(data));
        }
        public void TestSetOthers()
        {
            // Uncovered by other tests
            var dict = new MutableDictionaryObject();

            dict.SetFloat("pi", 3.14f);
            dict.SetDouble("better_pi", 3.14159);
            dict.SetBoolean("use_better", true);

            dict.GetFloat("pi").Should().Be(3.14f);
            dict.GetDouble("better_pi").Should().Be(3.14159);
            dict.GetDouble("pi").Should().BeApproximately(3.14, 0.00001);
            dict.GetFloat("better_pi").Should().BeApproximately(3.14159f, 0.0000000001f);
            dict.GetBoolean("use_better").Should().BeTrue();
        }
Пример #9
0
        public void TestMutableDictSetJsonWithInvalidParam()
        {
            var md = new MutableDictionaryObject();
            // with random string
            Action badAction = (() => md.SetJSON("random string"));

            badAction.Should().Throw <CouchbaseLiteException>(CouchbaseLiteErrorMessage.InvalidJSON);

            //with array json string
            string[] arr  = { "apple", "banana", "orange" };
            var      jarr = JsonConvert.SerializeObject(arr);

            badAction = (() => md.SetJSON(jarr));
            badAction.Should().Throw <CouchbaseLiteException>(CouchbaseLiteErrorMessage.InvalidJSON);
        }
        protected override DictionaryObject DoPrediction(DictionaryObject input)
        {
            var numbers = input.GetArray("numbers");

            if (numbers == null)
            {
                return(null);
            }

            var output = new MutableDictionaryObject();

            output.SetLong("sum", numbers.Cast <long>().Sum());
            output.SetLong("min", numbers.Cast <long>().Min());
            output.SetLong("max", numbers.Cast <long>().Max());
            output.SetDouble("avg", numbers.Cast <long>().Average());
            return(output);
        }
Пример #11
0
        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 void TestQueryPredictionValues()
        {
            CreateDocument(1, 2, 3, 4, 5);
            CreateDocument(6, 7, 8, 9, 10);

            var aggregateModel = new AggregateModel();

            aggregateModel.RegisterModel();

            var model      = nameof(AggregateModel);
            var input      = AggregateModel.CreateInput("numbers");
            var prediction = Function.Prediction(model, input);

            using (var q = QueryBuilder.Select(SelectResult.Property("numbers"),
                                               SelectResult.Expression(prediction.Property("sum")).As("sum"),
                                               SelectResult.Expression(prediction.Property("min")).As("min"),
                                               SelectResult.Expression(prediction.Property("max")).As("max"),
                                               SelectResult.Expression(prediction.Property("avg")).As("avg"))
                           .From(DataSource.Database(Db))) {
                var rows = VerifyQuery(q, (n, result) =>
                {
                    var numbers = result.GetArray(0);
                    var dict    = new MutableDictionaryObject();
                    dict.SetArray("numbers", numbers);
                    var expected = aggregateModel.Predict(dict);

                    var sum = result.GetInt(1);
                    var min = result.GetInt(2);
                    var max = result.GetInt(3);
                    var avg = result.GetDouble(4);

                    result.GetInt("sum").Should().Be(sum);
                    result.GetInt("min").Should().Be(min);
                    result.GetInt("max").Should().Be(max);
                    result.GetDouble("avg").Should().Be(avg);

                    sum.Should().Be(expected.GetInt("sum"));
                    min.Should().Be(expected.GetInt("min"));
                    max.Should().Be(expected.GetInt("max"));
                    avg.Should().Be(expected.GetDouble("avg"));
                });

                rows.Should().Be(2);
            }
        }
Пример #13
0
        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);
        }
Пример #14
0
        public void TestCreateDictionary()
        {
            var address = new MutableDictionaryObject();

            address.Count.Should().Be(0, "because the dictionary is empty");
            address.ToDictionary().Should().BeEmpty("because the dictionary is empty");

            var doc1 = new MutableDocument("doc1");

            doc1.SetDictionary("address", address);
            doc1.GetDictionary("address")
            .Should()
            .BeSameAs(address, "because the document should return the same instance");

            Db.Save(doc1);
            var gotDoc = Db.GetDocument("doc1");

            gotDoc.GetDictionary("address").ToDictionary().Should().BeEmpty("because the content should not have changed");
        }
Пример #15
0
        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));
        }
Пример #16
0
        public void TestEnumeratingDictionary()
        {
            var dict = new MutableDictionaryObject();

            for (int i = 0; i < 20; i++)
            {
                dict.SetInt($"key{i}", i);
            }

            var content = dict.ToDictionary();
            var result  = new Dictionary <string, object>();

            foreach (var item in dict)
            {
                result[item.Key] = item.Value;
            }

            result.ShouldBeEquivalentTo(content, "because that is the correct content");
            content = dict.Remove("key2").SetInt("key20", 20).SetInt("key21", 21).ToDictionary();

            result = new Dictionary <string, object>();
            foreach (var item in dict)
            {
                result[item.Key] = item.Value;
            }

            result.ShouldBeEquivalentTo(content, "because that is the correct content");

            var doc = new MutableDocument("doc1");

            doc.SetDictionary("dict", dict);
            SaveDocument(doc, d =>
            {
                result      = new Dictionary <string, object>();
                var dictObj = d.GetDictionary("dict");
                foreach (var item in dictObj)
                {
                    result[item.Key] = item.Value;
                }

                result.ShouldBeEquivalentTo(content, "because that is the correct content");
            });
        }
Пример #17
0
        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 void JsonApiDictionary()
        {
            var ourdbname = "ournewdb";

            if (Database.Exists(ourdbname, "/"))
            {
                Database.Delete(ourdbname, "/");
            }
            Database dbNew = new Database(ourdbname);

            // tag::tojson-dictionary[]

            // Get dictionary from JSONstring
            var aJSONstring = "{'id':'1002','type':'hotel','name':'Hotel Ned','city':'Balmain','country':'Australia','description':'Undefined description for Hotel Ned','features':['Cable TV','Toaster','Microwave']}".Replace("'", "\"");
            var myDict      = new MutableDictionaryObject(json: aJSONstring); // <.>

            // use dictionary to get name value
            var name = myDict.GetString("name");


            // Iterate through keys
            foreach (string key in myDict.Keys)
            {
                System.Console.WriteLine("Data -- {0} = {1}", key, myDict.GetValue(key).ToString());
            }
            // end::tojson-dictionary[]

            /*
             * // tag::tojson-dictionary-output[]
             *
             *  mono-stdout: Data -- id = 1002
             *  mono-stdout: Data -- type = hotel
             *  mono-stdout: Data -- name = Hotel Ned
             *  mono-stdout: Data -- city = Balmain
             *  mono-stdout: Data -- country = Australia
             *  mono-stdout: Data -- description = Undefined description for Hotel Ned
             *  mono-stdout: Data -- features = Couchbase.Lite.MutableArrayObject
             *
             * // end::tojson-dictionary-output[]
             */
        } /* end of func */
Пример #19
0
        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);
        }
Пример #20
0
        public void TestTypesInDictionaryToJSON()
        {
            var dic = PopulateDictData();
            var md  = new MutableDictionaryObject();

            foreach (var item in dic)
            {
                md.SetValue(item.Key, item.Value); // platform dictionary and list or array will be converted into Couchbase object in SetValue method
            }

            using (var doc = new MutableDocument("doc1")) {
                doc.SetDictionary("dict", md);
                Db.Save(doc);
            }

            using (var doc = Db.GetDocument("doc1")) {
                var dict = doc.GetDictionary("dict");
                var json = dict.ToJSON();
                ValidateToJsonValues(json, dic);
            }
        }
        protected override DictionaryObject DoPrediction(DictionaryObject input)
        {
            var blob = input.GetBlob("text");

            if (blob == null)
            {
                return(null);
            }

            ContentType = blob.ContentType;

            var text = Encoding.UTF8.GetString(blob.Content);
            var wc   = text.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length;
            var sc   = text.Split('.', StringSplitOptions.RemoveEmptyEntries).Length;

            var output = new MutableDictionaryObject();

            output.SetInt("wc", wc);
            output.SetInt("sc", sc);
            return(output);
        }
Пример #22
0
        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");
        }
Пример #23
0
        public bool Save(ISaveable aSauver)
        {
            string docId = $"{aSauver.Table}_{Guid.NewGuid()}";

            ITechnicalKey technicalKey = aSauver as ITechnicalKey;
            IDateable     dateable     = aSauver as IDateable;

            if (technicalKey == null || dateable == null)
            {
                return(false);
            }

            MutableDocument document = null;

            if (string.IsNullOrEmpty(technicalKey.Id))
            {
                technicalKey.Id       = docId;
                dateable.DateCreation = DateTime.Now;
            }
            else
            {
                if (dateable.DateCreation == DateTime.MinValue)
                {
                    dateable.DateCreation = DateTime.Now;
                }
                dateable.DateModif = DateTime.Now;
                document           = _dataBaseGiver.Get().GetDocument(technicalKey.Id).ToMutable();
            }

            MutableDictionaryObject dico = aSauver.DocumentInitialize();

            document = dico.ToDocument(docId, document);

            _dataBaseGiver.Get().Save(document);

            return(true);
        }
Пример #24
0
        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");
            });
        }
Пример #25
0
        public void TestGetValueFromNewEmptyDictionary()
        {
            DictionaryObject dict = new MutableDictionaryObject();

            dict.GetInt("key").Should().Be(0, "because that is the default value");
            dict.GetLong("key").Should().Be(0L, "because that is the default value");
            dict.GetDouble("key").Should().Be(0.0, "because that is the default value");
            dict.GetBoolean("key").Should().Be(false, "because that is the default value");
            dict.GetDate("key").Should().Be(DateTimeOffset.MinValue, "because that is the default value");
            dict.GetBlob("key").Should().BeNull("because that is the default value");
            dict.GetValue("key").Should().BeNull("because that is the default value");
            dict.GetString("key").Should().BeNull("because that is the default value");
            dict.GetDictionary("key").Should().BeNull("because that is the default value");
            dict.GetArray("key").Should().BeNull("because that is the default value");
            dict.ToDictionary().Should().BeEmpty("because the dictionary is empty");

            var doc = new MutableDocument("doc1");

            doc.SetDictionary("dict", dict);

            Db.Save(doc);
            var gotDoc = Db.GetDocument("doc1");

            dict = gotDoc.GetDictionary("dict");
            dict.GetInt("key").Should().Be(0, "because that is the default value");
            dict.GetLong("key").Should().Be(0L, "because that is the default value");
            dict.GetDouble("key").Should().Be(0.0, "because that is the default value");
            dict.GetBoolean("key").Should().Be(false, "because that is the default value");
            dict.GetDate("key").Should().Be(DateTimeOffset.MinValue, "because that is the default value");
            dict.GetBlob("key").Should().BeNull("because that is the default value");
            dict.GetValue("key").Should().BeNull("because that is the default value");
            dict.GetString("key").Should().BeNull("because that is the default value");
            dict.GetDictionary("key").Should().BeNull("because that is the default value");
            dict.GetArray("key").Should().BeNull("because that is the default value");
            dict.ToDictionary().Should().BeEmpty("because the dictionary is empty");
        }
Пример #26
0
        public void TestBlobJsonStringInLayersOfMutableDict()
        {
            var blob = ArrayTestBlob();

            Db.SaveBlob(blob);
            var nestedBlob = new Blob("text/plain", Encoding.UTF8.GetBytes("abcde"));

            Db.SaveBlob(nestedBlob);
            var b1 = new Blob("text/plain", Encoding.UTF8.GetBytes("alpha"));

            Db.SaveBlob(b1);
            var b2 = new Blob("text/plain", Encoding.UTF8.GetBytes("beta"));

            Db.SaveBlob(b2);
            var b3 = new Blob("text/plain", Encoding.UTF8.GetBytes("omega"));

            Db.SaveBlob(b3);

            var KeyValueDictionary = new Dictionary <string, object>()
            {
                { "blob", blob },
                { "blobUnderDict", new Dictionary <string, object>()
                  {
                      { "nestedBlob", nestedBlob }
                  } },
                { "blobUnderArr", new List <object>()
                  {
                      b1, b2, b3
                  } }
            };

            var dicJson = JsonConvert.SerializeObject(KeyValueDictionary);
            var md      = new MutableDictionaryObject(dicJson);

            using (var mdoc = new MutableDocument("doc1")) {
                mdoc.SetDictionary("dict", md);
                Db.Save(mdoc);
            }

            var dic = Db.GetDocument("doc1").GetDictionary("dict");

            var blob1 = dic.GetBlob("blob");

            blob1.Content.Should().NotBeNull();
            blob1.Should().BeEquivalentTo(KeyValueDictionary["blob"]);

            var blob2 = dic.GetDictionary("blobUnderDict").GetBlob("nestedBlob");

            blob2.Content.Should().NotBeNull();
            var d = (Dictionary <string, object>)KeyValueDictionary["blobUnderDict"];

            blob2.Should().BeEquivalentTo(d["nestedBlob"]);

            var blobs    = dic.GetArray("blobUnderArr");
            var cnt      = blobs.Count;
            var blobList = (List <object>)KeyValueDictionary["blobUnderArr"];

            for (int i = 0; i < cnt; i++)
            {
                var b = blobs.GetBlob(i);
                b.Content.Should().NotBeNull();
                b.Should().BeEquivalentTo(blobList[i]);
            }
        }
        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);
        }