Exemplo n.º 1
0
        void IDisposable.Dispose()
        {
            _families.Each(
                family =>
            {
                family.Value.Instances.Each(instance =>
                {
                    _singletonCache.Eject(family.Value.PluginType, instance);
                    if (instance is IDisposable)
                    {
                        instance.SafeDispose();
                    }
                });
            });


            _profiles.Each(x => x.SafeDispose());
            _profiles.Clear();

            var containerFamily = _families[typeof(IContainer)];

            PluginFamily c;

            _families.TryRemove(typeof(IContainer), out c);
            containerFamily.RemoveAll();

            _missingTypes.Clear();

            _families.Each(x => x.SafeDispose());
            _families.Clear();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Used internally to build the fixture model that the Storyteller client
        /// uses to render the screens
        /// </summary>
        /// <param name="conversions"></param>
        /// <returns></returns>
        public virtual FixtureModel Compile(CellHandling conversions)
        {
            GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance).Where(methodFromThis).Where(x => !x.HasAttribute <HiddenAttribute>()).Each(method =>
            {
                var grammarKey = method.GetKey();
                if (_grammars.Has(grammarKey))
                {
                    return;
                }

                var grammar      = GrammarBuilder.BuildGrammar(method, this);
                grammar.Key      = grammarKey;
                this[grammarKey] = grammar;
            });

            var grammars = new List <GrammarModel>();

            _grammars.Each((key, grammar) =>
            {
                var model      = grammar.Compile(this, conversions);
                model.key      = key;
                model.IsHidden = grammar.IsHidden;

                grammars.Add(model);
            });

            return(new FixtureModel(Key)
            {
                title = Title ?? Key.SplitCamelCase(),
                grammars = grammars.Where(x => !x.IsHidden).ToArray(),
                implementation = GetType().FullName
            });
        }
Exemplo n.º 3
0
        public FixtureLibrary ApplyOverrides(FixtureLibrary overrides)
        {
            var newLibrary = new FixtureLibrary();

            Models.Each(model =>
            {
                FixtureModel over;
                overrides.Models.TryRetrieve(model.key, out over);
                newLibrary.Models[model.key] = (FixtureModel)model.ApplyOverrides(over);
            });

            var keys    = newLibrary.Models.Select(x => x.key).ToList();
            var missing = overrides.Models.Where(x => !keys.Contains(x.key));

            missing.Each(model =>
            {
                model.IsMissing = true;

                model.grammars.Each(x => x.IsMissing = true);

                newLibrary.Models[model.key] = model;
            });

            newLibrary.Models
            .SelectMany(x => x.grammars)
            .OfType <EmbeddedSection>()
            .Where(x => x.IsMissing)
            .Each(x => x.ApplyFixtureOverrides(this, overrides));

            return(newLibrary);
        }
Exemplo n.º 4
0
        public override void TearDown()
        {
            _receivers.Each(x => x.Dispose());
            _receivers.ClearAll();

            _senders.Each(x => x.Dispose());
            _senders.ClearAll();

            _messageLogger.BuildReports().Each(x => Context.Reporting.Log(x));
        }
Exemplo n.º 5
0
        void IDisposable.Dispose()
        {
            _byType.Each(x => (x as IDisposable)?.Dispose());

            _byName.Each(cache =>
            {
                cache.Each(x => (x as IDisposable)?.Dispose());
            });

            _byName.ClearAll();
            _byType.ClearAll();
        }
Exemplo n.º 6
0
        public void RegisterSingleImplementations(PluginGraph graph)
        {
            var singleImplementationRegistry = new SingleImplementationRegistry();

            _types.Each((pluginType, types) => {
                if (types.Count == 1)
                {
                    singleImplementationRegistry.AddType(pluginType, types[0]);
                    ConfigureFamily(singleImplementationRegistry.For(pluginType));
                }
            });
            singleImplementationRegistry.As <IPluginGraphConfiguration>().Configure(graph);
        }
Exemplo n.º 7
0
        public void Write()
        {
            // TODO -- really need to go add this in Baseline.
            var keys = new List <string>();

            _data.Each((key, value) => keys.Add(key));

            var firstLength = keys.Max(x => x.Length);

            Console.WriteLine();

            ConsoleWriter.PrintHorizontalLine(2);
            Console.WriteLine("    " + _title);
            ConsoleWriter.PrintHorizontalLine(2);

            var format = "    {0," + firstLength + "} -> ";

            if (!SecondColumnColor.HasValue)
            {
                format += "{1}";
            }

            _data.Each((left, right) =>
            {
                if (SecondColumnColor.HasValue)
                {
                    Console.Write(format, left, right);
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(right);
                    Console.ResetColor();
                }
                else
                {
                    Console.WriteLine(format, left, right);
                }
            });

            ConsoleWriter.PrintHorizontalLine(2);
        }
Exemplo n.º 8
0
        public static string GetTypeAlias(Type type)
        {
            var alias = "unknown";

            TypeAliases.Each((a, t) =>
            {
                if (t == type)
                {
                    alias = a;
                }
            });

            return(alias);
        }
        protected void WriteBeginTag(HtmlTextWriter html)
        {
            if (!HasTag())
            {
                return;
            }

            _htmlAttributes.Each((key, attribute) =>
            {
                if (attribute != null)
                {
                    var value       = attribute.Value;
                    var stringValue = !(value is string) && key.StartsWith(DataPrefix)
                        ? JsonConvert.SerializeObject(value)
                        : value.ToString();
                    html.AddAttribute(key, stringValue, attribute.IsEncoded);
                }
                else
                {
                    // HtmlTextWriter treats a null value as an attribute with no value (e.g., <input required />).
                    html.AddAttribute(key, null, false);
                }
            });

            if (_cssClasses.Count > 0)
            {
                var classValue = _cssClasses.Join(" ");
                html.AddAttribute(CssClassAttribute, classValue);
            }

            if (_metaData.Count > 0)
            {
                var dictionary = new Dictionary <string, object>();
                _metaData.Each((key, value) => dictionary.Add(key, value));

                var metadataValue = JsonConvert.SerializeObject(dictionary);
                html.AddAttribute(MetadataAttribute, metadataValue);
            }

            if (_customStyles.Count > 0)
            {
                var attValue = _customStyles
                               .Select(x => x.Key + ":" + x.Value)
                               .ToArray().Join(";");

                html.AddAttribute(CssStyleAttribute, attValue);
            }

            html.RenderBeginTag(_tag);
        }
Exemplo n.º 10
0
        void IDisposable.Dispose()
        {
            _singletonCache.DisposeAndClear();

            _profiles.Each(x => x.SafeDispose());
            _profiles.Clear();

            var containerFamily = _families[typeof(IContainer)];

            _families.Remove(typeof(IContainer));
            containerFamily.RemoveAll();

            _families.Each(x => x.SafeDispose());
            _families.ClearAll();
        }
Exemplo n.º 11
0
        public override void TearDown()
        {
            _receivers.Each(x => x.Dispose());
            _receivers.ClearAll();

            _senders.Each(x => x.Dispose());
            _senders.ClearAll();

            _busLogger.BuildReports().Each(x => Context.Reporting.Log(x));

            _receiverStore.Dispose();
            _receiverStore = null;
            _sendingStore.Dispose();
            _sendingStore = null;
        }
Exemplo n.º 12
0
        public void Write()
        {
            ConsoleWriter.Line();


            ConsoleWriter.PrintHorizontalLine();
            Console.WriteLine(_title);
            ConsoleWriter.PrintHorizontalLine();

            _data.Each((left, right) =>
            {
                ConsoleWriter.Write(left);
                ConsoleWriter.WriteWithIndent(SecondLineColor, 4, right);
            });

            ConsoleWriter.PrintHorizontalLine();
        }
Exemplo n.º 13
0
        void IDisposable.Dispose()
        {
            _families.Each(family => {
                family.Instances.Each(instance => {
                    _singletonCache.Eject(family.PluginType, instance);
                });
            });


            _profiles.Each(x => x.SafeDispose());
            _profiles.Clear();

            var containerFamily = _families[typeof(IContainer)];

            _families.Remove(typeof(IContainer));
            containerFamily.RemoveAll();

            _families.Each(x => x.SafeDispose());
            _families.ClearAll();
        }
Exemplo n.º 14
0
        protected void WriteBeginTag(HtmlTextWriter html)
        {
            if (!HasTag())
            {
                return;
            }

            _htmlAttributes.Each((key, attribute) =>
            {
                if (attribute != null)
                {
                    var value       = attribute.Value;
                    var stringValue = value.ToString();
                    html.AddAttribute(key, stringValue, attribute.IsEncoded);
                }
                else
                {
                    // HtmlTextWriter treats a null value as an attribute with no value (e.g., <input required />).
                    html.AddAttribute(key, null, false);
                }
            });

            if (_cssClasses.Count > 0)
            {
                var classValue = _cssClasses.Join(" ");
                html.AddAttribute(CssClassAttribute, classValue);
            }

            if (_customStyles.Count > 0)
            {
                var attValue = _customStyles
                               .Select(x => x.Key + ":" + x.Value)
                               .ToArray().Join(";");

                html.AddAttribute(CssStyleAttribute, attValue);
            }

            html.RenderBeginTag(_tag);
        }
Exemplo n.º 15
0
 void IDisposable.Dispose()
 {
     _instances.Each(x => x.SafeDispose());
 }
Exemplo n.º 16
0
        public static XmlElement WithProperties(this XmlElement element, LightweightCache <string, string> properties)
        {
            properties.Each((k, v) => element.SetAttribute(k, v));

            return(element);
        }
Exemplo n.º 17
0
        public static XmlElement WithProperties(this XmlElement element, LightweightCache<string, string> properties)
        {
            properties.Each((k, v) => element.SetAttribute(k, v));

            return element;
        }