private void Write(object arg = null, [CallerMemberName] string method = null)
        {
            var message = ChannelWriteHelper.FormatOutput(arg, method);
            var writer  = new StreamWriter(TcpClient.GetStream())
            {
                AutoFlush = true
            };

            writer.WriteLine(message);
        }
        /// <summary>
        ///     Sends a new message using the AppServiceConnection, containing the contract name, the method name and the
        ///     serialized argument
        /// </summary>
        public static IAsyncOperation <AppServiceResponse> InvokeChannelAsync(
            this AppServiceConnection connection,
            Type contractType,
            object argument,
            string method)
        {
            //Create a new instance of the channel writer and format the message (format: <Method> <Argument - can be null and is serialized as JSON>)
            var channelWriteHelper = new ChannelWriteHelper(contractType);
            var message            = channelWriteHelper.FormatOutput(argument, method);

            //Send the message with the key being the contract name and the value being the serialized message
            return(connection.SendMessageAsync(new ValueSet {
                { contractType.Name, message }
            }));
        }
Exemplo n.º 3
0
        private IAsyncOperation <AppServiceResponse> SendToForegroundAsync(object arg = null,
                                                                           [CallerMemberName] string method = null)
        {
            if (Hub.Instance.ForegroundConnection == null)
            {
                return(Task.FromResult((AppServiceResponse)null).AsAsyncOperation());
            }
            var channelWriteHelper = new ChannelWriteHelper(typeof(IForegroundChannel));
            var message            = channelWriteHelper.FormatOutput(arg, method);

            return(Hub.Instance.ForegroundConnection.SendMessageAsync(new ValueSet
            {
                { typeof(IForegroundChannel).Name, message }
            }));
        }
Exemplo n.º 4
0
        private void EnqueueMessage(IMessage message, [CallerMemberName] string method = null)
        {
            var serializedString = ChannelWriteHelper.FormatOutput(message, method);
            var queueItem        = new RegisteredClientMessageQueueItem
            {
                SerializedMessage = serializedString,
                Message           = message,
                Method            = method
            };

            if (ActiveConnection == null)
            {
                _pushNotificationSender?.SendNotification(queueItem.SerializedMessage);
            }

            MessageQueue.Enqueue(queueItem);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sends a new message using the AppServiceConnection, containing the contract name, the method name and the serialized argument
        /// </summary>
        public static ValueSet InvokeChannel(this AppServiceConnection connection, Type contractType, object argument,
                                             string method)
        {
            //Create a new instance of the channel writer and format the message (format: <Method> <Argument - can be null and is serialized as JSON>)
            var channelWriteHelper = new ChannelWriteHelper(contractType);
            var message            = channelWriteHelper.FormatOutput(argument, method);

            //Send the message with the key being the contract name and the value being the serialized message
            var sendMessageTask = connection.SendMessageAsync(new ValueSet {
                { contractType.Name, message }
            }).AsTask();

            sendMessageTask.Wait();

            //If the message send resulted in a failure, return null, otherwise return the ValueSet result
            return(sendMessageTask.Result.Status != AppServiceResponseStatus.Success
                ? null
                : sendMessageTask.Result.Message);
        }
        private ValueSet SendToForeground(object arg = null, [CallerMemberName] string method = null)
        {
            if (Hub.Instance.ForegroundConnection == null)
            {
                return(null);
            }

            var channelWriteHelper = new ChannelWriteHelper(typeof(IForegroundChannel));
            var message            = channelWriteHelper.FormatOutput(arg, method);
            var sendMessageTask    = Hub.Instance.ForegroundConnection.SendMessageAsync(new ValueSet
            {
                { typeof(IForegroundChannel).Name, message }
            }).AsTask();

            sendMessageTask.Wait();
            return(sendMessageTask.Result.Status != AppServiceResponseStatus.Success
                ? null
                : sendMessageTask.Result.Message);
        }
 private void EnqueueOutput(object message = null, [CallerMemberName] string method = null)
 {
     WriteQueue.Enqueue(ChannelWriteHelper.FormatOutput(message, method));
 }
 private void SendToServer(object arg = null, [CallerMemberName] string method = null)
 {
     WriteQueue.Enqueue(ChannelWriteHelper.FormatOutput(arg, method));
 }