示例#1
0
        public HastyClient(Uri serverUrl, string realm, string username, string password, CommandDefinitions definitions, string baseDir, object target, ILog log)
        {
            this.username = username;
            this.password = password;
            this.realm    = realm;
            this.log      = log.CreateLog(typeof(HastyClient));
            var storage = new StreamStorage(baseDir, log);

            preferences      = new Preferences(baseDir, log);
            streamStorage    = storage;
            this.definitions = definitions;
            defaultTarget    = target;

            SetStatus(ConnectionStatus.Idle);
            SetState(ConnectionState.Establishing);
            connectionMaintainer = new ConnectionMaintainer(serverUrl, realm, log);
            connectionMaintainer.OnPacketRead += OnPacketRead;
            connectionMaintainer.OnDisconnect += OnDisconnect;
            connectionMaintainer.OnConnecting += OnConnecting;
            connectionMaintainer.OnConnected  += OnMaintainerConnected;

            ulong userAssignedChannelId;

            var foundUserAssignedChannel = preferences.GetUserChannel(serverUrl.ToString(), realm, out userAssignedChannelId);

            if (foundUserAssignedChannel)
            {
                Subscribe((uint)userAssignedChannelId, target);
            }

            connectionMaintainer.Start();
        }