Example #1
0
        private async Task PushCipherAsync(Cipher cipher, PushType type)
        {
            if (!cipher.UserId.HasValue)
            {
                // No push for org ciphers at the moment.
                return;
            }

            var message = new SyncCipherPushNotification
            {
                Type           = type,
                Id             = cipher.Id,
                UserId         = cipher.UserId,
                OrganizationId = cipher.OrganizationId,
                RevisionDate   = cipher.RevisionDate,
                Aps            = new PushNotification.AppleData {
                    ContentAvailable = 1
                }
            };

            var excludedTokens = new List <string>();

            if (!string.IsNullOrWhiteSpace(_currentContext.DeviceIdentifier))
            {
                excludedTokens.Add(_currentContext.DeviceIdentifier);
            }

            await PushToAllUserDevicesAsync(cipher.UserId.Value, JObject.FromObject(message), excludedTokens);
        }
        private async Task PushCipherAsync(Cipher cipher, PushType type, IEnumerable <Guid> collectionIds)
        {
            if (cipher.OrganizationId.HasValue)
            {
                // We cannot send org pushes since access logic is much more complicated than just the fact that they belong
                // to the organization. Potentially we could blindly send to just users that have the access all permission
                // device registration needs to be more granular to handle that appropriately. A more brute force approach could
                // me to send "full sync" push to all org users, but that has the potential to DDOS the API in bursts.

                // await SendPayloadToOrganizationAsync(cipher.OrganizationId.Value, type, message, true);
            }
            else if (cipher.UserId.HasValue)
            {
                var message = new SyncCipherPushNotification
                {
                    Id             = cipher.Id,
                    UserId         = cipher.UserId,
                    OrganizationId = cipher.OrganizationId,
                    RevisionDate   = cipher.RevisionDate,
                    CollectionIds  = collectionIds,
                };

                await SendPayloadToUserAsync(cipher.UserId.Value, type, message, true);
            }
        }
 public static async Task RequestSendAsync(PushType type, long requestNo, long sentSeq, PushState state)
 {
     using (var conn = new MySqlConnection(GetConnectionString()))
     {
         await SpRequestSendAsync(conn, null, type, requestNo, sentSeq, (sbyte)state);
     }
 }
Example #4
0
 public static async Task RequestFailAsync(long requestNo, int count, PushType type)
 {
     using (var conn = new MySqlConnection(GetConnectionString()))
     {
         await SpRequestFailAsync(conn, null, requestNo, count, type);
     }
 }
        private async Task SendMessageAsync <T>(PushType type, T payload, bool excludeCurrentContext)
        {
            var contextId = GetContextIdentifier(excludeCurrentContext);
            var request   = new PushNotificationData <T>(type, payload, contextId);

            await SendAsync(HttpMethod.Post, "send", request);
        }
Example #6
0
 private async Task SendMessageAsync <T>(PushType type, T payload, bool excludeCurrentContext)
 {
     var contextId = GetContextIdentifier(excludeCurrentContext);
     var message   = JsonConvert.SerializeObject(new PushNotificationData <T>(type, payload, contextId),
                                                 _jsonSettings);
     await _queueClient.SendMessageAsync(message);
 }
Example #7
0
        /// <summary>
        /// ios push
        /// </summary>
        /// <param name="isProduc">推送模式 groupcast broadcast</param>
        public static void PushIosMsg(PushType pushType, bool isProduc, dynamic tagjsonobj, string starttime, string title, string content, string description, string alias)
        {
            var push     = new UMengMessagePush("5d1c3c604ca3575ac2000a82", "idvcltvfmsd3qpvjnexdchrplgrvjgsc");//可以配置到web.config中
            var postJson = new PostUMengJson <IOSPayload>
            {
                PushType       = pushType,
                ProductionMode = isProduc
            };

            postJson.Payload.Aps.Alert.Body  = content;
            postJson.Payload.Aps.Alert.Title = title;
            postJson.Payload.Aps.Sound       = "default";
            postJson.Alias      = alias;
            postJson.Alias_Type = "LY_ZEUS";
            if (tagjsonobj != null)
            {
                postJson.Filter = tagjsonobj;//不能传字符串
            }
            if (!string.IsNullOrWhiteSpace(starttime))
            {
                postJson.Policy.Start_Time = starttime;
            }

            //postJson.Payload.Extra.Add("ActivityId", thirdparty_id);
            postJson.Description = description;
            //postJson.Thirdparty_Id = thirdparty_id;

            //ReturnJsonClass resu = push.SendMessage(postJson);
            var result = push.SendMessage(postJson);
        }
Example #8
0
 private async Task SendMessageAsync <T>(PushType type, T payload, bool excludeCurrentContext)
 {
     var contextId = GetContextIdentifier(excludeCurrentContext);
     var message   = JsonSerializer.Serialize(new PushNotificationData <T>(type, payload, contextId),
                                              JsonHelpers.IgnoreWritingNull);
     await _queueClient.SendMessageAsync(message);
 }
Example #9
0
        private async Task PushCipherAsync(Cipher cipher, PushType type, IEnumerable <Guid> collectionIds)
        {
            if (cipher.OrganizationId.HasValue)
            {
                var message = new SyncCipherPushNotification
                {
                    Id             = cipher.Id,
                    OrganizationId = cipher.OrganizationId,
                    RevisionDate   = cipher.RevisionDate,
                    CollectionIds  = collectionIds,
                };

                await SendMessageAsync(type, message, true);
            }
            else if (cipher.UserId.HasValue)
            {
                var message = new SyncCipherPushNotification
                {
                    Id           = cipher.Id,
                    UserId       = cipher.UserId,
                    RevisionDate = cipher.RevisionDate,
                };

                await SendMessageAsync(type, message, true);
            }
        }
Example #10
0
        public static Output <List <object>, bool> Push(BHoMAdapter adapter, IEnumerable <object> objects, string tag = "",
                                                        PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null,
                                                        bool active       = false)
        {
            var noOutput = BH.Engine.Reflection.Create.Output(new List <object>(), false);

            if (!active)
            {
                return(noOutput);
            }

            ActionConfig pushConfig = null;

            if (!adapter.SetupPushConfig(actionConfig, out pushConfig))
            {
                BH.Engine.Reflection.Compute.RecordError($"Invalid `{nameof(actionConfig)}` input.");
                return(noOutput);
            }

            PushType pt = pushType;

            if (!adapter.SetupPushType(pushType, out pt))
            {
                BH.Engine.Reflection.Compute.RecordError($"Invalid `{nameof(pushType)}` input.");
                return(noOutput);
            }

            List <object> result = adapter.Push(objects, tag, pt, pushConfig);

            return(BH.Engine.Reflection.Create.Output(result, objects?.Count() == result?.Count()));
        }
Example #11
0
        /// <summary>
        /// Update queue.
        /// </summary>
        public async Task <bool> UpdateAsync(PushType pushtype = PushType.Multicast, int retries = 3, int retriesDelay = 60, params string[] subscribers)
        {
            var content  = new JsonContent(content: new _Update(pushtype, retries, retriesDelay, subscribers));
            var response = await _client.PostAsync(string.Format("queues/{0}", Name), content);

            return(response.IsSuccessStatusCode);
        }
Example #12
0
 public static async Task <List <PushToken> > GetPushTokenAsync(PushType type, long sentSeq, string targets, int limit)
 {
     using (var conn = new MySqlConnection(GetConnectionString()))
     {
         return(await SpGetPushTokenAsync(conn, null, type, sentSeq, targets, limit));
     }
 }
Example #13
0
    public virtual void Push(PushType _forceType, Vector3 _pushDirectionFlat, PushForce _force)
    {
        if (!isBumpable)
        {
            return;
        }
        RaycastHit i_hit;

        if (Physics.Raycast(GetCenterPosition(), _pushDirectionFlat, out i_hit, 1f, LayerMask.GetMask("Environment")))
        {
            return;
        }
        switch (_forceType)
        {
        case PushType.Light:
            PushLight(_pushDirectionFlat, _force);
            break;

        case PushType.Heavy:
            Vector3 forwardDirection = _pushDirectionFlat.normalized;
            transform.forward = forwardDirection;
            ChangePawnState("PushedHeavy", PushHeavy_C(_pushDirectionFlat, _force), CancelPush_C());
            break;
        }
    }
 public static async Task <PushRequest> RequestAllGetAsync(PushType type)
 {
     using (var conn = new MySqlConnection(GetConnectionString()))
     {
         return(await SpRequestAllGetAsync(conn, null, type));
     }
 }
        public static bool PostToSiteimproveServer(TreeNode node, PushType pushType)
        {
            var pp = new PushParameters();

            pp.url = GetFullUrl(node);

            // if it is a full site recrawl, get the root
            if (pushType == PushType.recrawl)
            {
                pp.url = GetSiteRoot(node.Site);
            }

            pp.token = GetAuthToken(node.Site);
            pp.type  = pushType.ToString();

            var paramaters = new System.Collections.Specialized.NameValueCollection();

            // TODO: Map it automatically
            paramaters.Add("url", pp.url);
            paramaters.Add("token", pp.token);
            paramaters.Add("type", pp.type);

            // TODO: Error handling

            var response = CommonUtility.Post(ApiUrl + "/cms-recheck", paramaters);

            if (response == @"{ ""ordered"": true }")
            {
                return(true);
            }
            else
            {
                throw new Exception("Siteimprove Error: " + response);
            }
        }
 /// <summary>
 /// 内推
 /// </summary>
 /// <param name="pushtype"></param>
 /// <param name="body"></param>
 /// <param name="packType"></param>
 public InternalPushInfo(PushType pushtype, string body, int[] packType)
 {
     PushType     = pushtype;
     Body         = body;
     PackType     = packType;
     this.MsgID   = Guid.NewGuid().ToString("N");
     this.AddTime = DateTime.Now;
 }
Example #17
0
        /***************************************************/
        /**** Override Methods                          ****/
        /***************************************************/

        public override List <object> Push(IEnumerable <object> objects,
                                           string tag                = "",
                                           PushType pushType         = PushType.AdapterDefault,
                                           ActionConfig actionConfig = null)
        {
            Engine.Base.Compute.RecordError("POST request not implemented.");
            return(new List <object>());
        }
        /// <summary>
        /// Ensure the type stack exists, and store given push type there.
        /// </summary>
        /// <param name="pushType">the push type to store</param>
        private void PushTypeStack(PushType pushType)
        {
            if (_pushTypeStack == null)
            {
                _pushTypeStack = new Stack <PushType>(2);
            }

            _pushTypeStack.Push(pushType);
        }
 private async Task SendPayloadAsync(string tag, PushType type, object payload)
 {
     await RenewClientAndExecuteAsync(async client => await client.SendTemplateNotificationAsync(
                                          new Dictionary <string, string>
     {
         { "type", ((byte)type).ToString() },
         { "payload", JsonConvert.SerializeObject(payload) }
     }, tag));
 }
 private async Task SendPayloadAsync(string tag, PushType type, object payload)
 {
     await _client.SendTemplateNotificationAsync(
         new Dictionary <string, string>
     {
         { "type", ((byte)type).ToString() },
         { "payload", JsonSerializer.Serialize(payload) }
     }, tag);
 }
Example #21
0
 ///<summary>Sends a push notification as an alert. Makes an alert on the device if possible.
 ///If the user clicks on the alert or the app is already open, will do the given action.
 ///Swallows errors and logs to PushNotifications Logger directory.  </summary>
 ///<param name="pushType">The action for apps to take in the background.</param>
 ///<param name="alertTitle">The title of the alert that will appear in the notification center.</param>
 ///<param name="alertMessage">The contents of the alert.</param>
 ///<param name="mobileAppDeviceNum">The MobileAppDeviceNum for the devices that the push notification will be sent to.
 ///Only use this when notification is intended for one and only one device. ClinicNum param will be ignored if MobileAppDeviceNum is specified.
 ///In this case the ClinicNum belonging to this MobileAppDevice row will be used instead..</param>
 ///<param name="clinicNum">The ClinicNum for the devices that the push notification will be sent to.
 ///If the office does not have clinics enabled, use clinicNum of 0. -1 is a flag that means do not attach or validate a specific clinic.</param>
 ///<param name="userNum">The UserNum for the UserOD that the push notification will be sent to.
 ///Only applies to ODMobile. If userNum=0 then will not be targeted to a specific UserOD.</param>
 ///<param name="listPrimaryKeys">Varies depending on specific PushType(s).</param>
 ///<param name="listTags">Varies depending on specific PushType(s).</param>
 ///<param name="runAsync">Spawn thread and do not wait for result if true.</param>
 private static void SendPushAlert(PushType pushType, string alertTitle, string alertMessage, long mobileAppDeviceNum = 0, long clinicNum = 0,
                                   long userNum = 0, List <long> listPrimaryKeys = null, List <string> listTags = null, bool runAsync = true)
 {
     if (string.IsNullOrEmpty(alertTitle) || string.IsNullOrEmpty(alertMessage))
     {
         throw new Exception("Alert title and message are required.");
     }
     SendPush(pushType, true, mobileAppDeviceNum, clinicNum, userNum, listPrimaryKeys, listTags, alertTitle, alertMessage, runAsync);
 }
Example #22
0
        private async Task PushUserAsync(Guid userId, PushType type)
        {
            var message = new UserPushNotification
            {
                UserId = userId,
                Date   = DateTime.UtcNow
            };

            await SendMessageAsync(type, message, false);
        }
        private async Task PushSyncUserAsync(Guid userId, PushType type)
        {
            var message = new SyncUserPushNotification
            {
                UserId = userId,
                Date   = DateTime.UtcNow
            };

            await SendPayloadToUserAsync(userId, type, message, false);
        }
        private async Task PushFolderAsync(Folder folder, PushType type)
        {
            var message = new SyncFolderPushNotification
            {
                Id           = folder.Id,
                UserId       = folder.UserId,
                RevisionDate = folder.RevisionDate
            };

            await SendPayloadToUserAsync(folder.UserId, type, message, true);
        }
Example #25
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public IFSContainer Create(ILocatableResource resource, PushType pushType, PushConfig pushConfig)
        {
            if (resource == null)
            {
                return(null);
            }

            IFSContainer fileOrDir = resource.ToFiling();

            return(Create(fileOrDir, pushType, pushConfig));
        }
 public void SetPushType(PushType type)
 {
     if (type == IronMQ.PushType.Unicast)
     {
         PushType = PushStyle.Unicast;
     }
     else
     {
         PushType = PushStyle.Multicast;
     }
 }
 /// <summary>
 /// userId deviceId 二选一
 /// </summary>
 /// <param name="title"></param>
 /// <param name="titleContent"></param>
 /// <param name="body"></param>
 /// <param name="fromUserId"></param>
 /// <param name="toUserIds"></param>
 /// <param name="packType"></param>
 /// <param name="pushType"></param>
 /// <param name="deviceId"></param>
 public PushInfo(string title, string titleContent, string body, long fromUserId, long[] toUserIds, int[] packType, PushType pushType)
 {
     Title         = title;
     TitleContent  = titleContent;
     Body          = body;
     ToUserIDs     = toUserIds;
     PackType      = packType;
     PushType      = pushType;
     FromUserID    = fromUserId;
     this.PushTime = DateTime.Now;
 }
        public bool SendNotification(PushType pushType, string text,string imageSource)
        {
            bool result = false;
 
            try
            {
                string rawType = "wns/";
                string notificationContent = String.Empty;
 
                switch (pushType)
                {
                    case PushType.Badge:
                        rawType += "badge";
                        notificationContent = String.Format("<?xml version='1.0' encoding='utf-8'?><badge value=\"{0}\"/>", text);
                        break;
                    case PushType.Tile:
                        rawType += "tile";
                        notificationContent = String.Format("<?xml version='1.0' encoding='utf-8'?><tile><visual lang=\"en-US\"><binding template=\"TileWideSmallImageAndText03\"><image id=\"1\" src=\"{0}\"/><text id=\"1\">{1}</text></binding></visual></tile>", imageSource, text);
                        break;
                    case PushType.Toast:
                        rawType += "toast";
                        notificationContent = String.Format("<?xml version='1.0' encoding='utf-8'?><toast><visual><binding template=\"ToastImageAndText01\"><image id=\"1\" src=\"{0}\" alt=\"Placeholder image\"/><text id=\"1\">{1}</text></binding></visual></toast>", imageSource, text);
                        break;
                    default:
                        break;
                }
 
                var subscriptionUri = new Uri(_uri);
                var request = (HttpWebRequest)WebRequest.Create(subscriptionUri);
                request.Method = "POST";
                request.ContentType = "text/xml";
                request.Headers = new WebHeaderCollection();
                request.Headers.Add("X-WNS-Type", rawType);
                request.Headers.Add("Authorization", "Bearer " + _accessToken);
                byte[] notificationMessage = Encoding.Default.GetBytes(notificationContent);
                request.ContentLength = notificationMessage.Length;
 
                using (Stream requestStream = request.GetRequestStream())
                {
                    requestStream.Write(notificationMessage, 0, notificationMessage.Length);
                }
 
                var response = (HttpWebResponse)request.GetResponse();
 
                result = (response.StatusCode == HttpStatusCode.OK);
            }
            catch (Exception)
            {
                result = false;
            }
 
            return result;
        }
Example #29
0
        public async Task SendPayloadToOrganizationAsync(string orgId, PushType type, object payload, string identifier,
                                                         string deviceId = null)
        {
            var tag = BuildTag($"template:payload && organizationId:{orgId}", identifier);

            await SendPayloadAsync(tag, type, payload);

            if (InstallationDeviceEntity.IsInstallationDeviceId(deviceId))
            {
                await _installationDeviceRepository.UpsertAsync(new InstallationDeviceEntity(deviceId));
            }
        }
Example #30
0
        /// <summary>
        /// 创建信息推送对象
        /// </summary>
        /// <param name="type"></param>
        /// <param name="setting"></param>
        /// <returns></returns>
        public static IPush?CreatePushObject(PushType type, string setting)
        {
            IPush?push = null;

            switch (type)
            {
            case PushType.GoEasy:
                push = new GoEasy(setting);
                break;
            }
            return(push);
        }
        private async Task SendPayloadToOrganizationAsync(Guid orgId, PushType type, object payload, bool excludeCurrentContext)
        {
            var request = new PushSendRequestModel
            {
                OrganizationId = orgId.ToString(),
                Type           = type,
                Payload        = payload
            };

            await AddCurrentContextAsync(request, excludeCurrentContext);
            await SendAsync(HttpMethod.Post, "push/send", request);
        }
Example #32
0
        private async Task PushCipherAsync(Cipher cipher, PushType type)
        {
            var message = new SyncCipherPushNotification
            {
                Type = type,
                Id = cipher.Id,
                UserId = cipher.UserId,
                RevisionDate = cipher.RevisionDate,
                Aps = new PushNotification.AppleData { ContentAvailable = 1 }
            };

            var excludedTokens = new List<string>();
            if(!string.IsNullOrWhiteSpace(_currentContext.DeviceIdentifier))
            {
                excludedTokens.Add(_currentContext.DeviceIdentifier);
            }

            await PushToAllUserDevicesAsync(cipher.UserId, JObject.FromObject(message), excludedTokens);
        }
        /// <summary>
        /// Ensure the type stack exists, and store given push type there. 
        /// </summary>
        /// <param name="pushType">the push type to store</param>
        private void PushTypeStack(PushType pushType)
        { 
            if (_pushTypeStack == null)
            { 
                _pushTypeStack = new Stack<PushType>(2); 
            }
 
            _pushTypeStack.Push(pushType);
        }
 /// <summary>
 /// 使用指定的参数初始化推送实例
 /// </summary>
 /// <param name="_info">推送服务属性类</param>
 /// <param name="_payload">推送主体内容</param>
 /// <param name="type">推送通知的类型</param>
 public SingleApplePushServer(ApplePushServicesInfo _info, Payload<PayloadContext> _payload, PushType type)
     : this()
 {
     this.info = _info;
     this.PushPayload = _payload;
     Public.PushType = type;
 }
Example #35
0
 /// <summary>
 /// Update queue.
 /// </summary>
 public async Task<bool> UpdateAsync(PushType pushtype = PushType.Multicast, int retries = 3, int retriesDelay = 60, params string[] subscribers)
 {
     var content = new JsonContent(content: new _Update( pushtype, retries, retriesDelay, subscribers));
     var response = await _client.PostAsync(string.Format("queues/{0}", Name), content);
     return response.IsSuccessStatusCode;
 }
Example #36
0
 internal _Update(PushType pushtype = PushType.Multicast, int retries = 3, int retriesDelay = 60, params string[] subscribers)
     : this()
 {
     this._json = new JsonObject();
     if (retriesDelay != 60) _json.retries_delay = retriesDelay;
     if (retries != 3) _json.retries = retries;
     if (pushtype != PushType.Multicast) _json.push_type = pushtype;
     if (subscribers.Length != 0)
     {
         _json.subscribers = new JsonArray(subscribers.Select(url => (JsonValue)new _Url(url)));
     }
 }