Ejemplo n.º 1
0
        private async void Save()
        {
            InputDialog dialog = new InputDialog();

            var result = await dialog.ShowAsync(
                "Attention",
                "Enter an Identifier for the Connection",
                "Save",
                "Cancel");

            switch (result)
            {
            case "Save":
                string name = dialog.InputText;

                RTRequest request = new RTRequest()
                {
                    Method = Method, Name = name, Protocol = Protocol, Url = Url, Raw = Raw, Headers = Headers
                };
                RequestsList.Add(request);
                break;

            case "Cancel":
                break;
            }
        }
Ejemplo n.º 2
0
        private void LoadCommandHandler(IUICommand command)
        {
            RTRequest request = command.Id as RTRequest;

            Url      = request.Url;
            Method   = request.Method;
            Protocol = request.Protocol;
            Raw      = request.Raw;
            Headers  = request.Headers;
        }
Ejemplo n.º 3
0
        private async void SelectRequest(ItemClickEventArgs args)
        {
            RTRequest     request = args.ClickedItem as RTRequest;
            string        message = string.Format("What do you want to do?\nLoad {0}\nDelete {0}", request.Name);
            MessageDialog dialog  = new MessageDialog(message, "Attention!!");

            dialog.Commands.Add(new UICommand("Load", new UICommandInvokedHandler(LoadCommandHandler), request));
            dialog.Commands.Add(new UICommand("Delete", new UICommandInvokedHandler(DeleteCommandHandler), request));
            dialog.Commands.Add(new UICommand("Cancel", new UICommandInvokedHandler(CancelCommandHandler)));
            dialog.DefaultCommandIndex = 0;
            dialog.CancelCommandIndex  = 2;
            await dialog.ShowAsync();
        }
Ejemplo n.º 4
0
        public override int Send(RTRequest request)
        {
            MemoryStream ms = PooledObjects.MemoryStreamPool.Pop();

            try {
                ms.Position = 0;

                Packet p = request.ToPacket(session, true);

                try {
                    Packet.SerializeLengthDelimited(ms, p);
                } finally {
                    PooledObjects.PacketPool.Push(p);
                }

                try {
#if __WINDOWS__
                    Task t = Task.Run(async() => {
                        byte[] newArray = ms.ToArray();

                        Array.Resize <byte>(ref newArray, (int)ms.Position);

                        DataWriter writer = new DataWriter(client.OutputStream);

                        writer.WriteBytes(newArray);

                        await writer.StoreAsync();
                        await writer.FlushAsync();

                        writer.DetachStream();
                        writer.Dispose();
                    });
                    t.Wait();
                    //client.OutputStream.AsStreamForWrite().WriteAsync(newArray, 0, (int)ms.Position);
#else
                    client.Send(ms.GetBuffer(), (int)ms.Position);
#endif
                } catch (Exception e) {
                    System.Diagnostics.Debug.WriteLine(e);

                    session.Log("fastConnection", GameSparksRT.LogLevel.INFO, "Exception sending UDP {0}", e.Message);
                }

                return((int)ms.Position);
            } finally {
                PooledObjects.MemoryStreamPool.Push(ms);
            }
        }
Ejemplo n.º 5
0
        public override int Send(RTRequest request)
        {
            if (socket != null && socket.State == GameSparksWebSocketState.Open)
            {
                Packet       p  = request.ToPacket(session, false);
                MemoryStream ms = PooledObjects.MemoryStreamPool.Pop();

                ms.Position = 0;

                try
                {
                    Packet.SerializeLengthDelimited(ms, p);

                    int ret = (int)ms.Position;

                    socket.SendBinary(ms.GetBuffer(), 0, ret);

                    return(ret);
                }
                catch (Exception e)
                {
                    if (session != null && !stopped)
                    {
                        session.ConnectState = GameSparksRT.ConnectState.Disconnected;
                        session.Log("ReliableWSConnection", GameSparksRT.LogLevel.DEBUG, e.Message);
                        try
                        {
                            session.OnReady(false);
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex);
                        }
                    }

                    return(0);
                }
                finally
                {
                    PooledObjects.PacketPool.Push(p);
                    PooledObjects.MemoryStreamPool.Push(ms);
                }
            }

            return(-1);
        }
Ejemplo n.º 6
0
        private void DeleteCommandHandler(IUICommand command)
        {
            RTRequest request = command.Id as RTRequest;

            RequestsList.Remove(request);
        }
Ejemplo n.º 7
0
 public abstract int Send(RTRequest request);
Ejemplo n.º 8
0
        /*private string GetCertificateInformation(
         *  Certificate serverCert,
         *  IReadOnlyList<Certificate> intermediateCertificates)
         * {
         *  StringBuilder sb = new StringBuilder();
         *
         *  sb.AppendLine("\tFriendly Name: " + serverCert.FriendlyName);
         *  sb.AppendLine("\tSubject: " + serverCert.Subject);
         *  sb.AppendLine("\tIssuer: " + serverCert.Issuer);
         *  sb.AppendLine("\tValidity: " + serverCert.ValidFrom + " - " + serverCert.ValidTo);
         *
         *  // Enumerate the entire certificate chain.
         *  if (intermediateCertificates.Count > 0)
         *  {
         *      sb.AppendLine("\tCertificate chain: ");
         *      foreach (var cert in intermediateCertificates)
         *      {
         *          sb.AppendLine("\t\tIntermediate Certificate Subject: " + cert.Subject);
         *      }
         *  }
         *  else
         *  {
         *      sb.AppendLine("\tNo certificates within the intermediate chain.");
         *  }
         *
         *  return sb.ToString();
         * }*/
#endif

        public override int Send(RTRequest request)
        {
#if __WINDOWS__
            if (client != null && connected)
#else
            if (client.Connected)
#endif
            {
                Packet p = request.ToPacket(session, false);
                try
                {
#if __WINDOWS__
                    MemoryStream stream = new MemoryStream();

                    int result = Packet.SerializeLengthDelimited(stream, p);

                    Task t = Task.Run(async() =>
                    {
                        DataWriter writer = new DataWriter(client.OutputStream);

                        writer.WriteBytes(stream.ToArray());

                        await writer.StoreAsync();
                        await writer.FlushAsync();

                        writer.DetachStream();
                        writer.Dispose();
                    });
                    t.Wait();

                    return(result);
#else
                    int ret = Packet.SerializeLengthDelimited(clientStream, p);
                    clientStream.Flush();
                    return(ret);
#endif
                }
                catch (Exception e)
                {
                    if (session != null && !stopped)
                    {
                        session.ConnectState = GameSparksRT.ConnectState.Disconnected;
                        session.Log("ReliableConnection", GameSparksRT.LogLevel.DEBUG, e.Message);
                        try
                        {
                            session.OnReady(false);
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex);
                        }
                    }
                    return(0);
                }
                finally
                {
                    PooledObjects.PacketPool.Push(p);
                }
            }
            return(-1);
        }