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();
            }
        }
        public static void Main(string[] args)
        {
            Console.WriteLine("Create an example Coresight display");

            Console.WriteLine("Paste in your PI WebAPI URL:");
            Uri webApiBaseUri = new Uri(Console.ReadLine().TrimEnd('/') + "/");

            Console.WriteLine("Paste in your Coresight URL:");
            string coresightUri = Console.ReadLine();

            Console.WriteLine("Paste in the path to an AF Element whose template will form the default display");
            string elementPath = Console.ReadLine();

            Console.WriteLine("Optionally, provide a semicolon-delimited list of attribute categories to be included. By default, all are included.");
            string        attributeCategoryList = Console.ReadLine();
            List <string> includedCategories    = attributeCategoryList.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            PIWebAPIClient        piWebApiClient  = new PIWebAPIClient(webApiBaseUri);
            AFElementDTO          elementDTO      = piWebApiClient.GetElementDTOByPathAsync(elementPath).GetAwaiter().GetResult();
            AFElementTemplateSlim elementTemplate = piWebApiClient.GetElementTemplateSlimAsync(elementDTO).GetAwaiter().GetResult();

            CoresightDefaultDisplayFactory displayFactory = new CoresightDefaultDisplayFactory(coresightUri);
            DisplayRevision defaultDisplay = displayFactory.CreateDefaultDisplayAsync(elementTemplate, elementPath, includedCategories).GetAwaiter().GetResult();

            Uri displayUri = defaultDisplay.GetUri(displayFactory.CoresightBaseUri);

            Console.WriteLine("New display created at {0}", displayUri);

            Console.ReadKey();
            Console.ReadKey();
        }
示例#4
0
        private static void loadPIData()
        {
            var username = "******";
            var password = "******";
            var client   = new PIWebAPIClient(username, password);

            string pressure         = "https://pi.dvnhackathon.com/piwebapi/streams/A0EkmIZsN6_90OPP6Ztf91JxQQG-r8JTT5xGpRgANOmHTrQfy8liDPVAlkrZEtw0Fh1wgT1NJU09GVFBJLTAwMVxERVZPTlxTS0lEU1xTS0lEICM3N3xUUkVBVElORyBQUkVTU1VSRQ/interpolated?endtime=11-2-2017&starttime=11-1-2017&interval=00:01:00";
            string slurrytotal      = "https://pi.dvnhackathon.com/piwebapi/streams/A0EkmIZsN6_90OPP6Ztf91JxQQG-r8JTT5xGpRgANOmHTrQa89DYKgMTlMuXLgXHniPvAT1NJU09GVFBJLTAwMVxERVZPTlxTS0lEU1xTS0lEICM3N3xTTFVSUlkgVE9UQUw/interpolated?endtime=11-2-2017&starttime=11-1-2017&interval=00:01:00";
            string slurryrate       = "https://pi.dvnhackathon.com/piwebapi/streams/A0EkmIZsN6_90OPP6Ztf91JxQQG-r8JTT5xGpRgANOmHTrQcEDba2FtgFkj3SMDEZwBswT1NJU09GVFBJLTAwMVxERVZPTlxTS0lEU1xTS0lEICM3N3xTTFVSUlkgUkFURQ/interpolated?endtime=11-2-2017&starttime=11-1-2017&interval=00:01:00";
            string blenderpropconc  = "https://pi.dvnhackathon.com/piwebapi/streams/A0EkmIZsN6_90OPP6Ztf91JxQQG-r8JTT5xGpRgANOmHTrQHN-mPjB1alEYAvezJAEdoQT1NJU09GVFBJLTAwMVxERVZPTlxTS0lEU1xTS0lEICM3N3xCTEVOREVSIFBST1AgQ09OQw/interpolated?endtime=11-2-2017&starttime=11-1-2017&interval=00:01:00";
            string blenderproptotal = "https://pi.dvnhackathon.com/piwebapi/streams/A0EkmIZsN6_90OPP6Ztf91JxQQG-r8JTT5xGpRgANOmHTrQkvD3Bcu-DlUONGgrz-y0cAT1NJU09GVFBJLTAwMVxERVZPTlxTS0lEU1xTS0lEICM3N3xCTEVOREVSIFBST1AgVE9UQUw/interpolated?endtime=11-2-2017&starttime=11-1-2017&interval=00:01:00";
            string stage            = "https://pi.dvnhackathon.com/piwebapi/streams/A0EkmIZsN6_90OPP6Ztf91JxQQG-r8JTT5xGpRgANOmHTrQ5uD6lW622l41riCZoX1AuAT1NJU09GVFBJLTAwMVxERVZPTlxTS0lEU1xTS0lEICM3N3xTVEFHRSBBVCBCTEVOREVS/interpolated?endtime=11-2-2017&starttime=11-1-2017&interval=00:01:00";
            string wellname         = "https://pi.dvnhackathon.com/piwebapi/streams/A0EkmIZsN6_90OPP6Ztf91JxQQG-r8JTT5xGpRgANOmHTrQiUnrl8rj_l0vh2Ywz6NfjQT1NJU09GVFBJLTAwMVxERVZPTlxTS0lEU1xTS0lEICM3N3xXRUxMTkFNRQ/interpolated?endtime=11-2-2017&starttime=11-1-2017&interval=00:01:00";

            var pressureData  = client.GetRequest(pressure);
            var pressureItems = pressureData["Items"].ToString();

            WriteDataToDatabase(pressureItems, "TreatingPressure");

            var slurrytotalData  = client.GetRequest(slurrytotal);
            var slurrytotalItems = slurrytotalData["Items"].ToString();

            WriteDataToDatabase(slurrytotalItems, "SlurryTotal");

            var slurryrateData  = client.GetRequest(slurryrate);
            var slurryrateItems = slurryrateData["Items"].ToString();

            WriteDataToDatabase(slurryrateItems, "SlurryRate");

            var blenderpropconcData  = client.GetRequest(blenderpropconc);
            var blenderpropconcItems = blenderpropconcData["Items"].ToString();

            WriteDataToDatabase(blenderpropconcItems, "BlenderPropConc");

            var blenderproptotalData = client.GetRequest(blenderproptotal);
            var blenderproptotaltems = blenderproptotalData["Items"].ToString();

            WriteDataToDatabase(blenderproptotaltems, "BlenderPropConc");

            var stageData  = client.GetRequest(stage);
            var stageltems = stageData["Items"].ToString();

            WriteDataToDatabase(stageltems, "Stage");

            var wellNameData  = client.GetRequest(wellname);
            var wellnameItems = wellNameData["Items"].ToString();

            WriteDataToDatabase(wellnameItems, "Wellname");
        }
        public async Task <ActionResult> Navigation(int?id)
        {
            List <Item>       LocationsAll = db.Items.ToList(); List <Item> Locations = new List <Item>();
            type              _type = new type(); string url = string.Empty; Item _locationSelected = new Item();
            List <Indicators> _indicators = new List <Indicators>();

            if (id != null)
            {
                Locations         = LocationsAll.Where(x => x.ParentId == id).ToList();
                _type             = LocationsAll.Where(x => x.id == id).Select(x => x.Nodo).FirstOrDefault();
                _locationSelected = LocationsAll.Where(x => x.id == id).FirstOrDefault();
                url = PIWebAPIClient.RequestDirectory(_type.ToString());
                try
                {
                    JObject data = await client.GetAsync(url);

                    _indicators           = CastData(data);
                    Session["Indicators"] = _indicators;
                    _locationSelected     = LocationsAll.Where(x => x.id == id).FirstOrDefault();
                }
                catch {
                    JObject data = null;
                    _indicators           = CastData(data);
                    Session["Indicators"] = _indicators;
                }
            }

            VMNavigation _vm = new VMNavigation()
            {
                Locations        = Locations,
                MyMenu           = BuildMenu(id),
                IndicatorsValues = _indicators,
                LocationSelected = _locationSelected
            };

            return(View(_vm));
        }