示例#1
0
 /// <summary>
 /// logout from the exchange.
 /// You should stop listening to events first.
 ///
 /// <param name="successCallback">Will be called when the logout request suceeds.</param> 
 /// <param name="onFailure">Will be called when the logout request fails.</param> 
 /// </summary>
 public void Logout(OnSuccess successCallback, OnFailure onFailure)
 {
     SendRequest(new LogoutRequest(), new DefaultHandler(), delegate() { successCallback(); }, onFailure);
 }
示例#2
0
 public void RequestHistoricMarketData(IHistoricMarketDataRequest historicMarketDataRequest, OnSuccess successCallback, OnFailure failureCallback)
 {
     DefaultHandler handler = new DefaultHandler();
     SendRequest(historicMarketDataRequest, handler, delegate() { successCallback(); }, failureCallback);
 }
示例#3
0
 public void RequestHeartbeat(HeartbeatRequest heartbeatRequest, OnSuccess successCallback, OnFailure failureCallback)
 {
     DefaultHandler handler = new DefaultHandler();
     SendRequest(heartbeatRequest, handler, delegate() { successCallback(); }, failureCallback);
 }
示例#4
0
 public void Subscribe(ISubscriptionRequest subscriptionRequest, OnSuccess successCallback, OnFailure failureCallback)
 {
     DefaultHandler handler = new DefaultHandler();
     SendRequest(subscriptionRequest, handler, delegate() { successCallback(); }, failureCallback);
 }
示例#5
0
 public void RequestAccountState(AccountStateRequest accountStateRequest, OnSuccess successCallback, OnFailure failureCallback)
 {
     DefaultHandler handler = new DefaultHandler();
     SendRequest(accountStateRequest, handler, delegate() { successCallback(); }, failureCallback);
 }
示例#6
0
 private static extern Boolean VidyoGatewayConnectNative(IntPtr gateway, IntPtr host, IntPtr token, IntPtr displayName, IntPtr resourceId, OnSuccess onSuccess, OnFailure onFailure, OnDisconnected onDisconnected);
 public IMParticleTask <IdentityApiResult> AddSuccessListener(OnSuccess listener)
 {
     _task.AddSuccessListener(new TaskSuccessWrapper(listener));
     return(this);
 }
示例#8
0
 protected void _OnSuccess(Request request)
 {
     Scheduler.IncreaseSuccessCounter();
     OnSuccess?.Invoke(request);
 }
示例#9
0
        private async Task <IResult <bool> > ConfigurMediaAsync()
        {
            try
            {
                Debug.WriteLine($"----------------------------------------Configure{(UploadItem.IsVideo ? "Video" : "Photo")}{(UploadItem.IsStory ? " to Story": "")} Async----------------------------------");
                var instaUri     = GetMediaConfigureUri(UploadItem.IsVideo, UploadItem.IsStory);
                var retryContext = GetRetryContext();
                var _user        = InstaApi.GetLoggedUser();
                var _deviceInfo  = InstaApi.GetCurrentDevice();
                var data         = GetMediaConfigure();

                var _httpRequestProcessor = InstaApi.HttpRequestProcessor;
                var request = InstaApi.HttpHelper.GetSignedRequest(HttpMethod.Post, instaUri, _deviceInfo, data);
                request.Headers.Add("retry_context", GetRetryContext());
                var response = await _httpRequestProcessor.SendAsync(request);

                MainPage.Current?.HideMediaUploadingUc();

                var json = await response.Content.ReadAsStringAsync();

                var mediaResponse = JsonConvert.DeserializeObject <InstaMediaItemResponse>(json, new InstaMediaDataConverter());
                var converter     = ConvertersFabric.Instance.GetSingleMediaConverter(mediaResponse);

                try
                {
                    var obj = converter.Convert();
                    if (obj != null)
                    {
                        if (UploadItem.IsStory)
                        {
                            Main.MainView.Current?.MainVM.RefreshStories(true);
                        }
                        else
                        {
                            Main.MainView.Current?.MainVM.PostsGenerator.Items.Insert(0, new InstaPost
                            {
                                Media = obj,
                                Type  = InstagramApiSharp.Enums.InstaFeedsType.Media
                            });
                        }
                        ShowNotify($"Your {(UploadItem.IsStory ? "Story" : (UploadItem.IsVideo ? "Video" : "Photo"))} uploaded successfully...", 3500);
                        NotificationHelper.ShowNotify(UploadItem.Caption?.Truncate(50), NotifyFile?.Path, (UploadItem.IsStory ? "Story" :"Media") + " uploaded");
                    }
                }
                catch { }
                SendNotify(102);
                //RemoveThis();
                OnSuccess?.Invoke(this);
                MainPage.Current?.HideMediaUploadingUc();
                return(Result.Success(true));
            }
            catch (HttpRequestException httpException)
            {
                SendNotify(102);
                //RemoveThis();

                OnFailed?.Invoke(this);
                MainPage.Current?.HideMediaUploadingUc();
                return(Result.Fail(httpException, false, ResponseType.NetworkProblem));
            }
            catch (Exception exception)
            {
                OnFailed?.Invoke(this);
                SendNotify(102);
                //RemoveThis();
                MainPage.Current?.HideMediaUploadingUc();
                return(Result.Fail <bool>(exception));
            }
        }
示例#10
0
 public void Resolve(T response)
 {
     resolvedValue = response;
     resolved      = true;
     OnSuccess?.Invoke(this);
 }
示例#11
0
 private static extern Boolean VidyoGatewayConnectNative(IntPtr gateway, [MarshalAs(UnmanagedType.LPStr)] String host, [MarshalAs(UnmanagedType.LPStr)] String token, [MarshalAs(UnmanagedType.LPStr)] String displayName, [MarshalAs(UnmanagedType.LPStr)] String resourceId, OnSuccess onSuccess, OnFailure onFailure, OnDisconnected onDisconnected);
        public virtual async Task <IRestResponse> RequestAsync(string path, Method method = Method.GET, object dto = null, Action <RestRequest> buildRequest = null, string contentType = null)
        {
            try
            {
                Log($"Request: [/{path}] {method} {path}");
                RestClient client  = CreateClient(BaseUrl);
                var        request = CreateRequest(path, method);
                buildRequest?.Invoke(request);
                if (dto != null)
                {
                    if (method == Method.GET)
                    {
                        var json = JsonConvert.SerializeObject(dto);
                        var dic  = JsonConvert.DeserializeObject <Dictionary <string, object> >(json);
                        foreach (var pair in dic)
                        {
                            if (pair.Value != null)
                            {
                                if (!(pair.Value is string) && pair.Value is IEnumerable e)
                                {
                                    foreach (var item in e)
                                    {
                                        request.AddQueryParameter(pair.Key, item.ToString());
                                    }
                                }
                                else
                                {
                                    request.AddQueryParameter(pair.Key, pair.Value.ToString());
                                }
                            }
                        }
                    }
                    else
                    {
                        request.AddJsonBody(dto);
                    }
                }
                contentType = contentType ?? "application/json";
                request.AddHeader("Content-Type", contentType);
                request.AddHeader("Accept", contentType);
                Stopwatch watch = new Stopwatch();
                watch.Start();
                try
                {
                    var result = await client.ExecuteAsync(request);

                    OnResponse?.Invoke(this, result);
                    Log($"[{watch.Elapsed.TotalSeconds}s/{client.BaseUrl}] {request.Method} {result?.ResponseUri?.ToString() ?? path} response ({result.StatusCode}): {result.Content.Head(1024)}\n");
                    if (result.StatusCode == HttpStatusCode.Gone)
                    {
                        OnGone?.Invoke(this, result);
                        return(null);
                    }
                    if (result.StatusCode != HttpStatusCode.OK)
                    {
                        OnServerError?.Invoke(this, result);
                    }
                    OnSuccess?.Invoke(this, result);
                    return(result);
                }
                catch (Exception ex)
                {
                    Log($"Exception while executing task: {ex}");
                }
                finally
                {
                    watch.Stop();
                }
            }
            catch (Exception ex)
            {
                Log($"Exception while executing task: {ex}");
            }
            return(null);
        }