Exemplo n.º 1
0
        /// <summary>
        /// Create an instance of a LoggingService and returns is as an IBuildComponent
        /// </summary>
        /// <returns>An instance of a LoggingService as a IBuildComponent</returns>
        public IBuildComponent CreateInstance(BuildComponentType type)
        {
            ErrorUtilities.VerifyThrow(type == BuildComponentType.LoggingService, "Cannot create components of type {0}", type);
            IBuildComponent loggingService = (IBuildComponent)LoggingService.CreateLoggingService(_logMode, _nodeId);

            return(loggingService);
        }
Exemplo n.º 2
0
 public void InitializeComponentNullHost()
 {
     Assert.Throws <InternalErrorException>(() =>
     {
         IBuildComponent logServiceComponent = (IBuildComponent)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
         logServiceComponent.InitializeComponent(null);
     }
                                            );
 }
Exemplo n.º 3
0
        /// <summary>
        /// Create a TestExtension for a given component type.
        /// </summary>
        /// <param name="componentName">Name of the component for which the TestExtension is to be created.</param>
        /// <param name="testExtensionName">Fully qualified TestExtension name.</param>
        /// <param name="buildManagerTestExtension">BuildManager Test extension entry.</param>
        /// <returns>New TestExtension.</returns>
        private static TestExtension CreateTestExtensionForComponent(string componentName, string testExtensionName, BuildManagerTestExtension buildManagerTestExtension)
        {
            BuildComponentType type      = StringToEnum <BuildComponentType>(componentName);
            IBuildComponent    component = buildManagerTestExtension.GetComponent(type);
            Type testExtensionType       = Assembly.GetAssembly(typeof(BuildManagerContainerGenerator)).GetType(testExtensionName, true, true);

            object[] parameters = { component };
            return((TestExtension)testExtensionType.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, parameters, CultureInfo.InvariantCulture));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Shuts down the single instance for this component type.
 /// </summary>
 public void ShutdownSingletonInstance()
 {
     ErrorUtilities.VerifyThrow(Pattern == CreationPattern.Singleton, "Cannot shutdown non-singleton.");
     if (_singleton != null)
     {
         _singleton.ShutdownComponent();
         _singleton = null;
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Set the value of a component type on this context.
 /// NOTE: The build configuration asset is not modified.
 /// </summary>
 /// <param name="type"><see cref="Type"/> of the component.</param>
 /// <param name="value">Value of the component to set.</param>
 public void SetComponent(Type type, IBuildComponent value)
 {
     BuildConfiguration.ValidateComponentTypeAndThrow(type);
     if (type.IsInterface || type.IsAbstract)
     {
         throw new InvalidOperationException($"{nameof(type)} cannot be interface or abstract.");
     }
     m_Components[type] = value;
 }
Exemplo n.º 6
0
        public void AddInput(IBuildComponent component)
        {
            if (component.ConsumedBy != null)
            {
                throw new InvalidOperationException("Component is already consumed by a build step.");
            }

            component.ConsumedBy = this;
            m_consumes.Add(component);
        }
Exemplo n.º 7
0
        private KitBuildItem CreateKitBuildItemNode(IBuildComponent buildComponent)
        {
            var fabricStyles = new FabricStyleList();

            foreach (var style in buildComponent.FabricStyles)
            {
                fabricStyles.Add(new FabricStyle(style.Sku, style.Color));
            }

            return(new KitBuildItemNode(buildComponent.Id, buildComponent.Quantity, buildComponent.ComponentType, buildComponent.ComponentSubtype, fabricStyles, buildComponent.Area, buildComponent.Node));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Try to get the value of a component type.
        /// Throws if component type is not in UsedComponents list.
        /// </summary>
        /// <param name="type">The component type.</param>
        /// <param name="value">The component value.</param>
        /// <returns><see langword="true"/> if the component is found, otherwise <see langword="false"/>.</returns>
        public bool TryGetComponent(Type type, out IBuildComponent value)
        {
            ValidateUsedComponentTypesAndThrow(type);

            BuildConfiguration.ValidateComponentTypeAndThrow(type);
            if (m_Components.TryGetValue(type, out value))
            {
                return(true);
            }

            return(BuildConfiguration.TryGetComponent(type, out value));
        }
Exemplo n.º 9
0
        private IBuildStep FindOrCreateStep(IBuildComponent component)
        {
            var styleKey = component.StyleKey;

            var result = m_pendingSteps.Where(r => r.CanProduceQuantity(styleKey) >= component.Quantity).FirstOrDefault();

            if (result == null)
            {
                result = m_pendingSteps.Where(r => r.CanProduceQuantity(styleKey) > 0).FirstOrDefault();
            }

            if (result == null)
            {
                var styleType = styleKey.Substring(0, styleKey.IndexOf(BuildComponent.StyleKeyDelimiter));

                switch (styleType)
                {
                case nameof(BuildComponentQuilt):
                    result = new BuildStepAssembleQuilt(styleKey);
                    break;

                case nameof(BuildComponentLayout):
                    result = new BuildStepAssembleLayout(styleKey);
                    break;

                case nameof(BuildComponentFlyingGoose):
                    result = new BuildStepFlyingGoose(styleKey);
                    break;

                case nameof(BuildComponentHalfSquareTriangle):
                    result = new BuildStepHalfSquareTriangle(styleKey);
                    break;

                case nameof(BuildComponentRectangle):
                    result = new BuildStepCut(styleKey);
                    break;

                case nameof(BuildComponentYardage):

                    // Source component - no build step required.
                    //
                    return(null);

                default:
                    throw new InvalidOperationException(string.Format("No build step for style type {0}.", styleType));
                }

                m_allSteps.Add(result);
                m_pendingSteps.Add(result);
            }

            return(result);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Instantiate and Initialize a new loggingService.
        /// This is used by the test setup method to create
        /// a new logging service before each test.
        /// </summary>
        private void InitializeLoggingService()
        {
            BuildParameters parameters = new BuildParameters();

            parameters.MaxNodeCount = 2;
            MockHost mockHost = new MockHost(parameters);

            IBuildComponent logServiceComponent = (IBuildComponent)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);

            logServiceComponent.InitializeComponent(mockHost);
            _initializedService = logServiceComponent as LoggingService;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Try to get the value of a component type.
        /// Throws if component type is not in UsedComponents list.
        /// </summary>
        /// <param name="type">The component type.</param>
        /// <param name="value">The component value.</param>
        /// <returns><see langword="true"/> if the component is found, otherwise <see langword="false"/>.</returns>
        public bool TryGetComponent(Type type, out IBuildComponent value)
        {
            CheckUsedComponentTypesAndThrowIfMissing(type);

            BuildConfiguration.CheckComponentTypeAndThrowIfInvalid(type);
            if (m_Components.TryGetValue(type, out value))
            {
                return(true);
            }

            return(BuildConfiguration.TryGetComponent(type, out value));
        }
Exemplo n.º 12
0
        public void AddOutput(IBuildComponent component)
        {
            if (component.ProducedBy != null)
            {
                throw new InvalidOperationException("Component is already produced by a build step.");
            }

            if (CanProduceQuantity(component.StyleKey) == 0)
            {
                throw new InvalidOperationException("Build step does not produce desired style.");
            }

            component.ProducedBy = this;
            m_produces.Add(component);
        }
Exemplo n.º 13
0
        private void ProcessComponent(IBuildComponent component, BuildComponentFactory factory)
        {
            var step = FindOrCreateStep(component);

            if (step != null)
            {
                int quantity = step.CanProduceQuantity(component.StyleKey);
                if (quantity < component.Quantity)
                {
                    var splitComponent = component.Split(factory, component.Quantity - quantity);
                    PushPendingComponent(splitComponent);
                }

                step.AddOutput(component);
            }
        }
Exemplo n.º 14
0
        public virtual void WriteBuildConfiguration(BuildContext context, string path)
        {
            var componentTypes = new HashSet <Type>();

            foreach (var usedComponent in context.UsedComponents)
            {
                if (usedComponent.IsAbstract || usedComponent.IsInterface)
                {
                    var derivedComponents = TypeCache.GetTypesDerivedFrom(usedComponent);
                    foreach (var derivedComponent in derivedComponents)
                    {
                        if (derivedComponent.IsAbstract || derivedComponent.IsInterface)
                        {
                            continue;
                        }
                        componentTypes.Add(derivedComponent);
                    }
                }
                else
                {
                    componentTypes.Add(usedComponent);
                }
            }

            var realComponents    = new List <IBuildComponent>();
            var defaultComponents = new List <IBuildComponent>();

            foreach (var componentType in componentTypes)
            {
                var component = context.GetComponentOrDefault(componentType);
                if (context.HasComponent(componentType))
                {
                    realComponents.Add(component);
                }
                else
                {
                    defaultComponents.Add(component);
                }
            }

            var components = new IBuildComponent[][] { realComponents.ToArray(), defaultComponents.ToArray() };
            var json       = JsonSerialization.ToJson(components);

            File.WriteAllText(Path.Combine(path, "buildconfiguration.json"), json);
        }
Exemplo n.º 15
0
            /// <summary>
            /// Gets an instance of the component.
            /// </summary>
            public IBuildComponent GetInstance(IBuildComponentHost host)
            {
                if (Pattern == CreationPattern.Singleton)
                {
                    if (_singleton == null)
                    {
                        _singleton = _factory(ComponentType);
                        _singleton.InitializeComponent(host);
                    }

                    return(_singleton);
                }

                IBuildComponent component = _factory(ComponentType);

                component.InitializeComponent(host);
                return(component);
            }
Exemplo n.º 16
0
        public void InitializeComponent()
        {
            IBuildComponent logServiceComponent = (IBuildComponent)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);

            BuildParameters parameters = new BuildParameters();

            parameters.MaxNodeCount          = 4;
            parameters.OnlyLogCriticalEvents = true;

            IBuildComponentHost loggingHost = new MockHost(parameters);

            // Make sure we are in the Instantiated state before initializing
            Assert.Equal(((LoggingService)logServiceComponent).ServiceState, LoggingServiceState.Instantiated);

            logServiceComponent.InitializeComponent(loggingHost);

            // Makesure that the parameters in the host are set in the logging service
            LoggingService service = (LoggingService)logServiceComponent;

            Assert.Equal(service.ServiceState, LoggingServiceState.Initialized);
            Assert.Equal(4, service.MaxCPUCount);
            Assert.True(service.OnlyLogCriticalEvents);
        }
Exemplo n.º 17
0
        public virtual void WriteBuildConfiguration(BuildContext context, string path)
        {
            var realComponents    = new List <IBuildComponent>();
            var defaultComponents = new List <IBuildComponent>();

            foreach (var c in UsedComponents)
            {
                var component = context.GetComponentOrDefault(c);
                if (context.HasComponent(c))
                {
                    realComponents.Add(component);
                }
                else
                {
                    defaultComponents.Add(component);
                }
            }

            var components = new IBuildComponent[][] { realComponents.ToArray(), defaultComponents.ToArray() };
            var json       = JsonSerialization.ToJson(components);

            File.WriteAllText(Path.Combine(path, "buildconfiguration.json"), json);
        }
Exemplo n.º 18
0
        public void CreateLogger()
        {
            // Generic host which has some default properties set inside of it
            IBuildComponent logServiceComponent = (IBuildComponent)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);

            // Create a synchronous logging service and do some quick checks
            Assert.NotNull(logServiceComponent);
            LoggingService logService = (LoggingService)logServiceComponent;

            Assert.Equal(logService.LoggingMode, LoggerMode.Synchronous);
            Assert.Equal(logService.ServiceState, LoggingServiceState.Instantiated);

            // Create an asynchronous logging service
            logServiceComponent = (IBuildComponent)LoggingService.CreateLoggingService(LoggerMode.Asynchronous, 1);
            Assert.NotNull(logServiceComponent);
            logService = (LoggingService)logServiceComponent;
            Assert.Equal(logService.LoggingMode, LoggerMode.Asynchronous);
            Assert.Equal(logService.ServiceState, LoggingServiceState.Instantiated);

            // Shutdown logging thread
            logServiceComponent.InitializeComponent(new MockHost());
            logServiceComponent.ShutdownComponent();
            Assert.Equal(logService.ServiceState, LoggingServiceState.Shutdown);
        }
Exemplo n.º 19
0
        public BuildComponentInspectorData(BuildConfigurationInspectorData config, IBuildComponent value)
        {
            m_Config = config;

            ComponentType         = value.GetType();
            ComponentSource       = config.GetComponentSource(ComponentType);
            IsComponentPresent    = config.HasComponent(ComponentType);
            IsComponentInherited  = config.IsComponentInherited(ComponentType);
            IsComponentOverriding = config.IsComponentOverriding(ComponentType);
            IsComponentUsed       = config.IsComponentUsed(ComponentType);
            ConfigHasPipeline     = config.HasPipeline;
            ComponentName         = ObjectNames.NicifyVariableName(ComponentType.Name);

            var visitor = new ComponentVisitor();

            PropertyContainer.Visit(ref value, visitor);
            FieldNames = visitor.FieldNames;

            IsPipelineComponent = typeof(IBuildPipelineComponent).IsAssignableFrom(ComponentType);
            IsTagComponent      = FieldNames.Length == 0;
            Icon = Resources.BuildComponentIcon;

            Value = value;
        }
 /// <summary>
 /// Registers a factory to replace one of the defaults.  Creation pattern is inherited from the original.
 /// </summary>
 /// <param name="componentType">The type which is created by this factory.</param>
 /// <param name="instance">The instance to be registered.</param>
 public void ReplaceFactory(BuildComponentType componentType, IBuildComponent instance)
 {
     ErrorUtilities.VerifyThrow(_componentEntriesByType[componentType].Pattern == CreationPattern.Singleton, "Previously existing factory for type {0} was not a singleton factory.", componentType);
     _componentEntriesByType[componentType] = new BuildComponentEntry(componentType, instance);
 }
Exemplo n.º 21
0
#pragma warning disable IDE0051 // Remove unused private members
        private IBuildComponent Split(BuildComponentFactory factory, IBuildComponent component, int quantity)
#pragma warning restore IDE0051 // Remove unused private members
        {
            return(component.Split(factory, quantity));
        }
Exemplo n.º 22
0
 private void PushPendingComponent(IBuildComponent component)
 {
     m_allComponents.Add(component);
     m_pendingComponents.Add(component);
 }
 /// <summary>
 /// Shuts down the single instance for this component type.
 /// </summary>
 public void ShutdownSingletonInstance()
 {
     ErrorUtilities.VerifyThrow(Pattern == CreationPattern.Singleton, "Cannot shutdown non-singleton.");
     if (_singleton != null)
     {
         _singleton.ShutdownComponent();
         _singleton = null;
     }
 }
Exemplo n.º 24
0
 private KitBuildItem CreateKitBuildItem(IBuildComponent buildComponent)
 {
     return(buildComponent is BuildComponentYardage buildComponentYardage
         ? CreateKitBuildItemPattern(buildComponentYardage)
         : CreateKitBuildItemNode(buildComponent));
 }
Exemplo n.º 25
0
 /// <summary>
 /// Constructor for existing singleton.
 /// </summary>
 public BuildComponentEntry(BuildComponentType type, IBuildComponent singleton)
 {
     ComponentType = type;
     _singleton    = singleton;
     Pattern       = CreationPattern.Singleton;
 }
Exemplo n.º 26
0
 /// <summary>
 /// Registers a factory to replace one of the defaults.  Creation pattern is inherited from the original.
 /// </summary>
 /// <param name="componentType">The type which is created by this factory.</param>
 /// <param name="instance">The instance to be registered.</param>
 public void ReplaceFactory(BuildComponentType componentType, IBuildComponent instance)
 {
     ErrorUtilities.VerifyThrow(_componentEntriesByType[componentType].Pattern == CreationPattern.Singleton, "Previously existing factory for type {0} was not a singleton factory.", componentType);
     _componentEntriesByType[componentType] = new BuildComponentEntry(componentType, instance);
 }
 public void SetComponent(IBuildComponent value)
 {
     Target.SetComponent(value);
 }
 /// <summary>
 /// Constructor for existing singleton.
 /// </summary>
 public BuildComponentEntry(BuildComponentType type, IBuildComponent singleton)
 {
     _singleton   = singleton;
     this.Pattern = CreationPattern.Singleton;
 }
 /// <summary>
 /// Constructor for existing singleton.
 /// </summary>
 public BuildComponentEntry(BuildComponentType type, IBuildComponent singleton)
 {
     _singleton = singleton;
     this.Pattern = CreationPattern.Singleton;
 }
            /// <summary>
            /// Gets an instance of the component.
            /// </summary>
            public IBuildComponent GetInstance(IBuildComponentHost host)
            {
                if (Pattern == CreationPattern.Singleton)
                {
                    if (_singleton == null)
                    {
                        _singleton = _factory(ComponentType);
                        _singleton.InitializeComponent(host);
                    }

                    return _singleton;
                }
                else
                {
                    IBuildComponent component = _factory(ComponentType);
                    component.InitializeComponent(host);
                    return component;
                }
            }
Exemplo n.º 31
0
 public void SetComponent(IBuildComponent value)
 {
     m_Config.SetComponent(value);
     Update(); // Update since we're not rebuilding
 }
Exemplo n.º 32
0
        public void InitializeComponentNullHost()
        {
            IBuildComponent logServiceComponent = (IBuildComponent)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);

            logServiceComponent.InitializeComponent(null);
        }
Exemplo n.º 33
0
        /// <summary>
        /// Constructs and returns a component of the specified type.
        /// </summary>
        public IBuildComponent GetComponent(BuildComponentType type)
        {
            IBuildComponent returnComponent = null;

            switch (type)
            {
            case BuildComponentType.LoggingService:     // Singleton
                return((IBuildComponent)this.loggingService);

            case BuildComponentType.TestDataProvider:     // Singleton
                if (this.testDataProvider != null)
                {
                    return((IBuildComponent)this.testDataProvider);
                }

                returnComponent = this.getComponentCallback(type);
                if (returnComponent != null)
                {
                    returnComponent.InitializeComponent(this);
                    this.testDataProvider = (ITestDataProvider)returnComponent;
                }

                break;

            case BuildComponentType.RequestEngine:     // Singleton
                if (this.requestEngine != null)
                {
                    return((IBuildComponent)this.requestEngine);
                }

                returnComponent = this.getComponentCallback(type);
                if (returnComponent != null)
                {
                    returnComponent.InitializeComponent(this);
                    this.requestEngine = (IBuildRequestEngine)returnComponent;
                    this.requestEngine.OnEngineException         += new EngineExceptionDelegate(RequestEngine_OnEngineException);
                    this.requestEngine.OnNewConfigurationRequest += new NewConfigurationRequestDelegate(RequestEngine_OnNewConfigurationRequest);
                    this.requestEngine.OnRequestBlocked          += new RequestBlockedDelegate(RequestEngine_OnNewRequest);
                    this.requestEngine.OnRequestComplete         += new RequestCompleteDelegate(RequestEngine_OnRequestComplete);
                    this.requestEngine.OnStatusChanged           += new EngineStatusChangedDelegate(RequestEngine_OnStatusChanged);
                }

                break;

            default:
                returnComponent = this.getComponentCallback(type);
                if (returnComponent != null)
                {
                    returnComponent.InitializeComponent(this);
                }
                break;
            }

            if (returnComponent != null)
            {
                lock (this.buildComponents)
                {
                    this.buildComponents.Enqueue(returnComponent);
                }
            }

            return(returnComponent);
        }