private static void applyValueLookupForDynamicProperties(Schema schemaProperty, PropertyInfo propertyInfo) { // Applies dynamic value lookup for the current property (if DynamicValueLookupAttribute is present) if (schemaProperty == null || propertyInfo == null) { return; } var valueLookupInfo = propertyInfo.GetCustomAttribute <DynamicValueLookupAttribute>(); if (valueLookupInfo == null) { return; } var valueLookup = new DynamicValuesModel() { Parameters = ParsingUtility.ParseJsonOrUrlEncodedParams(valueLookupInfo.Parameters), ValueCollection = valueLookupInfo.ValueCollection, ValuePath = valueLookupInfo.ValuePath, ValueTitle = valueLookupInfo.ValueTitle }; valueLookup.OperationId = valueLookupInfo.LookupOperation; schemaProperty.SetValueLookup(valueLookup); }
public static void SetValueLookup(this Schema modelDescription, DynamicValuesModel dynamicValuesSettings) { modelDescription.EnsureVendorExtensions(); if (!modelDescription.vendorExtensions.ContainsKey(Constants.X_MS_DYNAMIC_VALUES)) { modelDescription.vendorExtensions.Add(Constants.X_MS_DYNAMIC_VALUES, dynamicValuesSettings); } }
public static void SetValueLookup(this Parameter parameter, DynamicValuesModel dynamicValuesSettings) { parameter.EnsureVendorExtensions(); if (!parameter.vendorExtensions.ContainsKey(Constants.X_MS_DYNAMIC_VALUES)) { parameter.vendorExtensions.Add(Constants.X_MS_DYNAMIC_VALUES, dynamicValuesSettings); } }
private static void applyValueLookupForDynamicParameters(Operation operation, ApiDescription apiDescription) { if (operation == null || apiDescription == null) { return; } var lookupParameters = from p in apiDescription.ParameterDescriptions let valueLookupInfo = p.ParameterDescriptor.GetFirstOrDefaultCustomAttribute <DynamicValueLookupAttribute>() where valueLookupInfo != null select new { SwaggerParameter = operation.parameters.FirstOrDefault(param => param.name == p.Name), Parameter = p, ValueLookupInfo = valueLookupInfo }; if (!lookupParameters.Any()) { return; } foreach (var param in lookupParameters) { var valueLookup = new DynamicValuesModel() { Parameters = ParsingUtility.ParseJsonOrUrlEncodedParams(param.ValueLookupInfo.Parameters), ValueCollection = param.ValueLookupInfo.ValueCollection, ValuePath = param.ValueLookupInfo.ValuePath, ValueTitle = param.ValueLookupInfo.ValueTitle }; valueLookup.OperationId = apiDescription.ResolveOperationIdForSiblingAction( param.ValueLookupInfo.LookupOperation, valueLookup.Parameters.Properties().Select(p => p.Name).ToArray()); param.SwaggerParameter.SetValueLookup(valueLookup); } }
//public void SendIOSPushNotification(List<UserDevice> devices, AdminNotifications AdminNotification = null, Notification OtherNotification = null, int EntityType = 0, int EntityId = 0) //{ // string serverKey = GCMWebAPIKey; // var result = "-1"; // var notificationid = 0; // try // { // var webAddr = "https://fcm.googleapis.com/fcm/send"; // foreach (var device in devices.Where(x => x.IsActive)) // { // var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr); // httpWebRequest.ContentType = "application/json"; // httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, "key=" + serverKey); // httpWebRequest.Method = "POST"; // NotificationMessage pushModel = new NotificationMessage(); // if (AdminNotification != null) // { // pushModel.notification.title = AdminNotification.Title; // pushModel.notification.text= AdminNotification.Description; // //pushModel.data.contentavailable = 1; // } // else // { // pushModel.notification.title = OtherNotification.Title; // pushModel.notification.text = OtherNotification.Text; // //pushModel.notification.NotificationId = OtherNotification.Id; // //pushModel.notification.DeliveryMan_Id = OtherNotification.DeliveryMan_ID; // // pushModel.notification.EntityType = EntityType; // // pushModel.notification.EntityId = OtherNotification.EntityId; // //pushModel.aps.contentavailable = 1; // } // using (StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) // { // //var dta = new DynamicValuesModel // //{ // // entityid = pushModel.notification.EntityId, // // entitytype = pushModel.notification.EntityType, // // notificationid = pushModel.notification.NotificationId, // // isread = true // //}; // var messageInformation = new NotificationMessage(); // //string[] authTokens = new string[1]; // //authTokens[0]=new string // string[] authTokens = { device.AuthToken }; // messageInformation.registration_ids = authTokens; // // messageInformation.data = dta; // //Object to JSON STRUCTURE => using Newtonsoft.Json; // string jsonMessage = JsonConvert.SerializeObject(messageInformation); // streamWriter.Write(jsonMessage); // streamWriter.Flush(); // } // var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); // using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) // { // result = streamReader.ReadToEnd(); // if (result.Contains("success") && result.Contains("failure")) // { // dynamic token = JObject.Parse(result); // string success = token.success.ToString(); // //return success == "1" ? true : false; // } // else // { // } // } // } // // return result; // } // catch (Exception ex) // { // Utility.LogError(ex); // } //} public void SendIOSPushNotification(List <UserDevice> devices, AdminNotifications AdminNotification = null, Notification OtherNotification = null, int EntityType = 0, int EntityId = 0) { string serverKey = GCMWebAPIKey; var result = "-1"; var notificationid = 0; try { var webAddr = "https://fcm.googleapis.com/fcm/send"; foreach (var device in devices.Where(x => x.IsActive)) { var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr); httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, "key=" + serverKey); httpWebRequest.Method = "POST"; IosPush pushModel = new IosPush(); if (AdminNotification != null) { pushModel.aps.alert.title = AdminNotification.Title; pushModel.aps.alert.body = AdminNotification.Description; //using (RiscoContext ctx=new RiscoContext()) //{ // ctx.Notifications.Count(); //} //if (device.User != null) // pushModel.notification.NotificationId = device.User.SendingUserNotifications.FirstOrDefault(x => x.AdminNotification_Id == AdminNotification.Id).Id; //else //pushModel.notification.NotificationId = device.DeliveryMan.Notifications.FirstOrDefault(x => x.AdminNotification_Id == AdminNotification.Id).Id; pushModel.notification.EntityType = (int)PushNotificationType.Announcement; //pushModel.notification.EntityId = OtherNotification.Entity_ID.Value; pushModel.aps.contentavailable = 1; } else { pushModel.aps.alert.title = OtherNotification.Title; pushModel.aps.alert.body = OtherNotification.Text; pushModel.notification.NotificationId = OtherNotification.Id; //pushModel.notification.DeliveryMan_Id = OtherNotification.DeliveryMan_ID; pushModel.notification.EntityType = EntityType; pushModel.notification.EntityId = 1; pushModel.aps.contentavailable = 1; } using (StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { var dta = new DynamicValuesModel { entityid = pushModel.notification.EntityId, entitytype = pushModel.notification.EntityType, notificationid = pushModel.notification.NotificationId, isread = true }; var messageInformation = new NotificationMessage(); //string[] authTokens = new string[1]; //authTokens[0]=new string string[] authTokens = { device.AuthToken }; messageInformation.notification = new SendNotification() { title = pushModel.aps.alert.title, text = pushModel.aps.alert.body }; messageInformation.registration_ids = authTokens; messageInformation.data = dta; //Object to JSON STRUCTURE => using Newtonsoft.Json; string jsonMessage = JsonConvert.SerializeObject(messageInformation); //string json = ""; //json = "{\"to\": \"" + device.AuthToken + "\",\"notification\": {\"body\": \"" + pushModel.aps.alert.body + "\",\"title\": \"" + pushModel.aps.alert.title + "\",\"notificationid\": \"" + pushModel.notification.NotificationId + "\",\"entitytype\": \"" + pushModel.notification.EntityType + "\",\"entityid\": \"" + pushModel.notification.EntityId + "\",\"isread\": \"" + true + "\",}}"; //json = "{\"to\": \"" + device.AuthToken + "\",\"notification\": {\"text\": \"" + pushModel.aps.alert.body + "\",\"title\": \"" + pushModel.aps.alert.title + "\",\"notificationid\": \"" + notificationid + "\",\"isread\": \"" + true + "\",},\"data\":{\"entitytype\": \"" + pushModel.notification.EntityType + "\",\"entityid\": \"" + pushModel.notification.EntityId + "\",}}"; streamWriter.Write(jsonMessage); streamWriter.Flush(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { result = streamReader.ReadToEnd(); if (result.Contains("success") && result.Contains("failure")) { dynamic token = JObject.Parse(result); string success = token.success.ToString(); //return success == "1" ? true : false; } else { } } } // return result; } catch (Exception ex) { } }