コード例 #1
0
        public IHttpActionResult PostServer(Model.Server server)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Servers.Add(server);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ServerExists(server.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = server.Id }, server));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: y1026/Aras.Model
        static void Main(string[] args)
        {
            // Connect to Server
            Model.Server server = new Model.Server("http://localhost/11SP9");

            // Load Solution
            server.LoadAssembly("Aras.Model.Design");

            // Get Database
            Model.Database database = server.Database("Development");

            // Start Session
            Model.Session session = database.Login("admin", IO.Server.PasswordHash("innovator"));

            // Find Document
            Model.Query docquery = session.Query("Document");
            docquery.Select = "item_number,name,description";
            Model.Design.Document document = (Model.Design.Document)docquery.Store.First();

            using (Transaction trans = session.BeginTransaction())
            {
                document.Update(trans);
                document.Name = "Test";
                trans.Commit(true);
            }
        }
コード例 #3
0
        public IHttpActionResult PutServer(string id, Model.Server server)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != server.Id)
            {
                return(BadRequest());
            }

            db.Entry(server).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ServerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #4
0
        public IHttpActionResult GetServer(string id)
        {
            Model.Server server = db.Servers.Find(id);
            if (server == null)
            {
                return(NotFound());
            }

            return(Ok(server));
        }
コード例 #5
0
        public void UpdateLastRead(Model.Server server)
        {
            logger.Debug($"last read: {server.FriendlyName()}");

            ServerStatus status;

            if (_serverStatus.TryGetValue(server, out status))
            {
                status.lastRead = DateTime.Now;
            }
        }
コード例 #6
0
        public void UpdateLastWrite(Model.Server server)
        {
            Logging.Debug($"last write: {server.FriendlyName()}");

            ServerStatus status;

            if (_serverStatus.TryGetValue(server, out status))
            {
                status.lastWrite = DateTime.Now;
            }
        }
コード例 #7
0
        public void SetFailure(Model.Server server)
        {
            logger.Debug($"failure: {server.ToString()}");

            ServerStatus status;

            if (_serverStatus.TryGetValue(server, out status))
            {
                status.lastFailure = DateTime.Now;
            }
        }
コード例 #8
0
        public void UpdateLastWrite(Model.Server server)
        {
            Logging.Debug(String.Format("last write: {0}", server.FriendlyName()));

            ServerStatus status;

            if (_serverStatus.TryGetValue(server, out status))
            {
                status.LastWrite = DateTime.Now;
            }
        }
コード例 #9
0
        public void SetFailure(Model.Server server)
        {
            Logging.Debug(String.Format("failure: {0}", server.FriendlyName()));

            ServerStatus status;

            if (_serverStatus.TryGetValue(server, out status))
            {
                status.LastFailure = DateTime.Now;
            }
        }
コード例 #10
0
        public void UpdateLastWrite(Model.Server server)
        {
            logger.Debug($"last write: {server.ToString()}");

            ServerStatus status;

            if (_serverStatus.TryGetValue(server, out status))
            {
                status.lastWrite = DateTime.Now;
            }
        }
コード例 #11
0
        public void SetFailure(Model.Server server)
        {
            Logging.Debug($"failure: {server.FriendlyName()}");

            ServerStatus status;

            if (_serverStatus.TryGetValue(server, out status))
            {
                status.lastFailure = DateTime.Now;
            }
        }
コード例 #12
0
        public void UpdateLatency(Model.Server server, TimeSpan latency)
        {
            Logging.Debug($"latency: {server.FriendlyName()} {latency}");

            ServerStatus status;

            if (_serverStatus.TryGetValue(server, out status))
            {
                status.latency = latency;
                status.lastTimeDetectLatency = DateTime.Now;
            }
        }
コード例 #13
0
        public void UpdateLatency(Model.Server server, TimeSpan latency)
        {
            Logging.Debug(String.Format("latency: {0} {1}", server.FriendlyName(), latency));

            ServerStatus status;

            if (_serverStatus.TryGetValue(server, out status))
            {
                status.Latency = latency;
                status.LastTimeDetectLatency = DateTime.Now;
            }
        }
コード例 #14
0
        public IHttpActionResult DeleteServer(string id)
        {
            Model.Server server = db.Servers.Find(id);
            if (server == null)
            {
                return(NotFound());
            }

            db.Servers.Remove(server);
            db.SaveChanges();

            return(Ok(server));
        }
コード例 #15
0
        public NodeModel GetNode(Model.Server server)
        {
            Enable         = server.Enable;
            Group          = server.Group;
            Method         = server.Method;
            Obfs           = server.obfs;
            Obfsparam      = server.ObfsParam;
            Password       = server.Password;
            Protocol       = server.Protocol;
            Remarks        = server.Remarks;
            Remarks_Base64 = server.Remarks_Base64;
            Server         = server.server;
            Server_Port    = server.Server_Port;

            return(this);
        }
コード例 #16
0
        public Model.Server GetServer()
        {
            Model.Server server = new Model.Server();
            server.Enable         = Enable;
            server.Group          = Group;
            server.Method         = Method;
            server.obfs           = Obfs;
            server.ObfsParam      = Obfsparam;
            server.Password       = Password;
            server.Protocol       = Protocol;
            server.Remarks        = Remarks;
            server.Remarks_Base64 = Remarks_Base64;
            server.server         = Server;
            server.Server_Port    = Server_Port;
            server.ProtocolParam  = "18:PEUvBV"; // TODO:让后台添加此参数

            return(server);
        }
コード例 #17
0
        public void RemoveTimedOutServers_RemovesTimedOutServer()
        {
            // GIVEN
            const string serverId = "server-001";
            var          server   = new Model.Server {
                Id = serverId, LastHeartBeat = new DateTime(2000, 1, 1)
            };

            _elasticClient.Index(server, descr => descr.Refresh(Refresh.True)).ThrowIfInvalid();

            // WHEN
            var removedServersCount = _elasticConnection.RemoveTimedOutServers(TimeSpan.FromSeconds(1));

            // THEN
            removedServersCount.Should().Be(1);
            var getServerResponse = _elasticClient.Get <Model.Server>(serverId).ThrowIfInvalid();

            getServerResponse.Found.Should().BeFalse();
        }
コード例 #18
0
        public void Heartbeat_WithExistingServer_UpdatesHeartbeat()
        {
            // GIVEN
            const string serverId = "server-001";
            var          server   = new Model.Server {
                Id = serverId, LastHeartBeat = new DateTime(2017, 10, 1)
            };

            _elasticClient.Index(server, descr => descr.Refresh(Refresh.True)).ThrowIfInvalid();

            // WHEN
            _elasticConnection.Heartbeat(serverId);

            // THEN
            var getServerResponse = _elasticClient.Get <Model.Server>(serverId).ThrowIfInvalid();

            getServerResponse.Found.Should().BeTrue();
            getServerResponse.Source.LastHeartBeat.Should().NotBe(server.LastHeartBeat);
        }
コード例 #19
0
ファイル: Server.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// Connects to local WSUS server
        /// </summary>
        /// <returns>
        /// Object representing the WSUS Server
        /// </returns>
        public static IUpdateServer Connect(Model.Server connectionSettings)
        {
            if (connectionSettings != null)
            {
                var hostname = connectionSettings.Hostname;
                if (string.IsNullOrEmpty(hostname))
                {
                    throw new System.ArgumentException("Server hostname must be specified if using a server element in the config file.");
                }

                int port   = connectionSettings.Port;
                var secure = connectionSettings.Secure;

                System.Console.Out.WriteLine("Connecting to server: " + hostname + ":" + port);
                return(Microsoft.UpdateServices.Administration.AdminProxy.GetUpdateServer(hostname, secure, port));
            }

            System.Console.Out.WriteLine("Connecting to server: localhost");
            return(Microsoft.UpdateServices.Administration.AdminProxy.GetUpdateServer());
        }
コード例 #20
0
        public void RemoveTimedOutServers_WithNoTimedOutServers_DoesNothing()
        {
            // GIVEN
            const string serverId = "server-001";
            var          server   = new Model.Server {
                Id = serverId, LastHeartBeat = DateTime.UtcNow
            };

            _elasticClient.Index(server, descr => descr.Refresh(Refresh.True)).ThrowIfInvalid();

            // WHEN
            var removedServersCount = _elasticConnection.RemoveTimedOutServers(TimeSpan.FromDays(1));

            // THEN
            removedServersCount.Should().Be(0);
            var getServerResponse = _elasticClient.Get <Model.Server>(serverId).ThrowIfInvalid();

            getServerResponse.Found.Should().BeTrue();
            getServerResponse.Source.ShouldBeEquivalentTo(server);
        }
コード例 #21
0
        // TODO handle errors
        private int AddToRepo(ServerResource serverResource)
        {
            var server = new Model.Server
            {
                Name        = serverResource.Name,
                Description = serverResource.Description,
                AuthorId    = userManager.Users.First().Id // TODO current user
            };

            foreach (var link in serverResource.Links.Where(l => l.Rel == LinkTemplates.Servers.GetSimulations.Rel))
            {
                server.AddSimulation(simulationsRepo.Get(link.GetId()));
            }

            foreach (var link in serverResource.Links.Where(l => l.Rel == LinkTemplates.Servers.GetPresentations.Rel))
            {
                server.AddPresentation(presentationsRepo.Get(link.GetId()));
            }

            serversRepo.Add(server);
            return(server.Id);
        }
コード例 #22
0
        // -----------------------------------------------------------------------------------
        private void ButtonServerStartOnClick(object sender, RoutedEventArgs routedEventArgs)
        {
            if (View.ButtonServerStart.Content.ToString() == "Start")
            {
                View.ButtonServerStart.Content = "Stop";
                View.LabelServerStatus.Background = Brushes.Yellow;
                View.LabelServerStatus.Content = "Server starting...";
                Server = new Model.Server();
                _serverListenThread = new Thread(StartServer);
                _serverListenThread.Start();
            }
            else if (View.ButtonServerStart.Content.ToString() == "Stop")
            {
                Server.StopServer(() =>
                {
                    View.LabelServerStatus.Background = Brushes.Red;
                    View.LabelServerStatus.Content = "Server stopped...";

                    View.ButtonServerStart.Content = "Start";
                });

            }
        }
コード例 #23
0
 public void SetFailure(Model.Server server)
 {
     // do nothing
 }
コード例 #24
0
 public void UpdateLastWrite(Model.Server server)
 {
     // do nothing
 }
コード例 #25
0
 public void UpdateLatency(Model.Server server, TimeSpan latency)
 {
     // do nothing
 }
コード例 #26
0
 public void UpdateLastRead(Model.Server server)
 {
     // do nothing
 }
コード例 #27
0
 public FreeServers(ShadowsocksController controller)
 {
     this.controller = controller;
     Model.Server server = new Model.Server();
 }