示例#1
0
    static void Main(string[] args)
    {
        ServerList   serverList   = new ServerList();
        ActiveServer activeServer = new ActiveServer();

        activeServer.SetState("Sicilia", "66.77.88.999");

        serverList.Add(activeServer.GetSnaphot());

        activeServer.SetState("Ireland", "55.66.77.999");

        serverList.Add(activeServer.GetSnaphot());

        activeServer.Restore(serverList.Get(0));

        activeServer.Restore(serverList.Get(1));

        activeServer.SetState("Oregon", "88.99.77.999");

        serverList.Add(activeServer.GetSnaphot());

        activeServer.Restore(serverList.Get(1));

        activeServer.Restore(serverList.Get(2));

        Console.ReadKey();
    }
示例#2
0
        public async Task TopicTest()
        {
            int          counter      = 0;
            ActiveServer activeServer = new ActiveServer();

            activeServer.Register(services =>
            {
                services.AddActiveProducer(options =>
                {
                    options.IsCluster     = true;
                    options.BrokerUris    = brokerUris;
                    options.Destination   = $"service.{topic}";
                    options.IsPersistent  = true;
                    options.Transactional = false;
                    options.Password      = password;
                    options.UserName      = userName;
                });

                services.AddActiveConsumer(options =>
                {
                    options.IsCluster       = true;
                    options.BrokerUris      = brokerUris;
                    options.Durable         = false;
                    options.Destination     = $"service.{topic}";
                    options.AutoAcknowledge = false;
                    options.FromQueue       = false;
                    options.Password        = password;
                    options.UserName        = userName;
                    options.ClientId        = "service.topic";
                    options.PrefetchCount   = 10;
                }).AddListener(result =>
                {
                    Output.WriteLine(JsonSerializer.Serialize(result));
                    counter++;
                    result.Commit();
                });
            });
            await activeServer.StartAsync();

            Thread.Sleep(1000);//等待运行1秒

            var serviceProvider = activeServer.ServiceProvider;
            var factory         = serviceProvider.GetService <IActiveProducerFactory>();
            var producer        = factory.Create();

            for (var i = 0; i < 10; i++)
            {
                await producer.PublishAsync("message" + i);
            }

            BlockUntil(() => counter >= 10, 3000);

            Thread.Sleep(1000);//等待运行1秒
            Assert.Equal(10, counter);

            await activeServer.StopAsync();
        }
示例#3
0
 /// <summary>
 /// Handler URL server was changed.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ServerURL_Changed(object sender, EventArgs e)
 {
     try
     {
         ActiveServer.SetUrl(ServerURL.Text);
         InvalidServerURL.Visible = false;
     }
     catch
     {
         InvalidServerURL.Visible = true;
     }
 }
示例#4
0
 /// <summary>
 /// Connect to any server, if a server is already connected, disconnect from it and no connect again
 /// </summary>
 public void ConnectToAnyServer()
 {
     m_FailedConnetions = 0;
     if (m_ConnectionIndex >= Count)
     {
         m_ConnectionIndex = 0;
     }
     if (ActiveServer != null)
     {
         ActiveServer.Disconnect();
         ActiveServer = null;
         //if (!CKernel.Preferences.GetBool("AutoReconnect")) m_ConnectToNextServers();
         return;
     }
     m_ConnectToNextServers();
 }
示例#5
0
        /// <summary>
        /// Search sources for the 15 next files using TCP
        /// </summary>
        public void SearchNextSourcesTCP()
        {
            if ((ActiveServer != null) &&
                (!ActiveServer.AllFilesPublished) &&
                (DateTime.Now - ActiveServer.LastPublishedTime > new TimeSpan(0, 1, 0)))
            {
                ActiveServer.PublishSharedFiles();
            }
            if ((m_NextTCPSourcesSearch > DateTime.Now) || (ActiveServer == null) || (CKernel.FilesList.Count == 0))
            {
                return;
            }

            if (m_TimesshownUDPClosedMessage < 8)
            {
                m_TimesshownUDPClosedMessage++;
            }
            if ((!CKernel.UDPListener.PortIsAccesible) &&
                (m_TimesshownUDPClosedMessage < 8) &&
                (m_TimesshownUDPClosedMessage > 2) &&              //ignore first 2 pass
                (CKernel.Preferences.GetUInt("ID") > Protocol.LowIDLimit))
            {
                if (m_TimesshownUDPClosedMessage < 7)
                {
                    CLog.Log(Types.Constants.Log.Info, "UDP_PORT_NOT_OPEN");
                }
                else
                {
                    CLog.Log(Types.Constants.Log.Notify, "UDP_PORT_NOT_OPEN");
                }
            }
            ArrayList hashes = new ArrayList();
            CElement  Element;

            do
            {
                if (CKernel.FilesList.Count <= m_TCPSourceSearchFileIndex)
                {
                    m_TCPSourceSearchFileIndex = 0;
                    break;
                }
                else
                {
                    Element = CKernel.FilesList[m_TCPSourceSearchFileIndex];
                    m_TCPSourceSearchFileIndex++;
                }
                if ((Element.SourcesList != null) && (Element.File.FileStatus != Protocol.FileState.Stopped) && (Element.File.MaxSources > Element.SourcesList.Count() - 5))
                {
                    hashes.Add(Element.File.FileHash);
                }
            }while (hashes.Count < Protocol.SourcesPerTCPFrame);
            if ((m_TCPSourceSearchFileIndex == 0) || (hashes.Count == 0))
            {
                m_NextTCPSourcesSearch = DateTime.Now + new TimeSpan(0, Protocol.ReaskServerTCP, 0);
            }
            else
            {
                m_NextTCPSourcesSearch = DateTime.Now + new TimeSpan(0, 0, Protocol.ReaskNextTCPFile * hashes.Count);
            }
            if (hashes.Count > 0)
            {
                ActiveServer.RequestSources(hashes);
            }
        }
        private void HandleSelect(ActiveServer selectedServer)
        {
            foreach (var server in this.Servers)
            {
                server.IsSelected = false;
            }

            selectedServer.IsSelected = true;

            this.manager.SetSelectedServer(selectedServer.Name);
        }
示例#7
0
        public async Task LoggerTest()
        {
            int          counter      = 0;
            ActiveServer activeServer = new ActiveServer();

            activeServer.Register(services =>
            {
                services.AddLogging(builder =>
                {
                    builder.SetMinimumLevel(LogLevel.Trace);
                });
                services.AddActiveLogger(options =>
                {
                    options.IsCluster       = true;
                    options.ApplicationName = nameof(ActiveMqServiceTest);
                    options.BrokerUris      = brokerUris;
                    options.Category        = nameof(ActiveMqServiceTest);
                    options.UseQueue        = true;
                    options.Destination     = $"service.{logger}";
                    options.MinLevel        = LogLevel.Trace;
                    options.InitializeCount = 10;
                    options.IsPersistent    = true;
                    options.Password        = password;
                    options.UserName        = userName;
                });

                services.AddActiveConsumer(options =>
                {
                    options.IsCluster       = true;
                    options.BrokerUris      = brokerUris;
                    options.Durable         = false;
                    options.FromQueue       = true;
                    options.Destination     = $"service.{logger}";
                    options.AutoAcknowledge = true;
                    options.Password        = password;
                    options.UserName        = userName;
                }).AddListener(result =>
                {
                    WriteLogger(result);
                    if (result.Message.Contains(nameof(ActiveMqServiceTest)))
                    {
                        counter++;
                    }
                });
            });
            await activeServer.StartAsync();

            Thread.Sleep(1000);//等待运行1秒

            var serviceProvider = activeServer.ServiceProvider;
            var loggerFactory   = serviceProvider.GetService <ILoggerFactory>();
            var _logger         = loggerFactory.CreateLogger <ActiveMqServiceTest>();

            _logger.LogTrace("LogTrace");
            _logger.LogDebug("LogDebug");
            _logger.LogInformation("LogInformation");
            _logger.LogWarning("LogWarning");
            _logger.LogError("LogError");
            _logger.LogCritical("LogCritical");

            BlockUntil(() => counter >= 6, 3000);

            Thread.Sleep(1000);//等待运行1秒
            Assert.Equal(6, counter);

            await activeServer.StopAsync();
        }