Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / XamlBuildTask / Microsoft / Build / Tasks / Xaml / CompilationPass2TaskInternal.cs / 1606072 / CompilationPass2TaskInternal.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace Microsoft.Build.Tasks.Xaml
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Xaml;
using System.Xaml.Schema;
using System.Xml;
using System.Reflection;
using System.Runtime;
internal class CompilationPass2TaskInternal : MarshalByRefObject, IExceptionLogger
{
IList applicationMarkup;
IList references;
IList logData;
public IList ApplicationMarkup
{
get
{
if (this.applicationMarkup == null)
{
this.applicationMarkup = new List();
}
return this.applicationMarkup;
}
set
{
this.applicationMarkup = value;
}
}
public string AssemblyName
{ get; set; }
public string LocalAssemblyReference
{ get; set; }
public string RootNamespace
{ get; set; }
public IList LogData
{
get
{
if (this.logData == null)
{
this.logData = new List();
}
return this.logData;
}
}
public IList References
{
get
{
if (this.references == null)
{
this.references = new List();
}
return this.references;
}
set
{
this.references = value;
}
}
public bool Execute()
{
try
{
if (this.ApplicationMarkup == null || this.ApplicationMarkup.Count == 0)
{
return true;
}
IList loadedAssemblyList = null;
if (this.References != null)
{
loadedAssemblyList = XamlBuildTaskServices.Load(this.References);
}
Assembly localAssembly = null;
if (LocalAssemblyReference != null)
{
try
{
localAssembly = XamlBuildTaskServices.Load(LocalAssemblyReference);
loadedAssemblyList.Add(localAssembly);
}
catch (FileNotFoundException e)
{
LogException(e, e.FileName);
return false;
}
}
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(XamlBuildTaskServices.ReflectionOnlyAssemblyResolve);
XamlNsReplacingContext wxsc = new XamlNsReplacingContext(loadedAssemblyList, localAssembly.GetName().Name, this.AssemblyName);
bool foundValidationErrors = false;
foreach (string app in ApplicationMarkup)
{
try
{
if (!ProcessMarkupItem(app, wxsc, localAssembly))
{
foundValidationErrors = true;
}
}
catch (Exception e)
{
if (Fx.IsFatal(e))
{
throw;
}
LogException(e, app);
return false;
}
}
return !foundValidationErrors;
}
catch (Exception e)
{
if (Fx.IsFatal(e))
{
throw;
}
// Log unknown errors that do not originate from the task.
// Assumes that all known errors are logged when the exception is thrown.
if (!(e is LoggedException))
{
LogException(e);
}
return false;
}
}
public Exception LogException(Exception exception, string fileName)
{
return LogException(exception, fileName, 0, 0);
}
public Exception LogException(Exception exception, string fileName, int lineNumber, int linePosition)
{
this.LogData.Add(new LogData()
{
Message = exception.Message,
FileName = fileName,
LineNumber = lineNumber,
LinePosition = linePosition
});
return new LoggedException(exception);
}
public Exception LogException(Exception exception)
{
this.LogData.Add(new LogData()
{
Message = exception.Message,
LineNumber = 0,
LinePosition = 0
});
return new LoggedException(exception);
}
bool ProcessMarkupItem(string markupItem, XamlNsReplacingContext wxsc, Assembly localAssembly)
{
XamlXmlReaderSettings settings = new XamlXmlReaderSettings() { LocalAssembly = localAssembly, ProvideLineInfo = true, AllowProtectedMembersOnRoot = true };
using (StreamReader streamReader = new StreamReader(markupItem))
{
var xamlReader = new XamlXmlReader(XmlReader.Create(streamReader), wxsc, settings);
ClassValidator validator = new ClassValidator(this, markupItem, localAssembly, this.RootNamespace);
IList validationErrors = null;
if (validator.ValidateXaml(xamlReader, false, this.AssemblyName, out validationErrors))
{
return true;
}
else
{
foreach (LogData logData in validationErrors)
{
this.LogData.Add(logData);
}
return false;
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace Microsoft.Build.Tasks.Xaml
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Xaml;
using System.Xaml.Schema;
using System.Xml;
using System.Reflection;
using System.Runtime;
internal class CompilationPass2TaskInternal : MarshalByRefObject, IExceptionLogger
{
IList applicationMarkup;
IList references;
IList logData;
public IList ApplicationMarkup
{
get
{
if (this.applicationMarkup == null)
{
this.applicationMarkup = new List();
}
return this.applicationMarkup;
}
set
{
this.applicationMarkup = value;
}
}
public string AssemblyName
{ get; set; }
public string LocalAssemblyReference
{ get; set; }
public string RootNamespace
{ get; set; }
public IList LogData
{
get
{
if (this.logData == null)
{
this.logData = new List();
}
return this.logData;
}
}
public IList References
{
get
{
if (this.references == null)
{
this.references = new List();
}
return this.references;
}
set
{
this.references = value;
}
}
public bool Execute()
{
try
{
if (this.ApplicationMarkup == null || this.ApplicationMarkup.Count == 0)
{
return true;
}
IList loadedAssemblyList = null;
if (this.References != null)
{
loadedAssemblyList = XamlBuildTaskServices.Load(this.References);
}
Assembly localAssembly = null;
if (LocalAssemblyReference != null)
{
try
{
localAssembly = XamlBuildTaskServices.Load(LocalAssemblyReference);
loadedAssemblyList.Add(localAssembly);
}
catch (FileNotFoundException e)
{
LogException(e, e.FileName);
return false;
}
}
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(XamlBuildTaskServices.ReflectionOnlyAssemblyResolve);
XamlNsReplacingContext wxsc = new XamlNsReplacingContext(loadedAssemblyList, localAssembly.GetName().Name, this.AssemblyName);
bool foundValidationErrors = false;
foreach (string app in ApplicationMarkup)
{
try
{
if (!ProcessMarkupItem(app, wxsc, localAssembly))
{
foundValidationErrors = true;
}
}
catch (Exception e)
{
if (Fx.IsFatal(e))
{
throw;
}
LogException(e, app);
return false;
}
}
return !foundValidationErrors;
}
catch (Exception e)
{
if (Fx.IsFatal(e))
{
throw;
}
// Log unknown errors that do not originate from the task.
// Assumes that all known errors are logged when the exception is thrown.
if (!(e is LoggedException))
{
LogException(e);
}
return false;
}
}
public Exception LogException(Exception exception, string fileName)
{
return LogException(exception, fileName, 0, 0);
}
public Exception LogException(Exception exception, string fileName, int lineNumber, int linePosition)
{
this.LogData.Add(new LogData()
{
Message = exception.Message,
FileName = fileName,
LineNumber = lineNumber,
LinePosition = linePosition
});
return new LoggedException(exception);
}
public Exception LogException(Exception exception)
{
this.LogData.Add(new LogData()
{
Message = exception.Message,
LineNumber = 0,
LinePosition = 0
});
return new LoggedException(exception);
}
bool ProcessMarkupItem(string markupItem, XamlNsReplacingContext wxsc, Assembly localAssembly)
{
XamlXmlReaderSettings settings = new XamlXmlReaderSettings() { LocalAssembly = localAssembly, ProvideLineInfo = true, AllowProtectedMembersOnRoot = true };
using (StreamReader streamReader = new StreamReader(markupItem))
{
var xamlReader = new XamlXmlReader(XmlReader.Create(streamReader), wxsc, settings);
ClassValidator validator = new ClassValidator(this, markupItem, localAssembly, this.RootNamespace);
IList validationErrors = null;
if (validator.ValidateXaml(xamlReader, false, this.AssemblyName, out validationErrors))
{
return true;
}
else
{
foreach (LogData logData in validationErrors)
{
this.LogData.Add(logData);
}
return false;
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SafeProcessHandle.cs
- FigureParaClient.cs
- DetailsViewUpdateEventArgs.cs
- UriScheme.cs
- securestring.cs
- DiffuseMaterial.cs
- DataBindingsDialog.cs
- safePerfProviderHandle.cs
- IncrementalReadDecoders.cs
- ResourceReferenceExpression.cs
- Int32CollectionConverter.cs
- WebSysDisplayNameAttribute.cs
- TypeExtensionSerializer.cs
- Ref.cs
- RegistrationProxy.cs
- LifetimeServices.cs
- WindowsScroll.cs
- HtmlTableRowCollection.cs
- DayRenderEvent.cs
- ProviderBase.cs
- SafeNativeMethods.cs
- StorageBasedPackageProperties.cs
- RelationshipEndMember.cs
- TreeNode.cs
- DefaultWorkflowSchedulerService.cs
- Ticks.cs
- MemberRelationshipService.cs
- CssTextWriter.cs
- odbcmetadatafactory.cs
- AutomationPeer.cs
- HtmlInputText.cs
- IdentityModelStringsVersion1.cs
- DataTableReaderListener.cs
- ForceCopyBuildProvider.cs
- BuildProvider.cs
- base64Transforms.cs
- DispatcherEventArgs.cs
- XsltCompileContext.cs
- ProfileService.cs
- SplineQuaternionKeyFrame.cs
- ZipIOExtraField.cs
- WebPartsPersonalization.cs
- CachingHintValidation.cs
- StreamInfo.cs
- CompiledXpathExpr.cs
- TrustSection.cs
- StateDesigner.cs
- ValueConversionAttribute.cs
- DigitShape.cs
- IntegerValidatorAttribute.cs
- IPAddressCollection.cs
- ObjectDataSourceSelectingEventArgs.cs
- ApplicationFileCodeDomTreeGenerator.cs
- GraphicsContainer.cs
- AnnotationMap.cs
- WebPartDisplayModeCancelEventArgs.cs
- SHA384Managed.cs
- CheckBoxPopupAdapter.cs
- SHA512Managed.cs
- XamlTreeBuilderBamlRecordWriter.cs
- ChtmlPhoneCallAdapter.cs
- RegexCapture.cs
- WaitHandle.cs
- ContextDataSourceContextData.cs
- CurrentTimeZone.cs
- SchemaElementDecl.cs
- BindMarkupExtensionSerializer.cs
- ObjectDataSourceSelectingEventArgs.cs
- FileUtil.cs
- ModuleElement.cs
- DirectoryRedirect.cs
- DataSvcMapFile.cs
- DiffuseMaterial.cs
- JobPageOrder.cs
- ServerProtocol.cs
- DataRowComparer.cs
- BrowserCapabilitiesCompiler.cs
- TagPrefixCollection.cs
- EntitySqlQueryCacheKey.cs
- DescendantOverDescendantQuery.cs
- DataGridTextBoxColumn.cs
- ProtectedConfigurationSection.cs
- Condition.cs
- GenericAuthenticationEventArgs.cs
- MethodBody.cs
- CodeSnippetStatement.cs
- MarkupExtensionReturnTypeAttribute.cs
- ConvertBinder.cs
- COM2EnumConverter.cs
- Resources.Designer.cs
- IdentityHolder.cs
- MonitorWrapper.cs
- ComplexLine.cs
- TraceSection.cs
- FontSizeConverter.cs
- XpsResource.cs
- remotingproxy.cs
- AliasExpr.cs
- LOSFormatter.cs
- DataGridViewColumnTypePicker.cs