示例#1
0
        public void Configuration(IAppBuilder app)
        {
            //create your server provider
            ServerProvider serverProvider = new ServerProvider();

            //register your server service
            serverProvider.RegisterServerService <HelloWorldService>();
            //register client service
            serverProvider.RegisterClientService <IHelloCallbackClientService>();
            //handle cross origin
            serverProvider.ProviderSetting.HttpSetting.HandleCrossOriginAccess = true;
            //add signalgo middlleware
            app.Use <SignalGo.Server.Owin.SignalGoOwinMiddleware>(serverProvider);

            HttpConfiguration config = new HttpConfiguration();

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);
            config.Routes.MapHttpRoute(
                "DefaultApi", // Route name
                "", "http://localhost:10012/HellowWorld/Hello");
            app.UseWebApi(config);
        }
示例#2
0
        private async void GetEfficiency()
        {
            foreach (var efficiency in this.DevicesEfficiency)
            {
                this.DevicesEfficiency.Remove(efficiency);
            }

            var deviceEfficiencyHttpQuery = string.Format("{0}{1}/{2}/", constants.Constants.ServerHostURL, DevicesHttpUrl, "Efficiency");

            foreach (var device in this.Devices)
            {
                var http     = deviceEfficiencyHttpQuery + device.DeviceId;
                var response = await ServerProvider.Get(http);

                try
                {
                    var value = JsonConvert.DeserializeObject <double>(response);
                    this.DevicesEfficiency.Add(new DeviceEfficiency()
                    {
                        DeviceId = device.DeviceId,
                        Value    = value
                    });
                }
                catch { }
            }
        }
        private async void RegisterExecute()
        {
            var registerURL = constants.Constants.ServerHostURL + RegisterHttpQuery;

            var json           = JsonConvert.SerializeObject(this.UserRegisterRequestModel);
            var responseResult = await ServerProvider.Post(json, registerURL);

            try
            {
                var token = JsonConvert.DeserializeObject <JwtToken>(responseResult);
                ServiceLocator.Current.GetInstance <UserViewModel>().JwtToken = token;
                this.IsErrorOccured = false;
            }
            catch
            {
                this.IsErrorOccured = true;
            }

            if (this.IsErrorOccured)
            {
                ServiceLocator.Current.GetInstance <MainNavigationViewModel>().ViewType = ViewType.AuthorizationView;
            }
            else
            {
                ServiceLocator.Current.GetInstance <MainNavigationViewModel>().ViewType = ViewType.MainAuthorizedView;
            }
        }
示例#4
0
        public void Ctor_CreatesMappingTable_WhereModuloIsNotEmpty()
        {
            var first = new ServerConfig
            {
                Ip   = "192.168.0.1",
                Port = 5000
            };

            var second = new ServerConfig
            {
                Ip   = "192.168.0.1",
                Port = 5001
            };

            var three = new ServerConfig
            {
                Ip   = "192.168.0.1",
                Port = 5002
            };

            ClusterConfig config = new ClusterConfig
            {
                Servers = new[] { first, second, three }
            };

            int modulo         = 100 % config.Servers.Length;
            int rangePerServer = 100 / config.Servers.Length;

            ServerProvider provider = new ServerProvider(config);

            Assert.Equal(provider.Mappings.Values.Count(x => x.EndPoint.Equals(first.EndPoint)), rangePerServer + modulo);
            Assert.Equal(provider.Mappings.Values.Count(x => x.EndPoint.Equals(second.EndPoint)), rangePerServer);
            Assert.Equal(provider.Mappings.Values.Count(x => x.EndPoint.Equals(three.EndPoint)), rangePerServer);
        }
示例#5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //create your server provider
            ServerProvider serverProvider = new ServerProvider();

            //register your server service
            serverProvider.RegisterServerService <HelloWorldService>();
            serverProvider.RegisterServerService <TestStreamService>();
            serverProvider.RegisterClientService <IHelloCallbackClientService>();
            //handle cross origin
            serverProvider.ProviderSetting.HttpSetting.HandleCrossOriginAccess = true;
            //serverProvider.Start("http://localhost:6235/any");
            //websocket for duplex clients
            WebSocketOptions webSocketOptions = new WebSocketOptions()
            {
                KeepAliveInterval = TimeSpan.FromSeconds(120),
                ReceiveBufferSize = 4 * 1024,
            };

            app.UseWebSockets(webSocketOptions);

            //add signalgo middlleware
            app.UseMiddleware <SignalGoNetCoreMiddleware>(serverProvider);
        }
示例#6
0
        public void SelectServers_ReturnsCollectionOfServers()
        {
            // Arrange
            ClusterConfig config = new ClusterConfig
            {
                Servers = new[] {
                    new ServerConfig {
                        Ip = "8.8.8.8", Port = 50
                    },
                    new ServerConfig {
                        Ip = "8.8.8.8", Port = 60
                    },
                    new ServerConfig {
                        Ip = "8.8.8.4", Port = 60
                    },
                    new ServerConfig {
                        Ip = "8.8.8.4", Port = 60
                    }
                }
            };

            // Act
            ServerProvider provider = new ServerProvider(config);

            ServerConfig[] servers = provider.SelectServers();

            // Assert
            Assert.Equal(config.Servers, servers);
        }
示例#7
0
        private void DanMuJieMain_ReceivedDanmaku(object sender, ReceivedDanmakuArgs e)
        {
            string commentText = e.Danmaku.CommentText;

            this.AddDM(commentText);
            if (!commentText.Trim().StartsWith("dmj"))
            {
                return;
            }
            this.AddDM(commentText);
            string[] apiAndSongInfo = commentText.Trim().Split(new char[] { '-' });
            if (apiAndSongInfo != null && apiAndSongInfo.Length >= 3)
            {
                ServerProvider api = SelectServerProvider(apiAndSongInfo[1]);
                this.Api.Server = api;
                try
                {
                    var songs = Api.SearchObj(apiAndSongInfo[2]);

                    if (songs != null && songs.Length >= 1)
                    {
                        _window.ReLoadSearchResult(songs);

                        var song = songs.FirstOrDefault();

                        try
                        {
                            _window.ShowMessage("正在播放: " + song.name + " - " + string.Join(",", song.artist));
                        }
                        catch (Exception ex)
                        { }

                        this.AddDM("开始播放: " + song.name);

                        try
                        {
                            PlayMusicHelper.AddPlayList(GetPlayUrlById(song.url_id));
                        }
                        catch (Exception ex)
                        {
                            throw;
                        }
                    }
                    else
                    {
                        try
                        {
                            _window.ShowMessage("无搜索结果: " + apiAndSongInfo[2]);
                        }
                        catch (Exception ex)
                        { }
                    }
                }
                catch (Exception ex)
                {
                    this.AddDM("错误: " + ex.Message);
                }
            }
        }
示例#8
0
 public MusicList(Music_search_item aItem, ServerProvider server, string baseUrl)
 {
     Title  = aItem.name;
     Author = string.Join(" / ", aItem.artist);
     Url    = $"{baseUrl}?server={server:G}&type=url&id={aItem.url_id}";
     Pic    = $"{baseUrl}?server={server:G}&type=pic&id={aItem.pic_id}";
     Lrc    = $"{baseUrl}?server={server:G}&type=lrc&id={aItem.lyric_id}";
 }
示例#9
0
文件: Program.cs 项目: v235/D2-D3
        static void Main(string[] args)
        {
            Params         serverParam = new Params();
            ServerProvider server      = new ServerProvider(serverParam.Adress, serverParam.Port, 10);

            server.Start();
            Console.ReadKey();
        }
 public AddDeviceRequest(string projectId, string locationId, string planId, string operatingSystemId, ServerProvider provider)
 {
     ProjectId         = projectId;
     LocationId        = locationId;
     PlanId            = planId;
     OperatingSystemId = operatingSystemId;
     Provider          = provider;
 }
示例#11
0
        private static void Main(string[] args)
        {
            ServerProvider serverProvider = new ServerProvider();

            serverProvider.RegisterServerService <UserService>();
            serverProvider.Start("http://localhost:6525/any");
            Console.WriteLine("server started");
            Console.ReadKey();
        }
示例#12
0
        static void Main(string[] args)
        {
            ServerProvider serverProvider = new ServerProvider();

            serverProvider.RegisterServerService <ChatService>();
            serverProvider.RegisterClientService <IClientChatService>();
            serverProvider.Start("http://localhost:6262/any");
            Console.WriteLine("server started");
            Console.ReadLine();
        }
示例#13
0
        public void Ctor_AssingsClusterConfig()
        {
            ClusterConfig config = new ClusterConfig {
                Servers = new[] { new ServerConfig(), new ServerConfig() }
            };
            ServerProvider provider = new ServerProvider(config);

            Assert.NotNull(provider);
            Assert.Equal(provider.ServersCount, config.Servers.Length);
        }
示例#14
0
        public void Ctor_AssingsClusterConfig()
        {
            ClusterConfig config = new ClusterConfig {
                Servers = CreateServers(2)
            };
            ServerProvider provider = new ServerProvider(config);

            Assert.NotNull(provider);
            Assert.Equal(provider.Servers.Length, config.Servers.Length);
            Assert.Equal(provider.Servers, config.Servers);
        }
示例#15
0
        public void SelectServer_ReturnsServerFroMappingTable()
        {
            ServerConfig[] servers = CreateServers(1);
            ClusterConfig  config  = new ClusterConfig {
                Servers = servers
            };

            ServerProvider provider       = new ServerProvider(config);
            ServerConfig   selectedServer = provider.SelectServer(GetHashCode());

            Assert.Equal(selectedServer, servers[0]);
        }
 private async void LogOutExecute()
 {
     var loginURL = constants.Constants.ServerHostURL + LogoutCommand;
     var responseStatus = await ServerProvider.Post(loginURL);
     this.IsUserAuthorized = !(responseStatus == HttpStatusCode.OK ||
         responseStatus == HttpStatusCode.Accepted ||
         responseStatus == HttpStatusCode.Created);
     if (!this.isUserAuthorized)
     {
         ServiceLocator.Current.GetInstance<MainNavigationViewModel>().ViewType = ViewType.AuthorizationView;
     }
 }
示例#17
0
        public MainWindow()
        {
            This = this;
            InitializeComponent();
            mainframe.Navigate(new FirstPage());
            Closing += MainWindow_Closing;

            ServerProvider serverProvider = new ServerProvider();

            serverProvider.RegisterServerService <ServerManagerService>();
            serverProvider.Start("http://localhost:5468/ServerManager/SignalGo");
        }
示例#18
0
        static void Main(string[] args)
        {
            ServerProvider serverProvider = new ServerProvider();

            serverProvider.RegisterServerService <Services.HelloWorldService>();
            serverProvider.RegisterServerService <Services.TestStreamService>();
            serverProvider.RegisterClientService <ClientServices.IHelloCallbackClientService>();
            //to handle cross origin errors
            serverProvider.ProviderSetting.HttpSetting.HandleCrossOriginAccess = true;
            serverProvider.Start("http://localhost:9674/SignalGo");
            Console.WriteLine("server started");
            Console.ReadKey();
        }
        public async void SetBaby(int id)
        {
            var babyUrl  = string.Format("{0}{1}/{2}", Constants.ServerHostURL, UserHttpQuery, id);
            var userBaby = await ServerProvider.Get(babyUrl);

            try
            {
                this.BabyFeedingModel = JsonConvert.DeserializeObject <BabyFeedingModel>(userBaby);
            }
            catch
            {
                //Debug.WriteLine("Set user failed.");
            }
        }
示例#20
0
        public async void SetUser(string id)
        {
            var userUrl  = string.Format("{0}{1}/{2}", Constants.ServerHostURL, UserHttpQuery, id);
            var userJson = await ServerProvider.Get(userUrl);

            try
            {
                this.User = JsonConvert.DeserializeObject <User>(userJson);
            }
            catch
            {
                //Debug.WriteLine("Set user failed.");
            }
        }
示例#21
0
        public void Ctor_CreatesMappingTable_WhereModuloIsEmpty()
        {
            ServerConfig[] servers = CreateServers(2);
            ClusterConfig  config  = new ClusterConfig {
                Servers = servers
            };

            int rangePerServer = 100 / config.Servers.Length;

            ServerProvider provider = new ServerProvider(config);

            Assert.Equal(provider.Mappings.Values.Count(x => x.EndPoint.Equals(servers[0].EndPoint)), rangePerServer);
            Assert.Equal(provider.Mappings.Values.Count(x => x.EndPoint.Equals(servers[1].EndPoint)), rangePerServer);
        }
示例#22
0
        private static void Main(string[] args)
        {
            ServerProvider serverProvider = new ServerProvider();

            serverProvider.RegisterServerService <AuthenticationService>();
            serverProvider.RegisterServerService <BookService>();
            serverProvider.ProviderSetting.IsEnabledDataExchanger = false;
            serverProvider.Start("http://localhost:6452/SignalGoTest/any");

            SignalGoBotManager signalGoBotManager = new SignalGoBotManager();

            signalGoBotManager.Start("your telegram bot token here", serverProvider);
            Console.WriteLine("server started successfuly call your services with telegram bot or http request, example http://localhost:6452/Book/GetListOfBook");
            Console.ReadLine();
        }
示例#23
0
        public void ReturnServerMapPathResult()
        {
            // Arrange
            var mockedContext = new Mock <HttpContextBase>();
            var returnedPath  = "returned/path";

            mockedContext.Setup(x => x.Server.MapPath(It.IsAny <string>())).Returns(returnedPath);

            var provider = new ServerProvider(mockedContext.Object);

            // Act
            var result = provider.MapPath("path");

            // Assert
            Assert.AreEqual(returnedPath, result);
        }
示例#24
0
        public void CallServerMapPathWithCorrectPath()
        {
            // Arrange
            var mockedContext = new Mock <HttpContextBase>();

            mockedContext.Setup(x => x.Server.MapPath(It.IsAny <string>())).Verifiable();
            var provider = new ServerProvider(mockedContext.Object);

            var path = "~/path/img/jpg";

            // Act
            var result = provider.MapPath(path);

            // Assert
            mockedContext.Verify(x => x.Server.MapPath(path), Times.Once);
        }
示例#25
0
        private static void Main(string[] args)
        {
            try
            {
                ServerProvider serverProvider = new ServerProvider();
                serverProvider.RegisterServerService <FullHttpSupportService>();
                serverProvider.Start("http://localhost:8080/TestService/any");

                Console.WriteLine("seerver started");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.ReadLine();
        }
示例#26
0
        private IConnectionData GetMsSqlConnectionData(XDocument configFile)
        {
            var provider = new ServerProvider()
            {
                Name = configFile.Element("DataProvider").Element("Provider").Value
            };
            var database = new DataBaseStorage()
            {
                Name = configFile.Element("DataProvider").Element("DataBase").Value
            };
            var credentials = new MsSqlLoginPasswordCredentials()
            {
                Login = configFile.Element("DataProvider").Element("Login").Value, Password = configFile.Element("DataProvider").Element("Password").Value
            };

            return(new MsSqlConnectionData(provider, database, credentials));
        }
        public override async Task InvokeAsync(ClientActionContext context)
        {
            if (context.ServerConnection == null)
            {
                context.ServerConnection = ServerProvider.GetServer();
            }

            context.GetRequestOrThrow().RequestUri = EndpointProvider.GetEndpoint(context.ServerConnection.Server, context.Contract, context.Action);
            try
            {
                await Next(context).ConfigureAwait(false);
            }
            catch (HttpRequestException)
            {
                ServerProvider.OnServerUnavailable(context.Request.RequestUri);
                throw;
            }
        }
示例#28
0
        //private async void GetActiveBabyExecute()
        //{
        //    var device = ServiceLocator.Current.GetInstance<DeviceViewModel>().SelectedDevice;
        //    var deviceId = device.DeviceId;
        //    var devicePoint = new Point()
        //    {
        //        X = 49.993499,
        //        Y = 36.230376
        //    };

        //    var babies = await this.GetAllBabies();

        //    for (int i = this.Babies.Count - 1; i >= 0; i++)
        //    {
        //        this.Babies.RemoveAt(i);
        //    }

        //    foreach (var baby in babies)
        //    {
        //        this.Babies.Add(baby);
        //    }
        //}

        private async Task <List <Baby> > GetActiveBaby(int deviceId, Point location)
        {
            var activeTrashCans = new List <Baby>();
            var httpQuery       = string.Format("{0}{1}{2}", constants.Constants.ServerHostURL, BabyHttp, deviceId);
            var json            = JsonConvert.SerializeObject(location);
            var serverResponse  = await ServerProvider.Post(json, httpQuery);

            try
            {
                var nearestTrashCans = JsonConvert.DeserializeObject <List <Baby> >(serverResponse);
                activeTrashCans = nearestTrashCans;
            }
            catch
            {
                Debug.WriteLine("Get active babies failed.");
            }
            return(activeTrashCans);
        }
示例#29
0
        private async void DeleteExecute()
        {
            var httpDeleteUrl = string.Format("{0}{1}/{2}", constants.Constants.ServerHostURL, DevicesHttpUrl, this.SelectedDevice.DeviceId);
            var response      = await ServerProvider.Delete(httpDeleteUrl);

            try
            {
                var deviceFromJson = JsonConvert.DeserializeObject <Device>(response);
                this.Devices.RemoveAt(selectedDeviceIndex);
                if (this.SelectedDeviceIndex > 0)
                {
                    this.SelectedDeviceIndex--;
                }
            }
            catch
            {
                Debug.WriteLine("Device deleting failed.");
            }
        }
示例#30
0
        public void GetServer_CalledTwoTimes_ServerShouldBeTheSame()
        {
            var mockedModsetProvider = CreateMockedModsetProvider();

            var dedicatedServerFactoryMock = CreateDedicatedServerFactoryMock(ServerPort);

            var serverProvider = new ServerProvider(
                mockedModsetProvider,
                PrepareProcessDiscoverer(),
                dedicatedServerFactoryMock.Object,
                _logger);

            var firstDedicatedServer  = serverProvider.GetServer(ServerPort, _modset);
            var secondDedicatedServer = serverProvider.GetServer(ServerPort, _modset);

            dedicatedServerFactoryMock
            .Verify(x => x.CreateDedicatedServer(ServerPort, _modset, 1), Times.Once);
            firstDedicatedServer.Should().Be(secondDedicatedServer);
        }