예제 #1
0
        /// <summary>
        /// authorized:
        ///  ID_CAP_PUSH_NOTIFICATION
        ///  ID_CAP_IDENTITY_DEVICE
        /// </summary>
        public void rebind()
        {
            HttpNotificationChannel channel = HttpNotificationChannel.Find(BmobWindowsPhone.PushChannel);

            //如果用户通过更改应用程序中的设置关闭了通知,如应用程序策略的第 2.9 节中所述,则您应该确保使用 Close()()()() 方法来关闭推送通道。

            if (channel == null)
            {
                // 感谢赵越大哥无私的贡献!
                channel = new HttpNotificationChannel(BmobWindowsPhone.PushChannel, "urn:wp-ac-hash-2:bchdqmkdpwamzk1umxagzovixy2mwp8-b9vfeea9l2c");
                registerPushChannelEvent(channel);

                channel.Open();

                /// 如果您想接收 Toast 通知,则应该调用 BindToShellToast()方法将通道绑定到 Toast 通知。
                channel.BindToShellToast();
                // 如果您想接收磁贴通知,则将通道绑定到磁贴通知,方法是:调用 BindToShellTile()方法以访问设备上的本地资源或调用
                // BindToShellTile(Collection<(Of <<'(Uri>)>>)) 方法以访问远程资源。若要访问远程资源,您必须提供从中访问远程图像的所允许域的集合。集合中的每个 URI 都限制为 256 个字符。
                channel.BindToShellTile();
            }
            else
            {
                registerPushChannelEvent(channel);
                NotificationUri = channel.ChannelUri.ToString();
                BmobDebug.Log("NotificationUri: " + NotificationUri);

                fetchAndUpdateNotifactionUri();
            }
        }
 // 调用内部方法请求url网页的内容
 private void url_Click(object sender, RoutedEventArgs e)
 {
     new BmobWindows().Request("http://www.baidu.com", "GET", "", new byte[0], new Dictionary <string, string>(), (resp, status, ex) =>
     {
         BmobDebug.Log(resp);
     });
 }
        // JSON解析测试
        private void json_Click(object sender, RoutedEventArgs e)
        {
            var data = new BmobApi();

            data.name = "winse";
            BmobDebug.Log(JsonAdapter.JSON.ToDebugJsonString(data));
        }
예제 #4
0
        public void HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
        {
            string message;

            using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body))
            {
                message = reader.ReadToEnd();
            }
            BmobDebug.Log(String.Format("Received Notification {0}:\n{1}", DateTime.Now.ToShortTimeString(), message));
        }
예제 #5
0
        /// <summary>
        /// Event handler for when the push channel Uri is updated.
        /// </summary>
        public void ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
        {
            NotificationUri = e.ChannelUri.ToString();
            installaction.notificationUri = NotificationUri;

            // Display the new URI for testing purposes.   Normally, the URI would be passed back to your web service at this point.
            BmobDebug.Log(String.Format("Channel Uri is {0}", NotificationUri));

            fetchAndUpdateNotifactionUri();
        }
 // start push
 private void installation_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Bmob.StartPush();
     }
     catch (Exception ex)
     {
         BmobDebug.Log(ex);
     }
 }
예제 #7
0
            // obj to IDictionary<String, Object>
            public override bool TrySerializeNonPrimitiveObject(object input, out object output)
            {
                try
                {
                    Type objectType = input.GetType();

                    if (/*typeof(IBmobWritable).IsAssignableFrom(objectType)*/ input is IBmobWritable)
                    {
                        IBmobWritable obj     = (IBmobWritable)input;
                        BmobOutput    tOutput = new BmobOutput();
                        obj.write(tOutput, isPrint);

                        output = tOutput.getData();
                        return(true);
                    }
                    else if (objectType == typeof(BmobInt) ||
                             objectType == typeof(BmobLong) ||
                             objectType == typeof(BmobDouble) ||
                             objectType == typeof(BmobBoolean) ||
                             objectType == typeof(BmobACL))
                    {
                        object value = 0;
                        if (input is BmobInt)
                        {
                            value = (input as BmobInt).Get();
                        }
                        else if (input is BmobLong)
                        {
                            value = (input as BmobLong).Get();
                        }
                        else if (input is BmobDouble)
                        {
                            value = (input as BmobDouble).Get();
                        }
                        else if (input is BmobBoolean)
                        {
                            value = (input as BmobBoolean).Get();
                        }
                        else if (input is BmobACL)
                        {
                            value = (input as BmobACL).Get();
                        }

                        output = value;
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    BmobDebug.Log(e);
                }

                return(base.TrySerializeNonPrimitiveObject(input, out output));
            }
예제 #8
0
        private static double toDouble(Object data)
        {
            if (data is int)
            {
                return((int)data);
            }
            else if (data is long)
            {
                return((long)data);
            }
            else if (data is double)
            {
                return((double)data);
            }
            else
            {
                BmobDebug.Log("[ERROR] 获取数值类型失败,原值为:" + JsonAdapter.JSON.ToDebugJsonString(data));
            }

            return(0);
        }
        // 注册用户
        private void signup_Click(object sender, RoutedEventArgs e)
        {
            SignUser user = new SignUser();

            user.username    = "******";
            user.password    = "******";
            user.friendNames = "a ,b ,c ";

            Bmob.Signup <SignUser>(user, (resp, ex) =>
            {
                string status = "OK";
                if (ex != null)
                {
                    status = "ERROR";
                }
                BmobDebug.Log(JsonAdapter.JSON.ToDebugJsonString(resp));

                Dispatcher.BeginInvoke(() =>
                {
                    updateStatus(signup, status);
                });
            });
        }
예제 #10
0
        internal static void Save <V>(IDictionary <String, V> data, String key, V value)
        {
            if (value == null)
            {
                return;
            }

            try
            {
                data.Add(key, value);
            }
            catch (ArgumentException e)
            {
                BmobDebug.Log("ERROR: " + e.Message);

                // 处理重复修改同一列的值
                if (data.ContainsKey(key))
                {
                    data.Remove(key);
                    data.Add(key, value);
                }
            }
        }
예제 #11
0
        public void ShellToastNotificationReceived(object sender, NotificationEventArgs e)
        {
            StringBuilder message     = new StringBuilder();
            string        relativeUri = string.Empty;

            message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString());

            // Parse out the information that was part of the message.
            foreach (string key in e.Collection.Keys)
            {
                message.AppendFormat("{0}: {1}\n", key, e.Collection[key]);

                if (string.Compare(
                        key,
                        "wp:Param",
                        System.Globalization.CultureInfo.InvariantCulture,
                        System.Globalization.CompareOptions.IgnoreCase) == 0)
                {
                    relativeUri = e.Collection[key];
                }
            }

            BmobDebug.Log(message.ToString());
        }