/// <summary>
        /// Creates a new instance of the RPC.
        /// </summary>
        /// <param name="applicationID">The ID of the Discord App</param>
        /// <param name="processID">The ID of the currently running process</param>
        /// <param name="targetPipe">The target pipe to connect too</param>
        /// <param name="client">The pipe client we shall use.</param>
        /// <param name="maxRxQueueSize">The maximum size of the out queue</param>
        /// <param name="maxRtQueueSize">The maximum size of the in queue</param>
        public RpcConnection(
            string applicationID,
            int processID,
            int targetPipe,
            INamedPipeClient client,
            uint maxRxQueueSize = 128,
            uint maxRtQueueSize = 512)
        {
            this._discordApplicationId        = applicationID;
            this._discordApplicationProcessId = processID;
            this._currentTargetPipeNumber     = targetPipe;
            this._namedPipe   = client;
            this.ShutdownOnly = true;

            //Assign a default logger
            Logger = new ConsoleLogger();

            _delay          = new BackoffDelay(500, 60 * 1000);
            _maxRtQueueSize = maxRtQueueSize;
            _rtQueue        = new Queue <ICommand>((int)_maxRtQueueSize + 1);

            _maxRxQueueSize = maxRxQueueSize;
            _rxQueue        = new Queue <IMessage>((int)_maxRxQueueSize + 1);

            _currentNonce = 0;
        }
Beispiel #2
0
        public App(IMediator mediator, INamedPipeClient pipeClient)
        {
            _mediator   = mediator;
            _pipeClient = pipeClient;

            ShutdownMode = ShutdownMode.OnExplicitShutdown;
        }
 private static bool SendPipeMessage(INamedPipeClient pipeClient, string message)
 {
     if (pipeClient.Connect(3000))
     {
         pipeClient.SendRequest(message);
         return(true);
     }
     return(false);
 }
Beispiel #4
0
        private BackoffDelay delay;                             //The backoff delay before reconnecting.
        #endregion

        /// <summary>
        /// Creates a new instance of the RPC.
        /// </summary>
        /// <param name="applicationID">The ID of the Discord App</param>
        /// <param name="processID">The ID of the currently running process</param>
        /// <param name="targetPipe">The target pipe to connect too</param>
        /// <param name="client">The pipe client we shall use.</param>
        public RpcConnection(string applicationID, int processID, int targetPipe, INamedPipeClient client)
        {
            this.applicationID = applicationID;
            this.processID     = processID;
            this.targetPipe    = targetPipe;
            this.namedPipe     = client;
            this.ShutdownOnly  = true;

            delay    = new BackoffDelay(500, 60 * 1000);
            _rtqueue = new Queue <ICommand>();
            _rxqueue = new Queue <IMessage>();

            nonce = 0;
        }
        private BackoffDelay delay;                             //The backoff delay before reconnecting.
        #endregion

        /// <summary>
        /// Creates a new instance of the RPC.
        /// </summary>
        /// <param name="applicationID">The ID of the Discord App</param>
        /// <param name="processID">The ID of the currently running process</param>
        /// <param name="targetPipe">The target pipe to connect too</param>
        public RpcConnection(string applicationID, int processID, int targetPipe, INamedPipeClient client)
        {
            this.applicationID = applicationID;
            this.processID     = processID;
            this.targetPipe    = targetPipe;
            this.namedPipe     = client;

            //Assign a default logger
            Logger = new ConsoleLogger();

            delay    = new BackoffDelay(500, 60 * 1000);
            _rtqueue = new Queue <ICommand>();
            _rxqueue = new Queue <IMessage>();

            nonce = 0;
        }
Beispiel #6
0
        private BackoffDelay delay;                             //The backoff delay before reconnecting.
        #endregion

        /// <summary>
        /// Creates a new instance of the RPC.
        /// </summary>
        /// <param name="applicationID">The ID of the Discord App</param>
        /// <param name="processID">The ID of the currently running process</param>
        /// <param name="targetPipe">The target pipe to connect too</param>
        /// <param name="client">The pipe client we shall use.</param>
        /// <param name="maxRxQueueSize">The maximum size of the out queue</param>
        public RpcConnection(string applicationID, int processID, int targetPipe, INamedPipeClient client, uint maxRxQueueSize = 128)
        {
            this.applicationID = applicationID;
            this.processID     = processID;
            this.targetPipe    = targetPipe;
            this.namedPipe     = client;
            this.ShutdownOnly  = true;

            //Assign a default logger
            Logger = new ConsoleLogger();

            delay    = new BackoffDelay(500, 60 * 1000);
            _rtqueue = new Queue <ICommand>();

            _maxRxQueueSize = maxRxQueueSize;
            _rxqueue        = new Queue <IMessage>((int)_maxRxQueueSize + 1);

            nonce = 0;
        }
Beispiel #7
0
 public DiscordRpcClient(
     string applicationID,
     string steamID,
     bool registerUriScheme,
     int pipe,
     INamedPipeClient client)
 {
     this.ApplicationID          = applicationID;
     this.SteamID                = steamID;
     this.HasRegisteredUriScheme = registerUriScheme;
     this.ProcessID              = Process.GetCurrentProcess().Id;
     this._pipe = pipe;
     if (registerUriScheme)
     {
         UriScheme.RegisterUriScheme(applicationID, steamID, (string)null);
     }
     this.connection = new RpcConnection(this.ApplicationID, this.ProcessID, this.TargetPipe, client)
     {
         ShutdownOnly = this._shutdownOnly
     };
     this.connection.Logger = this._logger;
 }
Beispiel #8
0
        /// <summary>
        /// Creates a new Discord RPC Client using the steam uri scheme.
        /// </summary>
        /// <param name="applicationID">The ID of the application created at discord's developers portal.</param>
        /// <param name="steamID">The steam ID of the app. This is used to launch Join / Spectate through steam URI scheme instead of manual launching</param>
        /// <param name="registerUriScheme">Should a URI scheme be registered for Join / Spectate functionality? If false, the Join / Spectate functionality will be disabled.</param>
        /// <param name="pipe">The pipe to connect too. -1 for first available pipe.</param>
        /// <param name="client">The pipe client to use and communicate to discord through</param>
        public DiscordRpcClient(string applicationID, string steamID, bool registerUriScheme, int pipe, INamedPipeClient client)
        {
            //Store our values
            ApplicationID          = applicationID;
            SteamID                = steamID;
            HasRegisteredUriScheme = registerUriScheme;
            ProcessID              = System.Diagnostics.Process.GetCurrentProcess().Id;
            _pipe = pipe;

            //If we are to register the URI scheme, do so.
            //The UriScheme.RegisterUriScheme function takes steamID as a optional parameter, its null by default.
            //   this means it will handle a null steamID for us :)
            if (registerUriScheme)
            {
                UriScheme.RegisterUriScheme(applicationID, steamID);
            }

            //Create the RPC client
            connection = new RpcConnection(ApplicationID, ProcessID, TargetPipe, client)
            {
                ShutdownOnly = _shutdownOnly
            };
        }
Beispiel #9
0
        /// <summary>
        /// Creates a new Discord RPC Client which can be used to send Rich Presence and receive Join / Spectate events. This constructor exposes more advance features such as custom NamedPipeClients and Loggers.
        /// </summary>
        /// <param name="applicationID">The ID of the application created at discord's developers portal.</param>
        /// <param name="pipe">The pipe to connect too. If -1, then the client will scan for the first available instance of Discord.</param>
        /// <param name="logger">The logger used to report messages. If null, then a <see cref="NullLogger"/> will be created and logs will be ignored.</param>
        /// <param name="autoEvents">Should events be automatically invoked from the RPC Thread as they arrive from discord?</param>
        /// <param name="client">The pipe client to use and communicate to discord through. If null, the default <see cref="ManagedNamedPipeClient"/> will be used.</param>
        public DiscordRpcClient(string applicationID, int pipe = -1, ILogger logger = null, bool autoEvents = true, INamedPipeClient client = null)
        {
            //Make sure appID is NOT null.
            if (string.IsNullOrEmpty(applicationID))
            {
                throw new ArgumentNullException("applicationID");
            }

            //Ensure we actually have json ahead of time. If statement is pointless, but its there just to ensure there is no unused warnings.
            Type jsonConverterType = typeof(Newtonsoft.Json.JsonConverter);

            if (jsonConverterType == null)
            {
                throw new Exception("JsonConverter Type Not Found");
            }

            //Store the properties
            ApplicationID          = applicationID.Trim();
            TargetPipe             = pipe;
            ProcessID              = System.Diagnostics.Process.GetCurrentProcess().Id;
            HasRegisteredUriScheme = false;
            AutoEvents             = autoEvents;

            //Prepare the logger
            _logger = logger ?? new NullLogger();

            //Create the RPC client, giving it the important details
            connection = new RpcConnection(ApplicationID, ProcessID, TargetPipe, client ?? new ManagedNamedPipeClient(), autoEvents ? 0 : 128U)
            {
                ShutdownOnly = _shutdownOnly,
                Logger       = _logger
            };

            //Subscribe to its event
            connection.OnRpcMessage += (sender, msg) =>
            {
                if (OnRpcMessage != null)
                {
                    OnRpcMessage.Invoke(this, msg);
                }

                if (AutoEvents)
                {
                    ProcessMessage(msg);
                }
            };
        }
 public CNamedPipe(string PName, int Mode, INamedPipeClient client)
 {
     pipeName   = PName;
     ClientType = Mode;//0 Reading Pipe, 1 Writing Pipe
     _client    = client;
 }