public static GetString ( string name ) : string | ||
name | string | |
Résultat | string |
static internal Exception CantAllocateEnvironmentHandle(ODBC32.RetCode retcode) { return(ADP.DataAdapter(Res.GetString(Res.Odbc_CantAllocateEnvironmentHandle, ODBC32.RetcodeToString(retcode)))); }
private void OpenSqlFileStream ( string path, byte[] transactionContext, System.IO.FileAccess access, System.IO.FileOptions options, Int64 allocationSize ) { //----------------------------------------------------------------- // precondition validation // these should be checked by any caller of this method // ensure we have validated and normalized the path before Debug.Assert(path != null); Debug.Assert(transactionContext != null); if (access != FileAccess.Read && access != FileAccess.Write && access != FileAccess.ReadWrite) { throw ADP.ArgumentOutOfRange("access"); } // FileOptions is a set of flags, so AND the given value against the set of values we do not support if ((options & ~(FileOptions.WriteThrough | FileOptions.Asynchronous | FileOptions.RandomAccess | FileOptions.SequentialScan)) != 0) { throw ADP.ArgumentOutOfRange("options"); } //----------------------------------------------------------------- // normalize the provided path // * compress path to remove any occurences of '.' or '..' // * trim whitespace from the beginning and end of the path // * ensure that the path starts with '\\' // * ensure that the path does not start with '\\.\' // * ensure that the path is not longer than Int16.MaxValue path = GetFullPathInternal(path); // ensure the running code has permission to read/write the file DemandAccessPermission(path, access); FileFullEaInformation eaBuffer = null; SecurityQualityOfService qos = null; UnicodeString objectName = null; Microsoft.Win32.SafeHandles.SafeFileHandle hFile = null; int nDesiredAccess = UnsafeNativeMethods.FILE_READ_ATTRIBUTES | UnsafeNativeMethods.SYNCHRONIZE; UInt32 dwCreateOptions = 0; UInt32 dwCreateDisposition = 0; System.IO.FileShare shareAccess = System.IO.FileShare.None; switch (access) { case System.IO.FileAccess.Read: nDesiredAccess |= UnsafeNativeMethods.FILE_READ_DATA; shareAccess = System.IO.FileShare.Delete | System.IO.FileShare.ReadWrite; dwCreateDisposition = (uint)UnsafeNativeMethods.CreationDisposition.FILE_OPEN; break; case System.IO.FileAccess.Write: nDesiredAccess |= UnsafeNativeMethods.FILE_WRITE_DATA; shareAccess = System.IO.FileShare.Delete | System.IO.FileShare.Read; dwCreateDisposition = (uint)UnsafeNativeMethods.CreationDisposition.FILE_OVERWRITE; break; case System.IO.FileAccess.ReadWrite: default: // we validate the value of 'access' parameter in the beginning of this method Debug.Assert(access == System.IO.FileAccess.ReadWrite); nDesiredAccess |= UnsafeNativeMethods.FILE_READ_DATA | UnsafeNativeMethods.FILE_WRITE_DATA; shareAccess = System.IO.FileShare.Delete | System.IO.FileShare.Read; dwCreateDisposition = (uint)UnsafeNativeMethods.CreationDisposition.FILE_OVERWRITE; break; } if ((options & System.IO.FileOptions.WriteThrough) != 0) { dwCreateOptions |= (uint)UnsafeNativeMethods.CreateOption.FILE_WRITE_THROUGH; } if ((options & System.IO.FileOptions.Asynchronous) == 0) { dwCreateOptions |= (uint)UnsafeNativeMethods.CreateOption.FILE_SYNCHRONOUS_IO_NONALERT; } if ((options & System.IO.FileOptions.SequentialScan) != 0) { dwCreateOptions |= (uint)UnsafeNativeMethods.CreateOption.FILE_SEQUENTIAL_ONLY; } if ((options & System.IO.FileOptions.RandomAccess) != 0) { dwCreateOptions |= (uint)UnsafeNativeMethods.CreateOption.FILE_RANDOM_ACCESS; } try { eaBuffer = new FileFullEaInformation(transactionContext); qos = new SecurityQualityOfService(UnsafeNativeMethods.SecurityImpersonationLevel.SecurityAnonymous, false, false); // NOTE: the Name property is intended to reveal the publicly available moniker for the // FILESTREAM attributed column data. We will not surface the internal processing that // takes place to create the mappedPath. string mappedPath = InitializeNtPath(path); objectName = new UnicodeString(mappedPath); UnsafeNativeMethods.OBJECT_ATTRIBUTES oa; oa.length = Marshal.SizeOf(typeof(UnsafeNativeMethods.OBJECT_ATTRIBUTES)); oa.rootDirectory = IntPtr.Zero; oa.attributes = (int)UnsafeNativeMethods.Attributes.CaseInsensitive; oa.securityDescriptor = IntPtr.Zero; oa.securityQualityOfService = qos; oa.objectName = objectName; UnsafeNativeMethods.IO_STATUS_BLOCK ioStatusBlock; uint oldMode; uint retval = 0; UnsafeNativeMethods.SetErrorModeWrapper(UnsafeNativeMethods.SEM_FAILCRITICALERRORS, out oldMode); try { Bid.Trace("<sc.SqlFileStream.OpenSqlFileStream|ADV> %d#, desiredAccess=0x%08x, allocationSize=%I64d, fileAttributes=0x%08x, shareAccess=0x%08x, dwCreateDisposition=0x%08x, createOptions=0x%08x\n", ObjectID, (int)nDesiredAccess, allocationSize, 0, (int)shareAccess, dwCreateDisposition, dwCreateOptions); retval = UnsafeNativeMethods.NtCreateFile(out hFile, nDesiredAccess, ref oa, out ioStatusBlock, ref allocationSize, 0, shareAccess, dwCreateDisposition, dwCreateOptions, eaBuffer, (uint)eaBuffer.Length); } finally { UnsafeNativeMethods.SetErrorModeWrapper(oldMode, out oldMode); } switch (retval) { case 0: break; case UnsafeNativeMethods.STATUS_SHARING_VIOLATION: throw ADP.InvalidOperation(Res.GetString(Res.SqlFileStream_FileAlreadyInTransaction)); case UnsafeNativeMethods.STATUS_INVALID_PARAMETER: throw ADP.Argument(Res.GetString(Res.SqlFileStream_InvalidParameter)); case UnsafeNativeMethods.STATUS_OBJECT_NAME_NOT_FOUND: { System.IO.DirectoryNotFoundException e = new System.IO.DirectoryNotFoundException(); ADP.TraceExceptionAsReturnValue(e); throw e; } default: { uint error = UnsafeNativeMethods.RtlNtStatusToDosError(retval); if (error == UnsafeNativeMethods.ERROR_MR_MID_NOT_FOUND) { // status code could not be mapped to a Win32 error code error = retval; } System.ComponentModel.Win32Exception e = new System.ComponentModel.Win32Exception(unchecked ((int)error)); ADP.TraceExceptionAsReturnValue(e); throw e; } } if (hFile.IsInvalid) { System.ComponentModel.Win32Exception e = new System.ComponentModel.Win32Exception(UnsafeNativeMethods.ERROR_INVALID_HANDLE); ADP.TraceExceptionAsReturnValue(e); throw e; } UnsafeNativeMethods.FileType fileType = UnsafeNativeMethods.GetFileType(hFile); if (fileType != UnsafeNativeMethods.FileType.Disk) { hFile.Dispose(); throw ADP.Argument(Res.GetString(Res.SqlFileStream_PathNotValidDiskResource)); } // if the user is opening the SQL FileStream in read/write mode, we assume that they want to scan // through current data and then append new data to the end, so we need to tell SQL Server to preserve // the existing file contents. if (access == System.IO.FileAccess.ReadWrite) { uint ioControlCode = UnsafeNativeMethods.CTL_CODE(UnsafeNativeMethods.FILE_DEVICE_FILE_SYSTEM, IoControlCodeFunctionCode, (byte)UnsafeNativeMethods.Method.METHOD_BUFFERED, (byte)UnsafeNativeMethods.Access.FILE_ANY_ACCESS); uint cbBytesReturned = 0; if (!UnsafeNativeMethods.DeviceIoControl(hFile, ioControlCode, IntPtr.Zero, 0, IntPtr.Zero, 0, out cbBytesReturned, IntPtr.Zero)) { System.ComponentModel.Win32Exception e = new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()); ADP.TraceExceptionAsReturnValue(e); throw e; } } // now that we've successfully opened a handle on the path and verified that it is a file, // use the SafeFileHandle to initialize our internal System.IO.FileStream instance // NOTE: need to assert UnmanagedCode permissions for this constructor. This is relatively benign // in that we've done much the same validation as in the FileStream(string path, ...) ctor case // most notably, validating that the handle type corresponds to an on-disk file. bool bRevertAssert = false; try { SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode); sp.Assert(); bRevertAssert = true; System.Diagnostics.Debug.Assert(m_fs == null); m_fs = new System.IO.FileStream(hFile, access, DefaultBufferSize, ((options & System.IO.FileOptions.Asynchronous) != 0)); } finally { if (bRevertAssert) { SecurityPermission.RevertAssert(); } } } catch { if (hFile != null && !hFile.IsInvalid) { hFile.Dispose(); } throw; } finally { if (eaBuffer != null) { eaBuffer.Dispose(); eaBuffer = null; } if (qos != null) { qos.Dispose(); qos = null; } if (objectName != null) { objectName.Dispose(); objectName = null; } } }
static internal Exception InvalidPacketSize() { return(ADP.ArgumentOutOfRange(Res.GetString(Res.SQL_InvalidTDSPacketSize))); }
private static void ValidationCallbackWithErrorCode(object sender, ValidationEventArgs args) { Console.WriteLine(Res.GetString(Res.SchemaValidationWarningDetails, args.Message)); }
int Run(string[] args) { try { bool classesGen = false; bool dataSetGen = false; bool writeHeader = true; ArrayList elements = new ArrayList(); //default language is C# string language = "c#"; string ns = string.Empty; string outputdir = string.Empty; ArrayList typeNames = new ArrayList(); string uri = ""; ArrayList instances = new ArrayList(); ArrayList schemas = new ArrayList(); ArrayList xdrSchemas = new ArrayList(); ArrayList dlls = new ArrayList(); for (int i = 0; i < args.Length; i++) { string arg = args[i]; string value = string.Empty; bool argument = false; #if !PLATFORM_UNIX if (arg.StartsWith("/") || arg.StartsWith("-")) { argument = true; } #else if (arg.StartsWith("/")) { if ((arg.IndexOf(":") >= 0) || ((arg.IndexOf("/", 1) < 0) && (arg.IndexOf("\\", 1) < 0))) { argument = true; } } else if (arg.StartsWith("-")) { argument = true; } #endif if (argument) { int colonPos = arg.IndexOf(":"); if (colonPos != -1) { value = arg.Substring(colonPos + 1); arg = arg.Substring(0, colonPos); } } arg = arg.ToLower(); //the user may have wanted to provide an absolute path to the file, so detect that FIRST //for example. "c:bob.xsd" will be (erroneously) split up into arg = "c" and value = "bob.xsd" //however, "bob.xsd" will be "properly" split up into arg = "bob.xsd" and value = "" if (!argument && arg.EndsWith(".xsd")) { schemas.Add(args[i]); } else if (!argument && arg.EndsWith(".xdr")) { xdrSchemas.Add(args[i]); } else if (!argument && arg.EndsWith(".xml")) { instances.Add(args[i]); } else if (!argument && (arg.EndsWith(".dll") || arg.EndsWith(".exe"))) { dlls.Add(args[i]); } else if (ArgumentMatch(arg, "?") || ArgumentMatch(arg, "help")) { WriteHeader(); WriteHelp(); return(0); } else if (ArgumentMatch(arg, "classes")) { if (value.Length > 0) { WriteHeader(); throw new InvalidOperationException(Res.GetString(Res.ErrInvalidArgument, arg + ":" + value)); } classesGen = true; } else if (ArgumentMatch(arg, "dataset")) { if (value.Length > 0) { WriteHeader(); throw new InvalidOperationException(Res.GetString(Res.ErrInvalidArgument, arg + ":" + value)); } dataSetGen = true; } else if (ArgumentMatch(arg, "element")) { elements.Add(value); } else if (ArgumentMatch(arg, "language")) { language = value.ToLower(); } else if (ArgumentMatch(arg, "namespace")) { ns = value; } else if (ArgumentMatch(arg, "nologo")) { if (value.Length > 0) { WriteHeader(); throw new InvalidOperationException(Res.GetString(Res.ErrInvalidArgument, arg + ":" + value)); } writeHeader = false; } else if (ArgumentMatch(arg, "out") || ArgumentMatch(arg, "outputdir")) { outputdir = value; } else if (ArgumentMatch(arg, "type")) { typeNames.Add(value); } else if (ArgumentMatch(arg, "uri")) { uri = value; } else { WriteHeader(); throw new InvalidOperationException(Res.GetString(Res.ErrInvalidArgument, args[i])); } } if (writeHeader) { WriteHeader(); } bool schemasFound = schemas.Count > 0; bool xdrSchemasFound = xdrSchemas.Count > 0; bool dllsFound = dlls.Count > 0; bool instancesFound = instances.Count > 0; if (outputdir.Length == 0) { outputdir = Directory.GetCurrentDirectory(); } if (schemasFound) { if (dllsFound || instancesFound || xdrSchemasFound) { throw new InvalidOperationException(Res.GetString(Res.ErrInputFileTypes)); } if (classesGen == dataSetGen) { throw new InvalidOperationException(Res.GetString(Res.ErrClassOrDataset)); } ICodeGenerator codeGen = null; string fileExtension = string.Empty; CreateCodeGenerator(language, ref codeGen, ref fileExtension); if (classesGen) { ImportSchemasAsClasses(outputdir, codeGen, fileExtension, schemas, ns, uri, elements); } else { throw new Exception("DataSet import not supported in the SSCLI"); } } else if (dllsFound) { if (instancesFound || xdrSchemasFound) { throw new InvalidOperationException(Res.GetString(Res.ErrInputFileTypes)); } ExportSchemas(outputdir, dlls, typeNames); } else if (xdrSchemasFound) { if (instancesFound) { throw new InvalidOperationException(Res.GetString(Res.ErrInputFileTypes)); } throw new Exception("XDR schema conversion not supported in the SSCLI"); } else if (instancesFound) { throw new Exception("Schema inference not supported in the SSCLI"); } else { WriteHelp(); return(0); } } catch (Exception e) { Error(e, Res.GetString(Res.Error)); return(1); } return(0); }
internal static AdamInstance FindAliveAdamInstance(string configSetName, DirectoryContext context, ArrayList adamInstanceNames) { AdamInstance adamInstance; object name; object obj; bool flag = false; AdamInstance adamInstance1 = null; DateTime utcNow = DateTime.UtcNow; IEnumerator enumerator = adamInstanceNames.GetEnumerator(); try { while (enumerator.MoveNext()) { string current = (string)enumerator.Current; DirectoryContext newDirectoryContext = Utils.GetNewDirectoryContext(current, DirectoryContextType.DirectoryServer, context); DirectoryEntryManager directoryEntryManager = new DirectoryEntryManager(newDirectoryContext); DirectoryEntry cachedDirectoryEntry = directoryEntryManager.GetCachedDirectoryEntry(WellKnownDN.RootDSE); try { //TODO: REVIEW: URGENT!!: cachedDirectoryEntry.Bind(true); adamInstance1 = new AdamInstance(newDirectoryContext, current, directoryEntryManager, true); flag = true; } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (cOMException.ErrorCode == -2147016646 || cOMException.ErrorCode == -2147016690 || cOMException.ErrorCode == -2147016689 || cOMException.ErrorCode == -2147023436) { DateTime dateTime = DateTime.UtcNow; if (dateTime.Subtract(utcNow) > ConfigurationSet.locationTimeout) { string str = "ADAMInstanceNotFoundInConfigSet"; object[] objArray = new object[1]; object[] objArray1 = objArray; int num = 0; if (configSetName != null) { obj = configSetName; } else { obj = context.Name; } objArray1[num] = obj; throw new ActiveDirectoryObjectNotFoundException(Res.GetString(str, objArray), typeof(AdamInstance), null); } } else { throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } } if (!flag) { continue; } adamInstance = adamInstance1; return(adamInstance); } string str1 = "ADAMInstanceNotFoundInConfigSet"; object[] objArray2 = new object[1]; object[] objArray3 = objArray2; int num1 = 0; if (configSetName != null) { name = configSetName; } else { name = context.Name; } objArray3[num1] = name; throw new ActiveDirectoryObjectNotFoundException(Res.GetString(str1, objArray2), typeof(AdamInstance), null); } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } return(adamInstance); }
public static ConfigurationSet GetConfigurationSet(DirectoryContext context) { if (context != null) { if (context.ContextType == DirectoryContextType.ConfigurationSet || context.ContextType == DirectoryContextType.DirectoryServer) { if (context.isServer() || context.isADAMConfigSet()) { context = new DirectoryContext(context); DirectoryEntryManager directoryEntryManager = new DirectoryEntryManager(context); string propertyValue = null; try { DirectoryEntry cachedDirectoryEntry = directoryEntryManager.GetCachedDirectoryEntry(WellKnownDN.RootDSE); if (!context.isServer() || Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectoryApplicationMode)) { propertyValue = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.ConfigurationNamingContext); } else { object[] name = new object[1]; name[0] = context.Name; throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AINotFound", name), typeof(ConfigurationSet), null); } } catch (COMException cOMException1) { COMException cOMException = cOMException1; int errorCode = cOMException.ErrorCode; if (errorCode != -2147016646) { throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } else { if (context.ContextType != DirectoryContextType.ConfigurationSet) { object[] objArray = new object[1]; objArray[0] = context.Name; throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AINotFound", objArray), typeof(ConfigurationSet), null); } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ConfigSetNotFound"), typeof(ConfigurationSet), context.Name); } } } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { if (context.ContextType != DirectoryContextType.ConfigurationSet) { throw; } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ConfigSetNotFound"), typeof(ConfigurationSet), context.Name); } } return(new ConfigurationSet(context, propertyValue, directoryEntryManager)); } else { if (context.ContextType != DirectoryContextType.ConfigurationSet) { object[] name1 = new object[1]; name1[0] = context.Name; throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AINotFound", name1), typeof(ConfigurationSet), null); } else { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ConfigSetNotFound"), typeof(ConfigurationSet), context.Name); } } } else { throw new ArgumentException(Res.GetString("TargetShouldBeServerORConfigSet"), "context"); } } else { throw new ArgumentNullException("context"); } }
static internal Exception ConnectionStringTooLong() { return(ADP.Argument(Res.GetString(Res.OdbcConnection_ConnectionStringTooLong, ODBC32.MAX_CONNECTION_STRING_LENGTH))); }
static internal ArgumentException GetSchemaRestrictionRequired() { return(ADP.Argument(Res.GetString(Res.ODBC_GetSchemaRestrictionRequired))); }
static internal Exception OpenConnectionNoOwner() { return(ADP.InvalidOperation(Res.GetString(Res.Odbc_OpenConnectionNoOwner))); }
static internal Exception UnknownSQLType(ODBC32.SQL_TYPE sqltype) { return(ADP.Argument(Res.GetString(Res.Odbc_UnknownSQLType, sqltype.ToString()))); }
static internal Exception ConnectionClosed() { return(ADP.InvalidOperation(Res.GetString(Res.Odbc_ConnectionClosed))); }
static internal Exception NotInTransaction() { return(ADP.InvalidOperation(Res.GetString(Res.Odbc_NotInTransaction))); }
static internal Exception FailedToGetDescriptorHandle(ODBC32.RetCode retcode) { return(ADP.DataAdapter(Res.GetString(Res.Odbc_FailedToGetDescriptorHandle, ODBC32.RetcodeToString(retcode)))); }
internal override void SetResponseErrorCode(HttpResponse response, SoapException soapException) { response.StatusCode = (int)HttpStatusCode.InternalServerError; response.StatusDescription = Res.GetString(Res.WebRequestErrorStatusDescription); }
static internal ArgumentOutOfRangeException NotSupportedEnumerationValue(Type type, int value) { return(ADP.ArgumentOutOfRange(Res.GetString(Res.ODBC_NotSupportedEnumerationValue, type.Name, value.ToString(System.Globalization.CultureInfo.InvariantCulture)), type.Name)); }
public static ActiveDirectorySchema GetSchema(DirectoryContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (((context.ContextType != DirectoryContextType.Forest) && (context.ContextType != DirectoryContextType.ConfigurationSet)) && (context.ContextType != DirectoryContextType.DirectoryServer)) { throw new ArgumentException(Res.GetString("NotADOrADAM"), "context"); } if ((context.Name == null) && !context.isRootDomain()) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ContextNotAssociatedWithDomain"), typeof(ActiveDirectorySchema), null); } if (((context.Name != null) && !context.isRootDomain()) && (!context.isADAMConfigSet() && !context.isServer())) { if (context.ContextType == DirectoryContextType.Forest) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ForestNotFound"), typeof(ActiveDirectorySchema), context.Name); } if (context.ContextType == DirectoryContextType.ConfigurationSet) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ConfigSetNotFound"), typeof(ActiveDirectorySchema), context.Name); } throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ServerNotFound", new object[] { context.Name }), typeof(ActiveDirectorySchema), null); } context = new DirectoryContext(context); DirectoryEntryManager directoryEntryMgr = new DirectoryEntryManager(context); string distinguishedName = null; try { DirectoryEntry cachedDirectoryEntry = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE); if (context.isServer() && !Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectoryOrADAM)) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ServerNotFound", new object[] { context.Name }), typeof(ActiveDirectorySchema), null); } distinguishedName = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.SchemaNamingContext); } catch (COMException exception) { if (exception.ErrorCode != -2147016646) { throw ExceptionHelper.GetExceptionFromCOMException(context, exception); } if (context.ContextType == DirectoryContextType.Forest) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ForestNotFound"), typeof(ActiveDirectorySchema), context.Name); } if (context.ContextType == DirectoryContextType.ConfigurationSet) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ConfigSetNotFound"), typeof(ActiveDirectorySchema), context.Name); } throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ServerNotFound", new object[] { context.Name }), typeof(ActiveDirectorySchema), null); } catch (ActiveDirectoryObjectNotFoundException) { if (context.ContextType == DirectoryContextType.ConfigurationSet) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ConfigSetNotFound"), typeof(ActiveDirectorySchema), context.Name); } throw; } return(new ActiveDirectorySchema(context, distinguishedName, directoryEntryMgr)); }
static internal InvalidOperationException NoMappingForSqlTransactionLevel(int value) { return(ADP.DataAdapter(Res.GetString(Res.Odbc_NoMappingForSqlTransactionLevel, value.ToString(CultureInfo.InvariantCulture)))); }
internal static AdamInstance FindAnyAdamInstance(DirectoryContext context) { if (context.ContextType == DirectoryContextType.ConfigurationSet) { DirectoryEntry searchRootEntry = ConfigurationSet.GetSearchRootEntry(Forest.GetCurrentForest()); ArrayList arrayLists = new ArrayList(); try { try { StringBuilder stringBuilder = new StringBuilder(15); stringBuilder.Append("(&("); stringBuilder.Append(PropertyManager.ObjectCategory); stringBuilder.Append("=serviceConnectionPoint)"); stringBuilder.Append("("); stringBuilder.Append(PropertyManager.Keywords); stringBuilder.Append("=1.2.840.113556.1.4.1851)("); stringBuilder.Append(PropertyManager.Keywords); stringBuilder.Append("="); stringBuilder.Append(Utils.GetEscapedFilterValue(context.Name)); stringBuilder.Append("))"); string str = stringBuilder.ToString(); string[] serviceBindingInformation = new string[1]; serviceBindingInformation[0] = PropertyManager.ServiceBindingInformation; ADSearcher aDSearcher = new ADSearcher(searchRootEntry, str, serviceBindingInformation, SearchScope.Subtree, false, false); SearchResultCollection searchResultCollections = aDSearcher.FindAll(); try { foreach (SearchResult item in searchResultCollections) { string str1 = "ldap://"; IEnumerator enumerator = item.Properties[PropertyManager.ServiceBindingInformation].GetEnumerator(); try { while (enumerator.MoveNext()) { string str2 = item.ToString(); if (str2.Length <= str1.Length || string.Compare(str2.Substring(0, str1.Length), str1, StringComparison.OrdinalIgnoreCase) != 0) { continue; } arrayLists.Add(str2.Substring(str1.Length)); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } } finally { searchResultCollections.Dispose(); } } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } } finally { searchRootEntry.Dispose(); } return(ConfigurationSet.FindAliveAdamInstance(null, context, arrayLists)); } else { DirectoryEntryManager directoryEntryManager = new DirectoryEntryManager(context); DirectoryEntry cachedDirectoryEntry = directoryEntryManager.GetCachedDirectoryEntry(WellKnownDN.RootDSE); if (Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectoryApplicationMode)) { string propertyValue = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.DnsHostName); return(new AdamInstance(context, propertyValue, directoryEntryManager)); } else { directoryEntryManager.RemoveIfExists(directoryEntryManager.ExpandWellKnownDN(WellKnownDN.RootDSE)); throw new ArgumentException(Res.GetString("TargetShouldBeServerORConfigSet"), "context"); } } }
void ThrowInitException() { throw new Exception(Res.GetString(Res.WebConfigExtensionError), protocol.OnewayInitException); }
void ImportSchemasAsClasses( string outputdir, ICodeGenerator codeGen, string fileExtension, IList fileNames, string ns, string uri, IList elements) { XmlSchemas schemasToCompile = new XmlSchemas(); XmlSchemas userSchemas = new XmlSchemas(); string outputSchemaName = ""; // Create parent schema XmlSchema parent = new XmlSchema(); foreach (string fileName in fileNames) { schemasToCompile.Add(ReadSchema(fileName, false)); userSchemas.Add(ReadSchema(fileName, true)); outputSchemaName += Path.ChangeExtension(fileName, "").Replace('.', '_'); } Hashtable includeSchemas = new Hashtable(); foreach (XmlSchema schema in schemasToCompile) { CollectIncludes(schema, includeSchemas, false); } Compile(schemasToCompile); includeSchemas = new Hashtable(); foreach (XmlSchema schema in userSchemas) { CollectIncludes(schema, includeSchemas, true); } try { outputSchemaName = outputSchemaName.Substring(0, outputSchemaName.Length - 1); XmlSchemaImporter schemaImporter = new XmlSchemaImporter(userSchemas); CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); CodeNamespace codeNamespace = new CodeNamespace(ns); codeCompileUnit.Namespaces.Add(codeNamespace); GenerateVersionComment(codeNamespace); XmlCodeExporter codeExporter = new XmlCodeExporter(codeNamespace, codeCompileUnit); AddImports(codeNamespace, GetNamespacesForTypes(new Type[] { typeof(XmlAttributeAttribute) })); for (int i = 0; i < userSchemas.Count; i++) { XmlSchema schema = userSchemas[i]; for (int j = 0; j < schema.Items.Count; j++) { object item = schema.Items[j]; if (item is XmlSchemaElement) { XmlSchemaElement element = (XmlSchemaElement)item; if (!element.IsAbstract) { if (uri.Length == 0 || schema.TargetNamespace == uri) { bool found; if (elements.Count == 0) { found = true; } else { found = false; foreach (string e in elements) { if (e == element.Name) { found = true; break; } } } if (found) { XmlTypeMapping xmlTypeMapping = schemaImporter.ImportTypeMapping(new XmlQualifiedName(element.Name, schema.TargetNamespace)); codeExporter.ExportTypeMapping(xmlTypeMapping); } } } } } } CodeTypeDeclarationCollection classes = codeNamespace.Types; if (classes == null || classes.Count == 0) { Console.WriteLine(Res.GetString(Res.NoClassesGenerated)); } else { TextWriter writer = CreateOutputWriter(outputdir, outputSchemaName, fileExtension); codeGen.GenerateCodeFromCompileUnit(codeCompileUnit, writer, null); writer.Close(); } } catch (Exception e) { throw new InvalidOperationException(Res.GetString(Res.ErrGenerateClassesForSchema, outputSchemaName), e); } }
private TypeDesc ImportTypeDesc(Type type, MemberInfo memberInfo, bool directReference) { TypeDesc desc = null; TypeKind root; Type elementType = null; Type baseType = null; TypeFlags none = TypeFlags.None; Exception exception = null; if (!type.IsPublic && !type.IsNestedPublic) { none |= TypeFlags.Unsupported; exception = new InvalidOperationException(Res.GetString("XmlTypeInaccessible", new object[] { type.FullName })); } else if (type.IsAbstract && type.IsSealed) { none |= TypeFlags.Unsupported; exception = new InvalidOperationException(Res.GetString("XmlTypeStatic", new object[] { type.FullName })); } if (DynamicAssemblies.IsTypeDynamic(type)) { none |= TypeFlags.UseReflection; } if (!type.IsValueType) { none |= TypeFlags.Reference; } if (type == typeof(object)) { root = TypeKind.Root; none |= TypeFlags.HasDefaultConstructor; } else if (type == typeof(ValueType)) { root = TypeKind.Enum; none |= TypeFlags.Unsupported; if (exception == null) { exception = new NotSupportedException(Res.GetString("XmlSerializerUnsupportedType", new object[] { type.FullName })); } } else if (type == typeof(void)) { root = TypeKind.Void; } else if (typeof(IXmlSerializable).IsAssignableFrom(type)) { root = TypeKind.Serializable; none |= TypeFlags.CanBeElementValue | TypeFlags.Special; none |= GetConstructorFlags(type, ref exception); } else if (type.IsArray) { root = TypeKind.Array; if (type.GetArrayRank() > 1) { none |= TypeFlags.Unsupported; if (exception == null) { exception = new NotSupportedException(Res.GetString("XmlUnsupportedRank", new object[] { type.FullName })); } } elementType = type.GetElementType(); none |= TypeFlags.HasDefaultConstructor; } else if (typeof(ICollection).IsAssignableFrom(type)) { root = TypeKind.Collection; elementType = GetCollectionElementType(type, (memberInfo == null) ? null : (memberInfo.DeclaringType.FullName + "." + memberInfo.Name)); none |= GetConstructorFlags(type, ref exception); } else if (type == typeof(XmlQualifiedName)) { root = TypeKind.Primitive; } else if (type.IsPrimitive) { root = TypeKind.Primitive; none |= TypeFlags.Unsupported; if (exception == null) { exception = new NotSupportedException(Res.GetString("XmlSerializerUnsupportedType", new object[] { type.FullName })); } } else if (type.IsEnum) { root = TypeKind.Enum; } else if (type.IsValueType) { root = TypeKind.Struct; if (IsOptionalValue(type)) { baseType = type.GetGenericArguments()[0]; none |= TypeFlags.OptionalValue; } else { baseType = type.BaseType; } if (type.IsAbstract) { none |= TypeFlags.Abstract; } } else if (type.IsClass) { if (type == typeof(XmlAttribute)) { root = TypeKind.Attribute; none |= TypeFlags.CanBeAttributeValue | TypeFlags.Special; } else if (typeof(XmlNode).IsAssignableFrom(type)) { root = TypeKind.Node; baseType = type.BaseType; none |= TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.Special; if (typeof(XmlText).IsAssignableFrom(type)) { none &= ~TypeFlags.CanBeElementValue; } else if (typeof(XmlElement).IsAssignableFrom(type)) { none &= ~TypeFlags.CanBeTextValue; } else if (type.IsAssignableFrom(typeof(XmlAttribute))) { none |= TypeFlags.CanBeAttributeValue; } } else { root = TypeKind.Class; baseType = type.BaseType; if (type.IsAbstract) { none |= TypeFlags.Abstract; } } } else if (type.IsInterface) { root = TypeKind.Void; none |= TypeFlags.Unsupported; if (exception == null) { if (memberInfo == null) { exception = new NotSupportedException(Res.GetString("XmlUnsupportedInterface", new object[] { type.FullName })); } else { exception = new NotSupportedException(Res.GetString("XmlUnsupportedInterfaceDetails", new object[] { memberInfo.DeclaringType.FullName + "." + memberInfo.Name, type.FullName })); } } } else { root = TypeKind.Void; none |= TypeFlags.Unsupported; if (exception == null) { exception = new NotSupportedException(Res.GetString("XmlSerializerUnsupportedType", new object[] { type.FullName })); } } if ((root == TypeKind.Class) && !type.IsAbstract) { none |= GetConstructorFlags(type, ref exception); } if (((root == TypeKind.Struct) || (root == TypeKind.Class)) && typeof(IEnumerable).IsAssignableFrom(type)) { elementType = GetEnumeratorElementType(type, ref none); root = TypeKind.Enumerable; none |= GetConstructorFlags(type, ref exception); } desc = new TypeDesc(type, CodeIdentifier.MakeValid(TypeName(type)), type.ToString(), root, null, none, null) { Exception = exception }; if (directReference && (desc.IsClass || (root == TypeKind.Serializable))) { desc.CheckNeedConstructor(); } if (!desc.IsUnsupported) { this.typeDescs.Add(type, desc); if (elementType != null) { TypeDesc desc2 = this.GetTypeDesc(elementType, memberInfo, true, false); if ((directReference && (desc2.IsCollection || desc2.IsEnumerable)) && !desc2.IsPrimitive) { desc2.CheckNeedConstructor(); } desc.ArrayElementTypeDesc = desc2; } if (((baseType != null) && (baseType != typeof(object))) && (baseType != typeof(ValueType))) { desc.BaseTypeDesc = this.GetTypeDesc(baseType, memberInfo, false, false); } if (type.IsNestedPublic) { for (Type type4 = type.DeclaringType; (type4 != null) && !type4.ContainsGenericParameters; type4 = type4.DeclaringType) { this.GetTypeDesc(type4, null, false); } } } return(desc); }
void ExportSchemas(string outputdir, IList dlls, IList typeNames) { XmlReflectionImporter importer = new XmlReflectionImporter(); XmlSchemas schemas = new XmlSchemas(); XmlSchemaExporter exporter = new XmlSchemaExporter(schemas); foreach (string dll in dlls) { Assembly a = Assembly.LoadFrom(dll); if (a == null) { throw new InvalidOperationException(Res.GetString(Res.ErrLoadAssembly, dll)); } try { foreach (Type type in a.GetTypes()) { if (!type.IsPublic) { continue; } if (type.IsInterface) { continue; } bool found; if (typeNames.Count == 0) { found = true; } else { found = false; foreach (string typeName in typeNames) { if (type.FullName == typeName || type.Name == typeName || (typeName.EndsWith(".*") && type.FullName.StartsWith(typeName.Substring(0, typeName.Length - 2)))) { found = true; break; } } } if (found) { XmlTypeMapping xmlTypeMapping = importer.ImportTypeMapping(type); exporter.ExportTypeMapping(xmlTypeMapping); } } } catch (Exception e) { throw new InvalidOperationException(Res.GetString(Res.ErrGeneral, dll), e); } } for (int i = 0; i < schemas.Count; i++) { XmlSchema schema = schemas[i]; try { TextWriter writer = CreateOutputWriter(outputdir, "schema" + i.ToString(), ".xsd"); schemas[i].Write(writer); writer.Close(); } catch (Exception e) { throw new InvalidOperationException(Res.GetString(Res.ErrGeneral, schema.TargetNamespace), e); } } }
internal static Exception TryParse(string s, DurationType durationType, out XsdDuration result) { int num2; Parts hasNone = Parts.HasNone; result = new XsdDuration(); s = s.Trim(); int length = s.Length; int offset = 0; int numDigits = 0; if (offset >= length) { goto Label_02D8; } if (s[offset] == '-') { offset++; result.nanoseconds = 0x80000000; } else { result.nanoseconds = 0; } if ((offset >= length) || (s[offset++] != 'P')) { goto Label_02D8; } if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null) { goto Label_0301; } if (offset >= length) { goto Label_02D8; } if (s[offset] == 'Y') { if (numDigits == 0) { goto Label_02D8; } hasNone |= Parts.HasYears; result.years = num2; if (++offset == length) { goto Label_02BB; } if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null) { goto Label_0301; } if (offset >= length) { goto Label_02D8; } } if (s[offset] == 'M') { if (numDigits == 0) { goto Label_02D8; } hasNone |= Parts.HasMonths; result.months = num2; if (++offset == length) { goto Label_02BB; } if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null) { goto Label_0301; } if (offset >= length) { goto Label_02D8; } } if (s[offset] == 'D') { if (numDigits == 0) { goto Label_02D8; } hasNone |= Parts.HasDays; result.days = num2; if (++offset == length) { goto Label_02BB; } if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null) { goto Label_0301; } if (offset >= length) { goto Label_02D8; } } if (s[offset] == 'T') { if (numDigits != 0) { goto Label_02D8; } offset++; if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null) { goto Label_0301; } if (offset >= length) { goto Label_02D8; } if (s[offset] == 'H') { if (numDigits == 0) { goto Label_02D8; } hasNone |= Parts.HasHours; result.hours = num2; if (++offset == length) { goto Label_02BB; } if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null) { goto Label_0301; } if (offset >= length) { goto Label_02D8; } } if (s[offset] == 'M') { if (numDigits == 0) { goto Label_02D8; } hasNone |= Parts.HasMinutes; result.minutes = num2; if (++offset == length) { goto Label_02BB; } if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null) { goto Label_0301; } if (offset >= length) { goto Label_02D8; } } if (s[offset] == '.') { offset++; hasNone |= Parts.HasSeconds; result.seconds = num2; if (TryParseDigits(s, ref offset, true, out num2, out numDigits) != null) { goto Label_0301; } if (numDigits == 0) { num2 = 0; } while (numDigits > 9) { num2 /= 10; numDigits--; } while (numDigits < 9) { num2 *= 10; numDigits++; } result.nanoseconds |= (uint)num2; if ((offset >= length) || (s[offset] != 'S')) { goto Label_02D8; } if (++offset != length) { goto Label_02B3; } goto Label_02BB; } if (s[offset] == 'S') { if (numDigits == 0) { goto Label_02D8; } hasNone |= Parts.HasSeconds; result.seconds = num2; if (++offset == length) { goto Label_02BB; } } } Label_02B3: if ((numDigits != 0) || (offset != length)) { goto Label_02D8; } Label_02BB: if (hasNone == Parts.HasNone) { goto Label_02D8; } if (durationType == DurationType.DayTimeDuration) { if ((hasNone & (Parts.HasMonths | Parts.HasYears)) == Parts.HasNone) { goto Label_02D6; } goto Label_02D8; } if ((durationType == DurationType.YearMonthDuration) && ((hasNone & ~(Parts.HasMonths | Parts.HasYears)) != Parts.HasNone)) { goto Label_02D8; } Label_02D6: return(null); Label_02D8 :; return(new FormatException(Res.GetString("XmlConvert_BadFormat", new object[] { s, durationType }))); Label_0301 :; return(new OverflowException(Res.GetString("XmlConvert_Overflow", new object[] { s, durationType }))); }
// Get a code generator for the specified language. language can either be a known abbreviation // for C#, VB or JScript. Or it can be a fully-qualified (with assembly) name for an ICodeGenerator // or a CodeDomProvider. void CreateCodeGenerator(string language, ref ICodeGenerator codeGen, ref string fileExtension) { CodeDomProvider codeProvider = null; if ((string.Compare(language, "CSharp", true) == 0) || (string.Compare(language, "C#", true) == 0) || (string.Compare(language, "CS", true) == 0)) { codeProvider = new Microsoft.CSharp.CSharpCodeProvider(); } else if (string.Compare(language, "VB", true) == 0) { throw new Exception("VisualBasic not supported in the SSCLI"); } else if ((string.Compare(language, "js", true) == 0) || (string.Compare(language, "jscript", true) == 0)) { Type t = Type.GetType("Microsoft.JScript.JScriptCodeProvider, " + AssemblyRef.MicrosoftJScript); codeProvider = (CodeDomProvider)Activator.CreateInstance(t); } else { //try to reflect a custom code generator //ignore case when reflecting; language argument must specify the namespace Type t = Type.GetType(language, false, true); if (t == null) { throw new InvalidOperationException(Res.GetString(Res.ErrLanguage, language)); } object o = Activator.CreateInstance(t); if (o is CodeDomProvider) { codeProvider = (CodeDomProvider)o; } else if (o is ICodeGenerator) { codeGen = (ICodeGenerator)o; } else { throw new InvalidOperationException(Res.GetString(Res.ErrLanguage, language)); } } if (codeProvider != null) { codeGen = codeProvider.CreateGenerator(); fileExtension = codeProvider.FileExtension; if (fileExtension == null) { fileExtension = string.Empty; } else if (fileExtension.Length > 0 && fileExtension[0] != '.') { fileExtension = "." + fileExtension; } } else { fileExtension = ".src"; } }
internal static string InvalidOpStreamClosed(string method) { return(Res.GetString(Res.SqlMisc_InvalidOpStreamClosed, method)); }
internal virtual void AsyncBufferedSerialize(WebRequest request, Stream requestStream, object internalAsyncState) { throw new NotSupportedException(Res.GetString(Res.ProtocolDoesNotAsyncSerialize)); }
internal static string InvalidOpStreamNonSeekable(string method) { return(Res.GetString(Res.SqlMisc_InvalidOpStreamNonSeekable, method)); }
static internal Exception InvalidPacketSizeValue() { return(ADP.Argument(Res.GetString(Res.SQL_InvalidPacketSizeValue))); }
static internal Exception CantEnableConnectionpooling(ODBC32.RetCode retcode) { return(ADP.DataAdapter(Res.GetString(Res.Odbc_CantEnableConnectionpooling, ODBC32.RetcodeToString(retcode)))); }