예제 #1
0
파일: Client.cs 프로젝트: malsbi/IViewNet
        public ShutdownResult Shutdown()
        {
            ShutdownResult Result;

            try
            {
                if (IsShutdown == false)
                {
                    IsShutdown = true;
                    StopHeartBeat();
                    EstablishedConnection.Close();
                    PacketManager.Dispose();
                    WaitHandler.Dispose();
                    RemoveHandlers(OperationManager);
                    OperationManager.ShutdownOperation();
                    Result = new ShutdownResult("Client Shutdown Successfully", "Shutdown", DateTime.Now, true);
                }
                else
                {
                    throw new Exception("Client is not running");
                }
            }
            catch (Exception ex)
            {
                Result = new ShutdownResult(string.Format("Shutdown Exception: {0}", ex.Message), "Shutdown", DateTime.Now, false);
            }
            return(Result);
        }
예제 #2
0
        static async Task <int> RunStore(Context context, IContentStore store)
        {
            try
            {
                try
                {
                    StartupResult startupResult = await store.StartupAsync(context).ConfigureAwait(false);

                    if (startupResult.HasError)
                    {
                        throw new CacheException($"Failed to start store, error=[{startupResult.ErrorMessage}]");
                    }

                    var createSessionResult = store.CreateSession(context, "sample", ImplicitPin.None);
                    if (createSessionResult.HasError)
                    {
                        throw new CacheException($"Failed to create session, error=[{createSessionResult.ErrorMessage}]");
                    }

                    using (var session = createSessionResult.Session)
                    {
                        try
                        {
                            var sessionStartupResult = session.StartupAsync(context).Result;
                            if (sessionStartupResult.HasError)
                            {
                                throw new CacheException($"Failed to start session, error=[{createSessionResult.ErrorMessage}]");
                            }
                        }
                        finally
                        {
                            var sessionShutdownResult = session.ShutdownAsync(context).Result;
                            if (sessionShutdownResult.HasError)
                            {
                                context.Error($"Failed to shutdown session, error=[{sessionShutdownResult.ErrorMessage}]");
                            }
                        }
                    }
                }
                finally
                {
                    ShutdownResult shutdownResult = await store.ShutdownAsync(context).ConfigureAwait(false);

                    if (shutdownResult.HasError)
                    {
                        context.Error($"Failed to shutdown store, error=[{shutdownResult.ErrorMessage}]");
                    }
                }

                return(0);
            }
            catch (Exception)
            {
                return(1);
            }
        }
예제 #3
0
파일: Client.cs 프로젝트: malsbi/IViewNet
        public EstablishConnectionResult Connect(string Host, int Port)
        {
            EstablishConnectionResult Result;

            try
            {
                if (IsEstablished == false)
                {
                    WaitHandler           = new ManualResetEvent(false);
                    EstablishedConnection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    EstablishedConnection.BeginConnect(Host, Port, new AsyncCallback(ConnectCallBack), null);
                    WaitHandler.WaitOne();

                    if (IsEstablished)
                    {
                        PacketManager = new PacketManager();
                        PacketManager.AddPacket(new Packet(0000, "SetAuthentication", null));
                        PacketManager.AddPacket(new Packet(0001, "GetAuthentication", null));
                        PacketManager.AddPacket(new Packet(0002, "Synchronize", null));

                        OperationManager = new Operation(EstablishedConnection, Config, PacketManager);
                        AddHandlers(OperationManager);
                        SetOnClientConnect(OperationManager);
                        StartHeartBeat();
                        Result = new EstablishConnectionResult(true, "Client Successfully connected to the server");
                    }
                    else
                    {
                        Result = new EstablishConnectionResult(false, "Client Failed to connect to the server");
                    }
                }
                else
                {
                    Result = new EstablishConnectionResult(false, "Cannot preform 'Connect' operation while the client is connected to the server");
                    ShutdownResult ShutdownResult = Shutdown();
                    if (ShutdownResult.IsOperationSuccess)
                    {
                        Console.WriteLine(ShutdownResult.Message);
                    }
                    else
                    {
                        Console.WriteLine(ShutdownResult.Message);
                    }
                }
            }
            catch (Exception Ex)
            {
                Result = new EstablishConnectionResult(false, "Client Failed to connect to the server");
                SetOnException(Ex);
                IsEstablished = false;
            }
            return(Result);
        }
예제 #4
0
파일: Client.cs 프로젝트: malsbi/IViewNet
        private void SetOnClientDisconnect(Operation Client, string Reason)
        {
            OnClientDisconnect?.Invoke(Client, Reason);
            ShutdownResult ShutdownResult = Shutdown();

            if (ShutdownResult.IsOperationSuccess)
            {
                Console.WriteLine(ShutdownResult.Message);
            }
            else
            {
                Console.WriteLine(ShutdownResult.Message);
            }
        }
예제 #5
0
 public void Stop()
 {
     if (ServerInstance.IsListening)
     {
         ShutdownResult Result = ServerInstance.Shutdown();
         if (Result.IsOperationSuccess)
         {
             Logger.Log(new Log(Result.Message, ConsoleColor.Cyan));
             RemoveServerHandlers();
         }
         else
         {
             Logger.Log(new Log(Result.Message, ConsoleColor.Red));
         }
     }
 }
예제 #6
0
파일: Parent.cs 프로젝트: malsbi/PyExecutor
 public void CloseParent()
 {
     IsParentRunning = false;
     DestroyAllChildren();
     if (ParentServer.IsListening == true && ParentServer.IsShutdown == false)
     {
         ShutdownResult Result = ParentServer.Shutdown();
         if (Result.IsOperationSuccess)
         {
             SetOnParentClosed(Result.Message);
         }
         else
         {
             SetOnException(Result.Message);
         }
     }
 }
예제 #7
0
 public bool StopServer()
 {
     if (MyServer != null)
     {
         if (MyServer.IsListening)
         {
             ShutdownResult Result = MyServer.Shutdown();
             if (Result.IsOperationSuccess)
             {
                 Controller.Update(new LogModel(Result.Message, "Networking", DateTime.Now, LogColors.OnNews));
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     return(false);
 }
예제 #8
0
        /// <summary>
        /// Shutdown the server
        /// </summary>
        public ShutdownResult Shutdown()
        {
            ShutdownResult Result;

            try
            {
                if (IsShutdown == false)
                {
                    IsShutdown  = true;
                    IsListening = false;
                    StopHeartBeat();
                    DisconnectAll();
                    if (Clients != null)
                    {
                        Clients.Clear();
                    }
                    //if (BlackListedIP != null)
                    //{
                    //    BlackListedIP.Clear();
                    //}
                    if (PacketManager != null)
                    {
                        PacketManager.Dispose();
                    }
                    Listener.Close();
                    Result = new ShutdownResult("Server Shutdown Successfully", "Shutdown", DateTime.Now, true);
                }
                else
                {
                    throw new Exception("Server is not running");
                }
            }
            catch (Exception ex)
            {
                Result = new ShutdownResult(string.Format("Shutdown Exception Shutdown: {0}", ex.Message), "Shutdown", DateTime.Now, false);
            }
            return(Result);
        }