Beispiel #1
0
        public async Task <IActionResult> TestUploadImage()
        {
            MemoryStream imageStream = new MemoryStream();

            using (var file = new FileStream(@"C:\Users\Administrator\Desktop\image.png", FileMode.Open))
            {
                file.CopyTo(imageStream);
            }
            imageStream.Position = 0;
            var    postContent = new MultipartFormDataContent();
            string boundary    = string.Format("--{0}", DateTime.Now.Ticks.ToString("x"));

            postContent.Headers.Add("ContentType", $"multipart/form-data, boundary={boundary}");
            postContent.Add(new StreamContent(imageStream, (int)imageStream.Length), "file", "test.png");
            using (var fileClient = _clientFactory.CreateClient())
            {
                var uploadResponse = await fileClient.PostAsync("http://www.tzaqwl.com:5001/api/img/Upload/Img", postContent);
            }

            using (var insertClient = _clientFactory.CreateClient())
            {
                var dic = new Dictionary <string, object>()
                {
                    ["content"]    = "测试测试",
                    ["img"]        = "img_Id",
                    ["title"]      = "测试测试",
                    ["isDel"]      = true,
                    ["createTime"] = "2020-09-29 16:44"
                };

                await CustomClient.PostData <string>(insertClient, "http://www.tzaqwl.com:5001/api/Story/add", dic);
            }

            return(Ok("保存失败"));
        }
Beispiel #2
0
        private static void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var processUIDs = _allUIds.GetRange(_batchStartIndex, _batchLength);

            Console.WriteLine("Timer Processing", processUIDs);



            Parallel.ForEach(processUIDs, async uid => {
                CustomClient client = null;
                if (MailConnectionManager.TryGetClient(out client))
                {
                    Console.WriteLine(client.Id);
                    var proxy = new MailProxy("imap.gmail.com", EncryptionType.UNENCRYPTED, ref client);
                    if (!client.Connected)
                    {
                        proxy.Login("ramankingdom", "letusc");
                    }
                    proxy.SetWorkingEmailFolder("Inbox");
                    var header = await proxy.GetEmailHeaderAsync(uid);
                    Console.WriteLine(ApplicationHelpers.ConvertBytesToString(header));
                    client.FreeClient();
                }
            }
                             );
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //MailInteractionManager proxy = new MailInteractionManager("imap.gmail.com", EncryptionType.UNENCRYPTED);
            CustomClient client = null;

            if (MailConnectionManager.TryGetClient(out client))
            {
                var proxy = new MailProxy("imap.gmail.com", EncryptionType.UNENCRYPTED, ref client);

                if (!client.Connected)
                {
                    proxy.Login("ramankingdom", "letusc");
                }
                var folders = proxy.GetEmailFoldersAsync().GetAwaiter().GetResult();
                proxy.SetWorkingEmailFolder("Inbox");
                _allUIds = proxy.PopulateEmailHeadersIDAsync().GetAwaiter().GetResult();
                client.FreeClient();
            }

            Timer timer = new Timer(3000);

            timer.Elapsed += Timer_Elapsed;
            timer.Start();
            timer.Enabled = true;

            Console.ReadLine();
        }
 public static async Task<JsonMetricsContext> FetchRemoteMetrics(Uri remoteUri, Func<string, JsonMetricsContext> deserializer, CancellationToken token)
 {
     using (CustomClient client = new CustomClient())
     {
         client.Headers.Add("Accept-Encoding", "gizp");
         var json = await client.DownloadStringTaskAsync(remoteUri).ConfigureAwait(false);
         return deserializer(json);
     }
 }
Beispiel #5
0
 public static JsonMetricsContext FetchRemoteMetrics(Uri remoteUri, Func <string, JsonMetricsContext> deserializer, CancellationToken token)
 {
     using (CustomClient client = new CustomClient())
     {
         client.Headers.Add("Accept-Encoding", "gizp");
         var json = Metrics.Visualization.TaskHelper.RunAsync <string>(() => { return(client.DownloadString(remoteUri)); }, null).Result;
         return(deserializer(json));
     }
 }
        public static async Task <JsonMetricsContext> FetchRemoteMetrics(Uri remoteUri, Func <string, JsonMetricsContext> deserializer, CancellationToken token)
        {
            using (CustomClient client = new CustomClient())
            {
                client.Headers.Add("Accept-Encoding", "gizp");
                var json = await client.DownloadStringTaskAsync(remoteUri).ConfigureAwait(false);

                return(deserializer(json));
            }
        }
Beispiel #7
0
        public void Handle(Type type, CustomClient local, CustomClient remote, ProtocolJsonContent content)
        {
            if (type is null)
            {
                return;
            }
            MessageHandler handler = (MessageHandler)Activator.CreateInstance(type, new object[] { local, remote, content });

            new Action(handler.Handle).Run(handler.EndHandle, handler.Error);
        }
Beispiel #8
0
 /// <summary>
 /// ONLY MESSAGE FOR SERVER
 /// </summary>
 /// <param name="client"></param>
 /// <param name="receiver"></param>
 /// <param name="content"></param>
 public static void SendPrivateMessage(this CustomClient client, string receiver, string content)
 {
     client.Send(851, new BotoxSharedProtocol.Network.ProtocolJsonContent()
     {
         fields =
         {
             { "receiver", receiver },
             { "content",  content  }
         }
     });
 }
Beispiel #9
0
 /// <summary>
 /// ONLY MESSAGE FOR SERVER
 /// </summary>
 /// <param name="client"></param>
 /// <param name="channel"></param>
 /// <param name="content"></param>
 public static void SendChatMessage(this CustomClient client, string channelName, string content)
 {
     if (byte.TryParse(ProtocolManager.Instance.Protocol.enumerations.FirstOrDefault(x => x.name == "ChatActivableChannelsEnum")[channelName], out byte channel))
     {
         client.SendChatMessage(channel, content);
     }
     else
     {
         logger.Error($"Send chat error : no channel '{channelName}' found");
     }
 }
Beispiel #10
0
 /// <summary>
 /// ONLY MESSAGE FOR SERVER !!!
 /// </summary>
 /// <param name="channel"></param>
 /// <param name="content"></param>
 public static void SendChatMessage(this CustomClient client, byte channel, string content)
 {
     client.Send(861, new BotoxSharedProtocol.Network.ProtocolJsonContent()
     {
         fields =
         {
             { "channel", channel },
             { "content", content }
         }
     });
 }
 public CommunicationManager()
 {
     _baudRate      = string.Empty;
     _parity        = string.Empty;
     _stopBits      = string.Empty;
     _dataBits      = string.Empty;
     _portName      = "COM1";
     _displayWindow = null;
     _customClient  = new CustomClient();
     //add event handler
     comPort.DataReceived += comPort_DataReceived;
 }
Beispiel #12
0
 public MapComplementaryInformationsDataMessageHandler(CustomClient local, CustomClient remote, ProtocolJsonContent content)
     : base(local, remote, content)
 {
 }
Beispiel #13
0
        public void Handle(string protocolName, CustomClient local, CustomClient remote, ProtocolJsonContent content)
        {
            Type type = handlersType.FirstOrDefault(x => x.GetCustomAttribute <HandlerAttribute>().ProtocolName.ToLower() == protocolName.ToLower());

            Handle(type, local, remote, content);
        }
Beispiel #14
0
        public void Handle(int protocolId, CustomClient local, CustomClient remote, ProtocolJsonContent content)
        {
            Type type = handlersType.FirstOrDefault(x => x.GetCustomAttribute <HandlerAttribute>().ProtocolId == protocolId);

            Handle(type, local, remote, content);
        }
Beispiel #15
0
 public MessageHandler(CustomClient localClient, CustomClient remoteClient, ProtocolJsonContent content)
 {
     Content      = content;
     LocalClient  = localClient;
     RemoteClient = remoteClient;
 }
Beispiel #16
0
 public CharacterSelectedSuccessMessage(CustomClient local, CustomClient remote, ProtocolJsonContent content)
     : base(local, remote, content)
 {
 }
 public ProtocolRequiredHandler(CustomClient local, CustomClient remote, ProtocolJsonContent content)
     : base(local, remote, content)
 {
 }
        public void StoreAsync_WhenCalled_ExpectAction()
        {
            // Arrange
            var mockCacheConfiguration = new Mock<IConfiguration<RedisCacheConfigurationEntity>>();
            mockCacheConfiguration.Setup(r => r.Get).Returns(
                new RedisCacheConfigurationEntity
                {
                    CacheDuration = 10,
                    RedisCacheDefaultPrefix = "DEFAULT",
                    UseObjectCompression = false
                });

            var customMappersConfiguration = new CustomMappersConfiguration
            {
                ClientMapper = CustomMapperFactory.CreateClientMapper<CustomClient>()
            };

            var jsonSettingsFactory = new JsonSettingsFactory(customMappersConfiguration);

            var cacheManager = new RedisCacheManager<Token>(
                RedisHelpers.ConnectionMultiplexer,
                mockCacheConfiguration.Object,
                jsonSettingsFactory.Create());

            var tokenStore = new TokenHandleStore(
                cacheManager,
                mockCacheConfiguration.Object);

            var claim1 = new Claim("Type1", "Value1");
            var claim2 = new Claim("Type2", "Value2");

            var client = new CustomClient
            {
                Claims = new List<Claim> { claim1, claim2 }
            };

            var token = new Token
            {
                Claims = new List<Claim> { claim1, claim2 },
                Client = client,
                Type = "Type",
                CreationTime = new DateTimeOffset(new DateTime(2016, 1, 1)),
                Version = 1,
                Issuer = "Issuer",
                Lifetime = 120,
                Audience = "Audience"
            };

            // Act
            var stopwatch = Stopwatch.StartNew();
            tokenStore.StoreAsync("KeyToStore", token).Wait();
            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            var redisValue = RedisHelpers.ConnectionMultiplexer.GetDatabase().StringGet("DEFAULT_THS_KeyToStore");

            Assert.That(redisValue.HasValue, Is.True);
            Console.WriteLine(redisValue);
        }