示例#1
0
        public UserContext(CremaHost cremaHost, string address, ServiceInfo serviceInfo, string userID, SecureString password)
        {
            this.cremaHost = cremaHost;

            this.serviceDispatcher = new CremaDispatcher(this);
            var metaData = this.serviceDispatcher.Invoke(() =>
            {
                this.service = UserServiceFactory.CreateServiceClient(address, serviceInfo, this);
                this.service.Open();
                if (this.service is ICommunicationObject service)
                {
                    service.Faulted += Service_Faulted;
                }
                var version = AppUtility.ProductVersion;
                try
                {
                    var result = this.service.Subscribe(userID, UserContext.Encrypt(userID, password), $"{version}", $"{Environment.OSVersion.Platform}", $"{CultureInfo.CurrentCulture}");
                    result.Validate();
#if !DEBUG
                    this.timer          = new Timer(30000);
                    this.timer.Elapsed += Timer_Elapsed;
                    this.timer.Start();
#endif
                    return(result.Value);
                }
                catch
                {
                    if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                    {
                        this.service.Close();
                    }
                    else
                    {
                        this.service.Abort();
                    }
                    this.serviceDispatcher.Dispose();
                    this.serviceDispatcher = null;
                    throw;
                }
            });

            this.authenticationToken = metaData.AuthenticationToken;
            this.Initialize(metaData);
            this.Items.MessageReceived  += Users_MessageReceived;
            this.Items.MessageReceived2 += Users_MessageReceived2;
            this.Items.UsersLoggedIn    += Users_UsersLoggedIn;
            this.Items.UsersLoggedOut   += Users_UsersLoggedOut;
            this.Items.UsersKicked      += Users_UsersKicked;
            this.Items.UsersBanChanged  += Users_UsersBanChanged;
            this.cremaHost.AddService(this);
        }
示例#2
0
        public static UserServiceClient CreateServiceClient(string address, ServiceInfo serviceInfo, IUserServiceCallback userServiceCallback)
        {
            var factory = new UserServiceFactory(address, serviceInfo, userServiceCallback);

            return(new UserServiceClient(factory.instanceContext, factory.binding, factory.endPointAddress));
        }