Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / ComIntegration / ComIntegrationManifestGenerator.cs / 1 / ComIntegrationManifestGenerator.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.ComIntegration
{
using System;
using System.ServiceModel;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
using System.Collections;
using System.Reflection;
// this is a heavily modified version of the Win32ManifestGenerator found in the CLR
internal class ComIntegrationManifestGenerator : MarshalByRefObject
{
internal static void GenerateManifestCollectionFile(Guid[] manifests, String strAssemblyManifestFileName, String assemblyName)
{
String title = "";
String asmTitle = "";
String asmEnd = " ";
String path = Path.GetDirectoryName(strAssemblyManifestFileName);
if (!String.IsNullOrEmpty(path) && !Directory.Exists(path))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.DirectoryNotFound(path));
}
Stream s = null;
try
{
// manifest title
s = File.Create(strAssemblyManifestFileName);
WriteUTFChars(s, title + Environment.NewLine);
WriteUTFChars(s, asmTitle + Environment.NewLine);
WriteUTFChars(s, " " + Environment.NewLine, 8);
for (int i = 0; i < manifests.Length; i++)
{
WriteUTFChars(s, "" + Environment.NewLine, 4);
WriteUTFChars(s, "" + Environment.NewLine, 8);
WriteUTFChars(s, " " + Environment.NewLine, 16);
WriteUTFChars(s, " " + Environment.NewLine, 8);
WriteUTFChars(s, " " + Environment.NewLine, 4);
}
WriteUTFChars(s, asmEnd);
}
catch (Exception e)
{
if (e is NullReferenceException || e is SEHException)
{
throw;
}
s.Close();
File.Delete(strAssemblyManifestFileName);
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ManifestCreationFailed(strAssemblyManifestFileName, e.Message));
}
s.Close();
}
internal static void GenerateWin32ManifestFile(Type[] aTypes, String strAssemblyManifestFileName, String assemblyName)
{
String title = "";
String asmTitle = "";
String path = Path.GetDirectoryName(strAssemblyManifestFileName);
if (!String.IsNullOrEmpty(path) && !Directory.Exists(path))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.DirectoryNotFound(path));
}
Stream s = null;
try
{
// manifest title
s = File.Create(strAssemblyManifestFileName);
WriteUTFChars(s, title + Environment.NewLine);
WriteUTFChars(s, asmTitle + Environment.NewLine);
WriteUTFChars(s, " " + Environment.NewLine, 8);
AsmCreateWin32ManifestFile(s, aTypes);
}
catch (Exception e)
{
if (e is NullReferenceException || e is SEHException)
{
throw;
}
s.Close();
File.Delete(strAssemblyManifestFileName);
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ManifestCreationFailed(strAssemblyManifestFileName, e.Message));
}
s.Close();
}
private static void AsmCreateWin32ManifestFile(Stream s, Type[] aTypes)
{
String asmEnd = " ";
WriteTypes(s, aTypes, 4);
WriteUTFChars(s, asmEnd);
}
private static void WriteTypes(Stream s, Type[] aTypes, int offset)
{
RegistrationServices regServices = new RegistrationServices();
String name = null;
Assembly asm = Assembly.GetExecutingAssembly();
string asmver = asm.ImageRuntimeVersion;
foreach (Type t in aTypes)
{
// only registrable managed types will show up in the manifest file
if (!regServices.TypeRequiresRegistration(t))
{
DiagnosticUtility.DebugAssert("User defined types must be registrable");
throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false);
}
String strClsId = "{" + Marshal.GenerateGuidForType(t).ToString().ToUpperInvariant() + "}";
name = t.FullName;
// this type is a com imported type or Record
if (regServices.TypeRepresentsComType(t) || t.IsValueType)
{
WriteUTFChars(s, "" + Environment.NewLine, offset);
WriteUTFChars(s, " " + Environment.NewLine, offset);
}
}
}
private static void WriteUTFChars(Stream s, String value, int offset)
{
for (int i = 0; i < offset; i++)
{
WriteUTFChars(s, " ");
}
WriteUTFChars(s, value);
}
private static void WriteUTFChars(Stream s, String value)
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(value);
s.Write(bytes, 0, bytes.Length);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HitTestResult.cs
- Size.cs
- MarkerProperties.cs
- DesignBindingValueUIHandler.cs
- XDRSchema.cs
- SessionPageStatePersister.cs
- LOSFormatter.cs
- cookiecollection.cs
- TreeViewDesigner.cs
- JournalEntryStack.cs
- CompiledXpathExpr.cs
- XPathItem.cs
- _ProxyRegBlob.cs
- ValidationRuleCollection.cs
- UndoManager.cs
- InputElement.cs
- RepeaterDataBoundAdapter.cs
- SerialPort.cs
- _Rfc2616CacheValidators.cs
- EmbeddedObject.cs
- ResXBuildProvider.cs
- DiscoveryViaBehavior.cs
- PageThemeCodeDomTreeGenerator.cs
- MethodBody.cs
- EdmPropertyAttribute.cs
- BuildProviderCollection.cs
- WebPartZone.cs
- ClientSession.cs
- SingleAnimationUsingKeyFrames.cs
- TreeViewItem.cs
- MatrixKeyFrameCollection.cs
- PolyQuadraticBezierSegment.cs
- DataViewListener.cs
- JoinTreeSlot.cs
- DefaultMemberAttribute.cs
- BinaryMethodMessage.cs
- Event.cs
- MediaTimeline.cs
- WebBrowserDocumentCompletedEventHandler.cs
- InvokeMethod.cs
- EventLogWatcher.cs
- FileReader.cs
- PropertyDescriptorGridEntry.cs
- StorageMappingItemLoader.cs
- PrintPreviewGraphics.cs
- ParameterReplacerVisitor.cs
- CodeEventReferenceExpression.cs
- Container.cs
- SafeNativeMethods.cs
- Assembly.cs
- NegotiationTokenProvider.cs
- StylusPointDescription.cs
- ProfileGroupSettingsCollection.cs
- WeakReadOnlyCollection.cs
- PackageRelationshipSelector.cs
- IBuiltInEvidence.cs
- DecimalConstantAttribute.cs
- XmlIlTypeHelper.cs
- TemplateBuilder.cs
- SchemaTableOptionalColumn.cs
- OrderByLifter.cs
- WindowsAuthenticationEventArgs.cs
- BitConverter.cs
- GridViewDeleteEventArgs.cs
- CodeTypeMemberCollection.cs
- LinkConverter.cs
- PictureBox.cs
- StrokeCollectionDefaultValueFactory.cs
- Decoder.cs
- XmlLinkedNode.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- XomlCompilerError.cs
- _BaseOverlappedAsyncResult.cs
- FindCompletedEventArgs.cs
- LogFlushAsyncResult.cs
- UndoUnit.cs
- ByteStreamGeometryContext.cs
- ExecutionContext.cs
- HtmlInputRadioButton.cs
- SizeAnimationClockResource.cs
- FileSystemInfo.cs
- EntityClassGenerator.cs
- CompositeDuplexBindingElementImporter.cs
- ControlPaint.cs
- ZipIOModeEnforcingStream.cs
- PeerPresenceInfo.cs
- FixedSOMPage.cs
- FieldToken.cs
- DataProviderNameConverter.cs
- CssTextWriter.cs
- ContainerParaClient.cs
- ColorAnimationUsingKeyFrames.cs
- DefaultBinder.cs
- Drawing.cs
- WindowPatternIdentifiers.cs
- BuiltInExpr.cs
- ArglessEventHandlerProxy.cs
- XmlSchemaInclude.cs
- ErrorHandlingReceiver.cs
- ManipulationVelocities.cs