Exemplo n.º 1
0
        public async Task Sign(String Base, String id, HttpRequestBase Request, HttpResponseBase Response, Action <ExpandoObject> setParams)
        {
            try
            {
                var url = $"/_attachment{Base}/{id}";
                if (Request.Files.Count != 1)
                {
                    throw new RequestModelException("There is no file here");
                }
                var stream = Request.Files[0].InputStream;
                // save signature
                //subjCN, issuer, serial, time
                var prms = new ExpandoObject();
                setParams?.Invoke(prms);

                String strTime = Request.Form["time"];
                if (strTime != null)
                {
                    var time = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                    time = time.AddMilliseconds(Double.Parse(strTime));
                    prms.Set("Time", time);
                }

                prms.Set("Stream", stream);
                prms.Set("Issuer", Request.Form["issuer"]);
                prms.Set("Serial", Request.Form["serial"]);
                prms.Set("Subject", Request.Form["subjCN"]);
                prms.Set("Kind", Request.Form["kind"]);
                prms.Set("Title", Request.Form["title"]);

                var ri = await _baseController.SaveSignature(url, prms);

                Response.ContentType = "application/json";
                Response.Write(JsonConvert.SerializeObject(new { status = "success", id = ri.Id }));
            }
            catch (Exception ex)
            {
                _baseController.WriteExceptionStatus(ex, Response);
            }
        }