示例#1
0
        public Connection(IConnectionFactory factory, bool insist, IFrameHandler frameHandler, string clientProvidedName = null)
        {
            ClientProvidedName = clientProvidedName;
            KnownHosts         = null;
            FrameMax           = 0;
            m_factory          = factory;
            m_frameHandler     = frameHandler;

            var asyncConnectionFactory = factory as IAsyncConnectionFactory;

            if (asyncConnectionFactory != null && asyncConnectionFactory.DispatchConsumersAsync)
            {
                ConsumerWorkService = new AsyncConsumerWorkService();
            }
            else
            {
                ConsumerWorkService = new ConsumerWorkService();
            }

            m_sessionManager = new SessionManager(this, 0);
            m_session0       = new MainSession(this)
            {
                Handler = NotifyReceivedCloseOk
            };
            m_model0 = (ModelBase)Protocol.CreateModel(m_session0);

            StartMainLoop(factory.UseBackgroundThreadsForIO);
            Open(insist);
        }
        public Connection(ConnectionConfig config, IFrameHandler frameHandler)
        {
            _config       = config;
            _frameHandler = frameHandler;

            Action <Exception, string> onException = (exception, context) => OnCallbackException(CallbackExceptionEventArgs.Build(exception, context));

            _callbackExceptionWrapper   = new EventingWrapper <CallbackExceptionEventArgs>(string.Empty, (exception, context) => { });
            _connectionBlockedWrapper   = new EventingWrapper <ConnectionBlockedEventArgs>("OnConnectionBlocked", onException);
            _connectionUnblockedWrapper = new EventingWrapper <EventArgs>("OnConnectionUnblocked", onException);
            _connectionShutdownWrapper  = new EventingWrapper <ShutdownEventArgs>("OnShutdown", onException);

            _sessionManager = new SessionManager(this, 0);
            _session0       = new MainSession(this);
            _model0         = new Model(_config, _session0);;

            ClientProperties = new Dictionary <string, object?>(_config.ClientProperties)
            {
                ["capabilities"]    = Protocol.Capabilities,
                ["connection_name"] = ClientProvidedName
            };

            _mainLoopTask = Task.Factory.StartNew(MainLoop, TaskCreationOptions.LongRunning);
            try
            {
                Open();
            }
            catch
            {
                var ea = new ShutdownEventArgs(ShutdownInitiator.Library, Constants.InternalError, "FailedOpen");
                Close(ea, true, TimeSpan.FromSeconds(5));
                throw;
            }
        }
示例#3
0
        public Connection(IConnectionFactory factory, IFrameHandler frameHandler, string clientProvidedName = null)
        {
            ClientProvidedName = clientProvidedName;
            _factory           = factory;
            _frameHandler      = frameHandler;

            ConsumerWorkService = factory.DispatchConsumersAsync
                ? new AsyncConsumerWorkService(factory.ConsumerDispatchConcurrency)
                : new ConsumerWorkService(factory.ConsumerDispatchConcurrency);

            Action <Exception, string> onException = (exception, context) => OnCallbackException(CallbackExceptionEventArgs.Build(exception, context));

            _callbackExceptionWrapper   = new EventingWrapper <CallbackExceptionEventArgs>(string.Empty, (exception, context) => { });
            _connectionBlockedWrapper   = new EventingWrapper <ConnectionBlockedEventArgs>("OnConnectionBlocked", onException);
            _connectionUnblockedWrapper = new EventingWrapper <EventArgs>("OnConnectionUnblocked", onException);
            _connectionShutdownWrapper  = new EventingWrapper <ShutdownEventArgs>("OnShutdown", onException);

            _sessionManager = new SessionManager(this, 0);
            _session0       = new MainSession(this)
            {
                Handler = NotifyReceivedCloseOk
            };
            _model0 = (ModelBase)Protocol.CreateModel(_session0);

            StartMainLoop();
            Open();
        }
示例#4
0
        public Connection(IConnectionFactory factory, IFrameHandler frameHandler, string?clientProvidedName = null)
        {
            ClientProvidedName = clientProvidedName;
            _factory           = factory;
            _frameHandler      = frameHandler;

            Action <Exception, string> onException = (exception, context) => OnCallbackException(CallbackExceptionEventArgs.Build(exception, context));

            _callbackExceptionWrapper   = new EventingWrapper <CallbackExceptionEventArgs>(string.Empty, (exception, context) => { });
            _connectionBlockedWrapper   = new EventingWrapper <ConnectionBlockedEventArgs>("OnConnectionBlocked", onException);
            _connectionUnblockedWrapper = new EventingWrapper <EventArgs>("OnConnectionUnblocked", onException);
            _connectionShutdownWrapper  = new EventingWrapper <ShutdownEventArgs>("OnShutdown", onException);

            _sessionManager = new SessionManager(this, 0);
            _session0       = new MainSession(this);
            _model0         = (ModelBase)Protocol.CreateModel(factory, _session0);

            ClientProperties = new Dictionary <string, object?>(factory.ClientProperties)
            {
                ["capabilities"]    = Protocol.Capabilities,
                ["connection_name"] = ClientProvidedName
            };

            _mainLoopTask = Task.Factory.StartNew(MainLoop, TaskCreationOptions.LongRunning);
            Open();
        }
        public Connection(IConnectionFactory factory, bool insist, IFrameHandler frameHandler, string clientProvidedName = null)
        {
            this.ClientProvidedName = clientProvidedName;
            KnownHosts               = null;
            FrameMax                 = 0;
            m_factory                = factory;
            m_frameHandler           = frameHandler;
            this.ConsumerWorkService = new ConsumerWorkService(factory.TaskScheduler);

            m_sessionManager = new SessionManager(this, 0);
            m_session0       = new MainSession(this)
            {
                Handler = NotifyReceivedCloseOk
            };
            m_model0 = (ModelBase)Protocol.CreateModel(m_session0);

            StartMainLoop(factory.UseBackgroundThreadsForIO);
            Open(insist);

#if NETFX_CORE
#pragma warning disable 0168
            try
            {
                Windows.UI.Xaml.Application.Current.Suspending += this.HandleApplicationSuspend;
            }
            catch (Exception ex)
            {
                // If called from a desktop app (i.e. unit tests), then there is no current application
            }
#pragma warning restore 0168
#else
            AppDomain.CurrentDomain.DomainUnload += HandleDomainUnload;
#endif
        }
示例#6
0
                public void BeginInput()
                {
                    string result = ParsePS1(MainSession.GetEnvValue("PS1"));

                    StdOut.Write(result);
                    // Important!
                    StdOut.Write("\x1b[s");
                }
        public void Restore()
        {
            var key = typeof(MainSession).ToString();

            if (!mProperties.ContainsKey(key))
            {
                Init();
            }
            else
            {
                string json = (string)mProperties[key];
                MainSession = (MainSession)JsonConvert.DeserializeObject(json, typeof(MainSession));
            }
        }
示例#8
0
        public Connection(IConnectionFactory factory,
                          bool insist,
                          IFrameHandler frameHandler)
        {
            m_factory      = factory;
            m_frameHandler = frameHandler;

            m_sessionManager   = new SessionManager(this, 0);
            m_session0         = new MainSession(this);
            m_session0.Handler = new MainSession.SessionCloseDelegate(NotifyReceivedCloseOk);
            m_model0           = (ModelBase)Protocol.CreateModel(m_session0);

            StartMainLoop(factory.UseBackgroundThreadsForIO);
            Open(insist);
            StartHeartbeatTimers();
            AppDomain.CurrentDomain.DomainUnload += HandleDomainUnload;
        }
        public Connection(IConnectionFactory factory, bool insist, IFrameHandler frameHandler, string clientProvidedName = null)
        {
            this.ClientProvidedName = clientProvidedName;
            KnownHosts               = null;
            FrameMax                 = 0;
            m_factory                = factory;
            m_frameHandler           = frameHandler;
            this.ConsumerWorkService = new ConsumerWorkService(factory.TaskScheduler);

            m_sessionManager = new SessionManager(this, 0);
            m_session0       = new MainSession(this)
            {
                Handler = NotifyReceivedCloseOk
            };
            m_model0 = (ModelBase)Protocol.CreateModel(m_session0);

            StartMainLoop(factory.UseBackgroundThreadsForIO);
            Open(insist);
        }
        public Connection(IConnectionFactory factory, bool insist, IFrameHandler frameHandler)
        {
            KnownHosts               = null;
            FrameMax                 = 0;
            m_factory                = factory;
            m_frameHandler           = frameHandler;
            this.ConsumerWorkService = new ConsumerWorkService(factory.TaskScheduler);

            m_sessionManager = new SessionManager(this, 0);
            m_session0       = new MainSession(this)
            {
                Handler = NotifyReceivedCloseOk
            };
            m_model0 = (ModelBase)Protocol.CreateModel(m_session0);

            StartMainLoop(factory.UseBackgroundThreadsForIO);
            Open(insist);
            StartHeartbeatTimers();
            AppDomain.CurrentDomain.DomainUnload += HandleDomainUnload;
        }
示例#11
0
        private static void Save()
        {
            if (GetAgreement("Create new file?"))
            {
                CurrentFilePath = GetPath();
            }

            FileStream file = null;

            if (CatchFileExceptions(
                    () => file = File.Open(CurrentFilePath, FileMode.Create),
                    CurrentFilePath))
            {
                return;
            }

            MainSession.Save(file);
            file.Close();

            Saved = true;
        }
        public Connection(IConnectionFactory factory, bool insist, IFrameHandler frameHandler, string clientProvidedName = null)
        {
            ClientProvidedName = clientProvidedName;
            KnownHosts         = null;
            FrameMax           = 0;
            _factory           = factory;
            _frameHandler      = frameHandler;

            ConsumerWorkService = factory.DispatchConsumersAsync
                ? new AsyncConsumerWorkService(factory.ConsumerDispatchConcurrency)
                : new ConsumerWorkService(factory.ConsumerDispatchConcurrency);

            _sessionManager = new SessionManager(this, 0);
            _session0       = new MainSession(this)
            {
                Handler = NotifyReceivedCloseOk
            };
            _model0 = (ModelBase)Protocol.CreateModel(_session0);

            StartMainLoop();
            Open(insist);
        }
示例#13
0
                public List <string> Parse(string input)
                {
                    List <string> result = new List <string>();
                    string        curr   = "";

                    foreach (Match m in Parser.Matches(input))
                    {
                        if (m.Value.Length == 0)
                        {
                            continue;
                        }
                        char first = m.Value[0];
                        if (first == '<' || first == '>' || first == '|')
                        {
                            curr = curr.Trim();
                            if (curr.Length > 0)
                            {
                                result.Add(curr);
                            }
                            result.Add(first.ToString());
                            curr = "";
                        }
                        else if (first == '$' && m.Value.Length > 1)
                        {
                            curr += MainSession.GetEnvValue(m.Value.Substring(1));
                        }
                        else
                        {
                            curr += m.Value;
                        }
                    }
                    curr = curr.Trim();
                    if (curr.Length > 0)
                    {
                        result.Add(curr);
                    }
                    return(result);
                }
示例#14
0
                protected override void Run()
                {
                    if (Argv.Count <= 1)
                    {
                        StdOut.WriteLine("Need help");
                        return;
                    }
                    try{
                        NixPath newPath      = MainSession.WorkingDirectory.Combine(Argv[1]).ResolvePath();
                        NixPath followedPath = MainSystem.RootDrive.FollowLinks(MainSession.PhysicalDirectory.Combine(Argv[1]));

                        if (MainSystem.RootDrive.IsDirectory(followedPath))
                        {
                            MainSession.SetWorkingDirectory(newPath);
                        }
                        else
                        {
                            StdOut.Write(newPath.ToString() + " is not a directory.\n");
                        }
                    }
                    catch (System.Exception exp) {
                        Debug.Log("CD EXP: " + exp.Message);
                    }
                }
示例#15
0
 public void Init()
 {
     MainSession = new MainSession();
 }
示例#16
0
            public string GetTempFilenameHandler()
            {
                string tmpFolder = MainSession.GetEnvValue("TMPDIR", "/tmp");

                return(tmpFolder + "/" + System.Guid.NewGuid().ToString());
            }