protected ChannelReliableSession(ChannelBase channel, IReliableFactorySettings settings, IReliableChannelBinder binder, FaultHelper faultHelper)
 {
     this.channel = channel;
     this.settings = settings;
     this.binder = binder;
     this.faultHelper = faultHelper;
     this.inactivityTimer = new InterruptibleTimer(this.settings.InactivityTimeout, new WaitCallback(this.OnInactivityElapsed), null);
     this.initiationTime = ReliableMessagingConstants.UnknownInitiationTime;
 }
 public void Abort(ChannelBase channel)
 {
     lock (this.ThisLock)
     {
         this.aborted = true;
         if (!this.closed)
         {
             this.closed = true;
             this.retryTimer.Cancel();
             while (this.waitQueue.Count > 0)
             {
                 this.waitQueue.Dequeue().Abort(channel);
             }
             this.window.Close();
         }
     }
 }
Example #3
0
 protected ServiceHostBase(ChannelBase serverChannel) :
     base(serverChannel, MessageProtocolType.LanguageServer)
 {
 }
Example #4
0
 public override List <HostMask> GetList(ChannelBase channel)
 {
     return(channel.Bans);
 }
 public MessageDispatcher(ChannelBase protocolChannel)
 {
     this.protocolChannel = protocolChannel;
     this.MessageReader   = protocolChannel.MessageReader;
     this.MessageWriter   = protocolChannel.MessageWriter;
 }
Example #6
0
 public LanguageServiceClient(ChannelBase clientChannel)
     : base(clientChannel)
 {
 }
Example #7
0
 /// <summary>
 /// Create a new client instance for the specified service
 /// </summary>
 public GrpcClient(ChannelBase channel, string serviceName, BinderConfiguration?binderConfiguration = null, string?host = null)
     : this(channel.CreateCallInvoker(), serviceName, binderConfiguration, host)
 {
 }
Example #8
0
        private void OnDebugServiceClientConnect(object sender, ChannelBase serverChannel)
        {
            MessageDispatcher messageDispatcher = new MessageDispatcher(this.logger);

            ProtocolEndpoint protocolEndpoint =
                new ProtocolEndpoint(
                    serverChannel,
                    messageDispatcher,
                    this.logger);

            protocolEndpoint.UnhandledException += ProtocolEndpoint_UnhandledException;

            bool ownsEditorSession = this.editorSession == null;

            if (ownsEditorSession)
            {
                this.editorSession =
                    this.CreateDebugSession(
                        this.hostDetails,
                        profilePaths,
                        protocolEndpoint,
                        messageDispatcher,
                        this.languageServer?.EditorOperations,
                        this.enableConsoleRepl);
            }

            this.debugAdapter =
                new DebugAdapter(
                    this.editorSession,
                    ownsEditorSession,
                    messageDispatcher,
                    protocolEndpoint,
                    this.logger);

            this.debugAdapter.SessionEnded +=
                (obj, args) =>
            {
                if (!ownsEditorSession)
                {
                    this.logger.Write(
                        LogLevel.Normal,
                        "Previous debug session ended, restarting debug service listener...");
                    this.debugServiceListener.Stop();
                    this.debugServiceListener.Start();
                }
                else if (this.debugAdapter.IsUsingTempIntegratedConsole)
                {
                    this.logger.Write(
                        LogLevel.Normal,
                        "Previous temp debug session ended");
                }
                else
                {
                    // Exit the host process
                    this.serverCompletedTask.SetResult(true);
                }
            };

            this.debugAdapter.Start();
            protocolEndpoint.Start();
        }
Example #9
0
 /// <summary>
 /// Returns a <see cref="Grpc.Core.CallInvoker" /> instance that intercepts
 /// the channel with the given interceptors.
 /// </summary>
 /// <param name="channel">The channel to intercept.</param>
 /// <param name="interceptors">
 /// An array of interceptors to intercept the channel with.
 /// Control is passed to the interceptors in the order specified.
 /// </param>
 /// <remarks>
 /// Multiple interceptors can be added on top of each other by calling
 /// "channel.Intercept(a, b, c)".  The order of invocation will be "a", "b", and then "c".
 /// Interceptors can be later added to an existing intercepted channel, effectively
 /// building a chain like "channel.Intercept(c).Intercept(b).Intercept(a)".  Note that
 /// in this case, the last interceptor added will be the first to take control.
 /// </remarks>
 public static CallInvoker Intercept(this ChannelBase channel, params Interceptor[] interceptors)
 {
     return(channel.CreateCallInvoker().Intercept(interceptors));
 }
Example #10
0
 /// <summary>
 /// Returns a <see cref="Grpc.Core.CallInvoker" /> instance that intercepts
 /// the channel with the given interceptor.
 /// </summary>
 /// <param name="channel">The channel to intercept.</param>
 /// <param name="interceptor">The interceptor to intercept the channel with.</param>
 /// <remarks>
 /// Multiple interceptors can be added on top of each other by calling
 /// "channel.Intercept(a, b, c)".  The order of invocation will be "a", "b", and then "c".
 /// Interceptors can be later added to an existing intercepted channel, effectively
 /// building a chain like "channel.Intercept(c).Intercept(b).Intercept(a)".  Note that
 /// in this case, the last interceptor added will be the first to take control.
 /// </remarks>
 public static CallInvoker Intercept(this ChannelBase channel, Interceptor interceptor)
 {
     return(channel.CreateCallInvoker().Intercept(interceptor));
 }
        public void Fault(ChannelBase channel)
        {
            lock (this.ThisLock)
            {
                if (this.closed)
                    return;

                this.closed = true;

                this.retryTimer.Cancel();

                while (waitQueue.Count > 0)
                    waitQueue.Dequeue().Fault(channel);

                window.Close();
            }
        }
Example #12
0
 /// <summary>
 /// </summary>
 /// <param name="channel">
 /// </param>
 /// <param name="characterName">
 /// </param>
 /// <param name="text">
 /// </param>
 internal void ChannelMessageReceived(ChannelBase channel, string characterName, string text)
 {
     channel.ChannelMessageToIRC(characterName, text);
 }
Example #13
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="channelManager">信道管理器</param>
 /// <param name="innerChannel">内部信道</param>
 public ExChannelBase(ChannelManagerBase channelManager, ChannelBase innerChannel)
     : base(channelManager)
 {
     this.InnerChannel    = innerChannel;
     this.ChannelStackEnd = this.InnerChannel != null ? false : true;
 }
 internal TDSClientCommand(ChannelBase grpcChannel)
 {
     _client = new BBCommandClient(grpcChannel);
 }
Example #15
0
 public abstract List <HostMask> GetList(ChannelBase channel);
 private void InitializeChannel(ChannelBase channel)
 {
     channel.TaskFactory = TaskFactory;
     channel.ObserverRegistry = CreateObserverRegistry?.Invoke();
     channel.ChannelRouter = ChannelRouter;
 }
Example #17
0
 /// <summary>
 /// Returns a <see cref="Grpc.Core.CallInvoker" /> instance that intercepts
 /// the invoker with the given interceptor.
 /// </summary>
 /// <param name="channel">The channel to intercept.</param>
 /// <param name="interceptor">
 /// An interceptor delegate that takes the request metadata to be sent with an outgoing call
 /// and returns a <see cref="Grpc.Core.Metadata" /> instance that will replace the existing
 /// invocation metadata.
 /// </param>
 /// <remarks>
 /// Multiple interceptors can be added on top of each other by
 /// building a chain like "channel.Intercept(c).Intercept(b).Intercept(a)".  Note that
 /// in this case, the last interceptor added will be the first to take control.
 /// </remarks>
 public static CallInvoker Intercept(this ChannelBase channel, Func <Metadata, Metadata> interceptor)
 {
     return(channel.CreateCallInvoker().Intercept(interceptor));
 }
Example #18
0
 public NamingServiceConnection(string url)
 {
     target  = url;
     channel = ChannelPool.Instance.ForUrl(target);
     client  = new NamingServiceClient(channel);
 }
Example #19
0
 protected SimpleChannelBase(ChannelManagerBase channelManager, ChannelBase innerChannel) : base(channelManager)
 {
     InnerChannel = innerChannel;
 }
 public GrpcChannelWrapper(GrpcChannel channel)
 {
     Channel = channel;
 }
 public abstract T NewConnection(string key, ChannelBase channel);
Example #22
0
        /// <summary>
        /// Parse the Svxlink logs
        /// </summary>
        /// <param name="s">one Log line</param>
        public virtual void ParseLog(ChannelBase channel, string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return;
            }

            if (s.Contains("Connected nodes"))
            {
                Nodes.Clear();
                s.Split(':')[2].Split(',').ToList().ForEach(n => Nodes.Add(new Node {
                    Name = n
                }));
                Connected?.Invoke(channel);
                return;
            }

            if (s.Contains("Node left"))
            {
                var node = new Node {
                    Name = s.Split(":")[2]
                };
                Nodes.Remove(node);
                NodeDisconnected?.Invoke(node);
                return;
            }

            if (s.Contains("Node joined"))
            {
                var node = new Node {
                    Name = s.Split(":")[2]
                };
                Nodes.Add(node);
                NodeConnected?.Invoke(node);
                return;
            }

            if (s.Contains("Talker start"))
            {
                var node = Nodes.Single(nx => nx.Equals(new Node {
                    Name = s.Split(":")[2]
                }));
                node.ClassName = "node node-tx";
                NodeTx?.Invoke(node);
                return;
            }

            if (s.Contains("Talker stop"))
            {
                var node = Nodes.Single(nx => nx.Equals(new Node {
                    Name = s.Split(":")[2]
                }));
                node.ClassName = "node";
                NodeRx?.Invoke(node);
                return;
            }

            if (s.Contains("Access denied"))
            {
                telemetry.TrackTrace($"Impossible de se connecter au salon {channel.Name}. <br/> Accès refusé.", SeverityLevel.Error, channel.TrackProperties);
                Error?.Invoke("Echec de la connexion.", $"Impossible de se connecter au salon {channel.Name}. <br/> Accès refusé.");
                return;
            }

            if (s.Contains("Host not found"))
            {
                telemetry.TrackTrace($"Impossible de se connecter au salon {channel.Name}. <br/> Server introuvable.", SeverityLevel.Error, channel.TrackProperties);
                Error?.Invoke("Echec de la connexion.", $"Impossible de se connecter au salon {channel.Name}. <br/> Server introuvable.");
                return;
            }
        }
Example #23
0
 /// <summary>
 /// Create a new client instance for the specified service, inferring the service name from the type
 /// </summary>
 public GrpcClient(ChannelBase channel, Type contractType, BinderConfiguration?binderConfiguration = null, string?host = null)
     : this(channel.CreateCallInvoker(), GetServiceName(contractType, binderConfiguration), binderConfiguration, host)
 {
 }
Example #24
0
 public Connection(string key, ChannelBase channel)
 {
     _connkey = key;
     _channel = channel;
 }
 public TransactionRequestContext(ITransactionChannel transactionChannel, ChannelBase channel, RequestContext innerContext, TimeSpan defaultCloseTimeout, TimeSpan defaultSendTimeout) : base(innerContext.RequestMessage, defaultCloseTimeout, defaultSendTimeout)
 {
     this.transactionChannel = transactionChannel;
     this.innerContext = innerContext;
 }
        public void AsynchronousRequest()
        {
            byte[] data   = new byte[36];
            Random rndGen = new Random();

            rndGen.NextBytes(data);

            Message input = Formatting.BytesToMessage(data);

            ManualResetEvent evt = new ManualResetEvent(false);
            Uri    serverUri     = new Uri(SizedTcpTransportBindingElement.SizedTcpScheme + "://" + Environment.MachineName + ":" + Port);
            object channel       = ReflectionHelper.CreateInstance(
                typeof(SizedTcpTransportBindingElement),
                "JsonRpcOverTcp.Channels.SizedTcpRequestChannel",
                new ByteStreamMessageEncodingBindingElement().CreateMessageEncoderFactory().Encoder,
                BufferManager.CreateBufferManager(int.MaxValue, int.MaxValue),
                Mocks.GetChannelManagerBase(),
                new EndpointAddress(serverUri),
                serverUri);

            ChannelBase     channelBase    = (ChannelBase)channel;
            IRequestChannel requestChannel = (IRequestChannel)channel;

            channelBase.Open();

            object state   = new object();
            bool   success = true;

            requestChannel.BeginRequest(input, new AsyncCallback(delegate(IAsyncResult asyncResult)
            {
                try
                {
                    if (!Object.ReferenceEquals(asyncResult.AsyncState, state))
                    {
                        success = false;
                        Console.WriteLine("Error, state not preserved");
                    }
                    else
                    {
                        Message output = requestChannel.EndRequest(asyncResult);

                        try
                        {
                            byte[] outputBytes = Formatting.MessageToBytes(output);
                            Assert.Equal(data, outputBytes, new ArrayComparer <byte>());
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error: " + e);
                            success = false;
                        }
                    }
                }
                finally
                {
                    evt.Set();
                }
            }), state);

            evt.WaitOne();
            Assert.True(success, "Error in callback");
            channelBase.Close();
        }
 public MessageDispatcher(ChannelBase protocolChannel)
 {
     this.protocolChannel = protocolChannel;
 }
Example #28
0
        private void OnJoin(ChannelBase channel, UserBase user)
        {
            channel.BroadcastInclusive(CMD, user, channel.Name);
            user.Names(channel);

            if (channel.Properties.ContainsKey("Topic"))
            {             // Note: Shouldn't send RPL_NOTOPIC under any circumstances at this point.
                user.SendNumeric(Numerics.RPL_TOPIC, channel.Name, ":" + (string)channel.Properties["Topic"]);
            }

            if (channel.Users.Count < 2)
            {
                return;
            }

            string prefix = channel.GetPrefix(user);

            if (!string.IsNullOrEmpty(prefix))
            {
                StringBuilder modes = new StringBuilder(prefix.Length + 1).Append('+');
                StringBuilder args  = new StringBuilder(prefix.Length * (user.Mask.Nickname.Length + 1));
                foreach (char c in prefix)
                {
                    char m;
                    switch (c)
                    {
                    case '$':
                        m = 'X';
                        break;

                    case '~':
                        m = 'O';
                        break;

                    case '&':
                        m = 'a';
                        break;

                    case '@':
                        m = 'o';
                        break;

                    case '%':
                        m = 'h';
                        break;

                    case '+':
                        m = 'v';
                        break;

                    case '!':
                        m = 'x';
                        break;

                    default:
                        continue;
                    }

                    modes.Append(m);
                    args.Append(' ').Append(user.Mask.Nickname);
                }

                channel.BroadcastInclusive("MODE", null, channel.Name, modes.ToString() + args.ToString());
            }
        }
 public DebugAdapterClient(ChannelBase clientChannel)
     : base(clientChannel, MessageProtocolType.DebugAdapter)
 {
 }
Example #30
0
        public void Handler(object sender, ReceivedCommandEventArgs e)
        {
            if (e.Arguments.Length < 1)
            {
                e.User.ErrorNeedMoreParams(CMD);
                return;
            }

            string[] channels = e.Arguments[0].Split(',');
            int      key      = 0;

            for (int i = 0; i < channels.Length; i++)
            {
                try
                {
                    ChannelBase channel = e.Server.GetChannel(channels[i]);
                    if (channel == null)
                    {
                        if (e.Server.GetRegisteredChannel(channels[i]) != null)
                        {
                            channel = e.Server.CreateChannel(channels[i], e.User);
                        }
                        else
                        {
                            e.User.SendNumeric(Numerics.ERR_NOSUCHCHANNEL, ":That channel does not exist.  Did you mean to create/register a new channel?  If so, use /cjoin " + channels[i] + " or /quote cjoin " + channels[i] + ".");
                            continue;
                        }
                    }

                    if (channel.HasFlag("RegisteredOnly") && e.User.Level < Authorizations.Registered)
                    {
                        e.User.SendNumeric(Numerics.ERR_NOLOGIN, ":Only registered users can join that channel.");
                        Forward(e, channel);
                        continue;
                    }

                    if (channel.Properties.ContainsKey("Key"))
                    {
                        if (e.Arguments.Length <= ++key)
                        {
                            e.User.SendNumeric(Numerics.ERR_KEYSET, CMD, channels[i], ":Key not specified for channel.");
                            Forward(e, channel);
                            continue;
                        }
                        else if (e.Arguments[key] != (string)channel.Properties["Key"])
                        {
                            e.User.SendNumeric(Numerics.ERR_BADCHANNELKEY, CMD, channels[i], ":Incorrect channel key specified.");
                            Forward(e, channel);
                            continue;
                        }
                    }

                    if (channel.HasFlag("InviteOnly"))
                    {
                        if (!e.User.HasSessionFlag("Invite:" + channel.Name) &&
                            !e.User.IsVoice(channel))
                        {
                            bool inviteExcept = false;
                            for (int m = 0; m < channel.InviteExcepts.Count; m++)
                            {
                                if (e.User.Mask.Matches(channel.InviteExcepts[m]))
                                {
                                    inviteExcept = true;
                                    break;
                                }
                            }
                            if (!inviteExcept)
                            {
                                e.User.SendNumeric(Numerics.ERR_INVITEONLYCHAN, CMD, channels[i], ":That channel is marked invite-only.");
                                Forward(e, channel);
                                continue;
                            }
                        }
                    }

                    if (!e.User.IsVoice(channel))
                    {
                        if (e.User.IsBanned(channel))
                        {
                            e.User.SendNumeric(Numerics.ERR_BANNEDFROMCHAN, channels[i], ":You are banned from that channel.");
                            Forward(e, channel);
                            continue;
                        }
                    }

                    if (!e.User.AddToChannel(channel))
                    {
                        e.User.SendNumeric(Numerics.ERR_USERONCHANNEL, e.User.Mask.Nickname, channel.Name, ":You are already on that channel.");
                        return;
                    }

                    OnJoin(channel, e.User);
                }
                catch (Exception ex)
                {
                    e.User.SendNumeric(Numerics.ERR_UNKNOWNERROR, ":Error joining channel:", ex.Message);
                }
            }
        }
 public void Fault(ChannelBase channel)
 {
     this.shutdownWaitObject.Fault(channel);
     this.terminateWaitObject.Fault(channel);
 }
Example #32
0
        private void Forward(ReceivedCommandEventArgs e, ChannelBase from)
        {
            if (from.Properties.ContainsKey("Forward"))
            {
                ChannelBase channel = e.Server.GetChannel((string)from.Properties["Forward"]);
                if (channel == null)
                {
                    return;
                }
                else
                {
                    e.User.SendNumeric(Numerics.RPL_SUMMONING, CMD, from.Name, ":Forwarding to", channel.Name, "due to restricted access.");

                    if (channel.HasFlag("RegisteredOnly") && e.User.Level < Authorizations.Registered)
                    {
                        e.User.SendNumeric(Numerics.ERR_NOLOGIN, CMD, channel.Name, ":Only registered users can join that channel.");
                        return;
                    }

                    if (channel.Properties.ContainsKey("Key"))
                    {
                        e.User.SendNumeric(Numerics.ERR_KEYSET, CMD, channel.Name, ":Key not specified for channel.");
                        return;
                    }

                    if (channel.HasFlag("InviteOnly"))
                    {
                        if (!e.User.HasSessionFlag("Invite:" + channel.Name) &&
                            !e.User.IsVoice(channel))
                        {
                            bool inviteExcept = false;
                            for (int m = 0; m < channel.InviteExcepts.Count; m++)
                            {
                                if (e.User.Mask.Matches(channel.InviteExcepts[m]))
                                {
                                    inviteExcept = true;
                                    break;
                                }
                            }
                            if (!inviteExcept)
                            {
                                e.User.SendNumeric(Numerics.ERR_INVITEONLYCHAN, CMD, channel.Name, ":That channel is marked invite-only.");
                                return;
                            }
                        }
                    }

                    if (!e.User.IsVoice(channel))
                    {
                        bool except = false;
                        for (int m = 0; m < channel.Exceptions.Count; m++)
                        {
                            if (e.User.Mask.Matches(channel.Exceptions[m]))
                            {
                                except = true;
                                break;
                            }
                        }
                        if (!except)
                        {
                            bool banned = false;
                            for (int m = 0; m < channel.Bans.Count; m++)
                            {
                                if (e.User.Mask.Matches(channel.Bans[m]))
                                {
                                    banned = true;
                                    break;
                                }
                            }
                            if (banned)
                            {
                                e.User.SendNumeric(Numerics.ERR_BANNEDFROMCHAN, CMD, channel.Name, ":You are banned from that channel.");
                                return;
                            }
                        }
                    }
                }

                if (!e.User.AddToChannel(channel))
                {
                    e.User.SendNumeric(Numerics.ERR_UNKNOWNERROR, CMD, channel.Name, ":Unknown error occurred while joining channel.");
                }

                OnJoin(channel, e.User);
            }
        }
 public ServerReliableSession(
     ChannelBase channel,
     IReliableFactorySettings listener,
     IServerReliableChannelBinder binder,
     FaultHelper faultHelper,
     UniqueId inputID,
     UniqueId outputID)
     : base(channel, listener, binder, faultHelper)
 {
     this.InputID = inputID;
     this.OutputID = outputID;
 }
Example #34
0
 public DebugAdapterBase(ChannelBase serverChannel)
     : base(serverChannel, MessageProtocolType.DebugAdapter)
 {
 }
        public ClientReliableSession(ChannelBase channel, IReliableFactorySettings factory, IClientReliableChannelBinder binder, FaultHelper faultHelper, UniqueId inputID) :
            base(channel, factory, binder, faultHelper)
        {
            this.binder = binder;
            this.InputID = inputID;
            this.pollingTimer = new InterruptibleTimer(this.GetPollingInterval(), this.OnPollingTimerElapsed, null);

            if (this.binder.Channel is IRequestChannel)
            {
                this.requestor = new RequestReliableRequestor();
            }
            else if (this.binder.Channel is IDuplexChannel)
            {
                SendReceiveReliableRequestor sendReceiveRequestor = new SendReceiveReliableRequestor();
                sendReceiveRequestor.TimeoutIsSafe = !this.ChannelSupportsOneCreateSequenceAttempt();
                this.requestor = sendReceiveRequestor;
            }
            else
            {
                Fx.Assert("This channel type is not supported");
            }

            MessageVersion messageVersion = this.Settings.MessageVersion;
            ReliableMessagingVersion reliableMessagingVersion = this.Settings.ReliableMessagingVersion;
            this.requestor.MessageVersion = messageVersion;
            this.requestor.Binder = this.binder;
            this.requestor.IsCreateSequence = true;
            this.requestor.TimeoutString1Index = SR.TimeoutOnOpen;
            this.requestor.MessageAction = WsrmIndex.GetCreateSequenceActionHeader(messageVersion.Addressing,
                reliableMessagingVersion);
            if ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
                && (this.binder.GetInnerSession() is ISecureConversationSession))
            {
                this.requestor.MessageHeader = new WsrmUsesSequenceSTRHeader();
            }
            this.requestor.MessageBody = new CreateSequence(this.Settings.MessageVersion.Addressing,
                reliableMessagingVersion, this.Settings.Ordered, this.binder, this.InputID);
            this.requestor.SetRequestResponsePattern();
        }
 public CustomerGrpcClient(
     ChannelBase channel
     ) : base(channel)
 {
 }
 public void Fault(ChannelBase channel)
 {
     this.sendGuard.Abort();
     this.shutdownHandle.Fault(channel);
     this.strategy.Fault(channel);
 }
Example #38
0
 public override List <HostMask> GetList(ChannelBase channel)
 {
     return(channel.InviteExcepts);
 }