Beispiel #1
0
        private int FindPart1Solution(DesignDocument doc)
        {
            List <Triangle> triangleSpecs = ParseTriangleSpecs(doc.TrianglesList);
            int             count         = triangleSpecs.Where(x => x.ValidTriangle == true).Count();

            return(count);
        }
Beispiel #2
0
        public void Repository_loads_design_document_from_session()
        {
            DesignDocument design = null;

            if (_sx.IsEnrolled("_design/widget"))
            {
                design = _sx.Load <DesignDocument>("_design/widget");
            }
            else
            {
                design = new DesignDocument
                {
                    Language = "javascript",
                };
            }
            design.Views = new Dictionary <string, View>
            {
                { "all-widgets", new View {
                      Map = @"function(doc) { emit(null, null); }"
                  } },
                { "all-manufacturers", new View()
                  {
                      Map    = @"function(doc) { emit(doc.Manufacturer, 1); }",
                      Reduce = @"function(keys, values, rereduce) { return sum(values); }"
                  } }
            };
            _sx.Save(design, "_design/widget");

            var r = new Repository <Widget>(_sx);

            Assert.AreEqual(2, r.Queries.Count);
        }
Beispiel #3
0
        // GET: Day3
        public ActionResult Index()
        {
            DesignDocument doc = new DesignDocument();

            doc.Part1 = true; //default to part 1, allow user to select part 2 later
            return(View(doc));
        }
Beispiel #4
0
 private void VerifyDesignDoc(DesignDocument expected, DesignDocument result)
 {
     Assert.Equal("test_ddoc", result.Name);
     Assert.Single(result.Views);
     Assert.Equal(expected.Views.First().Value.Map, result.Views.First().Value.Map);
     Assert.Equal(expected.Views.First().Value.Reduce, result.Views.First().Value.Reduce);
 }
Beispiel #5
0
        private void NewDesign_Click(object sender, RoutedEventArgs e)
        {
            //OpenFileDialog ofd = new OpenFileDialog();
            //ofd.Filter = "TwoRatChat templates|*.trct";
            //ofd.InitialDirectory = App.DataFolder + "\\templates";
            //var ret = ofd.ShowDialog();

            //if( ret.HasValue && ret.Value ) {

            //}

            SelectTemplate st  = new SelectTemplate();
            var            ret = st.ShowDialog();

            if (ret.HasValue && ret.Value)
            {
                _document = new DesignDocument();
                if (_document.CreateNew(st.FileName))
                {
                    rebuildEditors();
                }
                else
                {
                    MessageBox.Show("Template load error!");
                }
            }
        }
Beispiel #6
0
        private void __init(Session sx, DesignDocument design)
        {
            Queries = new Dictionary <string, Query <TEntity> >();
            Session = sx;

            Design = design;
            if (null == Design)
            {
                try
                {
                    Design = Session.Load <DesignDocument>(GetDesignDocumentName());
                }
                catch
                {
                    Design          = new DesignDocument();
                    Design.Language = "javascript";
                    Design.Views    = new Dictionary <string, View>();
                    Session.Save(Design, GetDesignDocumentName());
                }
            }

            foreach (var v in Design.Views)
            {
                CreateQuery(v.Key, v.Value);
            }
        }
Beispiel #7
0
        private int FindPart2Solution(DesignDocument doc)
        {
            List <Triangle> triangleSpecs          = ParseTriangleSpecs(doc.TrianglesList);
            List <Triangle> correctedTriangleSpecs = GetVerticalTriangles(triangleSpecs);
            int             count = correctedTriangleSpecs.Where(x => x.ValidTriangle == true).Count();

            return(count);
        }
Beispiel #8
0
        public void Session_can_save_design_document()
        {
            var d = new DesignDocument {
                Language = "javascript"
            };

            _sx.Save(d, "_design/foo");
            Assert.True(_sx.ListDocuments().Any(x => x.Id == "_design/foo"));
        }
        public async Task TestIndexManager()
        {
            var cluster = _fixture.Cluster;
            var bucket  = await _fixture.GetDefaultBucket().ConfigureAwait(false);

            var manager = bucket.ViewIndexes;

            var designDoc = new DesignDocument
            {
                Name  = "test_ddoc",
                Views = new Dictionary <string, View>
                {
                    {
                        "test_view",
                        new View
                        {
                            Map    = "function (doc, meta) { emit(meta.id, null); }",
                            Reduce = "_count"
                        }
                    }
                }
            };

            try
            {
                // upsert
                await manager.UpsertDesignDocumentAsync(designDoc, DesignDocumentNamespace.Development).ConfigureAwait(false);

                await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false);

                // get
                var getResult = await manager.GetDesignDocumentAsync(designDoc.Name, DesignDocumentNamespace.Development).ConfigureAwait(false);

                VerifyDesignDoc(designDoc, getResult);

                // publish
                await manager.PublishDesignDocumentAsync(designDoc.Name).ConfigureAwait(false);

                await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false);

                // get all
                var getAllResult =
                    (await manager.GetAllDesignDocumentsAsync(DesignDocumentNamespace.Production).ConfigureAwait(false)).ToList();
                var result = getAllResult.First(p => p.Name == "test_ddoc");
                VerifyDesignDoc(designDoc, result);
            }
            finally
            {
                // drop
                await manager.DropDesignDocumentAsync(designDoc.Name, DesignDocumentNamespace.Production).ConfigureAwait(false);
            }
        }
Beispiel #10
0
        public void Session_preserves_design_document_when_reset()
        {
            var s = _cx.CreateSession(_sx.Database);
            var d = new DesignDocument {
                Language = "javascript"
            };

            s.Save(d, "_design/bang");
            s.Reset();
            var e = s.Load <DesignDocument>("_design/bang");

            Assert.That(e, Is.SameAs(d));
        }
Beispiel #11
0
        public ActionResult CountTriangles(DesignDocument doc)
        {
            TriangleCount count = new TriangleCount();

            if (doc.Part1 == true)
            {
                count.TotalValidTriangles = FindPart1Solution(doc);
            }
            else
            {
                count.TotalValidTriangles = FindPart2Solution(doc);
            }

            return(PartialView("TriangleCount", count));
        }
Beispiel #12
0
        public async Task TestIndexManager()
        {
            var cluster = _fixture.Cluster;
            var bucket  = await _fixture.GetDefaultBucket();

            var manager = bucket.ViewIndexes;

            var designDoc = new DesignDocument
            {
                Name  = "test_ddoc",
                Views = new Dictionary <string, View>
                {
                    {
                        "test_view",
                        new View
                        {
                            Map    = "function (doc, meta) { emit(meta.id, null); }",
                            Reduce = "_count"
                        }
                    }
                }
            };

            try
            {
                // upsert
                await manager.UpsertDesignDocumentAsync(designDoc, DesignDocumentNamespace.Development);

                // get
                var getResult = await manager.GetDesignDocumentAsync(designDoc.Name, DesignDocumentNamespace.Development);

                VerifyDesignDoc(designDoc, getResult);

                // publish
                await manager.PublishDesignDocumentAsync(designDoc.Name);

                // get all
                var getAllResult = await manager.GetAllDesignDocumentsAsync(DesignDocumentNamespace.Production);

                Assert.Single(getAllResult);
                VerifyDesignDoc(designDoc, getAllResult.First());
            }
            finally
            {
                // drop
                await manager.DropDesignDocumentAsync(designDoc.Name, DesignDocumentNamespace.Production);
            }
        }
Beispiel #13
0
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (_document != null)
            {
                if (!string.IsNullOrEmpty(_document.FileName))
                {
                    string f = _document.FileName;
                    _document.Save();
                    _document = new DesignDocument();
                    _document.Open(f);
                    rebuildEditors();
                    _document.Save();
                }
            }

            MainWindow.ReloadSkin();
        }
Beispiel #14
0
        private void OpenDesign_Click(object sender, RoutedEventArgs e)
        {
            ListSkinsDialog lsd = new ListSkinsDialog();
            var             ret = lsd.ShowDialog();

            if (ret.HasValue && ret.Value)
            {
                _document = new DesignDocument();
                if (_document.Open(App.MapFileName("\\" + lsd.SkinName)))
                {
                    rebuildEditors();
                }
                else
                {
                    editorRoot.Children.Clear();
                    MessageBox.Show("Сохранение не принадлежит шаблону и изменено быть не может.");
                }
            }
        }
        public async Task <DocumentHeaderResponse> CreateDesignDocument()
        {
            var doc = new DesignDocument()
            {
                views = new Dictionary <string, View>()
                {
                    { $"{EntityName}-all", new View()
                      {
                          map = "function (doc) {\n  emit(doc._id, doc);\n}"
                      } }
                },
                language = "javascript"
            };

            var request = new PutDocumentRequest($@"_design/{EntityName}", JsonConvert.SerializeObject(doc));

            var response = await Client.Documents.PutAsync(request);

            return(response);
        }
		public void ShouldCopyWithRevisionProperly()
		{
			var json = JsonValue.Parse(@"{
				""_id"": ""_design/bin_doc1"",
				""some_property1"": ""test content""
			}") as JsonObject;

			var document = new DesignDocument(json);
			var copiedDocument = document.CopyWithRevision("3-ee7084f94345720bf9fdcd8f087e5518");

			Assert.Equal("_design/bin_doc1", copiedDocument.Id);
			Assert.Equal("3-ee7084f94345720bf9fdcd8f087e5518", copiedDocument.Revision);
			Assert.Equal(
				JsonValue.Parse(@"{
					""_id"": ""_design/bin_doc1"",
					""some_property1"": ""test content"",
					""_rev"": ""3-ee7084f94345720bf9fdcd8f087e5518""
				}"),
				copiedDocument.RawJsonObject,
				new JsonObjectComparier()
			);
		}
Beispiel #17
0
        //TODO: Automate software phases
        public static void CheckDesign(DesignDocument document)
        {
            var   actors    = GameSettings.Instance.sActorManager.Actors;
            Actor bestActor = actors.FirstOrDefault();

            foreach (var actor in actors)
            {
                if (actor.employee.GetSkill(Employee.EmployeeRole.Designer) > bestActor.employee.GetSkill(Employee.EmployeeRole.Designer))
                {
                    bestActor = actor;
                }
            }

            if (!document.HasFinished)
            {
                document.DoWork(bestActor, 1f, 1f, false);
            }

            if (document.Done)
            {
                document.PromoteAction();
            }
        }
Beispiel #18
0
        public void Repository_can_create_queries_from_design()
        {
            var design = new DesignDocument
            {
                Language = "javascript",
                Views    = new Dictionary <string, View>
                {
                    { "all-widgets", new View {
                          Map = @"function(doc) { emit(null, null); }"
                      } },
                    { "all-manufacturers", new View()
                      {
                          Map    = @"function(doc) { emit(doc.Manufacturer, 1); }",
                          Reduce = @"function(keys, values, rereduce) { return sum(values); }"
                      } }
                }
            };
            var r = new Repository <Widget>(_sx, design);

            Assert.IsNotNull(r.Queries["all-widgets"]);
            Assert.IsNotNull(r.Queries["all-manufacturers"]);
            Assert.AreEqual("widget", r.Queries["all-manufacturers"].Design);
            Assert.IsTrue(r.Queries["all-manufacturers"].Group);
        }
        public async Task Can_get_view()
        {
            var bucket = await _fixture.Cluster.BucketAsync("default");

            var manager = bucket.ViewIndexes;

            var original = new DesignDocument
            {
                Name  = "test",
                Views = new Dictionary <string, View>
                {
                    {
                        "by_name", new View
                        {
                            Map    = "function (doc, meta) { emit(meta.id, null); }",
                            Reduce = "_count"
                        }
                    }
                }
            };

            try
            {
                // create
                await manager.CreateAsync(original);

                // upsert
                await manager.UpsertAsync(original);

                // get
                var designDoc = await manager.GetAsync(original.Name);

                Assert.Equal(original.Name, designDoc.Name);
                Assert.Single(original.Views);
                Assert.Equal(original.Views.First().Key, designDoc.Views.First().Key);
                Assert.Equal(original.Views.First().Value.Map, designDoc.Views.First().Value.Map);
                Assert.Equal(original.Views.First().Value.Reduce, designDoc.Views.First().Value.Reduce);

                // publish (& get again)
                await manager.PublishAsync(original.Name);

                designDoc = await manager.GetAsync(original.Name, options => options.WithIsProduction(true));

                Assert.Equal(original.Name, designDoc.Name);
                Assert.Single(original.Views);
                Assert.Equal(original.Views.First().Key, designDoc.Views.First().Key);
                Assert.Equal(original.Views.First().Value.Map, designDoc.Views.First().Value.Map);
                Assert.Equal(original.Views.First().Value.Reduce, designDoc.Views.First().Value.Reduce);

                // get all
                var getAllResult = await manager.GetAllAsync();

                Assert.Single(getAllResult);

                var ddoc = getAllResult.First();
                Assert.Equal(original.Name, ddoc.Name);
                Assert.Single(original.Views);
                Assert.Equal(original.Views.First().Key, ddoc.Views.First().Key);
                Assert.Equal(original.Views.First().Value.Map, ddoc.Views.First().Value.Map);
                Assert.Equal(original.Views.First().Value.Reduce, ddoc.Views.First().Value.Reduce);
            }
            finally
            {
                // drop
                await manager.DropAsync("dev_test", options => options.WithIsProduction(true));
            }
        }
        public async Task VerifyBeerSampleView()
        {
            var bucketName = "beer-sample";
            var viewName = "brewery_beers";
            var designDocName = "beer";
            var mapFunction = @"function(doc, meta) {
  switch(doc.type) {
  case ""brewery"":
            emit([meta.id]);
            break;
            case ""beer"":
            if (doc.brewery_id)
            {
                emit([doc.brewery_id, meta.id]);
            }
            break;
        }
    }";
            var reduce = "_count";
            var designDoc = new DesignDocument()
            {
                Name = designDocName,
                Views = new Dictionary<string, View>()
                {
                    {
                        viewName,
                        new View() {
                            Map = mapFunction,
                            Reduce = reduce
                        }
                    }
                }
            };

            var beerSample = await _fixture.Cluster.BucketAsync(bucketName);
            try
            {
                _ = await beerSample.ViewIndexes.GetDesignDocumentAsync(designDocName, DesignDocumentNamespace.Production);
                _outputHelper.WriteLine($"'{designDocName}' already exists.");
                return;
            }
            catch (DesignDocumentNotFoundException)
            {
                _outputHelper.WriteLine($"'{designDocName}' not found.");
            }

            _outputHelper.WriteLine($"Attempting to create '{designDocName}/{viewName}' view.");


            await beerSample.ViewIndexes.UpsertDesignDocumentAsync(designDoc, DesignDocumentNamespace.Production);

            var sw = Stopwatch.StartNew();
            while (sw.Elapsed < TimeSpan.FromSeconds(120))
            {
                try
                {
                    _ = await beerSample.ViewIndexes.GetDesignDocumentAsync(designDocName, DesignDocumentNamespace.Production);
                    break;
                }
                catch (DesignDocumentNotFound)
                {
                    _outputHelper.WriteLine("DesignDocumentNotFound.  Sleeping.");
                    await Task.Delay(TimeSpan.FromSeconds(5));
                }
            }
        }
Beispiel #21
0
 public Repository(Session sx, DesignDocument design)
 {
     __init(sx, design);
 }