Example #1
0
        private Status GenerateSuggestions(WorkflowInstance workflowInstance, ServerEntity entity, Dictionary <string, string> suggestionList)
        {
            Item item = entity as Item;

            if (item == null)
            {
                TraceLog.TraceError("Entity is not an Item");
                return(Status.Error);
            }

            try
            {
                BingSearch bingSearch = new BingSearch();

                // retrieve and format the search template, or if one doesn't exist, use $(Intent)

                string searchTemplate = null;
                if (InputParameters.TryGetValue(ActivityParameters.SearchTemplate, out searchTemplate) == false)
                {
                    searchTemplate = String.Format("$({0})", ActivityVariables.Intent);
                }
                string query = ExpandVariables(workflowInstance, searchTemplate);

                if (String.IsNullOrWhiteSpace(query))
                {
                    TraceLog.TraceInfo("No query to issue Bing");
                    return(Status.Complete);
                }

                // make a synchronous webservice call to bing
                //
                // Async has the problem that the caller of this method assumes that a
                // populated suggestionList will come out.  If it doesn't, the state will execute
                // again and trigger a fresh set of suggestions to be generated.  Eventually all
                // queries will return and populate the suggestions DB with duplicate data.
                // This can be fixed once we move to a "real" workflow system such as WF.
                var results = bingSearch.Query(query);
                foreach (var r in results)
                {
                    WebResult result = r as WebResult;
                    if (result != null)
                    {
                        suggestionList[result.Title] = result.Url;
                    }
                }
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("Bing query failed", ex);
                return(Status.Error);
            }

            // this activity is typically last and once links have been generated, no need
            // to keep the workflow instance around
            return(Status.Complete);
        }
Example #2
0
        private Status GenerateSuggestions(WorkflowInstance workflowInstance, ServerEntity entity, Dictionary<string, string> suggestionList)
        {
            Item item = entity as Item;
            if (item == null)
            {
                TraceLog.TraceError("Entity is not an Item");
                return Status.Error;
            }

            try
            {
                BingSearch bingSearch = new BingSearch();

                // retrieve and format the search template, or if one doesn't exist, use $(Intent)

                string searchTemplate = null;
                if (InputParameters.TryGetValue(ActivityParameters.SearchTemplate, out searchTemplate) == false)
                    searchTemplate = String.Format("$({0})", ActivityVariables.Intent);
                string query = ExpandVariables(workflowInstance, searchTemplate);

                if (String.IsNullOrWhiteSpace(query))
                {
                    TraceLog.TraceInfo("No query to issue Bing");
                    return Status.Complete;
                }

                // make a synchronous webservice call to bing
                //
                // Async has the problem that the caller of this method assumes that a
                // populated suggestionList will come out.  If it doesn't, the state will execute
                // again and trigger a fresh set of suggestions to be generated.  Eventually all
                // queries will return and populate the suggestions DB with duplicate data.
                // This can be fixed once we move to a "real" workflow system such as WF.
                var results = bingSearch.Query(query);
                foreach (var r in results)
                {
                    WebResult result = r as WebResult;
                    if (result != null)
                        suggestionList[result.Title] = result.Url;
                }
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("Bing query failed", ex);
                return Status.Error;
            }

            // this activity is typically last and once links have been generated, no need
            // to keep the workflow instance around
            return Status.Complete;
        }