Example #1
0
        void Bind(IEnumerable <string> exports, IEnumerable <string> imports, Action done = null)
        {
            var bind_args = BindRequest.CreateBuilder();

            // Services we export
            foreach (var export in exports)
            {
                var hash = Util.GetServiceHash(export);
                var id   = connection.ExportService(hash);
                bind_args.AddExportedService(new BoundService.Builder {
                    Hash = hash,
                    Id   = id
                });
            }

            var imports_array = imports.ToArray();

            // Services we want to import
            foreach (var import in imports_array)
            {
                var hash = Util.GetServiceHash(import);
                bind_args.AddImportedServiceHash(hash);
            }

            // Handle the response and import the services
            connectionService.Bind(null, bind_args.Build(), response => {
                for (int i = 0; i < imports_array.Length; i++)
                {
                    connection.ImportService(imports_array[i], response.ImportedServiceIdList[i]);
                }

                if (done != null)
                {
                    done();
                }
            });
        }