コード例 #1
0
        public ActionResult GetSeries(string sn, DateTime from, DateTime to, SeriesResolution?resolution)
        {
            // Sanitize from and to. Sometimes from is DateTime.MinValue for whatever reason, but earliest Qbox data is from 2012.
            var earliestDateWithNoDataForSure = new DateTime(2010, 1, 1);

            if (from < earliestDateWithNoDataForSure)
            {
                from = earliestDateWithNoDataForSure;
            }
            if (to < from)
            {
                to = from.AddDays(1);
            }

            var actualResolution = resolution ?? DeriveResolution(from, to);
            var fromUtc          = DateTimeUtils.NlDateTimeToUtc(from);
            var toUtc            = DateTimeUtils.NlDateTimeToUtc(to);
            var mini             = _miniRetriever.Retrieve(sn);
            var series           = RetrieveForAccount(mini, fromUtc, toUtc, actualResolution);
            var response         = new
            {
                result = true,
                data   = series
            };

            return(new OkObjectResult(response));
        }
コード例 #2
0
        /// <summary>
        /// Overide to allow the creation of the Qbox Data Dump context object.
        /// It retrieves the url and external ip from the request and adds the request bytes to the context.
        /// After decrypting the content (if found to be encrypted) the QboxDataDump object is constructed.
        /// </summary>
        /// <param name="context">The controller context holding associations and objects in relation to the controller</param>
        /// <param name="pn">Product number</param>
        /// <param name="sn">Serial number</param>
        /// <returns>An object model that is requested in the bindingcontext</returns>
        public QboxDataDumpContext CreateContext(ControllerContext context, string pn, string sn)
        {
            try
            {
                int    length;
                string lastSeenAtUrl;
                string externalIp;

                var bytes = GetRequestVariables(context, out length, out lastSeenAtUrl, out externalIp);

                var mini = _miniRetriever.Retrieve(sn);

                if (mini != null)
                {
                    mini.SetStorageProvider(_storageProviderFactory);
                    var message = QboxMessageDecrypter.DecryptPlainOrEncryptedMessage(bytes);
                    return(new QboxDataDumpContext(message, length, lastSeenAtUrl, externalIp, mini, error: null));
                }

                return(null);
            }
            catch (Exception e)
            {
                var s = string.Format("Serialnumber: {0} - orginal error message: {2} | {1}", sn, e.Message, pn);
                _logger.LogError(e, s);
                return(new QboxDataDumpContext("N/A", 0, "N/A", "N/A", null, error: e.Message + " - " + s));//refactor: beter oplossen wordt nu gecontroleerd in de controller en die gooit een exception
            }
            finally
            {
                _logger.LogTrace("Return");
            }
        }