public string CalculatePartialDeriv(string equation, char dependent)
        {
            string s = "(d/d" + dependent + ") " + equation;
            //replace equation operators with web-equivalent
            s = FormatEquationForURL(s);

            if (s == _prevQuery){
                return _prevResults.GetDerivative();
            }

            var results = QueryWolfram(s);
            _prevQuery = s;
            _prevResults = results;

            return results.GetDerivative();
        }
Exemple #2
0
        public QueryResults Execute()
        {
            OnProgress(ProgressType.Connecting);
            var results = new QueryResults();
            try
            {
                if (_parameters == null)
                {
                    results.ErrorMessage = "Connection parameters not set!";
                }
                else
                {
                    using (var tfs = Connection.Connect(_parameters))
                    {
                        var store = tfs.GetService<WorkItemStore>();
                        var itemCollection = store.Query(QueryString);

                        var total = itemCollection.Count;
                        var current = 1;
                        OnProgress(ProgressType.Querying, current, total);
                        foreach (WorkItem wi in itemCollection)
                        {
                            results.Add(new ResultItem(wi));
                            if (current++%ProgressGranularity == 0)
                            {
                                OnProgress(ProgressType.Querying, current, total);
                            }
                        }

                    }
                }
            }
            catch (Exception e)
            {
                results.ErrorMessage = e.Message;
            }
            finally
            {
                OnProgress(ProgressType.Complete);
            }
            return results;
        }
Exemple #3
0
        private ActionResult CompleteResponse(
            QueryResults results,
            ParsedQuery parsedQuery,
            QueryContextData context,
            int siteId
            )
        {
            results = TranslateResults(parsedQuery, context.IsText, results);

            var query = Current.DB.Query <Query>(
                "SELECT * FROM Queries WHERE QueryHash = @hash",
                new
            {
                hash = parsedQuery.Hash
            }
                ).FirstOrDefault();

            int      revisionId = 0;
            DateTime saveTime;

            // We only create revisions if something actually changed.
            // We'll log it as an execution anyway if applicable, so the user will
            // still get a link in their profile, just not their own revision.
            if (context.Revision == null && (context.QuerySet == null || query == null || context.QuerySet.CurrentRevision == null || context.QuerySet.CurrentRevision.QueryId != query.Id))
            {
                int queryId;
                if (query == null)
                {
                    queryId = (int)Current.DB.Queries.Insert(
                        new
                    {
                        QueryHash = parsedQuery.Hash,
                        QueryBody = parsedQuery.Sql
                    }
                        );
                }
                else
                {
                    queryId = query.Id;
                }

                revisionId = (int)Current.DB.Revisions.Insert(
                    new
                {
                    QueryId            = queryId,
                    OwnerId            = CurrentUser.IsAnonymous ? null : (int?)CurrentUser.Id,
                    OwnerIP            = GetRemoteIP(),
                    CreationDate       = saveTime = DateTime.UtcNow,
                    OriginalQuerySetId = context.QuerySet != null ? context.QuerySet.Id : (int?)null
                }
                    );

                int querySetId;
                // brand new queryset
                if (context.QuerySet == null)
                {
                    // insert it
                    querySetId = (int)Current.DB.QuerySets.Insert(new
                    {
                        InitialRevisionId = revisionId,
                        CurrentRevisionId = revisionId,
                        context.Title,
                        context.Description,
                        LastActivity = DateTime.UtcNow,
                        Votes        = 0,
                        Views        = 0,
                        Featured     = false,
                        Hidden       = false,
                        CreationDate = DateTime.UtcNow,
                        OwnerIp      = CurrentUser.IPAddress,
                        OwnerId      = CurrentUser.IsAnonymous?(int?)null:CurrentUser.Id
                    });

                    Current.DB.Revisions.Update(revisionId, new { OriginalQuerySetId = querySetId });
                }
                else if (
                    (CurrentUser.IsAnonymous && context.QuerySet.OwnerIp == CurrentUser.IPAddress) || context.QuerySet.OwnerId != CurrentUser.Id)
                {
                    // fork it
                    querySetId = (int)Current.DB.QuerySets.Insert(new
                    {
                        InitialRevisionId = context.QuerySet.InitialRevisionId,
                        CurrentRevisionId = revisionId,
                        context.Title,
                        context.Description,
                        LastActivity     = DateTime.UtcNow,
                        Votes            = 0,
                        Views            = 0,
                        Featured         = false,
                        Hidden           = false,
                        CreationDate     = DateTime.UtcNow,
                        OwnerIp          = CurrentUser.IPAddress,
                        OwnerId          = CurrentUser.IsAnonymous ? (int?)null : CurrentUser.Id,
                        ForkedQuerySetId = context.QuerySet.Id
                    });

                    Current.DB.Execute(@"insert QuerySetRevisions(QuerySetId, RevisionId) 
select @newId, RevisionId from QuerySetRevisions where QuerySetId = @oldId", new
                    {
                        newId = querySetId,
                        oldId = context.QuerySet.Id
                    });
                }
                else
                {
                    // update it
                    querySetId = context.QuerySet.Id;

                    context.Title       = context.Title ?? context.QuerySet.Title;
                    context.Description = context.Description ?? context.QuerySet.Description;

                    Current.DB.QuerySets.Update(context.QuerySet.Id, new { context.Title, context.Description, CurrentRevisionId = revisionId, LastActivity = DateTime.UtcNow });
                }

                Current.DB.QuerySetRevisions.Insert(new { QuerySetId = querySetId, RevisionId = revisionId });

                results.RevisionId = revisionId;
                results.Created    = saveTime;
                results.QuerySetId = querySetId;
            }
            else
            {
                results.RevisionId = context.Revision != null ? context.Revision.Id : context.QuerySet.CurrentRevisionId;
                results.QuerySetId = context.QuerySet.Id;
                results.Created    = null;
            }

            if (context.Title != null)
            {
                results.Slug = context.Title.URLFriendly();
            }

            QueryRunner.LogRevisionExecution(CurrentUser, siteId, results.RevisionId);

            // Consider handling this XSS condition (?) in the ToJson() method instead, if possible
            return(Content(results.ToJson().Replace("/", "\\/"), "application/json"));
        }
        public ActionResult ShowSingleSiteCsv(string sitename, int revisionId, string slug)
        {
            Query query = QueryUtil.GetQueryForRevision(revisionId);

            if (query == null)
            {
                return(PageNotFound());
            }

            Site site;

            if (!TryGetSite(sitename, out site))
            {
                return(site == null ?  (ActionResult)PageNotFound() : RedirectPermanent(string.Format("/{0}/csv/{1}{2}{3}",
                                                                                                      site.TinyName.ToLower(), revisionId, slug.HasValue() ? "/" + slug : "", Request.Url.Query
                                                                                                      )));
            }

            var parsedQuery = new ParsedQuery(query.QueryBody, Request.Params);

            if (!parsedQuery.IsExecutionReady)
            {
                return(PageBadRequest());
            }

            CachedResult cachedResults = QueryUtil.GetCachedResults(
                parsedQuery,
                Site.Id
                );
            List <ResultSet> resultSets;

            if (cachedResults != null)
            {
                resultSets = JsonConvert.DeserializeObject <List <ResultSet> >(cachedResults.Results, QueryResults.GetSettings());
            }
            else
            {
                resultSets = QueryRunner.GetResults(
                    parsedQuery,
                    site,
                    CurrentUser
                    ).ResultSets;
            }

            return(new CsvResult(resultSets));
        }
Exemple #5
0
        private ActionResult ShowCommon(Revision revision, string slug, bool latest)
        {
            if (revision == null)
            {
                return(PageNotFound());
            }

            var title   = revision.QuerySet.Title;
            int ownerId = revision.OwnerId ?? 0;

            title = title.URLFriendly();

            // if this user has a display name, and the title is missing or does not match, permanently redirect to it
            if (title.HasValue() && (string.IsNullOrEmpty(slug) || slug != title))
            {
                string url = "/{0}/query/{1}/{3}";

                if (!latest)
                {
                    url = "/{0}/query/{1}/{2}/{3}";
                }

                return(PageMovedPermanentlyTo(string.Format(url,
                                                            Site.Name.ToLower(),
                                                            revision.QuerySet.Id,
                                                            revision.Id,
                                                            title
                                                            ) + Request.Url.Query));
            }

            title = revision.QuerySet.Title;

            if (title.IsNullOrEmpty())
            {
                title = revision.Query.AsTitle();
            }

            SetHeader(title);
            SelectMenuItem("Queries");

            ViewData["GuessedUserId"] = Site.GuessUserId(CurrentUser);

            // Need to revamp voting process
            int totalVotes = Current.DB.Query <int>(@"
                SELECT
                    COUNT(*)
                FROM
                    Votes
                WHERE
                    QuerySetId = @querySetId AND
                    VoteTypeId = @voteType",
                                                    new
            {
                querySetId = revision.QuerySet.Id,
                voteType   = (int)VoteType.Favorite
            }
                                                    ).FirstOrDefault();

            var voting = new QuerySetVoting
            {
                TotalVotes = totalVotes,
                QuerySetId = revision.QuerySet.Id,
                ReadOnly   = CurrentUser.IsAnonymous
            };

            if (!Current.User.IsAnonymous)
            {
                voting.HasVoted = Current.DB.Query <Vote>(@"
                    SELECT
                        *
                    FROM
                        Votes
                    WHERE
                        QuerySetId = @querySetId AND
                        VoteTypeId = @voteType AND
                        UserId = @user",
                                                          new
                {
                    querySetId = revision.QuerySet.Id,
                    voteType   = (int)VoteType.Favorite,
                    user       = Current.User.Id
                }
                                                          ).FirstOrDefault() != null;
            }

            CachedResult cachedResults = QueryUtil.GetCachedResults(
                new ParsedQuery(revision.Query.QueryBody, Request.Params),
                Site.Id
                );

            ViewData["QueryVoting"]  = voting;
            ViewData["query_action"] = "run/" + Site.Id + "/" + revision.QuerySet.Id + "/" + revision.Id;

            if (cachedResults != null)
            {
                // Don't show cached execution plan, since the user didn't ask for it...
                cachedResults.ExecutionPlan = null;

                ViewData["cached_results"] = new QueryResults
                {
                    RevisionId = revision.Id,
                    QuerySetId = revision.QuerySet.Id,
                    SiteId     = Site.Id,
                    SiteName   = Site.Name,
                    Slug       = revision.QuerySet.Title.URLFriendly(),
                    Url        = Site.Url
                }.WithCache(cachedResults);
            }

            if (!IsSearchEngine())
            {
                QueryViewTracker.TrackQueryView(GetRemoteIP(), revision.QuerySet.Id);
            }

            var initialRevision = revision.QuerySet.InitialRevision;

            var viewmodel = new QueryViewerData
            {
                QuerySetVoting = voting,
                Revision       = revision
            };

            return(View("Viewer", viewmodel));
        }
Exemple #6
0
 internal NpSqlDataReader(QueryResults queryResults)
 {
     this.queryResults = queryResults;
 }
Exemple #7
0
 public static List <VmScenarioSummary> Build(QueryResults <SmScenarioSummary> entities)
 {
     return(entities?.Items?.Select(Build).ToList());
 }
Exemple #8
0
 public void Execute()
 {
     QueryResults.Query = BuildQuery;
     QueryResults.LoadPage();
 }
        public static QueryResults toQueryResultsFromDdr(VistaQuery query, String[] ddrResults)
        {
            QueryResults result = new QueryResults();

            IList <domain.reporting.Exceptional> errors = validateDdrResults(query, ref ddrResults);

            if (errors.Count > 0)
            {
                // no longer throwing an exception if zero results - a few cases found where the end of the file returns some kkoky
                //if (ddrResults.Length == 0) // if all of the records were marked invalid, i guess we should just fail big
                //{
                //    throw new DownstreamException(String.Format("Those DDR results appear to be invalid: {0}", ddrResults[0])) { VistaQuery = query };
                //}
                //else // otherwise just set our exceptions on the query results and we'll handle them further up the stack
                //{
                foreach (domain.reporting.Exceptional e in errors)
                {
                    result.Exceptionals.Add(e);
                }
                //}
            }

            // toQueryResults assumes the ddrResults string contains the WP/Computed fields already (i.e. added elsewhere to each line) - when we added those results, we used the FS character.
            // we need to swap that character back out with a carat so the loop below can parse the results more easily
            String[] wpAndComputed = new String[0];
            if (!String.IsNullOrEmpty(query.WP_Or_Computed_Fields) && String.IsNullOrEmpty(query.Gets_Alignment))
            {
                wpAndComputed = query.WP_Or_Computed_Fields.Split(semicolonDelim);
                for (int i = 0; i < ddrResults.Length; i++)
                {
                    ddrResults[i] = ddrResults[i].Replace(FIELD_SEPARATOR, "^");
                }
            }

            String[]  fields       = query.Fields.Split(semicolonDelim);
            DataTable currentTable = generateVistaQueryDataTable(query.VistaFile, fields, query.IsSubFileQuery, wpAndComputed);

            result.DdrResults.Add(currentTable);

            if (ddrResults == null || ddrResults.Length == 0)
            {
                return(result);
            }

            // Prepare to process our results
            Int16    intSiteCode   = Convert.ToInt16(query.SiteCode);
            DateTime retrievalTime = DateTime.Now;

            bool   hasIdentifiedFiles = !String.IsNullOrEmpty(query.IdentifiedFiles);
            String iensString         = "";

            String[] identifiedFiles           = null;
            int      identifiedFilesStartIndex = 0;

            if (hasIdentifiedFiles)
            {
                iensString                = query.IENS;
                result.SubQueryIens       = new Dictionary <String, IList <String> >();
                identifiedFiles           = query.IdentifiedFiles.Split(semicolonDelim);
                identifiedFilesStartIndex = query.Fields.Split(semicolonDelim).Length + 1 + wpAndComputed.Length; // we'll start looking at the resolved file indicators here - per ticket #16, we moved the identifier flags out to the end of the string so we need to go past the WP fields now, too
                foreach (String identifiedFile in identifiedFiles)
                {
                    result.SubQueryIens.Add(identifiedFile, new List <String>()); // only building our container objects here
                }
            }

            String pIenStr = ""; // string for DataTable - looks like third_second_first per db requirements

            if (query.IsSubFileQuery)
            {
                pIenStr = StringUtils.convertIensToIen(query.IENS);
            }

            // Push each valid ddrresult into our datatable
            String enDdiolChar = "&#94;";
            String carat       = "^";

            foreach (string ddrResult in ddrResults)
            {
                // Break our string up into it's parts
                string[] ddrValues = ddrResult.Replace(enDdiolChar, carat).Split(caratDelim);

                object[] rowVals = new object[result.DdrResults[0].Columns.Count]; // generateVistaQueryDataTable already determined the correct number of columns

                if (ddrValues.Length < fields.Length + 1)                          // +1 for the IEN - found some weird random cases where differing data seems to make it's way in to results - let's just ignore it for now
                {
                    logging.Log.LOG("Found a malformed record in this query result! We're ignoring for now but may need to look at it later: " + ddrResult);
                    continue;
                }

                int currentColumnIndex = 3;
                if (query.IsSubFileQuery)
                {
                    rowVals[0]         = pIenStr;                                   // SECONDPARENTIEN_FIRSTPARENTIEN <-- converted to format by StringUtils function above
                    rowVals[1]         = String.Concat(ddrValues[0], "_", pIenStr); // nthLevel_n-1Level_..._firstLevel
                    rowVals[2]         = intSiteCode;
                    rowVals[3]         = retrievalTime;
                    currentColumnIndex = 4;
                }
                else
                {
                    rowVals[0] = ddrValues[0];
                    rowVals[1] = intSiteCode;
                    rowVals[2] = retrievalTime;
                }

                for (int i = 1; i < (query.IsSubFileQuery ? currentTable.Columns.Count - 3 : currentTable.Columns.Count - 2); i++) // already stored IEN so start at 1, number of columns minus extra added
                {
                    rowVals[currentColumnIndex] = ddrValues[i];
                    currentColumnIndex++;
                }

                result.DdrResults[0].Rows.Add(rowVals);

                // now take care of identified files
                if (hasIdentifiedFiles)
                {
                    for (int i = 0; i < identifiedFiles.Length; i++)
                    {
                        if (!String.Equals("0", ddrValues[identifiedFilesStartIndex + i]))
                        {
                            if (String.IsNullOrEmpty(iensString))                                      // if  we don't already have an IENS string started, use a leading comma ',' character
                            {
                                result.SubQueryIens[identifiedFiles[i]].Add("," + ddrValues[0] + ","); // first child subfile - use parent's IEN in column 0
                            }
                            else // already started an IENS string (i.e. in a subfile) - concatenate the current IEN and a comma ',' character
                            {
                                result.SubQueryIens[identifiedFiles[i]].Add("," + ddrValues[0] + iensString); // add the IEN to the correct queue - if we're in a subfile, the IEN is the second column!!!
                            }
                        }
                    }
                }
            }

            return(result);
        }
 private void Exception_Query(QueryRequest req, Exception ex)
 {
     _queryResults = new QueryResults(req.ConnectionString, req.SQLStatement, ex.Message);
     DoSOM();
 }
 private void Finished_Query(QueryRequest req, QueryResults results)
 {
     _queryResults = results;
     DoSOM();
 }
        /// <summary>
        /// This looks at the current inputs, and starts a new SOM async
        /// </summary>
        private void DoSOM()
        {
            #region Init

            // Parse all the inputs
            QueryRequest queryReq = GetQueryRequest();

            if (queryReq.Columns.Length == 0)
            {
                lblErrorMessage.Text = "No columns specified";
                lblQueryStatus.Text = "";
                pnlColumns.Children.Clear();
                _queryResults = null;
                _columns = null;
                _result = null;
                return;
            }

            #endregion
            #region Query

            // Run query if changed
            if (_queryResults == null || _queryResults.ConnectionString != queryReq.ConnectionString || _queryResults.SQLStatement != queryReq.SQLStatement)
            {
                lblQueryStatus.Text = "Running query...";
                lblErrorMessage.Text = "";
                pnlColumns.Children.Clear();
                _columns = null;
                _result = null;

                _workerQuery.Start(queryReq);
                return;     //_workerQuery.finish will call this method again, and execution will flow past this if statement
            }

            lblQueryStatus.Text = "";

            if (!string.IsNullOrEmpty(_queryResults.Exception))
            {
                lblErrorMessage.Text = _queryResults.Exception;
                _result = null;
                return;
            }

            lblQueryStatus.Text = string.Format("{0} row{1}", _queryResults.Results.Length.ToString("N0"), _queryResults.Results.Length == 1 ? "" : "s");

            #endregion
            #region Columns

            if (_columns != null)
            {
                _columns = _columns.CloneIfSameNames(queryReq.Columns, _queryResults.ColumnNames);      //NOTE: This will still clone if it just holds an exception
            }

            if (_columns == null || !IsSame(queryReq.Columns, _columns.Names))
            {
                lblErrorMessage.Text = "";
                _result = null;
                _workerColumns.Start(new ColumnStatsRequest(queryReq.Columns, _queryResults));
                return;
            }

            if (_columns != null && !string.IsNullOrEmpty(_columns.Exception))
            {
                lblErrorMessage.Text = _columns.Exception;
                _result = null;
                return;
            }

            #endregion
            #region Do SOM

            if (_result == null)
            {
                RowInput[] inputs = GetSOMInputs(_columns.Columns, _queryResults, true);

                //TODO: Get these from the gui.  Add an option to randomize against their settings
                SOMRules rules = GetSOMRules_Rand();

                //TODO: Make an option for display1D.  Then do a SOM for each column and put the results in the column details dump
                _workerSOM.Start(new SOMRequest(inputs, rules));
                return;
            }

            #endregion
            #region Show Results

            var events = new SelfOrganizingMapsWPF.BlobEvents(Polygon_MouseMove, Polygon_MouseLeave, Polygon_Click);

            SelfOrganizingMapsWPF.ShowResults2D_Blobs(panelDisplay, _result, SelfOrganizingMapsWPF.GetNodeColor, events);

            #endregion
        }
 public ColumnStatsRequest(string[] names, QueryResults results)
 {
     this.Names = names;
     this.Results = results;
 }
        public static RowInput[] GetSOMInputs(ColumnStats[] columns, QueryResults results, bool randomSample)
        {
            var finalColumns = GetFinalColumnStats(columns);

            IEnumerable<int> indices = randomSample ?
                UtilityCore.RandomRange(0, results.Results.Length, StaticRandom.Next(100, 200)) :
                Enumerable.Range(0, results.Results.Length);

            return indices.
                Select(o =>
                {
                    return new RowInput()
                    {
                        Row = results.Results[o],
                        Weights = finalColumns.
                            Select(p => SelfOrganizingMapsDB.ConvertToVector(results.Results[o][p.Item1.Index], p.Item2, p.Item3)).
                            SelectMany(p => p).
                            ToArray(),
                    };
                }).
                ToArray();
        }
Exemple #15
0
        static QueryResults CachedQueryObjectLoader(ContentList results)
        {
            QueryResults final = new QueryResults(results.StartIndex, results.EndIndex);
            final.TotalResults = results.TotalResults;

            Dictionary<string, Type> types = new Dictionary<string,Type>();

            foreach (Content c in results)
            {
                Type t = null;
                if(!types.TryGetValue(c.Type, out t))
                {
                    t = Mubble.Models.Tools.GetActiveObjectType(c.Type);
                    types.Add(c.Type, t);
                }
                if (t == null) continue;
                IActiveObject obj = DataBroker.GetActiveObject(t, c.ActiveObjectID);
                if (obj != null) final.Add(obj, c);
            }
            return final;
        }
Exemple #16
0
        private static QueryResults TranslateResults(ParsedQuery query, bool textResults, QueryResults results)
        {
            textResults = textResults || (results.ResultSets.Count != 1);

            if (textResults)
            {
                results = results.ToTextResults();
            }

            if (query.IncludeExecutionPlan)
            {
                results = results.TransformQueryPlan();
            }
            return(results);
        }
Exemple #17
0
 internal ZipQueryOperatorResults(QueryResults <TLeftInput> leftChildResults, QueryResults <TRightInput> rightChildResults, Func <TLeftInput, TRightInput, TOutput> resultSelector, int partitionCount, bool preferStriping)
 {
     this.m_leftChildResults  = leftChildResults;
     this.m_rightChildResults = rightChildResults;
     this.m_resultSelector    = resultSelector;
     this.m_partitionCount    = partitionCount;
     this.m_preferStriping    = preferStriping;
     this.m_count             = Math.Min(this.m_leftChildResults.Count, this.m_rightChildResults.Count);
 }
        /// <summary>
        /// Get subqueries for all the child nodes in a configuration based off the query results
        /// </summary>
        /// <param name="config"></param>
        /// <param name="queryResults"></param>
        /// <returns></returns>
        public static ConcurrentQueue <VistaQuery> getSubQueriesFromResults(ExtractorConfiguration config, QueryResults queryResults)
        {
            ConcurrentQueue <VistaQuery> subQueries = new ConcurrentQueue <VistaQuery>();

            if (queryResults.DdrResults[0].Rows.Count == 0)
            {
                return(subQueries);
            }
            String queryResultsSiteCode = Convert.ToString((Int16)queryResults.DdrResults[0].Rows[0]["SiteCode"]);

            foreach (TreeNode <QueryConfiguration> child in config.QueryConfigurations.RootNode.Children)
            {
                foreach (String ien in queryResults.SubQueryIens["/" + child.Value.File]) // TODO - make sure we're checking against correct format (/45/45.06 vs 45.06
                {
                    VistaQuery current = new VistaQuery(config, child.Value);
                    current.MaxRecords     = "";                              // set blank because there is no looping in subfiles
                    current.IENS           = ien;
                    current.StartIen       = current.From = child.Value.From; // ticket #9 bug fix line - didn't uncover in testing because 1) weren't specifiying start IEN 2) not specifying start IEN on ExtractorConfiguration object which is where the property was being copied from. Get it instead directly from TreeNode
                    current.SiteCode       = queryResultsSiteCode;
                    current.IsSubFileQuery = true;
                    subQueries.Enqueue(current);
                }
            }
            return(subQueries);
        }
Exemple #19
0
 /// <summary>
 /// Find all values contained in the specified area.
 /// </summary>
 /// <returns>True if any values were found.</returns>
 /// <param name="quad">The area to search.</param>
 /// <param name="values">A list to populate with the results. If null, this function will create the list for you.</param>
 public void SearchArea(Quad quad)
 {
     QueryResults.Clear();
     Root.SearchQuad(quad, QueryResults);
 }
        /// <summary>
        /// Build a queue of VistaQuery for a single subfile of an ExtractorConfiguration
        /// </summary>
        /// <param name="config"></param>
        /// <param name="queryResults"></param>
        /// <param name="subfile">This call's subfile will be of the format "/2.98"</param>
        /// <returns></returns>
        public static ConcurrentQueue <VistaQuery> getSubQueriesFromResultsBySubfile(ExtractorConfiguration config, QueryResults queryResults, String subfile)
        {
            ConcurrentQueue <VistaQuery> subQueries = new ConcurrentQueue <VistaQuery>();

            if (queryResults.DdrResults[0].Rows.Count == 0)
            {
                return(subQueries);
            }
            String queryResultsSiteCode = Convert.ToString((Int16)queryResults.DdrResults[0].Rows[0]["SiteCode"]);

            TreeNode <QueryConfiguration> queryConfig = config.QueryConfigurations.search(new QueryConfiguration()
            {
                File = subfile.Substring(1)
            });                                                                                                                                     // search for non fully qualified file name

            if (queryConfig == null || queryConfig.Value == null)
            {
                throw new ArgumentException("The specified subfile ({0}) doesn't exist in the configuration tree!", subfile);
            }

            foreach (String ien in queryResults.SubQueryIens[subfile]) // TODO - make sure we're checking against correct format (/45/45.06 vs 45.06
            {
                VistaQuery current = new VistaQuery(config, queryConfig.Value);
                current.MaxRecords     = "";                                    // set blank because there is no looping in subfiles
                current.IENS           = ien;
                current.StartIen       = current.From = queryConfig.Value.From; // ticket #9 bug fix line - didn't uncover in testing because 1) weren't specifiying start IEN 2) not specifying start IEN on ExtractorConfiguration object which is where the property was being copied from. Get it instead directly from TreeNode
                current.SiteCode       = queryResultsSiteCode;
                current.IsSubFileQuery = true;
                subQueries.Enqueue(current);
            }
            return(subQueries);
        }
Exemple #21
0
        /// <summary>
        /// Executing the log analytics queries
        /// </summary>
        public void ExecuteLogAnalyticsQueries()
        {
            Console.WriteLine($"ExecuteLogAnalyticsQueries Start");
            var adSettings = new ActiveDirectoryServiceSettings
            {
                AuthenticationEndpoint = new Uri(AuthEndpoint),
                TokenAudience          = new Uri(TokenAudience),
                ValidateAuthority      = true
            };

            var creds  = ApplicationTokenProvider.LoginSilentAsync(Domain, AADClientId, ClientSecret, adSettings).GetAwaiter().GetResult();
            var client = new OperationalInsightsDataClient(creds);

            client.WorkspaceId = WorkspaceId;
            dirQueryResults    = new Dictionary <string, Quries>();
            bool         retry      = true;
            int          retryCount = 0;
            QueryResults results    = null;

            foreach (KeyValuePair <string, Quries> item in QueryData)
            {
                try
                {
                    try
                    {
                        while (retry && retryCount <= 2)
                        {
                            results = client.Query(item.Value.Query);
                            retry   = false;
                        }
                    }
                    catch (Exception e)
                    {
                        retryCount++;
                        Console.WriteLine($"Error while processing the query name {item.Key} retry count {retryCount}, Exception: {e}");
                        Thread.Sleep(threadSleepTime);
                        client             = new OperationalInsightsDataClient(creds);
                        client.WorkspaceId = WorkspaceId;
                    }
                    retry      = true;
                    retryCount = 0;
                    if (results != null && results.Tables.Count > 0)
                    {
#if DEBUG
                        //string rowformat = "{0},{1}";
                        //string rowData = string.Empty;
                        //foreach (var dr in results.Tables[0].Rows)
                        //{
                        //    foreach (string dc in dr)
                        //    {
                        //        if (dc != null)
                        //            rowData = rowData == "" ? dc : string.Format(rowformat, rowData, dc);
                        //    }
                        //    rowData = string.Empty;
                        //}
#endif
                        if (!string.IsNullOrEmpty(item.Value.Summarize))
                        {
                            item.Value.PerfResult = null;
                            Dictionary <string, double> PerfResult = new Dictionary <string, double>();
                            for (int i = 0; i < results.Tables[0].Rows.Count; i++)
                            {
                                if (results.Tables[0].Rows[i].Count > 1 && !string.IsNullOrEmpty(results.Tables[0].Rows[i][0]))
                                {
                                    //Console.WriteLine($"{item.Value.Category} Result Name: {results.Tables[0].Rows[i][0]} Result Value: {results.Tables[0].Rows[i][1]} == time :{DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")} UTC Time: {DateTime.UtcNow.ToString("MM/dd/yyyy HH:mm:ss")}");
                                    PerfResult.Add(results.Tables[0].Rows[i][0], Convert.ToDouble(results.Tables[0].Rows[i][1]));
                                }
                            }
                            item.Value.PerfResult = PerfResult;
                        }

                        item.Value.Result = results.Tables[0].Rows.Count.ToString();
                    }
                    else
                    {
                        item.Value.Result = "No Data";
                        Console.WriteLine("No Data");
                    }
                }
                catch (Exception ex)
                {
                    item.Value.Result = "Error";
                    Console.WriteLine($"Error while processing the query name {item.Key} Exception: {ex}");
                }
                results = null;
                dirQueryResults.Add(item.Key, item.Value);
            }
            Console.WriteLine($"ExecuteLogAnalyticsQueries End");
        }
Exemple #22
0
        public bool RestoreDB(string string_3, string string_4, string string_5, ProgressBar progressBar_1)
        {
            int  i;
            bool flag;

            this.progressBar_0 = progressBar_1;
            string    columnString   = "";
            string    str            = "";
            string    str1           = "";
            string    str2           = "";
            SQLServer sQLServerClass = new SQLServer();

            try
            {
                try
                {
                    sQLServerClass.Connect(this.ServerName, this.UserName, this.Password);
                    QueryResults queryResult = sQLServerClass.EnumProcesses(-1);
                    int          num         = -1;
                    int          num1        = -1;
                    for (i = 1; i <= queryResult.Columns; i++)
                    {
                        string columnName = queryResult.ColumnName[i];
                        if (columnName.ToUpper().Trim() == "SPID")
                        {
                            num = i;
                        }
                        else if (columnName.ToUpper().Trim() == "DBNAME")
                        {
                            num1 = i;
                        }
                        if ((num == -1 ? false : num1 != -1))
                        {
                            break;
                        }
                    }
                    for (i = 1; i <= queryResult.Rows; i++)
                    {
                        int columnLong = queryResult.GetColumnLong(i, num);
                        if (queryResult.GetColumnString(i, num1).ToUpper() == string_3.ToUpper())
                        {
                            sQLServerClass.KillProcess(columnLong);
                        }
                    }
                    Restore restoreClass = new Restore()
                    {
                        Action = SQLDMO_RESTORE_TYPE.SQLDMORestore_Database
                    };
                    restoreClass.PercentComplete += new RestoreSink_PercentCompleteEventHandler(this.Step);
                    restoreClass.Files            = string_4;
                    restoreClass.Database         = string_3;
                    restoreClass.RelocateFiles    = "[SuperOA],[D:\\aaaa.mdf]";
                    columnString = restoreClass.ReadFileList(sQLServerClass).GetColumnString(1, 1);
                    str          = restoreClass.ReadFileList(sQLServerClass).GetColumnString(2, 1);
                    str1         = string.Concat(string_5, columnString, ".mdf");
                    str2         = string.Concat(string_5, str, ".ldf");
                    string[] strArrays = new string[] { "[", columnString, "],[", str1, "],[", str, "],[", str2, "]" };
                    restoreClass.RelocateFiles   = string.Concat(strArrays);
                    restoreClass.ReplaceDatabase = true;
                    restoreClass.SQLRestore(sQLServerClass);
                    flag = true;
                }
                catch (Exception exception)
                {
                    exception.Message.ToString();
                    MessageBox.Show("恢复数据库失败,请关闭所有和该数据库连接的程序!");
                    flag = false;
                }
            }
            finally
            {
                sQLServerClass.DisConnect();
            }
            return(flag);
        }
        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            this.Result = ((PrestoSqlDbConnection)this.DbConnection).ExecuteQuery(this.CommandText);

            return(new PrestoSqlDbDataReader(this));
        }
				public QueryTuple(QueryResults queryResults, object value)
				{
					this.queryResults = queryResults;
					this.value = value;
				}
 public void SearchBounds(AxisAlignedBoundingBox bounds)
 {
     QueryResults.Clear();
     root.SearchBounds(bounds, QueryResults);
 }
 /// <summary>
 /// Find all values overlapping the specified point.
 /// </summary>
 /// <returns>True if any values were found.</returns>
 /// <param name="x">The x coordinate.</param>
 /// <param name="y">The y coordinate.</param>
 /// <param name="values">A list to populate with the results. If null, this function will create the list for you.</param>
 public void SearchPoint(double x, double y, double z)
 {
     QueryResults.Clear();
     root.SearchPoint(x, y, z, QueryResults);
 }
        internal void ExecuteQueries()
        {
            foreach (var query in Queries)
            {
                var operation = query.Operation;

                var adder   = query.Low;
                var operand = (query.Low + RunningSum) % M;

                var high      = query.High;
                var highRange = (high + RunningSum) % M;
                if (operation != Operations.Sum)
                {
                    highRange = 0;
                }

                switch (operation)
                {
                case Operations.Add:
                    if (!TreeNodes.Any() || Root == null)
                    {
                        TreeNodes.Add(new TreeNode(operand));
                        Root = TreeNodes[0];
                        UpdateSum(Root);
                        break;
                    }
                    SplayInsert(operand, Root);
                    break;

                case Operations.Find:
                    if (!TreeNodes.Any())
                    {
                        QueryResults.Add(Results.NotFound);
                        break;
                    }
                    var foundNode = SplayFind(operand, Root);
                    if (foundNode == null || foundNode.Value != operand)
                    {
                        QueryResults.Add(Results.NotFound);
                        break;
                    }
                    QueryResults.Add(Results.Found);
                    break;

                case Operations.Del:
                    if (!TreeNodes.Any())
                    {
                        break;
                    }
                    SplayDel(operand);
                    break;

                case Operations.Sum:
                    if (!TreeNodes.Any())
                    {
                        QueryResults.Add("0");
                        break;
                    }
                    var rangeSum = SumRange(operand, highRange);
                    QueryResults.Add(rangeSum.ToString());
                    RunningSum = rangeSum;
                    break;
                }
            }
        }
Exemple #28
0
        public bool StoreDatabase(string sFile, string sPath, string sDataBase)
        {
            bool      flag         = false;
            SQLServer serverObject = new SQLServerClass();

            SQLDMO.Restore restore = new RestoreClass();
            try
            {
                int num3;
                serverObject.LoginSecure = false;
                serverObject.Connect(this.Server, this.UserID, this.Password);
                QueryResults results = serverObject.EnumProcesses(-1);
                int          column  = -1;
                int          num2    = -1;
                for (num3 = 1; num3 < results.Columns; num3++)
                {
                    string str = results.get_ColumnName(num3);
                    if (str.ToUpper().Trim() == "SPID")
                    {
                        column = num3;
                    }
                    else if (str.ToUpper().Trim() == "DBNAME")
                    {
                        num2 = num3;
                    }
                    if ((column != -1) && (num2 != -1))
                    {
                        break;
                    }
                }
                num3 = 1;
                while (num3 < results.Rows)
                {
                    int columnLong = results.GetColumnLong(num3, column);
                    if (results.GetColumnString(num3, num2).ToUpper() == sDataBase.ToUpper())
                    {
                        serverObject.KillProcess(columnLong);
                    }
                    num3++;
                }
                QueryResults results2 = serverObject.ExecuteWithResults(string.Format("RESTORE FILELISTONLY FROM DISK = '{0}'", sFile), null);
                int          num5     = 0;
                int          num6     = 0;
                for (num3 = 1; num3 < results2.Columns; num3++)
                {
                    if ("LOGICALNAME" == results2.get_ColumnName(num3).ToUpper())
                    {
                        num5 = num3;
                    }
                    if ("PHYSICALNAME" == results2.get_ColumnName(num3).ToUpper())
                    {
                        num6 = num3;
                    }
                    if ((num6 != 0) && (num5 != 0))
                    {
                        break;
                    }
                }
                StringBuilder builder = new StringBuilder();
                for (num3 = 1; num3 <= results2.Rows; num3++)
                {
                    builder.Append(string.Format(@"[{0}],[{1}\{2}]", results2.GetColumnString(num3, num5), sPath, Path.GetFileName(results2.GetColumnString(num3, num6))));
                    if (num3 != results2.Rows)
                    {
                        builder.Append(",");
                    }
                }
                restore.Action          = SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
                restore.Database        = sDataBase;
                restore.Files           = sFile;
                restore.FileNumber      = 1;
                restore.ReplaceDatabase = false;
                restore.RelocateFiles   = builder.ToString();
                restore.SQLRestore(serverObject);
                Databases databases = serverObject.Databases;
                foreach (SQLDMO.Database database in databases)
                {
                    if (database.Name == sDataBase)
                    {
                        return(true);
                    }
                }
                return(flag);
            }
            catch (Exception exception)
            {
                Log.WriteLog(string.Format("还原数据库[{0}]:StoreDatabase(string sFile,string sPath,string sDataBase)", sDataBase), exception.Message);
                return(flag);
            }
            finally
            {
                serverObject.DisConnect();
            }
            return(flag);
        }
 public void Init()
 {
     instance = new QueryResults();
 }
Exemple #30
0
 public void RunQuery(string query, QueryResults results)
 {
     results.Success = _shouldSucceed;
     results.Time    = _time;
 }
Exemple #31
0
        public ActionResult Execute(int querySetId, int revisionId, int siteId, bool?textResults, bool?withExecutionPlan, TargetSites?targetSites)
        {
            if (CurrentUser.IsAnonymous && !CaptchaController.CaptchaPassed(GetRemoteIP()))
            {
                return(Json(new { captcha = true }));
            }

            ActionResult response = null;

            try
            {
                if (!ValidateTargetSites(targetSites))
                {
                    throw new ApplicationException("Invalid target sites selection");
                }

                QuerySet querySet = null;


                querySet = Current.DB.QuerySets.Get(querySetId);

                if (querySet == null)
                {
                    throw new ApplicationException("Invalid query set ID");
                }

                Revision revision = Current.DB.Revisions.Get(revisionId);
                if (revision == null)
                {
                    throw new ApplicationException("Invalid revision ID");
                }

                Query query = Current.DB.Queries.Get(revision.QueryId);

                var parsedQuery = new ParsedQuery(
                    query.QueryBody,
                    Request.Params,
                    withExecutionPlan == true,
                    targetSites ?? TargetSites.Current
                    );

                QueryResults results = null;
                Site         site    = GetSite(siteId);
                ValidateQuery(parsedQuery, site);

                var contextData = new QueryContextData
                {
                    IsText   = textResults == true,
                    QuerySet = querySet,
                    Revision = revision
                };

                var asyncResults = AsyncQueryRunner.Execute(parsedQuery, CurrentUser, site, contextData);

                if (asyncResults.State == AsyncQueryRunner.AsyncState.Failure)
                {
                    throw asyncResults.Exception;
                }

                if (asyncResults.State == AsyncQueryRunner.AsyncState.Success)
                {
                    results = asyncResults.QueryResults;
                }
                else
                {
                    return(Json(new { running = true, job_id = asyncResults.JobId }));
                }

                response = CompleteResponse(results, parsedQuery, contextData, siteId);
            }
            catch (Exception ex)
            {
                response = TransformExecutionException(ex);
            }

            return(response);
        }
        public void WindSpeed_MPH_Test()
        {
            QueryResults result = _homeController.QueryServices(_fahrenheit.Id, _mph.Id, TestLocation, new HomeController.QueryServiceDelegate(QueryService)).Result;

            Assert.Equal(7.5m, result.WindSpeedResult);
        }
Exemple #33
0
        public ActionResult Save(string sql, string title, string description, int siteId, int?querySetId, bool?textResults, bool?withExecutionPlan, TargetSites?targetSites)
        {
            if (CurrentUser.IsAnonymous && !CaptchaController.CaptchaPassed(GetRemoteIP()))
            {
                return(Json(new { captcha = true }));
            }

            ActionResult response = null;

            try
            {
                if (!ValidateTargetSites(targetSites))
                {
                    throw new ApplicationException("Invalid target sites selection");
                }

                QuerySet querySet = null;

                if (querySetId.HasValue)
                {
                    querySet = Current.DB.QuerySets.Get(querySetId.Value);

                    if (querySet == null)
                    {
                        throw new ApplicationException("Invalid query set ID");
                    }
                }

                var parsedQuery = new ParsedQuery(
                    sql,
                    Request.Params,
                    withExecutionPlan == true,
                    targetSites ?? TargetSites.Current
                    );

                QueryResults results = null;
                Site         site    = GetSite(siteId);
                ValidateQuery(parsedQuery, site);

                if (title.HasValue() && title.Length > 100)
                {
                    throw new ApplicationException("Title must be no more than 100 characters");
                }

                if (description.HasValue() && description.Length > 1000)
                {
                    throw new ApplicationException("Description must be no more than 1000 characters");
                }

                var contextData = new QueryContextData
                {
                    Title       = title,
                    Description = description,
                    IsText      = textResults == true,
                    QuerySet    = querySet
                };

                var asyncResults = AsyncQueryRunner.Execute(parsedQuery, CurrentUser, site, contextData);

                if (asyncResults.State == AsyncQueryRunner.AsyncState.Failure)
                {
                    throw asyncResults.Exception;
                }

                if (asyncResults.State == AsyncQueryRunner.AsyncState.Success || asyncResults.State == AsyncQueryRunner.AsyncState.Cancelled)
                {
                    results = asyncResults.QueryResults;
                }
                else
                {
                    return(Json(new { running = true, job_id = asyncResults.JobId }));
                }

                response = CompleteResponse(results, parsedQuery, contextData, siteId);
            }
            catch (Exception ex)
            {
                response = TransformExecutionException(ex);
            }

            return(response);
        }
        public void Temperature_Celsius_Test()
        {
            QueryResults result = _homeController.QueryServices(_celsius.Id, _kph.Id, TestLocation, new HomeController.QueryServiceDelegate(QueryService)).Result;

            Assert.Equal(15, result.TemperatureResult);
        }
Exemple #35
0
 /// <summary>
 /// Extracts syndication feed items.
 /// </summary>
 /// <param name="localization">The context <see cref="Localization"/>.</param>
 /// <returns>The extracted syndication feed items; a concatentation of syndication feed items provided by <see cref="QueryResults"/> (if any).</returns>
 public virtual IEnumerable <SyndicationItem> ExtractSyndicationFeedItems(Localization localization)
 {
     return(ConcatenateSyndicationFeedItems(QueryResults.OfType <ISyndicationFeedItemProvider>(), localization));
 }
        public void Temperature_Fahrenheit_Test()
        {
            QueryResults result = _homeController.QueryServices(_fahrenheit.Id, _mph.Id, TestLocation, new HomeController.QueryServiceDelegate(QueryService)).Result;

            Assert.Equal(59, result.TemperatureResult);
        }
Exemple #37
0
 public void postProcess(QueryResults qr, ExtractorConfiguration config)
 {
     qr = QueryResultsUtils.cleanupTicket76(qr, qr.LabChemIens); // strip top level file records per ticket #76
     qr = QueryResultsUtils.cleanupTicket85(qr);                 // change "&amp;" to just "&" in lab accession number per ticket #85
 }
        public void WindSpeed_KPH_Test()
        {
            QueryResults result = _homeController.QueryServices(_celsius.Id, _kph.Id, TestLocation, new HomeController.QueryServiceDelegate(QueryService)).Result;

            Assert.Equal(12, result.WindSpeedResult);
        }
Exemple #39
0
 /// <summary>
 /// Find all values overlapping the specified point.
 /// </summary>
 /// <returns>True if any values were found.</returns>
 /// <param name="x">The x coordinate.</param>
 /// <param name="y">The y coordinate.</param>
 /// <param name="values">A list to populate with the results. If null, this function will create the list for you.</param>
 public void SearchPoint(long x, long y)
 {
     QueryResults.Clear();
     Root.SearchPoint(x, y, QueryResults);
 }
Exemple #40
0
        public override void GetVisibleIndexes(QueryResults results, List<int> visibleIndexes)
        {
            for (int i = results.Count - 1; i >= 0; i--)
            {
                IActiveObject current = results[i];
                Content result = results.GetQueryObject(i);

                if (current.GetType().Equals(this.Content.GetType())
                    && current.DataManager.PrimaryKeyValue.Equals(this.Content.DataManager.PrimaryKeyValue))
                {
                    visibleIndexes.Remove(i);
                    continue;
                }
                //Content result = QueryResults.GetRawQueryContent(current);
                if (result.Score < this.Relevance)
                {
                    visibleIndexes.Remove(i);
                }
            }
        }