Ejemplo n.º 1
0
        private void InitializeContainer()
        {
            catalog          = new DirectoryCatalog(Properties.Settings.Default.AddInDirectory);
            catalog.Changed += (sender, e) =>
            {
                var sb = new StringBuilder();

                foreach (var definition in e.AddedDefinitions)
                {
                    foreach (var metadata in definition.Metadata)
                    {
                        sb.AppendFormat("added definition with metadata - key: {0}, value: {1}\n", metadata.Key, metadata.Value);
                    }
                }

                foreach (var definition in e.RemovedDefinitions)
                {
                    foreach (var metadata in definition.Metadata)
                    {
                        sb.AppendFormat("removed definition with metadata - key: {0}, value: {1}\n", metadata.Key, metadata.Value);
                    }
                }
                this.textStatus.Text += sb.ToString();
            };
            container = new CompositionContainer(catalog);
            container.ExportsChanged += (sender, e) =>
            {
                var sb = new StringBuilder();

                foreach (var item in e.AddedExports)
                {
                    sb.AppendFormat("added export {0}\n", item.ContractName);
                }
                foreach (var item in e.RemovedExports)
                {
                    sb.AppendFormat("removed export {0}\n", item.ContractName);
                }
                this.textStatus.Text += sb.ToString();
            };

            calcImport = new CalculatorImport();
            calcImport.ImportsSatisfied += (sender, e) =>
            {
                textStatus.Text += String.Format("{0}\n", e.StatusMessage);
            };
            // container.ComposeParts(calcImport);

            var batch = new CompositionBatch();

            batch.AddPart(calcImport);
            container.Compose(batch);

            InitializeOperations();
        }
Ejemplo n.º 2
0
        public async void InitializeContainer()
        {
            catalog = new DirectoryCatalog(Properties.Settings.Default.AddInDirectory);

            #region DirectoryCatalog Changed event
            catalog.Changed += (sender, e) =>
            {
                var sb = new StringBuilder();

                foreach (var definition in e.AddedDefinitions)
                {
                    foreach (var metadata in definition.Metadata)
                    {
                        sb.AppendFormat("added definition with metadata - key: {0}, value: {1}\n", metadata.Key, metadata.Value);
                    }
                }

                foreach (var definition in e.RemovedDefinitions)
                {
                    foreach (var metadata in definition.Metadata)
                    {
                        sb.AppendFormat("removed definition with metadata - key: {0}, value: {1}\n", metadata.Key, metadata.Value);
                    }
                }

                vm.Status += sb.ToString();
            };
            #endregion

            container = new CompositionContainer(catalog);

            #region Container ExportsChanged event
            container.ExportsChanged += (sender, e) =>
            {
                var sb = new StringBuilder();

                foreach (var item in e.AddedExports)
                {
                    sb.AppendFormat("added export {0}\n", item.ContractName);
                }
                foreach (var item in e.RemovedExports)
                {
                    sb.AppendFormat("removed export {0}\n", item.ContractName);
                }
                vm.Status += sb.ToString();
            };
            #endregion

            calcImport = new CalculatorImport();

            #region ImportsSatisfied event
            calcImport.ImportsSatisfied += (sender, e) =>
            {
                vm.Status += string.Format("{0}\n", e.StatusMessage);
            };
            #endregion

            await Task.Run(() =>
            {
                container.ComposeParts(calcImport);
            });

            await InitializeOperationsAsync();
        }