示例#1
0
        public override Task <RequestResult> SendTagsAsync(TagsBundle tags)
        {
            if (tags == null)
            {
                return(null);
            }
            var source = new TaskCompletionSource <RequestResult>();
            var dict   = tags.ToDictionary;

            Tags.TagsBundle.Builder tagsBundleBuilder = new Tags.TagsBundle.Builder();
            foreach (var kv in dict)
            {
                if (kv.Value is Nullable <int> )
                {
                    tagsBundleBuilder.PutInt(kv.Key, ((int?)kv.Value).Value);
                }
                else if (kv.Value is string)
                {
                    tagsBundleBuilder.PutString(kv.Key, (string)kv.Value);
                }
                else if (kv.Value is TagsBundle.IncrementalInteger)
                {
                    tagsBundleBuilder.IncrementInt(kv.Key, ((TagsBundle.IncrementalInteger)kv.Value).Value);
                }
                else if (kv.Value is IList <string> )
                {
                    tagsBundleBuilder.PutList(kv.Key, (IList <string>)kv.Value);
                }
            }
            nativeManager.SendTags(tagsBundleBuilder.Build(), new Callback()
            {
                ResultCallback = (Result obj) => {
                    source.SetResult(new RequestResult {
                        Error = ErrorFromJavaException(obj.Exception)
                    });
                }
            });
            return(source.Task);
        }
示例#2
0
        public Task <RequestResult> PostEventAsync(string anEvent, Dictionary <string, string> attributes)
        {
            var taskSource        = new TaskCompletionSource <RequestResult>();
            var tagsBundleBuilder = new Tags.TagsBundle.Builder();

            if (attributes != null)
            {
                foreach (var kv in attributes)
                {
                    tagsBundleBuilder.PutString(kv.Key, kv.Value);
                }
            }
            nativeManager.PostEvent(anEvent, tagsBundleBuilder.Build(), new PushManager.Callback()
            {
                ResultCallback = (Result result) => {
                    taskSource.SetResult(new RequestResult()
                    {
                        Error = PushManager.ErrorFromJavaException(result.Exception)
                    });
                }
            });

            return(taskSource.Task);
        }