Beispiel #1
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");
            }
        }
Beispiel #2
0
        /// <inheritdoc cref="IQboxDataDumpContextFactory.Create(QboxContext)"/>
        public QboxDataDumpContext Create(QboxContext context)
        {
            Guard.IsNotNull(context, nameof(context));

            string lastSeenAtUrl = context.LastSeenAtUrl;
            string externalIp    = context.ExternalIp;

            var message = QboxMessageDecrypter.DecryptPlainOrEncryptedMessage(context.Message);
            int length  = context.Message.Length;

            var mini = _qboxMiniFactory.Create(context.SerialNumber);

            return(new QboxDataDumpContext(message, length, lastSeenAtUrl, externalIp, mini));
        }