public int Count(String refID)
        {
            if (!this.Project.DataTypeReferences.Contains(refID))
            {
                throw new BuildException(String.Format("The refid {0} is not defined.", refID));
            }

            XmlQuery RefXmlQuery = (XmlQuery)this.Project.DataTypeReferences[refID];

            XmlDocument XmlDoc = new XmlDocument();

            XmlDoc.Load(RefXmlQuery.File);

            XmlNamespaceManager Manager = new XmlNamespaceManager(XmlDoc.NameTable);

            foreach (XmlNamespace NameSpace in RefXmlQuery.Namespaces)
            {
                if (NameSpace.IfDefined && !NameSpace.UnlessDefined)
                {
                    Manager.AddNamespace(NameSpace.Prefix, NameSpace.Uri);
                }
            }

            return(XmlDoc.SelectNodes(RefXmlQuery.Query, Manager).Count);
        }
        /// <summary>
        /// Query the app list on the server to get the Steam App ID
        /// </summary>
        /// <returns>True if the operation succeeded, false otherwise</returns>
        private static async Task<int> LookupAppIdForApp(CoreDispatcher dispatcher, NvHttp nv, String app)
        {
            XmlQuery appList;
            string appIdStr;

            appList = new XmlQuery(nv.BaseUrl + "/applist?uniqueid=" + nv.GetUniqueId());

            // App list query went well - try to get the app ID
            try
            {
                appIdStr = await appList.SearchElement("App", "AppTitle", app, "ID");
                Debug.WriteLine(appIdStr);
                if (appIdStr == null)
                {
                    // Not found
                    DialogUtils.DisplayDialog(dispatcher, "App Not Found", "App ID Lookup Failed");
                    return 0;
                }
            }
            // Exception connecting to the resource
            catch (Exception e)
            {
                // Steam ID lookup failed
                DialogUtils.DisplayDialog(dispatcher, "Failed to get app ID: " + e.Message, "App ID Lookup Failed");
                return 0;
            }

            // We're in the clear - save the app ID
            return Convert.ToInt32(appIdStr);
        }
 public void SpecifyNeitherLinesNorXmlFileName_ReturnFalse()
 {
     task             = new XmlQuery();
     task.BuildEngine = new MockBuild();
     task.XPath       = "count(/configuration/appSettings/*)";
     Assert.IsFalse(task.Execute(), "Should have failed to execute.");
 }
        /// <summary>
        /// Query the app list on the server to get the Steam App ID
        /// </summary>
        /// <returns>True if the operation succeeded, false otherwise</returns>
        private static async Task <int> LookupAppIdForApp(CoreDispatcher dispatcher, NvHttp nv, String app)
        {
            XmlQuery appList;
            string   appIdStr;

            appList = new XmlQuery(nv.BaseUrl + "/applist?uniqueid=" + nv.GetUniqueId());

            // App list query went well - try to get the app ID
            try
            {
                appIdStr = await appList.SearchElement("App", "AppTitle", app, "ID");

                Debug.WriteLine(appIdStr);
                if (appIdStr == null)
                {
                    // Not found
                    DialogUtils.DisplayDialog(dispatcher, "App Not Found", "App ID Lookup Failed");
                    return(0);
                }
            }
            // Exception connecting to the resource
            catch (Exception e)
            {
                // Steam ID lookup failed
                DialogUtils.DisplayDialog(dispatcher, "Failed to get app ID: " + e.Message, "App ID Lookup Failed");
                return(0);
            }

            // We're in the clear - save the app ID
            return(Convert.ToInt32(appIdStr));
        }
        private XmlQuery CreateXmlQuery(XElement queryXml)
        {
            var outputFileName = queryXml.Attribute("OutputFileName").Value;
            var orderByParam   = queryXml.Element("OrderBy").Value;
            var parsedQuery    = new XmlQuery(outputFileName, orderByParam);

            return(parsedQuery);
        }
Beispiel #6
0
        /// <summary>
        /// Called when a data object is selected.
        /// </summary>
        private void OnDataObjectSelected()
        {
            if (DataObject == null || DataObject == QueryTemplateText)
            {
                return;
            }

            var type  = ObjectTypes.GetObjectGroupType(DataObject, Model.WitsmlVersion);
            var query = Proxy.BuildEmtpyQuery(type, Model.WitsmlVersion);

            XmlQuery.SetText(WitsmlParser.ToXml(query));
        }
        private void GetWhereClauses(XElement queryXml, XmlQuery parsedQuery)
        {
            var whereClausesXml = queryXml.Element("WhereClauses").Elements("WhereClause");

            foreach (var whereClauseXml in whereClausesXml)
            {
                var propertyName = whereClauseXml.Attribute("PropertyName").Value;
                var type         = whereClauseXml.Attribute("Type").Value;
                var value        = whereClauseXml.Value;

                parsedQuery.WhereClauses.Add(new WhereClause(propertyName, type, value));
            }
        }
Beispiel #8
0
        /// <summary>
        /// Submits an asynchronous query to the WITSML server for a given function type.
        /// The results of a query are displayed in the Results and Messages tabs.
        /// </summary>
        /// <param name="functionType">Type of the function.</param>
        /// <param name="optionsIn">The options in.</param>
        /// <param name="isPartialQuery">if set to <c>true</c> [is partial query].</param>
        public void SubmitQuery(Functions functionType, string optionsIn = null, bool isPartialQuery = false)
        {
            // Trim query text before submitting request
            string xmlIn = XmlQuery.Text.Trim();

            // Format the text of XmlQuery
            XmlQuery.SetText(xmlIn);

            _log.DebugFormat("Query submitted for function '{0}'", functionType);

            // Options In
            if (string.IsNullOrEmpty(optionsIn))
            {
                optionsIn = GetOptionsIn(functionType, isPartialQuery);
            }
            else if (isPartialQuery)
            {
                var optionsInUpdated = new List <OptionsIn> {
                    OptionsIn.ReturnElements.DataOnly
                };
                var optionsInFromPreviousQuery = OptionsIn.Parse(optionsIn);
                foreach (var key in optionsInFromPreviousQuery.Keys)
                {
                    if (key != OptionsIn.ReturnElements.All.Key && key != OptionsIn.ReturnElements.DataOnly.Key)
                    {
                        optionsInUpdated.Add(new OptionsIn(key, optionsInFromPreviousQuery[key]));
                    }
                }
                optionsIn = OptionsIn.Join(optionsInUpdated.ToArray());
            }

            // Output Request
            OutputRequestMessages(functionType, functionType == Functions.GetCap ? string.Empty : xmlIn, optionsIn);

            Runtime.ShowBusy();

            Task.Run(async() =>
            {
                // Call internal SubmitQuery method with references to all inputs and outputs.
                var result = await SubmitQuery(functionType, xmlIn, optionsIn);

                // Clear any previous query results if this is not a partial query
                if (!isPartialQuery)
                {
                    ClearQueryResults();
                }

                ShowSubmitResult(functionType, result, isPartialQuery);
                Runtime.ShowBusy(false);
            });
        }
Beispiel #9
0
        /// <summary>
        /// Called when a data object is selected.
        /// </summary>
        private void OnDataObjectSelected()
        {
            if (DataObject == null || DataObject == QueryTemplateText)
            {
                return;
            }

            var template = QueryTemplates.GetTemplate(DataObject, "WITSML", Model.WitsmlVersion, Model.ReturnElementType);

            XmlQuery.SetText(template.ToString(SaveOptions.OmitDuplicateNamespaces));

            // Reset drop down list
            Runtime.InvokeAsync(() => DataObject = QueryTemplateText);
        }
        public void LoadXmlFromFile()
        {
            task             = new XmlQuery();
            task.BuildEngine = new MockBuild();

            string prjRootPath = TaskUtility.GetProjectRootDirectory(true);

            task.XmlFileName          = System.IO.Path.Combine(prjRootPath, @"Source\Subversion.proj");
            task.XPath                = "count(/n:Project/n:PropertyGroup/*)";
            task.NamespaceDefinitions = new ITaskItem[] {
                new TaskItem("n=http://schemas.microsoft.com/developer/msbuild/2003")
            };

            Assert.IsTrue(task.Execute(), "Should have executed successfully.");
            Assert.AreEqual("6", task.Values[0].ToString());
        }
Beispiel #11
0
        static void ScheduledTasksViaSpawn()
        {
            var ns = XNamespace.Get("http://schemas.microsoft.com/windows/2004/02/mit/task");

            var q =
                from xml in Spawn("schtasks", @"/query /xml ONE").Delimited(Environment.NewLine)
                from doc in XmlQuery.Xml(new StringContent(xml))
                from t in doc.Elements("Tasks").Elements(ns + "Task")
                from e in t.Elements(ns + "Actions").Elements(ns + "Exec")
                select new
            {
                Name      = ((XComment)t.PreviousNode).Value.Trim(),
                Command   = (string)e.Element(ns + "Command"),
                Arguments = (string)e.Element(ns + "Arguments"),
            };

            q.Dump();
        }
Beispiel #12
0
        /// <summary>
        /// Submits the automatic query.
        /// </summary>
        /// <param name="result">The result.</param>
        private void SubmitAutoQuery(WitsmlResult result)
        {
            var model = GetModel();

            // Do not execute an auto-query:
            // ... if the Partial Success return code is missing, or
            // ... if the user has not selected to retrieve parital results, or
            // ... if the current auto-query operation has been cancelled by the user
            if (result.ReturnCode <= 1 || !model.RetrievePartialResults || (AutoQueryProvider != null && AutoQueryProvider.IsCancelled))
            {
                AutoQueryProvider = null;
                return;
            }

            if (AutoQueryProvider == null)
            {
                AutoQueryProvider = new GrowingObjectQueryProvider <WitsmlSettings>(model, result.ObjectType, XmlQuery.Text);
            }

            //... update the query using the original XmlOut
            XmlQuery.SetText(AutoQueryProvider.UpdateDataQuery(result.XmlOut));

            // Submit the query if one was returned.
            if (!string.IsNullOrEmpty(XmlQuery.Text))
            {
                // Change return elements to requested
                AutoQueryProvider.Context.RetrievePartialResults = true;

                //... and Submit a Query for the next set of data.
                SubmitQuery(Functions.GetFromStore, result.OptionsIn, true);
            }
            else
            {
                AutoQueryProvider = null;
            }
        }
 public void setupTask(string xml)
 {
     task             = new XmlQuery();
     task.BuildEngine = new MockBuild();
     task.Lines       = new ITaskItem[] { new TaskItem(@"<?xml version=""1.0"" encoding=""utf-8"" ?>"), new TaskItem(xml) };
 }