Exemple #1
0
		/// <summary>
		/// Gets the value of the current associative object instance. Overrides the default behavior to return the Value property.
		/// </summary>
		/// <param name="templatingContext"> The templating context. </param>
		/// <returns> A value or null. </returns>
		protected override object CoreGetAssociativeObjectValue(ITemplatingContext templatingContext)
		{
			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			return this.Value;
		}
Exemple #2
0
		/// <summary>
		/// Gets the enumerator for the current associative object instance. Overrides the default behavior by returning an enumerator from a list of only IActualThing implementing child objects.
		/// </summary>
		/// <param name="templatingContext"> The templating context. </param>
		/// <returns> An instance of IEnumerator or null. </returns>
		protected override IEnumerator CoreGetAssociativeObjectEnumerator(ITemplatingContext templatingContext)
		{
			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			return this.Items.OfType<IObjectReference>().GetEnumerator();
		}
Exemple #3
0
		protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
		{
			string name;
			string content;
			IExpressionContainerConstruct expressionContainerConstruct;
			DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

			name = templatingContext.Tokenizer.ExpandTokens(this.Name, dynamicWildcardTokenReplacementStrategy);

			content = templatingContext.Input.LoadContent(name);

			expressionContainerConstruct = new ExpressionContainerConstruct();
			((IContentContainerXmlObject<IExpressionXmlObject>)expressionContainerConstruct).Content = new ValueConstruct()
																										{
																											__ = content
																										};

			new WriteConstruct()
			{
				Text = expressionContainerConstruct
			}.ExpandTemplate(templatingContext);
		}
Exemple #4
0
		/// <summary>
		/// Gets the enumerator for the current associative object instance. Overrides the default behavior and always return null.
		/// </summary>
		/// <param name="templatingContext"> The templating context. </param>
		/// <returns> An instance of IEnumerator or null. </returns>
		protected override IEnumerator CoreGetAssociativeObjectEnumerator(ITemplatingContext templatingContext)
		{
			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			return null;
		}
        public override WorkUnitResult Execute(ITemplatingContext context)
        {
            Stopwatch localTimer = new Stopwatch();
            string rootPath = Path.GetFullPath(context.TemplateData.TargetDirectory);
            // copy resources to output dir

            string target = Path.Combine(rootPath, this.ResourcePath);
            string targetDir = Path.GetDirectoryName(target);

            TraceSources.TemplateSource.TraceInformation("Copying resource: {0}", this.ResourcePath);

            if (!Directory.Exists(targetDir))
                Directory.CreateDirectory(targetDir);

            using (Stream streamSrc = context.FileProvider.OpenFile(Path.Combine(context.BasePath, this.ResourcePath)))
            using (Stream streamDest = File.Create(target))
            {
                streamSrc.CopyTo(streamDest);
                streamDest.Close();
                streamSrc.Close();
            }

            return new WorkUnitResult
                       {
                           WorkUnit = this,
                           Duration = (long)Math.Round((double)(localTimer.ElapsedTicks/Stopwatch.Frequency)*1000000)
                       };
        }
Exemple #6
0
		protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
		{
			string localName, namespaceUri, aqtn;
			Type aliasedType;
			DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

			localName = templatingContext.Tokenizer.ExpandTokens(this.LocalName, dynamicWildcardTokenReplacementStrategy);
			namespaceUri = templatingContext.Tokenizer.ExpandTokens(this.NamespaceUri, dynamicWildcardTokenReplacementStrategy);
			aqtn = templatingContext.Tokenizer.ExpandTokens(this.AssemblyQualifiedTypeName, dynamicWildcardTokenReplacementStrategy);

			aliasedType = Type.GetType(aqtn, false);

			if ((object)aliasedType == null)
				throw new InvalidOperationException(string.Format("Failed to load the aliased type '{0}' via Type.GetType(..).", aqtn));

			templatingContext.AddReference(new XmlName()
											{
												LocalName = localName,
												NamespaceUri = namespaceUri
											}, aliasedType);
		}
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
                throw new ArgumentNullException("templatingContext");

            //templatingContext.IteratorModels.Push(this.Dynamic.Content);
            // BUG: this never gets popped !!!
        }
        public TemplateXsltExtensions(ITemplatingContext context, Uri currentUri)
        {
            this._context = context;
            this._currentUri = currentUri;

            this._aidCache = new ConcurrentDictionary<string, AssetIdentifier>();
            this._resolveCache = new ConcurrentDictionary<AssetIdentifier, string>();
        }
Exemple #9
0
        /// <summary>
        /// Gets the enumerator for the current associative object instance. Overrides the default behavior by returning an enumerator from a list of only IActualThing implementing child objects.
        /// </summary>
        /// <param name="templatingContext"> The templating context. </param>
        /// <returns> An instance of IEnumerator or null. </returns>
        protected override IEnumerator CoreGetAssociativeObjectEnumerator(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            return(this.Items.OfType <IObjectReference>().GetEnumerator());
        }
Exemple #10
0
        /// <summary>
        /// Gets the dictionary enumerator for the current associative object instance.
        /// </summary>
        /// <param name="templatingContext"> The templating context. </param>
        /// <returns> An instance of IDictionaryEnumerator or null. </returns>
        public IDictionaryEnumerator GetAssociativeObjectEnumeratorDict(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            return(this.CoreGetAssociativeObjectEnumeratorDict(templatingContext));
        }
        /// <summary>
        /// Expands the template tree into the templating context current output.
        /// </summary>
        /// <param name="templatingContext"> The templating context. </param>
        public void ExpandTemplate(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            templatingContext.LaunchDebugger();
        }
Exemple #12
0
        /// <summary>
        /// Gets the enumerator for the current associative object instance. Overrides the default behavior to always return null.
        /// </summary>
        /// <param name="templatingContext"> The templating context. </param>
        /// <returns> An instance of IEnumerator or null. </returns>
        protected override IEnumerator CoreGetAssociativeObjectEnumerator(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            return(null);
        }
Exemple #13
0
		protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
		{
			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			// add global cleanup into context to suppro this....
			//templatingContext.IteratorModels.Push(this.Dynamic.Content);
			// BUG: this never gets popped !!!
		}
Exemple #14
0
        /// <summary>
        /// Gets the value of the current associative object instance.
        /// </summary>
        /// <param name="templatingContext"> The templating context. </param>
        /// <returns> A value or null. </returns>
        public object GetAssociativeObjectValue(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            return(this.CoreGetAssociativeObjectValue(templatingContext));
        }
Exemple #15
0
        /// <summary>
        /// Gets the value of the current associative object instance. Overrides the default behavior to return the Value property.
        /// </summary>
        /// <param name="templatingContext"> The templating context. </param>
        /// <returns> A value or null. </returns>
        protected override object CoreGetAssociativeObjectValue(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            return(this.Value);
        }
Exemple #16
0
        /// <summary>
        /// Gets the enumerator for the current associative object instance. Derived types can override the default behavior of returning the enumerator from the result of InnerAsDictionary (arrays should overrride this behavior for example).
        /// </summary>
        /// <param name="templatingContext"> The templating context. </param>
        /// <returns> An instance of IEnumerator or null. </returns>
        protected virtual IEnumerator CoreGetAssociativeObjectEnumerator(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            // default (except for Array)
            return(((IDictionary)this.InnerAsDictionary).GetEnumerator());
        }
Exemple #17
0
        /// <summary>
        /// Gets the value of the current associative object instance. Derived types can override the default behavior of returning 'this' (properties should overrride this behavior for example).
        /// </summary>
        /// <param name="templatingContext"> The templating context. </param>
        /// <returns> A value or null. </returns>
        protected virtual object CoreGetAssociativeObjectValue(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            // default (except for Property)
            return(this);
        }
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            // add global cleanup into context to suppro this....
            //templatingContext.IteratorModels.Push(this.Dynamic.Content);
            // BUG: this never gets popped !!!
        }
        /// <summary>
        /// Re-orders an enumerable of values, yielding a re-ordered enumerable.
        /// </summary>
        /// <param name="templatingContext"> The templating context. </param>
        /// <param name="values"> </param>
        /// <returns> </returns>
        public IEnumerable EvaluateSort(ITemplatingContext templatingContext, IEnumerable values)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            templatingContext.LaunchDebugger();

            return(values);
        }
Exemple #20
0
		protected override object CoreEvaluateExpression(ITemplatingContext templatingContext)
		{
			DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

			return this.__;
		}
        /// <summary>
        /// Gets the value of the current associative object instance.
        /// </summary>
        /// <param name="templatingContext"> The templating context. </param>
        /// <returns> A value or null. </returns>
        public object GetAssociativeObjectValue(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            templatingContext.LaunchDebugger();

            return(this);
        }
        /// <summary>
        /// Gets the dictionary enumerator for the current associative object instance.
        /// </summary>
        /// <param name="templatingContext"> The templating context. </param>
        /// <returns> An instance of IDictionaryEnumerator or null. </returns>
        public IDictionaryEnumerator GetAssociativeObjectEnumeratorDict(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            templatingContext.LaunchDebugger();

            return(null);
        }
        /// <summary>
        /// Evaluates at run-time, an expression tree yielding an object value result.
        /// </summary>
        /// <param name="templatingContext"> The templating context. </param>
        /// <returns> An expression return value or null. </returns>
        public object EvaluateExpression(ITemplatingContext templatingContext)
        {
            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            templatingContext.LaunchDebugger();

            return(null);
        }
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            string   name;
            Assembly assembly;
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

            Type[] exportedTypes;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            name = templatingContext.Tokenizer.ExpandTokens(this.Name, dynamicWildcardTokenReplacementStrategy);

            if (SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(name))
            {
                templatingContext.ClearReferences();
                return;
            }

            assembly = templatingContext.Input.LoadAssembly(name);

            if ((object)assembly == null)
            {
                throw new InvalidOperationException(string.Format("Failed to reference the assembly '{0}'.", name));
            }

            exportedTypes = assembly.GetExportedTypes();

            if ((object)exportedTypes != null)
            {
                foreach (Type exportedType in exportedTypes)
                {
                    var _exportedTypeInfo = exportedType.GetTypeInfo();

                    if (!_exportedTypeInfo.IsAbstract &&
                        typeof(IXmlObject).IsAssignableFrom(exportedType))
                    {
                        if (typeof(IXmlTextObject).IsAssignableFrom(exportedType))
                        {
                            templatingContext.SetReference(exportedType);
                        }
                        else
                        {
                            templatingContext.AddReference(exportedType);
                        }
                    }
                }
            }
        }
Exemple #25
0
        protected override object CoreEvaluateExpression(ITemplatingContext templatingContext)
        {
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            return(this);
        }
Exemple #26
0
        protected override void CoreConditionalIterationInitialize(ITemplatingContext templatingContext)
        {
            object value;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            if ((object)this.Initializer != null)
            {
                value = this.Initializer.EvaluateExpression(templatingContext);
            }
        }
		protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
		{
			string text;
			DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

			text = templatingContext.Tokenizer.ExpandTokens(this.Text, dynamicWildcardTokenReplacementStrategy);

			templatingContext.Output.CurrentTextWriter.Write(text);
		}
Exemple #28
0
        protected override void CoreConditionalIterationStep(ITemplatingContext templatingContext, uint indexOneBase)
        {
            object value;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            if ((object)this.Iterator != null)
            {
                value = this.Iterator.EvaluateExpression(templatingContext);
            }
        }
Exemple #29
0
		protected override IEnumerable CoreEvaluateSort(ITemplatingContext templatingContext, IEnumerable values)
		{
			DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;
			object obj;
			Type objType;
			Dictionary<object, IComparable> temp;
			IComparable comparable;

			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			if ((object)values == null)
				throw new ArgumentNullException(nameof(values));

			dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

			if ((object)this.Compare != null)
			{
				temp = new Dictionary<object, IComparable>();

				foreach (object value in values)
				{
					templatingContext.IteratorModels.Push(value);

					obj = this.Compare.EvaluateExpression(templatingContext);

					if ((object)obj == null)
						continue;

					templatingContext.IteratorModels.Pop();

					objType = obj.GetType();

					if (!typeof(IComparable).IsAssignableFrom(objType))
						throw new InvalidOperationException(string.Format("The target expression of ordering is not assignable to type '{0}'.", typeof(IComparable).FullName));

					comparable = (IComparable)obj;

					temp.Add(value, comparable);
				}

				if (this.Ascending)
					values = values.Cast<object>().OrderBy(o => temp[o], new ComparableComparer());
				else
					values = values.Cast<object>().OrderByDescending(o => temp[o], new ComparableComparer());
			}

			return values;
		}
Exemple #30
0
        protected override object CoreEvaluateExpression(ITemplatingContext templatingContext)
        {
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;
            object obj;

            if ((object)templatingContext == null)
                throw new ArgumentNullException("templatingContext");

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            if (!dynamicWildcardTokenReplacementStrategy.GetByPath(this.Name, out obj))
                throw new InvalidOperationException(string.Format("The facet name '{0}' was not found on the target model.", this.Name));

            return obj;
        }
		protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
		{
			DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

			if ((object)this.Items != null)
			{
				foreach (ITemplateMechanism templateMechanism in this.Items)
					templateMechanism.ExpandTemplate(templatingContext);
			}
		}
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            string text;
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            text = templatingContext.Tokenizer.ExpandTokens(this.Text, dynamicWildcardTokenReplacementStrategy);

            templatingContext.Output.CurrentTextWriter.Write(text);
        }
        public void ExpandTemplate(ITemplatingContext templatingContext)
        {
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

            if ((object)templatingContext == null)
                throw new ArgumentNullException("templatingContext");

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            if (this.IsScopeBlock)
                templatingContext.VariableTables.Push(new Dictionary<string, object>());

            this.CoreExpandTemplate(templatingContext);

            if (this.IsScopeBlock)
                templatingContext.VariableTables.Pop();
        }
Exemple #34
0
		protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
		{
			string name;
			Assembly assembly;
			DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;
			Type[] exportedTypes;

			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

			name = templatingContext.Tokenizer.ExpandTokens(this.Name, dynamicWildcardTokenReplacementStrategy);

			if (SolderLegacyInstanceAccessor.DataTypeFascadeLegacyInstance.IsNullOrWhiteSpace(name))
			{
				templatingContext.ClearReferences();
				return;
			}

			assembly = templatingContext.Input.LoadAssembly(name);

			if ((object)assembly == null)
				throw new InvalidOperationException(string.Format("Failed to reference the assembly '{0}'.", name));

			exportedTypes = assembly.GetExportedTypes();

			if ((object)exportedTypes != null)
			{
				foreach (Type exportedType in exportedTypes)
				{
					var _exportedTypeInfo = exportedType.GetTypeInfo();

					if (!_exportedTypeInfo.IsAbstract &&
						typeof(IXmlObject).IsAssignableFrom(exportedType))
					{
						if (typeof(IXmlTextObject).IsAssignableFrom(exportedType))
							templatingContext.SetReference(exportedType);
						else
							templatingContext.AddReference(exportedType);
					}
				}
			}
		}
        public override WorkUnitResult Execute(ITemplatingContext context)
        {
            Stopwatch localTimer = new Stopwatch();

            // copy resources to output dir
            string target = this.Destination ?? this.ResourcePath;

            if (this.Destination != null)
            {
                TraceSources.TemplateSource.TraceInformation("Copying resource: {0} => {1}",
                                                             this.ResourcePath,
                                                             this.Destination);
            }
            else
            {
                TraceSources.TemplateSource.TraceInformation("Copying resource: {0}", this.ResourcePath);
            }


            using (Stream streamSrc = this.FileProvider.OpenFile(this.ResourcePath, FileMode.Open))
                using (Stream streamDest = context.OutputFileProvider.OpenFile(target, FileMode.Create))
                {
                    Stream outStream = streamSrc;
                    for (int i = 0; i < this.Transforms.Length; i++)
                    {
                        TraceSources.TemplateSource.TraceInformation("Applying '{0}' to resource: {1}",
                                                                     this.Transforms[i].GetType().Name,
                                                                     this.ResourcePath);
                        Stream oldStream = outStream;
                        outStream = this.Transforms[i].Transform(outStream);
                        oldStream.Dispose();
                    }
                    outStream.CopyTo(streamDest);
                    streamDest.Close();
                    outStream.Dispose();
                }

            return(new WorkUnitResult
            {
                WorkUnit = this,
                Duration = (long)Math.Round(((double)localTimer.ElapsedTicks / Stopwatch.Frequency) * 1, 000, 000)
            });
        }
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            if ((object)this.Items != null)
            {
                foreach (ITemplateMechanism templateMechanism in this.Items)
                {
                    templateMechanism.ExpandTemplate(templatingContext);
                }
            }
        }
Exemple #37
0
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;
            object obj = null;
            string token;

            if ((object)templatingContext == null)
                throw new ArgumentNullException("templatingContext");

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            token = templatingContext.Tokenizer.ExpandTokens(this.Token, dynamicWildcardTokenReplacementStrategy);

            if ((object)this.Expression != null)
                obj = this.Expression.EvaluateExpression(templatingContext);

            if (!dynamicWildcardTokenReplacementStrategy.SetByPath(token, obj))
                throw new InvalidOperationException(string.Format("The facet name '{0}' was not found on the target model.", token));
        }
Exemple #38
0
        protected override object CoreEvaluateExpression(ITemplatingContext templatingContext)
        {
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;
            object obj;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            if (!dynamicWildcardTokenReplacementStrategy.GetByToken(this.Name, out obj))
            {
                throw new InvalidOperationException(string.Format("The facet name '{0}' was not found on the target model.", this.Name));
            }

            return(obj);
        }
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            object obj;
            bool   conditional;
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            if ((object)this.Condition == null)
            {
                return;
            }

            obj = this.Condition.EvaluateExpression(templatingContext);

            if ((object)obj != null && !(obj is bool) && !(obj is bool?))
            {
                throw new InvalidOperationException(string.Format("The conditional branch expression has evaluated to a non-null value with an unsupported type '{0}'; only '{1}' and '{2}' types are supported.", obj.GetType().FullName, typeof(bool).FullName, typeof(bool?).FullName));
            }

            conditional = ((bool)(obj ?? false));

            if (conditional || !this.Affirmative)
            {
                if ((object)this.Then != null)
                {
                    this.Then.ExpandTemplate(templatingContext);
                }
            }
            else
            {
                if ((object)this.Else != null)
                {
                    this.Else.ExpandTemplate(templatingContext);
                }
            }
        }
		protected override IEnumerable CoreEvaluateSort(ITemplatingContext templatingContext, IEnumerable values)
		{
			DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			if ((object)values == null)
				throw new ArgumentNullException(nameof(values));

			dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

			if ((object)this.Items != null)
			{
				foreach (ISortXmlObject child in this.Items)
					values = child.EvaluateSort(templatingContext, values);
			}

			return values;
		}
Exemple #41
0
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            string message;
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

            if ((object)templatingContext == null)
                throw new ArgumentNullException("templatingContext");

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            message = templatingContext.Tokenizer.ExpandTokens(this.Message, dynamicWildcardTokenReplacementStrategy);

            if (this.Newline)
                templatingContext.Output.LogTextWriter.WriteLine("{0}:\t{1}", this.Severity, message);
            else
                templatingContext.Output.LogTextWriter.Write("{0}:\t{1}", this.Severity, message);

            if (this.Severity == Severity.Error)
                throw new InvalidOperationException(string.Format("A user defined error occured: '{0}'", message));
        }
Exemple #42
0
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            string name;
            ITemplateXmlObject fragment;
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

            if ((object)templatingContext == null)
                throw new ArgumentNullException("templatingContext");

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            name = templatingContext.Tokenizer.ExpandTokens(this.Name, dynamicWildcardTokenReplacementStrategy);

            fragment = templatingContext.Input.LoadFragment(name);

            if ((object)fragment == null)
                throw new InvalidOperationException(string.Format("Failed to import the fragment '{0}'.", name));

            fragment.ExpandTemplate(templatingContext);
        }
        public override WorkUnitResult Execute(ITemplatingContext context)
        {
            Stopwatch localTimer = new Stopwatch();

            // copy resources to output dir
            string target = this.Destination ?? this.ResourcePath;

            if (this.Destination != null)
            {
                TraceSources.TemplateSource.TraceInformation("Copying resource: {0} => {1}",
                                                             this.ResourcePath,
                                                             this.Destination);
            }
            else
                TraceSources.TemplateSource.TraceInformation("Copying resource: {0}", this.ResourcePath);
            

            using (Stream streamSrc = this.FileProvider.OpenFile(this.ResourcePath, FileMode.Open))
            using (Stream streamDest = context.OutputFileProvider.OpenFile(target, FileMode.Create))
            {
                Stream outStream = streamSrc;
                for (int i = 0; i < this.Transforms.Length; i++)
                {
                    TraceSources.TemplateSource.TraceInformation("Applying '{0}' to resource: {1}",
                                                                 this.Transforms[i].GetType().Name,
                                                                 this.ResourcePath);
                    Stream oldStream = outStream;
                    outStream = this.Transforms[i].Transform(outStream);
                    oldStream.Dispose();
                }
                outStream.CopyTo(streamDest);
                streamDest.Close();
                outStream.Dispose();
            }

            return new WorkUnitResult
                       {
                           WorkUnit = this,
                           Duration = (long)Math.Round(((double)localTimer.ElapsedTicks / Stopwatch.Frequency) * 1,000,000)
                       };
        }
		public static object printf(ITemplatingContext context, string[] parameters)
		{
			const int CNT_P = 2; // token, format
			object value;

			if ((object)context == null)
				throw new ArgumentNullException(nameof(context));

			if ((object)parameters == null)
				throw new ArgumentNullException(nameof(parameters));

			if (parameters.Length != CNT_P)
				throw new InvalidOperationException(string.Format("printf expects '{1}' parameter(s) but received '{0}' parameter(s).", parameters.Length, CNT_P));

			var x = context.GetDynamicWildcardTokenReplacementStrategy();

			if (!x.GetByToken(parameters[0], out value))
				return null;

			return value.SafeToString(parameters[1]);
		}
Exemple #45
0
		protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
		{
			string token;
			DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

			token = templatingContext.Tokenizer.ExpandTokens(this.Token, dynamicWildcardTokenReplacementStrategy);

			if (!templatingContext.CurrentVariableTable.ContainsKey(token))
			{
				if (templatingContext.Tokenizer.StrictMatching)
					throw new InvalidOperationException(string.Format("When strict matching semantics are enabled, the variable '{0}' cannot be freed if it has not been defined previously in the given scope block.", token));

				return;
			}

			templatingContext.CurrentVariableTable.Remove(token);
		}
        public void ExpandTemplate(ITemplatingContext templatingContext)
        {
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            if (this.IsScopeBlock)
            {
                templatingContext.VariableTables.Push(new Dictionary <string, object>());
            }

            this.CoreExpandTemplate(templatingContext);

            if (this.IsScopeBlock)
            {
                templatingContext.VariableTables.Pop();
            }
        }
		protected override object CoreEvaluateExpression(ITemplatingContext templatingContext)
		{
			object ovalue;
			string svalue;
			DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

			if ((object)this.Content != null)
				ovalue = ((IExpressionXmlObject)this.Content).EvaluateExpression(templatingContext);
			else
				ovalue = null;

			svalue = ovalue as string;

			if ((object)svalue != null)
				ovalue = templatingContext.Tokenizer.ExpandTokens(svalue, dynamicWildcardTokenReplacementStrategy);

			return ovalue;
		}
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            string aqtn;
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;
            ISourceStrategy sourceStrategy;
            Type sourceStrategyType;
            object source;

            if ((object)templatingContext == null)
                throw new ArgumentNullException("templatingContext");

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            aqtn = templatingContext.Tokenizer.ExpandTokens(this.AssemblyQualifiedTypeName, dynamicWildcardTokenReplacementStrategy);

            sourceStrategyType = Type.GetType(aqtn, false);

            if ((object)sourceStrategyType == null)
                throw new InvalidOperationException(string.Format("Failed to load the source strategy type '{0}' via Type.GetType(..).", aqtn));

            if (!typeof(ISourceStrategy).IsAssignableFrom(sourceStrategyType))
                throw new InvalidOperationException(string.Format("The source strategy type is not assignable to type '{0}'.", typeof(ISourceStrategy).FullName));

            sourceStrategy = (ISourceStrategy)Activator.CreateInstance(sourceStrategyType);

            source = sourceStrategy.GetSourceObject("", new Dictionary<string, IList<string>>());

            templatingContext.IteratorModels.Push(source);

            if ((object)this.Items != null)
            {
                foreach (ITemplateMechanism templateMechanism in this.Items)
                    templateMechanism.ExpandTemplate(templatingContext);
            }

            templatingContext.IteratorModels.Pop();
        }
Exemple #49
0
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;
            string token;

            if ((object)templatingContext == null)
                throw new ArgumentNullException("templatingContext");

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            token = templatingContext.Tokenizer.ExpandTokens(this.Token, dynamicWildcardTokenReplacementStrategy);

            if (templatingContext.CurrentVariableTable.ContainsKey(token))
            {
                if (templatingContext.Tokenizer.StrictMatching)
                    throw new InvalidOperationException(string.Format("When strict matching semantics are enabled, the variable '{0}' cannot be defined more than once in a given scope block.", token));

                // [email protected]@2012-08-01: changed the semantics of this to re-allocate on non-strict mode instead of ignore
                //return;
                templatingContext.CurrentVariableTable.Remove(token);
            }

            templatingContext.CurrentVariableTable.Add(token, null);
        }
Exemple #50
0
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            string             name;
            ITemplateXmlObject fragment;
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            name = templatingContext.Tokenizer.ExpandTokens(this.Name, dynamicWildcardTokenReplacementStrategy);

            fragment = templatingContext.Input.LoadTemplate(name);

            if ((object)fragment == null)
            {
                throw new InvalidOperationException(string.Format("Failed to import the fragment '{0}'.", name));
            }

            fragment.ExpandTemplate(templatingContext);
        }
Exemple #51
0
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            object valueObj = null, defaultObj = null;
            string output;
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            if ((object)this.Text != null)
            {
                valueObj = this.Text.EvaluateExpression(templatingContext);
            }

            if ((object)this.Default != null)
            {
                defaultObj = this.Default.EvaluateExpression(templatingContext);
            }

            output = valueObj.SafeToString(this.Format, defaultObj.SafeToString(string.Empty, null, true), this.DoFvIsNoW);

            output = templatingContext.Tokenizer.ExpandTokens(output, dynamicWildcardTokenReplacementStrategy);

            if (this.Newline)
            {
                templatingContext.Output.CurrentTextWriter.WriteLine(output);
            }
            else
            {
                templatingContext.Output.CurrentTextWriter.Write(output);
            }
        }
 private void contextRegistry_ActiveContextChanged(object sender, EventArgs e)
 {
     TemplateContext = m_contextRegistry.GetMostRecentContext<ITemplatingContext>();
 }
Exemple #53
0
		protected override void CoreConditionalIterationTerminate(ITemplatingContext templatingContext)
		{
			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));
		}
Exemple #54
0
		public static void RegisterWellKnownTokenReplacementStrategies(this Tokenizer tokenizer, ITemplatingContext templatingContext)
		{
			if ((object)tokenizer == null)
				throw new ArgumentNullException(nameof(tokenizer));

			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));

			tokenizer.TokenReplacementStrategies.Add("StaticPropertyResolver", new DynamicValueTokenReplacementStrategy(DynamicValueTokenReplacementStrategy.StaticPropertyResolver));
			tokenizer.TokenReplacementStrategies.Add("StaticMethodResolver", new DynamicValueTokenReplacementStrategy(DynamicValueTokenReplacementStrategy.StaticMethodResolver));
			tokenizer.TokenReplacementStrategies.Add("js", new ContextualDynamicValueTokenReplacementStrategy<ITemplatingContext>(JavaScriptConstruct.JavaScriptExpressionResolver, templatingContext));
			tokenizer.TokenReplacementStrategies.Add("printf", new ContextualDynamicValueTokenReplacementStrategy<ITemplatingContext>(printf, templatingContext));
		}
Exemple #55
0
		protected override void CoreConditionalIterationStep(ITemplatingContext templatingContext, uint indexOneBase)
		{
			if ((object)templatingContext == null)
				throw new ArgumentNullException(nameof(templatingContext));
		}
 protected abstract void CoreConditionalIterationStep(ITemplatingContext templatingContext, uint indexOneBase);
Exemple #57
0
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            string aqtn;
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;
            ISourceStrategy sourceStrategy;
            Type            sourceStrategyType;
            string          sourceFilePath, var;
            object          source;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            aqtn           = templatingContext.Tokenizer.ExpandTokens(this.AssemblyQualifiedTypeName, dynamicWildcardTokenReplacementStrategy);
            sourceFilePath = templatingContext.Tokenizer.ExpandTokens(this.SourceFilePath, dynamicWildcardTokenReplacementStrategy);
            var            = templatingContext.Tokenizer.ExpandTokens(this.Var, dynamicWildcardTokenReplacementStrategy);

            sourceStrategyType = Type.GetType(aqtn, false);

            if ((object)sourceStrategyType == null)
            {
                throw new InvalidOperationException(string.Format("Failed to load the source strategy type '{0}' via Type.GetType(..).", aqtn));
            }

            if (!typeof(ISourceStrategy).IsAssignableFrom(sourceStrategyType))
            {
                throw new InvalidOperationException(string.Format("The source strategy type is not assignable to type '{0}'.", typeof(ISourceStrategy).FullName));
            }

            sourceStrategy = (ISourceStrategy)Activator.CreateInstance(sourceStrategyType);

            source = sourceStrategy.GetSourceObject(/*templatingContext, */ sourceFilePath, templatingContext.Properties);

            if (!this.UseAlloc)
            {
                templatingContext.IteratorModels.Push(source);

                if ((object)this.Items != null)
                {
                    foreach (ITemplateMechanism templateMechanism in this.Items)
                    {
                        templateMechanism.ExpandTemplate(templatingContext);
                    }
                }

                templatingContext.IteratorModels.Pop();
            }
            else
            {
                if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(var))
                {
                    IExpressionContainerConstruct expressionContainerConstruct;
                    ValueConstruct valueConstruct;

                    new AllocConstruct()
                    {
                        Token = var
                    }.ExpandTemplate(templatingContext);

                    expressionContainerConstruct = new ExpressionContainerConstruct();

                    valueConstruct = new ValueConstruct()
                    {
                        __ = source
                    };

                    ((IContentContainerXmlObject <IExpressionXmlObject>)expressionContainerConstruct).Content = valueConstruct;

                    new AssignConstruct()
                    {
                        Token      = var,
                        Expression = expressionContainerConstruct
                    }.ExpandTemplate(templatingContext);
                }
            }
        }
 protected abstract void CoreConditionalIterationTerminate(ITemplatingContext templatingContext);
        protected override void CoreExpandTemplate(ITemplatingContext templatingContext)
        {
            const uint MAX_ITERATIONS_INFINITE_LOOP_CHECK = 999999;
            string     varIx;
            uint       index = 1;       // one-based
            DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy;

            if ((object)templatingContext == null)
            {
                throw new ArgumentNullException(nameof(templatingContext));
            }

            dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy();

            varIx = templatingContext.Tokenizer.ExpandTokens(this.VarIx, dynamicWildcardTokenReplacementStrategy);

            if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varIx))
            {
                new AllocConstruct()
                {
                    Token = varIx
                }.ExpandTemplate(templatingContext);
            }

            this.CoreConditionalIterationInitialize(templatingContext);

            // DO NOT USE REAL FOR LOOP HERE
            while (true)
            {
                if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varIx))
                {
                    IExpressionContainerConstruct expressionContainerConstruct;
                    ValueConstruct valueConstruct;

                    expressionContainerConstruct = new ExpressionContainerConstruct();

                    valueConstruct = new ValueConstruct()
                    {
                        Type = typeof(int).FullName,
                        __   = index
                    };

                    ((IContentContainerXmlObject <IExpressionXmlObject>)expressionContainerConstruct).Content = valueConstruct;

                    new AssignConstruct()
                    {
                        Token      = varIx,
                        Expression = expressionContainerConstruct
                    }.ExpandTemplate(templatingContext);
                }

                if (index > MAX_ITERATIONS_INFINITE_LOOP_CHECK)
                {
                    throw new InvalidOperationException(string.Format("The conditional iteration construct has exceeded the maximun number of iterations '{0}'; this is an infinite loop prevention mechansim.", MAX_ITERATIONS_INFINITE_LOOP_CHECK));
                }

                if (this.Precondition)
                {
                    if (!this.CheckCondition(templatingContext))
                    {
                        break;
                    }
                }

                if ((object)this.Body != null)
                {
                    this.Body.ExpandTemplate(templatingContext);
                }

                this.CoreConditionalIterationStep(templatingContext, index);

                if (!this.Precondition)
                {
                    if (!this.CheckCondition(templatingContext))
                    {
                        break;
                    }
                }

                index++;
            }

            this.CoreConditionalIterationTerminate(templatingContext);

            if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varIx))
            {
                new FreeConstruct()
                {
                    Token = varIx
                }.ExpandTemplate(templatingContext);
            }
        }