Exemple #1
0
        public Guid Open(string address, string dataBase, string userID, SecureString password)
        {
            if (this.isConnected == true)
            {
                throw new InvalidOperationException(Resources.Exception_AlreadyConnected);
            }

            this.ipAddress    = AddressUtility.GetIPAddress(address);
            this.serviceInfos = GetServiceInfo(address).ToDictionary(item => item.Name);

            this.OnOpening(EventArgs.Empty);
            return(this.dispatcher.Invoke(() =>
            {
                try
                {
                    return OpenInternal(address, dataBase, userID, password);
                }
                catch
                {
                    this.userContext?.Close(CloseInfo.Empty);
                    this.userContext = null;
                    this.log?.Dispose();
                    this.log = null;
                    this.address = null;
                    throw;
                }
            }));
        }
        public static RuntimeServiceClient CreateServiceClient(string address)
        {
            var binding         = CreateBinding(TimeSpan.MaxValue);
            var ip              = AddressUtility.GetIPAddress(address);
            var port            = GetServicePort(address);
            var endPointAddress = new EndpointAddress($"net.tcp://{ip}:{port}/RuntimeService");

            return(new RuntimeServiceClient(binding, endPointAddress));
        }
        public static CremaServiceContext Create(string address)
        {
            var serviceHost = new CremaServiceHost();

            return(new CremaServiceContext(serviceHost)
            {
                Host = AddressUtility.GetIPAddress(address),
                Port = AddressUtility.GetPort(address)
            });
        }
Exemple #4
0
        public Guid Open(string address, string userID, SecureString password)
        {
            if (this.isConnected == true)
            {
                throw new InvalidOperationException(Resources.Exception_AlreadyConnected);
            }

            this.ipAddress    = AddressUtility.GetIPAddress(address);
            this.serviceInfos = GetServiceInfo(address).ToDictionary(item => item.Name);

            this.OnOpening(EventArgs.Empty);
            return(this.dispatcher.Invoke(() =>
            {
                try
                {
                    this.address = AddressUtility.GetDisplayAddress(address);
                    this.log = new LogService(this.address.Replace(':', '_'), userID, AppUtility.UserAppDataPath);
                    this.log.Verbose = this.verbose;
                    this.userContext = new UserContext(this, this.ipAddress, serviceInfos[nameof(UserService)], userID, password);
                    var user = this.userContext.Users[userID];
                    user.SetUserState(UserState.Online);
                    this.userID = userID;
                    this.authority = user.Authority;

                    this.dataBases = new DataBaseCollection(this, this.ipAddress, serviceInfos[nameof(DataBaseCollectionService)]);
                    this.domainContext = new DomainContext(this, this.ipAddress, serviceInfos[nameof(DomainService)]);
                    this.isConnected = true;
                    this.configs = new CremaConfiguration(this.ConfigPath);
                    this.plugins = this.container.GetService(typeof(IEnumerable <IPlugin>)) as IEnumerable <IPlugin>;
                    foreach (var item in this.plugins)
                    {
                        var authentication = new Authentication(new AuthenticationProvider(user), item.ID);
                        this.authentications.Add(authentication);
                        item.Initialize(authentication);
                    }

                    this.OnOpened(EventArgs.Empty);
                    this.token = Guid.NewGuid();
                    CremaLog.Info($"Crema opened : {address} {userID}");
                    return token;
                }
                catch
                {
                    this.userContext?.Close(CloseInfo.Empty);
                    this.userContext = null;
                    this.log?.Dispose();
                    this.log = null;
                    this.address = null;
                    throw;
                }
            }));
        }
        public static async Task <DataBaseInfo[]> GetDataBasesAsync(string address)
        {
            var serviceHost   = new CremaHostServiceHost();
            var clientContext = new ClientContext(serviceHost)
            {
                Host = AddressUtility.GetIPAddress(address),
                Port = AddressUtility.GetPort(address)
            };
            var token = Guid.Empty;

            try
            {
                token = await clientContext.OpenAsync();

                return(await serviceHost.GetDataBaseInfosAsync());
            }
            finally
            {
                await clientContext.CloseAsync(token, 0);
            }
        }