コード例 #1
0
ファイル: GraphQLClient.cs プロジェクト: weiplanet/ngraphql
        public async Task <ServerResponse> SendAsync(ClientRequest request)
        {
            var start    = GetTimestamp();
            var response = new ServerResponse(request);

            try {
                RequestStarting?.Invoke(this, new RequestStartingEventArgs(request));
                await SendAsync(request, response);

                response.DurationMs = GetTimeSince(start);
                RequestCompleted?.Invoke(this, new RequestCompletedEventArgs(response));
            } catch (Exception ex) {
                response.Exception = ex;
                RequestCompleted?.Invoke(this, new RequestCompletedEventArgs(response));
                if (response.Exception != null)
                {
                    if (response.Exception == ex)
                    {
                        throw;
                    }
                    else
                    {
                        throw response.Exception; //throw new exception
                    }
                }
            }
            return(response);
        }
コード例 #2
0
        protected virtual void OnRequestCompleted(HttpRequestMessage request, HttpResponseMessage response)
        {
            var responseEventArgs = new Events.GSResponseEventArgs {
                Request = request, Response = response
            };

            RequestCompleted?.Invoke(this, responseEventArgs);
        }
コード例 #3
0
        protected virtual void OnCompleted()
        {
            var result = new WBWebCompletedArgs <T>
            {
                UniqueName = config.UniqueName,
                Result     = new T[Result.Count]
            };

            Result.CopyTo(result.Result, 0);

            RequestCompleted?.Invoke(result);
        }
コード例 #4
0
 public async void SendRequestsUntilStopping(string address, int timeout, byte[] buffer, PingOptions options)
 {
     await Task.Factory.StartNew(() =>
     {
         try
         {
             Ping pingSender = new Ping();
             while (IsToContinueSending)
             {
                 PingReply reply = pingSender.Send(address, timeout, buffer, options);
                 if (reply.Status == IPStatus.Success)
                 {
                     RoundtripTimeList.Add(reply.RoundtripTime);
                     var requestItem = new RequestItem(reply.Address.ToString(), reply.RoundtripTime);
                     RequestCompleted.Invoke(requestItem);
                 }
                 else
                 {
                     LostPackageNum++;
                     var requestItem = new RequestItem("Ping failed", -1);
                     RequestCompleted.Invoke(requestItem);
                 }
                 RequestNum++;
             }
             AllRequestsCompleted.Invoke();
         }
         catch (System.Net.NetworkInformation.PingException)
         {
             System.Windows.MessageBox.Show("Error sending request. Check the parameters are correct.", "Error",
                                            System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
         }
         catch (System.ArgumentNullException)
         {
             System.Windows.MessageBox.Show("Not all parameters are entered for the request", "Error",
                                            System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
         }
         catch
         {
             System.Windows.MessageBox.Show("Some error sending request", "Error",
                                            System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
         }
     });
 }
コード例 #5
0
 protected override void OnCompleted()
 {
     tasksConsumerService.Enqueue(() => RequestCompleted?.Invoke(config.UniqueName, Result));
 }
コード例 #6
0
        private void Client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            LastError = string.Empty;

            if (e.Error != null)
            {
                LastError = e.Error.ToString();
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }

                return;
            }

            try
            {
                int count = 0;
                foreach (string line in e.Result.Split("\r\n".ToCharArray()))
                {
                    if (line == string.Empty)
                    {
                        continue;
                    }


                    string[] cmdParts = line.Split(":".ToCharArray(), 2);
                    string   command  = cmdParts[0];

                    if (command == "ERROR")
                    {
                        LastError = line;
                    }
                    else if (command == "MSG")
                    {
                    }
                    count++;
                }
            }
            catch (System.Exception ex)
            {
                //LastToken = string.Empty;
                LastError = ex.ToString();
            }


            if (LastError != string.Empty)
            {
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                LastUpdate = DateTime.Now;
                if (RequestCompleted != null)
                {
                    RequestCompleted.Invoke(this, EventArgs.Empty);
                }
            }

            UpdateInProgress = false;
        }
コード例 #7
0
 private void OnRequestCompleted()
 {
     RequestCompleted?.Invoke(this, EventArgs.Empty);
 }
コード例 #8
0
        private void Client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            LastError = string.Empty;
            LastToken = string.Empty;

            if (e.Error != null)
            {
                LastError = e.Error.ToString();
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }

                return;
            }

            ServerList.Clear();

            try
            {
                foreach (string line in e.Result.Split("\r\n".ToCharArray()))
                {
                    if (line == string.Empty)
                    {
                        continue;
                    }

                    string[] cmdParts = line.Split(":".ToCharArray(), 2);
                    string   command  = cmdParts[0];
                    if (command == "TOKEN")
                    {
                        LastToken = cmdParts[1].Trim();
                    }
                    else if (command == "NOTOK")
                    {
                        LastError = "No Token " + cmdParts[1].Trim();
                    }
                    else if (command == "ERROR")
                    {
                        LastError = "ERROR " + cmdParts[1].Trim();
                    }
                    else if (command == "NOTICE")
                    {
                        LastError = "NOTICE " + cmdParts[1].Trim();
                    }
                    else
                    {
                        ListServerData data = new ListServerData();

                        string[] dataParts = line.Split(" ".ToCharArray(), 5);
                        data.Name    = dataParts[0];
                        data.Version = dataParts[1];
                        data.Info.ReadFromString(dataParts[2]);
                        IPAddress.TryParse(dataParts[3], out data.Address);

                        data.Host = dataParts[3];
                        data.Port = 5154;
                        if (dataParts[0].Contains(":"))
                        {
                            string[] portParts = dataParts[0].Split(":".ToCharArray(), 2);

                            data.Host = portParts[0];
                            int.TryParse(portParts[1], out data.Port);
                        }

                        if (dataParts.Length > 4)
                        {
                            data.Description = dataParts[4];
                        }

                        ServerList.Add(data);
                    }
                }
            }
            catch (System.Exception ex)
            {
                //LastToken = string.Empty;
                LastError = ex.ToString();
            }


            if (LastError != string.Empty)
            {
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                if (RequestCompleted != null)
                {
                    RequestCompleted.Invoke(this, EventArgs.Empty);
                }
            }
        }
コード例 #9
0
        private void Client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            BZID           = string.Empty;
            LastError      = string.Empty;
            OK             = false;
            NameRegistered = false;

            if (e.Error != null)
            {
                LastError = e.Error.ToString();
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }

                return;
            }

            try
            {
                foreach (string line in e.Result.Split("\r\n".ToCharArray()))
                {
                    if (line == string.Empty || LastError != string.Empty)
                    {
                        continue;
                    }

                    string[] cmdParts = line.Split(":".ToCharArray(), 2);
                    string   command  = cmdParts[0];
                    if (command.ToUpperInvariant() == "MSG:")
                    {
                        continue;
                    }

                    if (command == "TOKGOOD")
                    {
                        LastError      = string.Empty;
                        OK             = true;
                        NameRegistered = true;

                        string[] parts = cmdParts[1].Trim().Split(":".ToCharArray());

                        string[] desiredGroups = Groups.ToArray();

                        Groups.Clear();
                        foreach (string g in parts) // scan the groups to match the names up to the requested format, if not just blast it in.
                        {
                            string n = g;
                            foreach (var dg in desiredGroups)
                            {
                                if (dg.ToUpperInvariant() == g.ToUpperInvariant())
                                {
                                    n = dg;
                                }
                            }

                            Groups.Add(n);
                        }
                    }
                    else if (command == "TOKBAD")
                    {
                        NameRegistered = true;
                        LastError      = "Bad Token";
                        OK             = false;
                    }
                    else if (command == "UNK")
                    {
                        OK             = false;
                        NameRegistered = true;
                    }
                    else if (command == "BZID")
                    {
                        if (cmdParts.Length == 1)
                        {
                            LastError = "Malformed BZID";
                        }
                        else
                        {
                            string[] parts = cmdParts[1].Trim().Split(" ".ToCharArray());
                            if (parts.Length == 0)
                            {
                                LastError = "Malformed BZID";
                            }
                            else
                            {
                                BZID = parts[0];
                            }
                        }
                    }
                    else if (command == "ERROR")
                    {
                        LastError = "ERROR " + cmdParts[1].Trim();
                    }
                    else if (command == "NOTICE")
                    {
                        LastError = "NOTICE " + cmdParts[1].Trim();
                    }
                    else
                    {
                    }
                }
            }
            catch (System.Exception ex)
            {
                //LastToken = string.Empty;
                LastError = ex.ToString();
            }

            if (OK && BZID == string.Empty)
            {
                OK        = false;
                LastError = "Missing BZID";
            }

            if (LastError != string.Empty)
            {
                OK = false;

                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                OK = true;
                if (RequestCompleted != null)
                {
                    RequestCompleted.Invoke(this, EventArgs.Empty);
                }
            }
        }
コード例 #10
0
 internal void OnRequestCompleted(RequestContext context)
 {
     RequestCompleted?.Invoke(this, new GraphQLServerEventArgs(context));
 }
コード例 #11
0
ファイル: PomonaClient.cs プロジェクト: anthrax3/Pomona
 protected void RaiseRequestCompleted(HttpRequestMessage request,
                                      HttpResponseMessage response,
                                      Exception thrownException = null)
 {
     RequestCompleted?.Invoke(this, new ClientRequestLogEventArgs(request, response, thrownException));
 }
コード例 #12
0
        private void Client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            LastError = string.Empty;
            LastToken = string.Empty;

            if (e.Error != null)
            {
                LastError = e.Error.ToString();
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }

                return;
            }

            try
            {
                foreach (string line in e.Result.Split("\r\n".ToCharArray()))
                {
                    if (line == string.Empty)
                    {
                        continue;
                    }

                    string[] cmdParts = line.Split(":".ToCharArray(), 2);
                    string   command  = cmdParts[0];
                    if (command == "TOKEN")
                    {
                        LastToken = cmdParts[1].Trim();
                    }
                    else if (command == "NOTOK")
                    {
                        LastError = "No Token " + cmdParts[1].Trim();
                    }
                    else if (command == "ERROR")
                    {
                        LastError = "ERROR " + cmdParts[1].Trim();
                    }
                    else if (command == "NOTICE")
                    {
                        LastError = "NOTICE " + cmdParts[1].Trim();
                    }
                    else
                    {
                    }
                }
            }
            catch (System.Exception ex)
            {
                //LastToken = string.Empty;
                LastError = ex.ToString();
            }


            if (LastError != string.Empty)
            {
                if (RequestErrored != null)
                {
                    RequestErrored.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                if (RequestCompleted != null)
                {
                    RequestCompleted.Invoke(this, EventArgs.Empty);
                }
            }
        }