Пример #1
0
        private bool IsInChannel(string zone, ChannelSettings settings)
        {
            //catch all
            if (String.IsNullOrEmpty(zone))
            {
                return(true);
            }

            return(settings.Zones.Any(x => x == zone));
        }
Пример #2
0
        private TcpChannel(TcpEndpointData endpointData,
                           IMessageSerializer serializer,
                           ChannelSettings channelSettings,
                           TcpConnectionSettings connetcionSettings)
            : this(endpointData, serializer)
        {
            connetcionSettings.SetupClient(_client);

            MaxMessageLength = channelSettings.MaxMessageLength;
        }
Пример #3
0
        public override void Run(BotMain bot, BotCommandController commandController, string[] rawTerms, string[] terms, string characterName, string channel, UserGeneratedCommand command)
        {
            ChannelSettings thisChannel = bot.GetChannelSettings(channel);

            bool characterIsAdmin = Utils.IsCharacterAdmin(bot.AccountSettings.AdminCharacters, characterName);

            if (thisChannel.ChipsClearance == ChipsClearanceLevel.ChannelOp && command.ops == null)
            {
                bot.RequestChannelOpListAndQueueFurtherRequest(command);
            }
            else if ((thisChannel.ChipsClearance == ChipsClearanceLevel.DicebotAdmin && !characterIsAdmin) ||
                     (thisChannel.ChipsClearance == ChipsClearanceLevel.ChannelOp && !command.ops.Contains(characterName) && !characterIsAdmin))
            {
                bot.SendMessageInChannel(Utils.GetCharacterUserTags(characterName) + " cannot perform [" + Name + "] under the current chip settings for this channel.", channel);
            }
            else if (thisChannel.AllowChips)
            {
                string messageString = "";
                if (terms.Length < 2)
                {
                    messageString = "Error: This command requires a number (first) and a user name (second).";
                }
                else
                {
                    bool all        = false;
                    int  giveAmount = Utils.GetNumberFromInputs(terms);

                    string[] rawTermsMost = new string[rawTerms.Length - 1];

                    for (int i = 1; i < rawTerms.Length; i++)
                    {
                        rawTermsMost[i - 1] = rawTerms[i];
                    }

                    string targetUserName = Utils.GetFullStringOfInputs(rawTermsMost).Trim();

                    if (giveAmount <= 0 && !all)
                    {
                        messageString = "Error: You must input a number to take an amount of chips.";
                    }
                    else
                    {
                        messageString = bot.DiceBot.TakeChips(characterName, targetUserName, channel, giveAmount, all);

                        commandController.SaveChipsToDisk();
                    }
                }

                bot.SendMessageInChannel(messageString, channel);
            }
            else
            {
                bot.SendMessageInChannel(Name + " is currently not allowed in this channel under " + Utils.GetCharacterUserTags("Dice Bot") + "'s settings for this channel.", channel);
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("TLS example");


            var serializer = new StringMessageSerializer();

            var serverTlsWrapper = new ServerTlsWrapper(new X509Certificate2("server.pfx"), false, CertificateValidationCallback);

            ICommunication <StringMessage> serverCommunication =
                new TcpCommunication <StringMessage>(new TcpEndpointData(IPAddress.Any, 2000),
                                                     serializer,
                                                     ChannelSettings.GetDefault(),
                                                     TcpConnectionSettingsBuilder.GetDefaultSettings(),
                                                     serverTlsWrapper);

            var server = Scenarios.RequestResponse.SetupServer(serverCommunication)
                         .UsingNewClientHandler((sender, a) => { Console.WriteLine("channel opened"); })
                         .UsingRequestHandler((sender, a) => { a.Response = new StringMessage(a.Request.Message.Replace("request", "response")); })
                         .UsingChannelClosedHandler((sender, a) => { Console.WriteLine("channel closed"); })
                         .Go();

            var clientTlsWrapper = new ClientTlsWrapper("SharpChannels Example Server Certificate",
                                                        new X509Certificate[] { new X509Certificate2("client.pfx") },
                                                        false,
                                                        CertificateValidationCallback);

            ICommunication <StringMessage> clientCommunication =
                new TcpCommunication <StringMessage>(new TcpEndpointData(IPAddress.Loopback, 2000),
                                                     serializer,
                                                     ChannelSettings.GetDefault(),
                                                     TcpConnectionSettingsBuilder.GetDefaultSettings(),
                                                     clientTlsWrapper);

            var r = Scenarios.RequestResponse.Requester(clientCommunication);

            using (r.Channel)
            {
                r.Channel.Open();

                var requester = new Requester(r.Channel);

                var requestMessage = new StringMessage($"request using tls");
                Console.WriteLine(requestMessage);

                var responseMessage = requester.Request(requestMessage);
                Console.WriteLine(responseMessage);

                r.Channel.Close();
            }

            server.Stop();

            Console.ReadKey();
        }
Пример #5
0
        public AudioSettings()
        {
            var channels = Channels;
            int count    = Channels.Count;
            var settings = this.settings = new ChannelSettings[count];

            for (int i = 0; i < count; ++i)
            {
                settings[i] = new ChannelSettings();
            }
        }
Пример #6
0
        private static IChannel <StringMessage> StartSecondInstance()
        {
            var channel = new TcpChannel <StringMessage>(new TcpEndpointData(IPAddress.Loopback, 2000),
                                                         new StringMessageSerializer(),
                                                         ChannelSettings.GetDefault(),
                                                         GetChatConnectionSettings(),
                                                         null);

            channel.Open();
            return(channel);
        }
Пример #7
0
 public TcpChannelAwaiter(TcpEndpointData endpointData,
                          IMessageSerializer serializer,
                          ChannelSettings channelSettings          = null,
                          TcpConnectionSettings connectionSettings = null,
                          ISecurityWrapper serverSecurityWrapper   = null)
     : base(endpointData,
            serializer,
            channelSettings,
            connectionSettings,
            serverSecurityWrapper)
 {
 }
Пример #8
0
        private ICommunication <StringMessage> GetIntradomainSubscriberCommunication()
        {
            var connectionSettings = new IntradomainConnectionSettingsBuilder()
                                     .UsingReceiveTimeout(TimeSpan.FromHours(1))
                                     .Build();

            return(new IntradomainCommunication <StringMessage>(new IntradomainEndpoint("pubsubpayload"),
                                                                new StringMessageSerializer(),
                                                                ChannelSettings.GetDefault(),
                                                                connectionSettings,
                                                                null));
        }
Пример #9
0
        private ICommunication <StringMessage> GetTcpSubscriberCommunication()
        {
            var connectionSettings = new TcpConnectionSettingsBuilder()
                                     .UsingReceiveTimeout(TimeSpan.FromHours(1))
                                     .Build();

            return(new TcpCommunication <StringMessage>(new TcpEndpointData(IPAddress.Loopback, 2000),
                                                        new StringMessageSerializer(),
                                                        ChannelSettings.GetDefault(),
                                                        connectionSettings,
                                                        null));
        }
    static void Main(string[] args)
    {
        var channelSettings = new ChannelSettings();

        channelSettings.attachments          = new AttachSettings();
        channelSettings.attachments.fallback = "test";

        var     testSerialize   = JsonConvert.SerializeObject(channelSettings);
        dynamic testDeserialize = JsonConvert.DeserializeObject <dynamic>(testSerialize);

        Console.WriteLine(testDeserialize.attachments.fallback);     // here you can access the parameters
    }
Пример #11
0
        public LocalChannel(DirectoryInfo workingDirectory, ChannelSettings channelSettings)
        {
            _channelSettings = channelSettings ?? throw new ArgumentNullException(nameof(channelSettings));

            _workingDirectory = workingDirectory ?? throw new ArgumentNullException(nameof(channelSettings));

            _channelDirection = ChannelDirectionFactory.Get(channelSettings);

            _source = ChannelHelper.GetSourceOrTarget(_channelSettings, workingDirectory).Item1;

            _target = ChannelHelper.GetSourceOrTarget(_channelSettings, workingDirectory).Item2;
        }
Пример #12
0
        internal static IntradomainChannel CreateAndOpen(AutoResetEvent channelCreatedEvent,
                                                         IntradomainSocket socket,
                                                         IMessageSerializer serializer,
                                                         ChannelSettings channelSettings = null,
                                                         IntradomainConnectionSettings connectionSettings = null,
                                                         ISecurityWrapper serverSecurityWrapper           = null)
        {
            var result = new IntradomainChannel(socket, serializer, channelSettings, connectionSettings, serverSecurityWrapper);

            EstablishConnection(result, channelCreatedEvent, socket, connectionSettings?.ConnectTimeout ?? IntradomainConnectionSettingsBuilder.GetDefaultSettings().ConnectTimeout);
            return(result);
        }
Пример #13
0
 public static ChannelDirection Get(ChannelSettings channelSettings)
 {
     if (channelSettings.GetType().Name == typeof(FromSettings).Name)
     {
         return(ChannelDirection.Inbound);
     }
     else if (channelSettings.GetType().Name == typeof(ToSettings).Name)
     {
         return(ChannelDirection.Outbound);
     }
     throw new InvalidCastException($"Invalid channel direction {channelSettings.GetType().Name}");
 }
Пример #14
0
        internal IntradomainChannel(IntradomainSocket socket,
                                    IMessageSerializer serializer,
                                    ChannelSettings channelSettings = null,
                                    IntradomainConnectionSettings connectionSettings = null,
                                    ISecurityWrapper serverSecurityWrapper           = null)
            : this(socket, serializer)
        {
            _connectionSettings = connectionSettings ?? IntradomainConnectionSettingsBuilder.GetDefaultSettings();
            MaxMessageLength    = channelSettings?.MaxMessageLength ?? ChannelSettings.GetDefault().MaxMessageLength;

            SecurityWrapper = serverSecurityWrapper;
        }
Пример #15
0
        public IntradomainChannel(IntradomainEndpoint endpoint,
                                  IMessageSerializer serializer,
                                  ChannelSettings channelSettings = null,
                                  IntradomainConnectionSettings connectionSettings = null,
                                  ISecurityWrapper clientSecurityWrapper           = null)
            : this(endpoint, SocketType.Client, serializer)
        {
            _connectionSettings = connectionSettings ?? IntradomainConnectionSettingsBuilder.GetDefaultSettings();
            MaxMessageLength    = channelSettings?.MaxMessageLength ?? ChannelSettings.GetDefault().MaxMessageLength;

            SecurityWrapper = clientSecurityWrapper;
        }
Пример #16
0
 internal IEndpoint GetEndpoint(string path, string contextPath, bool secure)
 {
     foreach (DictionaryEntry entry in this._endpoints)
     {
         IEndpoint       endpoint = entry.Value as IEndpoint;
         ChannelSettings settings = endpoint.GetSettings();
         if ((settings != null) && settings.Bind(path, contextPath))
         {
             return(endpoint);
         }
     }
     return(null);
 }
Пример #17
0
        public static ConnectionInfo AsConnectionInfo(this ChannelSettings channelSettings)
        {
            FileInfo privateKey = new FileInfo(channelSettings.PrivateKey);

            if (!File.Exists(privateKey.FullName))
            {
                throw new FileNotFoundException($"File with private key doesn't exist. {privateKey.FullName}");
            }
            PrivateKeyFile privateKeyFile = new PrivateKeyFile(privateKey.FullName);
            PrivateKeyAuthenticationMethod privateKeyAuthenticationMethod = new PrivateKeyAuthenticationMethod(channelSettings.UserName, privateKeyFile);
            int port = channelSettings.Port <= 0 ? Constants.DefaultSftpPort : channelSettings.Port;

            return(new ConnectionInfo(channelSettings.Host, port, channelSettings.UserName, privateKeyAuthenticationMethod));
        }
        public IOperation Create(string account, [FromBody] ChannelSettings channelSettings)
        {
            if (channelSettings == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var mediaServices  = App.Config.GetMediaServicesAccount(account);
            var context        = mediaServices.GetContext();
            var channelOptions = channelSettings.GetChannelCreationOptions();
            var operation      = context.Channels.SendCreateOperation(channelOptions);

            return(operation);
        }
Пример #19
0
        private IPublisher <StringMessage> StartTcpPublisher()
        {
            var connectionSettings = new TcpConnectionSettingsBuilder()
                                     .UsingSendTimeout(TimeSpan.FromHours(1))
                                     .Build();

            var communication = new TcpCommunication <StringMessage>(new TcpEndpointData(IPAddress.Any, 2000),
                                                                     new StringMessageSerializer(),
                                                                     ChannelSettings.GetDefault(),
                                                                     connectionSettings,
                                                                     null);

            return(Scenarios.PubSub.Publisher(communication));
        }
Пример #20
0
        public static ChannelSettings CreateIfNotExists(this ChannelSettings target)
        {
            var info = target.AsConnectionInfo();

            using (SftpClient client = new SftpClient(info))
            {
                client.Connect();
                if (!client.Exists(target.Path))
                {
                    client.CreateDirectory(target.Path);
                }
            }
            return(target);
        }
Пример #21
0
        public SftpChannel(DirectoryInfo workingDirectory, ChannelSettings channelSettings)
        {
            _channelSettings = channelSettings ?? throw new ArgumentNullException(nameof(channelSettings));

            _workingDirectory = workingDirectory ?? throw new ArgumentNullException(nameof(channelSettings));

            _channelDirection = ChannelDirectionFactory.Get(channelSettings);

            _source = string.IsNullOrEmpty(channelSettings.Path) ? throw new ArgumentException(nameof(channelSettings.Path))  :  channelSettings.Path;

            _target = _workingDirectory;

            _connectionInfo = channelSettings.AsConnectionInfo();
        }
Пример #22
0
        public TcpChannel(TcpEndpointData endpointData, IMessageSerializer serializer)
        {
            Enforce.NotNull(endpointData, nameof(endpointData));
            Enforce.NotNull(serializer, nameof(serializer));

            _endpointData = endpointData;
            Serializer    = serializer;
            _client       = new TcpClient(endpointData.Address.AddressFamily)
            {
                NoDelay = true
            };

            MaxMessageLength = ChannelSettings.GetDefault().MaxMessageLength;
        }
Пример #23
0
        public IActionResult Create(string account, [FromBody] ChannelSettings channelSettings)
        {
            if (channelSettings == null)
            {
                return(BadRequest());
            }

            var mediaServices  = App.Config.GetMediaServicesAccount(account);
            var context        = mediaServices.GetContext();
            var channelOptions = channelSettings.GetChannelCreationOptions();
            var operation      = context.Channels.SendCreateOperation(channelOptions);

            return(Ok(operation));
        }
Пример #24
0
        private IPublisher <StringMessage> StartIntradomainPublisher()
        {
            var connectionSettings = new IntradomainConnectionSettingsBuilder()
                                     .UsingSendTimeout(TimeSpan.FromHours(1))
                                     .Build();

            var communication = new IntradomainCommunication <StringMessage>(new IntradomainEndpoint("pubsubpayload"),
                                                                             new StringMessageSerializer(),
                                                                             ChannelSettings.GetDefault(),
                                                                             connectionSettings,
                                                                             null);

            return(Scenarios.PubSub.Publisher(communication));
        }
Пример #25
0
        public static ChannelSettings DeleteOneFile(this ChannelSettings target, FileInfo fileInfo)
        {
            var info = target.AsConnectionInfo();

            using (SftpClient client = new SftpClient(info))
            {
                client.Connect();

                if (client.Exists(target.Path))
                {
                    client.DeleteFile(Path.Combine(target.Path, fileInfo.Name));
                }
            }
            return(target);
        }
        private IRequester GetIntradomainRequester()
        {
            var connectionSettings = new IntradomainConnectionSettingsBuilder()
                                     .UsingSendTimeout(TimeSpan.FromHours(1))
                                     .UsingReceiveTimeout(TimeSpan.FromHours(1))
                                     .Build();

            var clientCommunication = new IntradomainCommunication <StringMessage>(new IntradomainEndpoint("payload"),
                                                                                   new StringMessageSerializer(),
                                                                                   ChannelSettings.GetDefault(),
                                                                                   connectionSettings,
                                                                                   null);

            return(Scenarios.RequestResponse.Requester(clientCommunication));
        }
        private IRequester GetTcpRequester()
        {
            var connectionSettings = new TcpConnectionSettingsBuilder()
                                     .UsingSendTimeout(TimeSpan.FromHours(1))
                                     .UsingReceiveTimeout(TimeSpan.FromHours(1))
                                     .Build();

            var clientCommunication = new TcpCommunication <StringMessage>(new TcpEndpointData(IPAddress.Loopback, 2000),
                                                                           new StringMessageSerializer(),
                                                                           ChannelSettings.GetDefault(),
                                                                           connectionSettings,
                                                                           null);

            return(Scenarios.RequestResponse.Requester(clientCommunication));
        }
        private NewChannelRequestAcceptor StartIntradomainServer()
        {
            var connectionSettings = new IntradomainConnectionSettingsBuilder()
                                     .UsingSendTimeout(TimeSpan.FromHours(1))
                                     .UsingReceiveTimeout(TimeSpan.FromHours(1))
                                     .Build();

            var communication = new IntradomainCommunication <StringMessage>(new IntradomainEndpoint("payload"),
                                                                             new StringMessageSerializer(),
                                                                             ChannelSettings.GetDefault(),
                                                                             connectionSettings,
                                                                             null);

            return(StartServer(communication));
        }
        private NewChannelRequestAcceptor StartTcpServer()
        {
            var connectionSettings = new TcpConnectionSettingsBuilder()
                                     .UsingSendTimeout(TimeSpan.FromHours(1))
                                     .UsingReceiveTimeout(TimeSpan.FromHours(1))
                                     .Build();

            var communication = new TcpCommunication <StringMessage>(new TcpEndpointData(IPAddress.Any, 2000),
                                                                     new StringMessageSerializer(),
                                                                     ChannelSettings.GetDefault(),
                                                                     connectionSettings,
                                                                     null);

            return(StartServer(communication));
        }
Пример #30
0
        //separation of concern issue + it validates as well :(
        public static (DirectoryInfo, DirectoryInfo) GetSourceOrTarget(ChannelSettings settings, DirectoryInfo workingDirectory)
        {
            var channelDirection = ChannelDirectionFactory.Get(settings);

            if (channelDirection == ChannelDirection.Inbound)
            {
                return(settings.Path.AsDirectoryInfo().ThrowExceptionIfNullOrDoesntExists(),
                       workingDirectory);
            }
            else
            {
                return(workingDirectory.ThrowExceptionIfNullOrDoesntExists(),
                       settings.Path.AsDirectoryInfo().ThrowExceptionIfNullOrDoesntExists());
            }
        }