public async Task <ActionResult> Devices()
        {
            // Manage session and Context
            HttpServiceUriBuilder contextUri = new HttpServiceUriBuilder().SetServiceName(this.context.ServiceName);

            if (HTTPHelper.IsSessionExpired(HttpContext, this))
            {
                return(Redirect(contextUri.GetServiceNameSiteHomePath()));
            }
            else
            {
                this.ViewData["TargetSite"]  = contextUri.GetServiceNameSite();
                this.ViewData["PageTitle"]   = "Devices";
                this.ViewData["HeaderTitle"] = "Devices Dashboard";

                string reportUniqueId = HashUtil.GetUniqueId();
                string reportName     = "DoverCivaconDemo"; // the dashboard

                EmbedConfig task = await ReportsHandler.GetEmbedReportConfigData(ClientId, GroupId, Username, Password, AuthorityUrl, ResourceUrl, ApiUrl, reportUniqueId, reportName, this.context, ServiceEventSource.Current);

                this.ViewData["EmbedToken"]     = task.EmbedToken.Token;
                this.ViewData["EmbedURL"]       = task.EmbedUrl;
                this.ViewData["EmbedId"]        = task.Id;
                this.ViewData["ReportUniqueId"] = "";

                return(this.View());
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Index()
        {
            // Manage session
            HttpServiceUriBuilder contextUri = new HttpServiceUriBuilder().SetServiceName(this.context.ServiceName);

            // if there is an ongoing session this method will make sure to pass along the session information
            // to the view
            HTTPHelper.IsSessionExpired(HttpContext, this);

            this.ViewData["TargetSite"]  = contextUri.GetServiceNameSite();
            this.ViewData["PageTitle"]   = "Home";
            this.ViewData["HeaderTitle"] = "Vibration Device Insights";

            ViewBag.RedirectURL = "";
            ViewBag.Message     = "";
            return(View("Index"));
        }
Beispiel #3
0
        public async Task <IActionResult> EmbedReport(string reportName, string reportParm = null, string reportParmStart = null, string reportParmEnd = null, int numberOfObservations = (-1), int minMagnitudeAllowed = 1)
        {
            // Manage session and Context
            HttpServiceUriBuilder contextUri = new HttpServiceUriBuilder().SetServiceName(this.context.ServiceName);

            ViewBag.RedirectURL = "";

            if (HTTPHelper.IsSessionExpired(HttpContext, this))
            {
                return(Ok(contextUri.GetServiceNameSiteHomePath()));
            }
            else
            {
                this.ViewData["TargetSite"]  = contextUri.GetServiceNameSite();
                this.ViewData["PageTitle"]   = "Report";
                this.ViewData["HeaderTitle"] = "Last Posted Events";

                string reportUniqueId = FnvHash.GetUniqueId();

                // Now it is time to refresh the data set
                List <DeviceViewModelList> deviceViewModelList = null;
                int  resampleSetsLimit = 0;
                var  refreshDataresult = false;
                bool publishReportData = true;

                if (reportName.Equals("PSG-VibrationDeviceReport-02"))
                {
                    refreshDataresult = true;
                    publishReportData = false;
                }
                else if (reportName.Equals("PSG-VibrationDeviceReport-01") && reportParm != null)
                {
                    deviceViewModelList = await DevicesController.GetDevicesDataAsync(reportParm, httpClient, fabricClient, appLifetime);
                }
                else
                {
                    resampleSetsLimit = 1;

                    deviceViewModelList = new List <DeviceViewModelList>();
                    ServiceUriBuilder uriBuilder = new ServiceUriBuilder(Names.InsightDataServiceName);
                    Uri serviceUri = uriBuilder.Build();

                    // service may be partitioned.
                    // this will aggregate device IDs from all partitions
                    ServicePartitionList partitions = await fabricClient.QueryManager.GetPartitionListAsync(serviceUri);

                    foreach (Partition partition in partitions)
                    {
                        string pathAndQuery      = null;
                        int    index             = 0;
                        float  indexInterval     = 1F;
                        bool   keepLooping       = true;
                        int    observationsCount = 0;
                        int    batchIndex        = 0;
                        int    batchSize         = 10000;


                        while (keepLooping)
                        {
                            if (reportParmEnd == null)
                            {
                                pathAndQuery = $"/api/devices/history/byKey/{reportParmStart}";
                                keepLooping  = false;
                            }
                            else if (numberOfObservations != (-1))
                            {
                                pathAndQuery = $"/api/devices/history/byKeyRange/{reportParmStart}/{reportParmEnd}/{batchIndex}/{batchSize}";

                                if (index == 0)
                                {
                                    string getCountPathAndQuery = $"/api/devices/history/count/interval/{reportParmStart}/{reportParmEnd}";
                                    Uri    getCountUrl          = new HttpServiceUriBuilder()
                                                                  .SetServiceName(serviceUri)
                                                                  .SetPartitionKey(((Int64RangePartitionInformation)partition.PartitionInformation).LowKey)
                                                                  .SetServicePathAndQuery(getCountPathAndQuery)
                                                                  .Build();

                                    HttpResponseMessage localResponse = await httpClient.GetAsync(getCountUrl, appLifetime.ApplicationStopping);

                                    if (localResponse.StatusCode == System.Net.HttpStatusCode.OK)
                                    {
                                        string localResult = await localResponse.Content.ReadAsStringAsync();

                                        long count = Int64.Parse(localResult);

                                        indexInterval = count / numberOfObservations;

                                        if (indexInterval < 1)
                                        {
                                            indexInterval = 1;
                                        }
                                    }
                                }
                            }
                            else if (reportParmEnd != null)
                            {
                                pathAndQuery = $"/api/devices/history/byKeyRange/{reportParmStart}/{reportParmEnd}";
                                keepLooping  = false;
                            }

                            Uri getUrl = new HttpServiceUriBuilder()
                                         .SetServiceName(serviceUri)
                                         .SetPartitionKey(((Int64RangePartitionInformation)partition.PartitionInformation).LowKey)
                                         .SetServicePathAndQuery(pathAndQuery)
                                         .Build();

                            HttpResponseMessage response = await httpClient.GetAsync(getUrl, appLifetime.ApplicationStopping);

                            if (response.StatusCode == System.Net.HttpStatusCode.OK)
                            {
                                JsonSerializer serializer = new JsonSerializer();
                                using (StreamReader streamReader = new StreamReader(await response.Content.ReadAsStreamAsync()))
                                {
                                    using (JsonTextReader jsonReader = new JsonTextReader(streamReader))
                                    {
                                        List <DeviceViewModelList> localResult = serializer.Deserialize <List <DeviceViewModelList> >(jsonReader);

                                        if (localResult != null)
                                        {
                                            if (localResult.Count != 0)
                                            {
                                                foreach (DeviceViewModelList device in localResult)
                                                {
                                                    if (index >= (observationsCount * indexInterval))
                                                    {
                                                        deviceViewModelList.Add(device);
                                                        observationsCount++;
                                                    }
                                                    index++;

                                                    if (numberOfObservations != (-1))
                                                    {
                                                        if (observationsCount == numberOfObservations)
                                                        {
                                                            keepLooping = false;
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                keepLooping = false;
                                            }
                                        }
                                        else
                                        {
                                            keepLooping = false;
                                        }
                                    }
                                }
                            }
                            batchIndex += batchSize;
                        }
                    }
                }

                if (publishReportData)
                {
                    refreshDataresult = await ReportsHandler.PublishReportDataFor(reportUniqueId, DevicesDataStream01URL, deviceViewModelList, context, httpClient, appLifetime.ApplicationStopping, ServiceEventSource.Current, resampleSetsLimit, minMagnitudeAllowed);
                }

                if (reportName.Equals("PSG-VibrationDeviceReport-02"))
                {
                    reportUniqueId = "";
                }

                EmbedConfig task = await ReportsHandler.GetEmbedReportConfigData(ClientId, GroupId, Username, Password, AuthorityUrl, ResourceUrl, ApiUrl, reportUniqueId, reportName, this.context, ServiceEventSource.Current);

                this.ViewData["EmbedToken"]     = task.EmbedToken.Token;
                this.ViewData["EmbedURL"]       = task.EmbedUrl;
                this.ViewData["EmbedId"]        = task.Id;
                this.ViewData["ReportUniqueId"] = reportUniqueId;

                return(this.View());
            }
        }