Ejemplo n.º 1
0
        /// <summary>Sets the expression.</summary>
        /// <param name="field">The field.</param>
        /// <param name="value">The value.</param>
        /// <param name="comparison">The comparison.</param>
        public void SetExpression(SearchField field, string value, ComparisonType comparison)
        {
            if (!string.IsNullOrEmpty(value) && Enum.IsDefined(typeof(SearchField), field) && Enum.IsDefined(typeof(ComparisonType), comparison))
            {
                Expression = "{'" + field.ToString() + "': {'" + comparison.ToString() + "': '" + value + "'}}";

                Value = value;
            }
        }
Ejemplo n.º 2
0
 private void SetAllEmptyRelationsToAnd(TreeNodeCollection treeNodeCollection)
 {
     foreach (TreeNode item in treeNodeCollection)
     {
         SearchField searchField = item.Tag as SearchField;
         if (searchField.Relation == SearchField.Relations.None)
         {
             searchField.Relation = SearchField.Relations.And;
             item.Tag             = searchField;
             item.Text            = searchField.ToString();
         }
         SetAllEmptyRelationsToAnd(item.Nodes);
     }
 }
Ejemplo n.º 3
0
        private void queryTreeView_DragDrop(object sender, DragEventArgs e)
        {
            TreeNode dragedNode;

            if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            {
                TreeNode destinationNode = queryTreeView.GetNodeAt(queryTreeView.PointToClient(new Point(e.X, e.Y)));
                dragedNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
                if (destinationNode != null && destinationNode != dragedNode)
                {
                    if (e.Effect == DragDropEffects.Move)
                    {
                        destinationNode.Nodes.Add((TreeNode)dragedNode.Clone());
                        dragedNode.Remove();
                        destinationNode.ExpandAll();
                    }
                    else if (e.Effect == DragDropEffects.Copy)
                    {
                        destinationNode.Nodes.Add((TreeNode)dragedNode.Clone());
                        destinationNode.ExpandAll();
                    }
                }
                else if (destinationNode == null)
                {
                    if (e.Effect == DragDropEffects.Move)
                    {
                        queryTreeView.Nodes.Add((TreeNode)dragedNode.Clone());
                        dragedNode.Remove();
                        queryTreeView.ExpandAll();
                    }
                    else if (e.Effect == DragDropEffects.Copy)
                    {
                        queryTreeView.Nodes.Add((TreeNode)dragedNode.Clone());
                        queryTreeView.ExpandAll();
                    }
                }
                if ((queryTreeView.Nodes[0].Tag as SearchField).Relation != SearchField.Relations.None)
                {
                    SetAllEmptyRelationsToAnd(queryTreeView.Nodes);
                    SearchField searchField = queryTreeView.Nodes[0].Tag as SearchField;
                    searchField.Relation        = SearchField.Relations.None;
                    queryTreeView.Nodes[0].Tag  = searchField;
                    queryTreeView.Nodes[0].Text = searchField.ToString();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Queries the SharePoint Web Service.
        /// </summary>
        /// <param name="keyword">Keyword to search for.</param>
        /// <param name="searchfields">Fields to return.</param>
        /// <returns>Collection with results.</returns>
        public List <Dictionary <string, string> > Search(string keyword, SearchField searchfields)
        {
            List <Dictionary <string, string> > items = new List <Dictionary <string, string> >();
            StringBuilder postXml = new StringBuilder();
            XmlDocument   doc     = new XmlDocument();

            QueryService query = new QueryService();

            query.Credentials = Credentials;
            query.Url         = Url.ToString().Replace("lists.asmx", "search.asmx");
            query.Proxy       = GetProxy();

            ServicePointManager.ServerCertificateValidationCallback += ((sender, certificate, chain, sslPolicyErrors) => true);

            //Start fill postXml
            postXml.Append(String.Format("<QueryPacket xmlns=\"urn:Microsoft.Search.Query\"><Query><SupportedFormats><Format>urn:Microsoft.Search.Response.Document:Document</Format></SupportedFormats><Context><QueryText type=\"STRING\" language=\"en-us\">{0}</QueryText></Context><Range><StartAt>1</StartAt><Count>50</Count></Range><Properties>", keyword));
            foreach (string field in searchfields.ToString().Replace(" ", "").Split(','))
            {
                postXml.Append(String.Format("<Property name=\"{0}\"/>", field));
            }
            postXml.Append("<Property name=\"Write\"/></Properties><EnableStemming>true</EnableStemming><TrimDuplicates>true</TrimDuplicates><IgnoreAllNoiseQuery>true</IgnoreAllNoiseQuery><ImplicitAndBehavior>true</ImplicitAndBehavior><IncludeRelevanceResults>true</IncludeRelevanceResults><IncludeSpecialTermResults>true</IncludeSpecialTermResults><IncludeHighConfidenceResults>true</IncludeHighConfidenceResults></Query></QueryPacket>");
            //End fill postXml

            doc.LoadXml(query.Query(postXml.ToString()));

            foreach (XmlNode node in RunXPathQuery(doc, "//r:Document"))
            {
                Dictionary <string, string> item = new Dictionary <string, string>();

                foreach (XmlAttribute attrib in node.Attributes)
                {
                    item.Add(attrib.Name, attrib.Value);
                }

                items.Add(item);
            }

            return(items);
        }