示例#1
0
 public void SetUp()
 {
     this.mocks      = new MockRepository();
     this.handler    = this.mocks.StrictMock <IBuildHandler>();
     this.properties = new BuildDataDictionary();
     this.testObject = new BuilderSerializer();
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:AllIwantToTest"/> class.
 /// </summary>
 public AllIwantToTest(
     int myInt, string myString, bool myBool, short myShort, Type myType, IBuildHandler myHandler)
 {
     if (this.PublicEventObject != null)
     {
     }
 }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:AllIwantToTest"/> class.
 /// </summary>
 public AllIwantToTest(
     int myInt, string myString, bool myBool, short myShort, Type myType, IBuildHandler myHandler)
 {
     if (this.PublicEventObject != null)
     {
     }
 }
示例#4
0
        public async Task ProcessFiles(IFolder sourceFolder, IFolder outputFolder, IBuildHandler buildHandler)
        {
            ITagServices      tagServices     = new TagServices(buildHandler);
            ITemplateServices templateService = new TemplateServices(buildHandler, tagServices);

            BuildService buildService = new BuildService(buildHandler, tagServices, templateService);
            await buildService.DoBuild(sourceFolder, outputFolder);
        }
示例#5
0
        /// <summary>
        /// Set the parameters in the properties storage from a specified xml representation of the data.
        /// </summary>
        /// <param name="xml">The xml representation of the data.</param>
        /// <param name="properties">The global properties storage.</param>
        /// <returns>
        /// A new instance of a matching parameter data set for the specified builder.
        /// </returns>
        /// <exception cref="InvalidCastException"><c>InvalidCastException</c> Problem building from serialization data.</exception>
        public IMemberBuildParameters SetParameters(string xml, IBuildDataDictionary properties)
        {
            Guard.NotNull(() => properties, properties);

            var           handlers = this.buildHandlers.Values.AsEnumerable();
            IBuildHandler handler  = this.serializer.DetermineIMemberBuilderFromXmlFragment(xml, handlers);

            return(this.serializer.SetParameters(xml, properties, handler));
        }
示例#6
0
        public BuilderPipelineContext AddLast(IBuildHandler handler)
        {
            var context     = new BuilderPipelineContext(handler);
            var origin_prev = _last.Prev;

            origin_prev.Next = context;
            context.Prev     = origin_prev;
            _last.Prev       = context;
            return(context);
        }
示例#7
0
        public BuilderPipelineContext AddFirst(IBuildHandler handler)
        {
            var context       = new BuilderPipelineContext(handler);
            var _origin_first = _head.Next;

            context.Next = _origin_first;
            _head.Next   = context;
            context.Prev = _head;
            if (_origin_first != null)
            {
                _origin_first.Prev = context;
            }
            return(context);
        }
示例#8
0
        /// <summary>
        /// Determines the matching member builder by the first childs name from a XML fragment.
        /// </summary>
        /// <param name="xml">The xml fragment.</param>
        /// <param name="handlers">The list of existing handlers to investigate.</param>
        /// <returns>The matching handler or <c>null</c> if none is found.</returns>
        public IBuildHandler DetermineIMemberBuilderFromXmlFragment(string xml, IEnumerable <IBuildHandler> handlers)
        {
            // <NStub.CSharp.ObjectGeneration.Builders.PropertyBuilder>
            var doc = new XmlDocument();

            doc.LoadXml(xml);
            var firstChild = doc.FirstChild;

            IBuildHandler handler = null;

            foreach (var item in handlers.Where(item => item.Type.FullName == firstChild.Name))
            {
                handler = item;
            }

            return(handler);
        }
示例#9
0
        /// <summary>
        /// Set the parameters in the properties storage from a specified xml representation of the data.
        /// </summary>
        /// <param name="xml">The xml representation of the data.</param>
        /// <param name="properties">The global properties storage.</param>
        /// <param name="handlers">The list of existing handlers to investigate.</param>
        /// <returns>
        /// A new instance of a matching parameter data set for the specified builder.
        /// </returns>
        /// <exception cref="InvalidCastException"><c>InvalidCastException</c> Problem building from serialization data.</exception>
        public IEnumerable <IMemberBuildParameters> DeserializeAllSetupData(
            string xml, IBuildDataDictionary properties, IEnumerable <IBuildHandler> handlers)
        {
            // <NStub.CSharp.ObjectGeneration.Builders.PropertyBuilder>
            var plist = new List <IMemberBuildParameters>();
            var doc   = new XmlDocument();

            doc.LoadXml(xml);
            foreach (XmlElement item in doc[BuilderConstants.BuildParametersXmlId])
            {
                IBuildHandler handler = this.DetermineIMemberBuilderFromXmlFragment(item.OuterXml, handlers);
                var           para    = this.SetParameters(item.OuterXml, properties, handler);

                plist.Add(para);

                // yield return para;
            }

            return(plist);
        }
示例#10
0
        private IMemberBuildParameters SetSingleNode(IBuildDataDictionary properties, IBuildHandler handler,
                                                     XmlNode firstChild)
        {
            Guard.NotNull(() => properties, properties);
            Guard.NotNull(() => handler, handler);
            var paraType = handler.ParameterDataType;

            if (!typeof(IBuilderData).IsAssignableFrom(paraType))
            {
                throw new ArgumentOutOfRangeException("handler",
                                                      "The handler for MemberBuilder '" + handler.Type.FullName +
                                                      "' is mapping to a invalid parameter of '" + handler.ParameterDataType.FullName + "' type. " +
                                                      "Parameter types have to implement the '" + typeof(IBuilderData).FullName + "' interface.");
            }
            object paraInstance = null;

            if (handler.IsMultiBuilder)
            {
                if (!typeof(IMultiBuildParameters).IsAssignableFrom(paraType))
                {
                    throw new ArgumentOutOfRangeException("handler",
                                                          "Requesting a parameter type of '" + firstChild.Name +
                                                          "' (via Xml) for the '" + handler.ParameterDataType.FullName + "' handler assigned type. " +
                                                          "Parameter types have to implement the '" + typeof(IMultiBuildParameters).FullName + "' interface.");
                }

                // null check paraType
                var xxx  = paraType.BaseType.GetGenericTypeDefinition();
                var xxxx = xxx.BaseType.GetGenericTypeDefinition();

                // null check xxxx
                var serializer2 = xxxx.BaseType.GetGenericTypeDefinition();

                // Todo: This strange thingy ... very good checking and logging! :)
                // null check serializer2
                paraInstance = serializer2
                               .MakeGenericType(paraType)
                               .GetMethod("Deserialize", new[] { typeof(string) })
                               .Invoke(null, new object[] { firstChild.InnerXml });
            }
            else
            {
                if (!typeof(IMemberBuildParameters).IsAssignableFrom(paraType))
                {
                    throw new ArgumentOutOfRangeException("handler",
                                                          "Requesting a parameter type for '" + firstChild.Name +
                                                          "' (via Xml) for the '" + paraType.FullName + "' handler assigned type. " +
                                                          "Parameter types have to implement the '" + typeof(IMemberBuildParameters).FullName + "' interface.");
                }

                // Todo: really need this stuff here? should this be done in the handler construction?
                // for example: checking if a multibuilder has IMultiBuildParameters and a
                // normal builder has IMemberBuildParameters.
                var xmlParaType = firstChild.FirstChild.Name;
                if (xmlParaType != paraType.Name)
                {
                    throw new ArgumentOutOfRangeException("firstChild",
                                                          "Requesting a parameter type of '" + xmlParaType + "' (via Xml). " +
                                                          "Parameter types for the '" + handler.Type.FullName + "' builder have to be of the '" + paraType.FullName + "' kind.");
                }

                // null check paraType
                var xxxx = paraType.BaseType.GetGenericTypeDefinition();

                // null check xxxx
                var serializer2 = xxxx.BaseType.GetGenericTypeDefinition();

                // Todo: This strange thingy ... very good checking and logging! :)
                // null check serializer2
                paraInstance = serializer2
                               .MakeGenericType(paraType)
                               .GetMethod("Deserialize", new[] { typeof(string) })
                               .Invoke(null, new object[] { firstChild.InnerXml });
            }

            var setupPara = (IMemberBuildParameters)paraInstance;

            try
            {
                var propertyKey = handler.Type.FullName;

                // IBuilderData property;
                // var found = properties.TryGetValue(propertyKey, out property);
                // if (found)
                // {
                if (handler.IsMultiBuilder)
                {
                    var multiPara = setupPara as IMultiBuildParameters;
                    properties.AddDataItem("Multi." + handler.Type.FullName, multiPara.Id.ToString(), setupPara, true);
                }
                else
                {
                    properties.AddDataItem(propertyKey, setupPara, true);
                }

                // return setupPara;
                // }
                // properties.AddDataItem(propertyKey, setupPara);
            }
            catch (Exception ex)
            {
                var message = string.Format(
                    "Problem building {0} from serialization data.{1}{2}{3}",
                    handler.Type.FullName,
                    Environment.NewLine,
                    firstChild.InnerXml,
                    Environment.NewLine);
                throw new InvalidCastException(message, ex);
            }
            return(setupPara);
        }
示例#11
0
        /// <summary>
        /// Set the parameters in the properties storage from a specified xml representation of the data.
        /// </summary>
        /// <param name="xml">The xml representation of the data.</param>
        /// <param name="properties">The global properties storage.</param>
        /// <param name="handler">The handler that holds the builder- to parameter-type relation.</param>
        /// <returns>
        /// A new instance of a matching parameter data set for the specified builder.
        /// </returns>
        /// <exception cref="InvalidCastException"><c>InvalidCastException</c> Problem building from serialization data.</exception>
        public IMemberBuildParameters SetParameters(string xml, IBuildDataDictionary properties, IBuildHandler handler)
        {
            Guard.NotNull(() => properties, properties);
            if (handler == null)
            {
                // Todo: or throw?
                return(new EmptyBuildParameters());
            }

            // <NStub.CSharp.ObjectGeneration.Builders.PropertyBuilder>
            var doc = new XmlDocument();

            doc.LoadXml(xml);

            IMemberBuildParameters setupPara = null;

            foreach (XmlNode child in doc.ChildNodes)
            {
                //var child = doc.FirstChild;
                if (handler.IsMultiBuilder)
                {
                    // Hier HAPERTS !!!!!!!!!!!!!!!!!!! multi fetchen ... document node klappt nicht
                    // setupPara = SetSingleNode(properties, handler, child, "Multi." + handler.Type.FullName, string.Empty);
                    setupPara = SetSingleNode(properties, handler, child);
                }
                else
                {
                    setupPara = SetSingleNode(properties, handler, child);
                }
            }

            return(setupPara);
        }
示例#12
0
        private IMemberBuildParameters SetSingleNode(IBuildDataDictionary properties, IBuildHandler handler, 
            XmlNode firstChild)
        {
            Guard.NotNull(() => properties, properties);
            Guard.NotNull(() => handler, handler);
            var paraType = handler.ParameterDataType;
            if (!typeof(IBuilderData).IsAssignableFrom(paraType))
            {
                throw new ArgumentOutOfRangeException("handler",
                    "The handler for MemberBuilder '" + handler.Type.FullName +
                    "' is mapping to a invalid parameter of '" + handler.ParameterDataType.FullName + "' type. " +
                "Parameter types have to implement the '" + typeof(IBuilderData).FullName + "' interface.");
            }
            object paraInstance = null;
            if (handler.IsMultiBuilder)
            {
                if (!typeof(IMultiBuildParameters).IsAssignableFrom(paraType))
                {
                    throw new ArgumentOutOfRangeException("handler",
                        "Requesting a parameter type of '" + firstChild.Name +
                        "' (via Xml) for the '" + handler.ParameterDataType.FullName + "' handler assigned type. " +
                    "Parameter types have to implement the '" + typeof(IMultiBuildParameters).FullName + "' interface.");
                }

                // null check paraType
                var xxx = paraType.BaseType.GetGenericTypeDefinition();
                var xxxx = xxx.BaseType.GetGenericTypeDefinition();

                // null check xxxx
                var serializer2 = xxxx.BaseType.GetGenericTypeDefinition();

                // Todo: This strange thingy ... very good checking and logging! :)
                // null check serializer2
                paraInstance = serializer2
                    .MakeGenericType(paraType)
                    .GetMethod("Deserialize", new[] { typeof(string) })
                    .Invoke(null, new object[] { firstChild.InnerXml });
            }
            else
            {

                if (!typeof(IMemberBuildParameters).IsAssignableFrom(paraType))
                {
                    throw new ArgumentOutOfRangeException("handler",
                        "Requesting a parameter type for '" + firstChild.Name +
                        "' (via Xml) for the '" + paraType.FullName + "' handler assigned type. " +
                    "Parameter types have to implement the '" + typeof(IMemberBuildParameters).FullName + "' interface.");
                }

                // Todo: really need this stuff here? should this be done in the handler construction?
                // for example: checking if a multibuilder has IMultiBuildParameters and a
                // normal builder has IMemberBuildParameters.
                var xmlParaType = firstChild.FirstChild.Name;
                if (xmlParaType != paraType.Name)
                {
                    throw new ArgumentOutOfRangeException("firstChild",
                        "Requesting a parameter type of '" + xmlParaType + "' (via Xml). " +
                    "Parameter types for the '" + handler.Type.FullName + "' builder have to be of the '" + paraType.FullName + "' kind.");
                }

                // null check paraType
                var xxxx = paraType.BaseType.GetGenericTypeDefinition();

                // null check xxxx
                var serializer2 = xxxx.BaseType.GetGenericTypeDefinition();

                // Todo: This strange thingy ... very good checking and logging! :)
                // null check serializer2
                paraInstance = serializer2
                    .MakeGenericType(paraType)
                    .GetMethod("Deserialize", new[] { typeof(string) })
                    .Invoke(null, new object[] { firstChild.InnerXml });
            }

            var setupPara = (IMemberBuildParameters)paraInstance;
            try
            {
                var propertyKey = handler.Type.FullName;

                // IBuilderData property;
                // var found = properties.TryGetValue(propertyKey, out property);
                // if (found)
                // {
                if (handler.IsMultiBuilder)
                {
                    var multiPara = setupPara as IMultiBuildParameters;
                    properties.AddDataItem("Multi." + handler.Type.FullName, multiPara.Id.ToString(), setupPara, true);
                 }
                 else
                 {
                    properties.AddDataItem(propertyKey, setupPara, true);
                 }

                // return setupPara;
                // }
                // properties.AddDataItem(propertyKey, setupPara);
            }
            catch (Exception ex)
            {
                var message = string.Format(
                    "Problem building {0} from serialization data.{1}{2}{3}",
                    handler.Type.FullName,
                    Environment.NewLine,
                    firstChild.InnerXml,
                    Environment.NewLine);
                throw new InvalidCastException(message, ex);
            }
            return setupPara;
        }
示例#13
0
        /// <summary>
        /// Set the parameters in the properties storage from a specified xml representation of the data.
        /// </summary>
        /// <param name="xml">The xml representation of the data.</param>
        /// <param name="properties">The global properties storage.</param>
        /// <param name="handler">The handler that holds the builder- to parameter-type relation.</param>
        /// <returns>
        /// A new instance of a matching parameter data set for the specified builder.
        /// </returns>
        /// <exception cref="InvalidCastException"><c>InvalidCastException</c> Problem building from serialization data.</exception>
        public IMemberBuildParameters SetParameters(string xml, IBuildDataDictionary properties, IBuildHandler handler)
        {
            Guard.NotNull(() => properties, properties);
            if (handler == null)
            {
                // Todo: or throw?
                return new EmptyBuildParameters();
            }

            // <NStub.CSharp.ObjectGeneration.Builders.PropertyBuilder>
            var doc = new XmlDocument();
            doc.LoadXml(xml);

            IMemberBuildParameters setupPara = null;
            foreach (XmlNode child in doc.ChildNodes)
            {
                //var child = doc.FirstChild;
                if (handler.IsMultiBuilder)
                {
                    // Hier HAPERTS !!!!!!!!!!!!!!!!!!! multi fetchen ... document node klappt nicht
                    // setupPara = SetSingleNode(properties, handler, child, "Multi." + handler.Type.FullName, string.Empty);
                    setupPara = SetSingleNode(properties, handler, child);
                }
                else
                {
                    setupPara = SetSingleNode(properties, handler, child);
                }
            }

            return setupPara;
        }
示例#14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:AllIwantToTest"/> class.
 /// </summary>
 public AllIwantToTest(short myShort, Type myType, IBuildHandler myHandler)
 {
 }
示例#15
0
 public BuildService(IBuildHandler buildHandler, ITagServices tagServices, ITemplateServices templateServices)
 {
     this.BuildHandler     = buildHandler;
     this.TagServices      = tagServices;
     this.TemplateServices = templateServices;
 }
示例#16
0
        public static BuilderPipelineContext AddStep(this BuilderPipelineContext ctx, IBuildHandler nextHandler)
        {
            var nextContext = new BuilderPipelineContext(nextHandler);
            var origin_next = ctx.Next;

            ctx.Next         = nextContext;
            nextContext.Next = origin_next;
            nextContext.Prev = ctx;
            if (origin_next != null)
            {
                origin_next.Prev = nextContext;
            }
            return(nextContext);
        }
示例#17
0
 /// <summary>
 /// Adds the specified handler to the factory.
 /// </summary>
 /// <param name="handler">The handler to be added.</param>
 public void AddHandler(IBuildHandler handler)
 {
     this.buildHandlers.Add(handler.Type, handler);
 }
示例#18
0
 public BuildRunner(IEngineServiceInternal engineService, IBuildHandler buildHandler)
 {
     _engineService = engineService;
     _buildHandler  = buildHandler;
 }
示例#19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:AllIwantToTest"/> class.
 /// </summary>
 public AllIwantToTest(short myShort, Type myType, IBuildHandler myHandler)
 {
 }
示例#20
0
 public TagServices(IBuildHandler buildHandler)
 {
     this.BuildHandler = buildHandler;
 }
示例#21
0
 public TemplateServices(IBuildHandler buildHandler, ITagServices tagServices)
 {
     this.BuildHandler = buildHandler;
     this.TagServices  = tagServices;
 }
示例#22
0
 public BuilderPipelineContext(IBuildHandler handler)
 {
     _handler = handler;
     Next     = null;
     Prev     = null;
 }