public async Task<ActionResult> Search(SearchModel model)
        {
            PIWebAPIClient client = new PIWebAPIClient("https://myserver/piwebapi");

            string query = model.Option.Equals("all") ? model.Query : model.Option + ":" + model.Query;
            int count = model.Count.HasValue ? (int)model.Count : 10;
            
            try
            {
                dynamic result = await client.SearchAsync(query, null, "name;itemtype;webid", count);
                List<SearchResult> searchResults = new List<SearchResult>();
                for (int i = 0; i < result.Items.Count; i++)
                {
                    SearchResult searchResult = new SearchResult();
                    searchResult.Name = result.Items[i].Name.Value;
                    searchResult.ItemType = result.Items[i].ItemType.Value;
                    searchResult.WebId = result.Items[i].WebID.Value;
                    searchResults.Add(searchResult);
                }
                return View(searchResults);
            }
            catch (Exception)
            {
                return View("Error");
                throw;
            }
            finally
            {
                client.Dispose();
            }
            
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.Write("Enter username: "******"Enter password: "******"Getting list of PI Data Archives...");
                Dictionary<string, string> serversWebId = client.GetDataServersWebIdAsync().Result;
                foreach (var server in serversWebId)
                {
                    Console.WriteLine(server.Key);
                }
                do
                {
                    Console.Write("Please type in name of the PI Data Archive: ");
                    string myPI = Console.ReadLine();
                    Console.Write("Please type in name of the tag: ");
                    string myTag = Console.ReadLine();

                    if (IsRead())
                    {
                        dynamic value = client.GetTagValueAsync(serversWebId[myPI], myTag).Result;
                        Console.WriteLine("Current value = {0}", value);
                    }
                    else
                    {
                        Console.Write("Value to write? ");
                        string valueToWrite = Console.ReadLine();
                        client.WriteTagValueAsync(serversWebId[myPI], myTag, valueToWrite).Wait();
                        Console.WriteLine("Value written.");
                    }
                    Console.WriteLine("Press any key to continue (esc to exit)...");
                } while (Console.ReadKey().Key != ConsoleKey.Escape);
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (KeyNotFoundException)
            {
                Console.WriteLine("The specified PI Data Archive cannot be found.");
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    Console.WriteLine(e.Message);
                }
            }
            finally
            {
                client.Dispose();
                Console.ReadKey();
            }
        }