Example #1
0
        private bool RunView(CouchViewDefinition viewDefinition)
        {
            var root      = tvResults.Nodes.Add(viewDefinition.Path() + "/" + txtParams.Text);
            var viewQuery = viewDefinition.Query();

            if (!String.IsNullOrEmpty(txtParams.Text))
            {
                foreach (var optionSet in txtParams.Text.Split('&'))
                {
                    var option = optionSet.Split('=');
                    if (option.Length != 2)
                    {
                        MessageBox.Show(txtParams.Text + " is not a valid view query string (needs to be in the form name=value[&name2=value2]).", "Invalid query", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }

                    viewQuery.Options[option[0]] = option[1];
                }
            }

            try
            {
                ShowResult(root, viewQuery.GetResult().result, null);
            }
            catch (Exception ex)
            {
                root.Nodes.Add("Error: " + ex.Message);
                MessageBox.Show(ex.ToString(), "Exception running view", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Creates the view node.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="view">The view.</param>
        /// <returns></returns>
        private TreeNode CreateViewNode(TreeNode parent, CouchViewDefinition view)
        {
            var node = parent.Nodes.Add(view.Name, view.Name);

            node.Tag                = view;
            node.ImageIndex         = 2;
            node.SelectedImageIndex = 2;
            return(node);
        }
Example #3
0
        public void SetUp()
        {
            var host = ConfigurationManager.AppSettings["CouchHost"] ?? "localhost";
            var port = Convert.ToInt32(ConfigurationManager.AppSettings["CouchPort"] ?? "5984");
            server = new CouchServer(host, port);
            db = server.GetNewDatabase(DbName);
            Car car = null;

            for (int i = 0; i < 10; i++)
            {
                car = new Car("Saab", "93", 170 + i);
                db.SaveDocument(car);
            }
            tempView = db.NewTempView("test", "test", "if (doc.docType && doc.docType == 'car') emit(doc.Hps, doc);");
        }
Example #4
0
        public async Task <CouchEntityInfo> PutView(string db, string designName, CouchViewDefinition couchView)
        {
            if (couchView == null)
            {
                throw new ArgumentNullException(nameof(couchView));
            }
            var design = await GetDesign(db, designName);

            var index = design.Views.FirstOrDefault(p => p.Name == couchView.Name);

            if (index == null)
            {
                throw new CouchException($"Can`t update view {db}/_design/{designName}/{couchView.Name} : View not found.");
            }
            index.Mapping = couchView.Mapping;
            return(await PutDesign(db, design));
        }
Example #5
0
        /// <summary>
        /// Processes the expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="db">The db.</param>
        /// <param name="definition">The view definition.</param>
        /// <returns></returns>
        public ExpressionVisitor ProcessExpression(Expression expression, CouchDatabase db, CouchViewDefinition definition)
        {
            Query = db.Query(definition);
            VisitExpression(expression);

            switch (keys.Count)
            {
                case 0: // 0 keys means it's a range query. do nothing.
                    break;
                case 1: // 1 key means it's a single Equals or a Contains on a single.
                    Query.Key(keys[0]);
                    break;
                default: // neither 0 nor 1 means that we've got a set of keys to test.
                    Query.Keys(keys);
                    break;
            }

            return this;
        }
Example #6
0
        public async Task <CouchDesignDocument> CreateView(string db, string designName, CouchViewDefinition couchView)
        {
            if (couchView == null)
            {
                throw new ArgumentNullException(nameof(couchView));
            }
            var design = await GetDesign(db, designName);

            if (design.Views.Any(p => p.Name == couchView.Name))
            {
                throw new CouchException($"Can`t create view {db}/_design/{designName}/{couchView.Name} : View with the same name already exists in document.");
            }

            design.Views = new List <CouchViewDefinition>(design.Views)
            {
                couchView
            };
            await PutDesign(db, design);

            return(design);
        }