Esempio n. 1
0
 public static void NotifyApplication(IServiceLocatorMaster masterLocator, Guid applicationId,
                                      int announcementApplicationId, int announcemnetType, string sessionKey, NotifyAppType type)
 {
     Task.Run(() => NotifyApplicationAsync(masterLocator, applicationId, announcementApplicationId, announcemnetType, sessionKey, type));
 }
Esempio n. 2
0
        public static async Task NotifyApplicationAsync(IServiceLocatorMaster masterLocator, Guid applicationId, int announcementApplicationId,
                                                        int announcemnetType, string sessionKey, NotifyAppType type)
        {
            try
            {
                var app   = masterLocator.ApplicationService.GetApplicationById(applicationId);
                var url   = app.Url;
                var token = masterLocator.ApplicationService.GetAccessToken(applicationId, sessionKey);
                var mode  = type == NotifyAppType.Attach
                    ? API.Settings.ANNOUNCEMENT_APPLICATION_SUBMIT
                    : API.Settings.ANNOUNCEMENT_APPLICATION_REMOVE;

                var ps = new Dictionary <string, string>
                {
                    ["apiRoot"] = "https://" + Chalkable.Common.Settings.Domain,
                    ["announcementApplicationId"] = announcementApplicationId.ToString(),
                    ["announcementType"]          = announcemnetType.ToString(),
                    ["mode"]  = mode,
                    ["token"] = token,
                    ["_"]     = Guid.NewGuid().ToString()
                };

                var webRequest = (HttpWebRequest)WebRequest.Create(url);

                webRequest.KeepAlive         = true;
                webRequest.Credentials       = CredentialCache.DefaultCredentials;
                webRequest.Method            = WebRequestMethods.Http.Post;
                webRequest.Accept            = "application/json";
                webRequest.AllowAutoRedirect = false;
                SignRequest(webRequest, ps, app.SecretKey);
                PrepareParams(webRequest, ps);

                var response = await webRequest.GetResponseAsync();

                using (var stream = response.GetResponseStream())
                {
                    var statusCode = (response as HttpWebResponse)?.StatusCode;
                    if (stream == null || (statusCode.HasValue && statusCode.Value != HttpStatusCode.OK))
                    {
                        HandleException(new ChalkableException($"Server {url} faild to responce." +
                                                               $"Request Parameters: {ps.Select(x => $"{x.Key}={x.Value}").JoinString("&")}"));
                    }
                }
            }
            catch (WebException ex)
            {
                HandleException(ex);
            }
            catch (Exception e)
            {
                HandleException(e);
            }
        }
Esempio n. 3
0
 //TODO: think to move notify Applications logic
 public static void NotifyApplications(IServiceLocatorMaster masterLocator, IList <AnnouncementApplication> annApps
                                       , int announcemnetType, string sessionKey, NotifyAppType type)
 {
     foreach (var annApp in annApps)
     {
         NotifyApplication(masterLocator, annApp.ApplicationRef, annApp.Id, announcemnetType, sessionKey, type);
     }
 }