示例#1
0
        public async Task SendDeleteAttachmentEvent(string docId)
        {
            var eventEntry = new PutEventsRequestEntry
            {
                Source       = "mono.deleteDocument",
                EventBusName = Environment.GetEnvironmentVariable("deleteEventBus"),
                DetailType   = "transaction",
                Time         = DateTime.Now,
                Detail       = Jsoner.Convert(
                    new
                {
                    docId
                }
                    )
            };

            await SendEvent(eventEntry);
        }
示例#2
0
        public string getJwt(string docId, UserModel user, List <Permission> permissions)
        {
            var json = Jsoner.Convert(new
            {
                docId,
                permissions = permissions.Where(i => i.Permissions != null).ToList(),
                meta        = new
                {
                    user.Id,
                    user.GivenName,
                    user.FamilyName
                }
            });

            var httpWebRequest = (HttpWebRequest)WebRequest.Create(Url_);

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";
            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(json);
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                var body   = JsonConvert.DeserializeObject <Dictionary <string, string> >(result);
                if (body.TryGetValue("jwt", out string response))
                {
                    return(response);
                }
                throw new Exception("Failed to get jwt");
            }
        }