Exemple #1
0
        protected override void ProcessRecord()
        {
            try
            {
                this.WriteVerbose($"[{DateTime.UtcNow}] Initializing Orleans Grain Client");
                var builder = new ClientBuilder();
                switch (this.ParameterSetName)
                {
                case FilePathSet:
                    this.WriteVerbose($"[{DateTime.UtcNow}] Using config file at '{this.ConfigFilePath}'...");
                    if (string.IsNullOrWhiteSpace(this.ConfigFilePath))
                    {
                        throw new ArgumentNullException(nameof(this.ConfigFilePath));
                    }
                    builder.LoadConfiguration(this.ConfigFilePath);
                    break;

                case FileSet:
                    this.WriteVerbose($"[{DateTime.UtcNow}] Using provided config file...");
                    if (this.ConfigFile == null)
                    {
                        throw new ArgumentNullException(nameof(this.ConfigFile));
                    }
                    builder.LoadConfiguration(this.ConfigFile);
                    break;

                case ConfigSet:
                    this.WriteVerbose($"[{DateTime.UtcNow}] Using provided 'ClientConfiguration' object...");
                    if (this.Config == null)
                    {
                        throw new ArgumentNullException(nameof(this.Config));
                    }
                    builder.UseConfiguration(this.Config);
                    break;

                case EndpointSet:
                    this.WriteVerbose($"[{DateTime.UtcNow}] Using default Orleans Grain Client initializer");
                    if (this.GatewayAddress == null)
                    {
                        throw new ArgumentNullException(nameof(this.GatewayAddress));
                    }
                    var config = this.GetOverriddenConfig();
                    builder.UseConfiguration(config);
                    break;

                default:
                    this.WriteVerbose($"[{DateTime.UtcNow}] Using default Orleans Grain Client initializer");
                    builder.LoadConfiguration();
                    break;
                }

                this.client = builder
                              .AddApplicationPartsFromAppDomain()
                              .Build();
                this.client.Connect().GetAwaiter().GetResult();
                this.SetClient(this.client);
                this.WriteObject(this.client);
            }
            catch (Exception ex)
            {
                this.WriteError(new ErrorRecord(ex, ex.GetType().Name, ErrorCategory.InvalidOperation, this));
            }
        }