public static NetworkAdapterConfigurationCollection GetInstances(ManagementScope mgmtScope, EnumerationOptions enumOptions)
        {
            if ((mgmtScope == null))
            {
                mgmtScope = new ManagementScope();
                mgmtScope.Path.NamespacePath = "root\\CimV2";
            }
            var pathObj = new ManagementPath();

            pathObj.ClassName     = "Win32_NetworkAdapterConfiguration";
            pathObj.NamespacePath = "root\\CimV2";
            var clsObject = new ManagementClass(mgmtScope, pathObj, null);

            if ((enumOptions == null))
            {
                enumOptions = new EnumerationOptions();
                enumOptions.EnsureLocatable = true;
            }
            return(new NetworkAdapterConfigurationCollection(clsObject.GetInstances(enumOptions)));
        }
Example #2
0
 public static string[] GetDirectories(string path, string searchPattern, EnumerationOptions enumerationOptions)
 => new List <string>(InternalEnumeratePaths(path, searchPattern, SearchTarget.Directories, enumerationOptions)).ToArray();
Example #3
0
 public static string[] GetFileSystemEntries(string path, string searchPattern, EnumerationOptions enumerationOptions)
 => new List <string>(InternalEnumeratePaths(path, searchPattern, SearchTarget.Both, enumerationOptions)).ToArray();
Example #4
0
 public IEnumerable <FileSystemInfo> EnumerateFileSystemInfos(string searchPattern, SearchOption searchOption)
 => EnumerateFileSystemInfos(searchPattern, EnumerationOptions.FromSearchOption(searchOption));
Example #5
0
 protected override string[] GetNames(string directory, EnumerationOptions options)
 {
     return(new DirectoryInfo(directory).GetDirectories("*", options).Select(i => i.Name).ToArray());
 }
Example #6
0
        protected override void ExecuteTask()
        {
            try {
                // we're only interested in in-process instances
                ObjectQuery query = new ObjectQuery("SELECT * FROM MSBTS_HostInstance WHERE HostType = 1");

                EnumerationOptions enumerationOptions = new EnumerationOptions();
                enumerationOptions.ReturnImmediately = false;

                using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query, enumerationOptions)) {
                    foreach (ManagementObject hostInstance in searcher.Get())
                    {
                        string hostName      = (string)hostInstance["HostName"];
                        string runningServer = (string)hostInstance["RunningServer"];

                        // perform case-insensitive comparison
                        if (string.Compare(hostName, HostName, true, CultureInfo.CurrentCulture) != 0)
                        {
                            continue;
                        }

                        // perform case-insensitive comparison
                        if (Server != null && string.Compare(runningServer, Server, true, CultureInfo.CurrentCulture) != 0)
                        {
                            continue;
                        }

                        if ((Action & HostAction.Stop) == HostAction.Stop)
                        {
                            Log(Level.Verbose, "Stopping \"{0}\" on \"{1}\"...",
                                hostName, runningServer);
                            try {
                                hostInstance.InvokeMethod("Stop", null);
                            } catch (Exception ex) {
                                ReportActionFailure("stopping", runningServer,
                                                    ex, FailOnError);
                            }
                        }

                        if ((Action & HostAction.Start) == HostAction.Start)
                        {
                            Log(Level.Verbose, "Starting \"{0}\" on \"{1}\"...",
                                hostName, runningServer);
                            try {
                                hostInstance.InvokeMethod("Start", null);
                            } catch (Exception ex) {
                                ReportActionFailure("starting", runningServer,
                                                    ex, FailOnError);
                            }
                        }

                        Log(Level.Info, "{0} \"{1}\" on \"{2}\"",
                            GetActionFinish(), hostName, runningServer);
                    }
                }
            } catch (BuildException) {
                throw;
            } catch (Exception ex) {
                ReportActionFailure(GetActionInProgress(), Server, ex, true);
            }
        }
Example #7
0
 protected override string[] GetPaths(string directory, string pattern, EnumerationOptions options)
 {
     return(Directory.GetFiles(directory, pattern, options));
 }
	public void GetRelationshipClasses(ManagementOperationObserver watcher, string relationshipClass, string relationshipQualifier, string thisRole, EnumerationOptions options) {}
	public ManagementObjectCollection GetRelationships(string relationshipClass, string relationshipQualifier, string thisRole, bool classDefinitionsOnly, EnumerationOptions options) {}
	public void GetSubclasses(ManagementOperationObserver watcher, EnumerationOptions options) {}
	public ManagementObjectCollection GetRelationshipClasses(string relationshipClass, string relationshipQualifier, string thisRole, EnumerationOptions options) {}
	public ManagementObjectCollection GetSubclasses(EnumerationOptions options) {}
	public void GetInstances(ManagementOperationObserver watcher, EnumerationOptions options) {}
	public ManagementObjectCollection GetInstances(EnumerationOptions options) {}
 public static List <EthernetPortSettingDataComponent> GetInstances(ManagementScope mgmtScope, EnumerationOptions enumOptions) => GetInstances(mgmtScope, enumOptions, ClassName).Cast <ManagementObject>().Select((mo) => new EthernetPortSettingDataComponent(mo)).ToList();
	public void GetRelationships(ManagementOperationObserver watcher, string relationshipClass, string relationshipQualifier, string thisRole, bool classDefinitionsOnly, EnumerationOptions options) {}
        private List <SystemProcesses> GetProcessInformation()
        {
            var processInformation = new List <SystemProcesses>();
            var simpleProcesses    = new List <SimpleProcessInfo>();

            try
            {
                using (var searcher =
                           new ManagementObjectSearcher("root\\CIMV2",
                                                        "SELECT ExecutablePath, ProcessId FROM Win32_Process"))
                {
                    simpleProcesses.AddRange(from ManagementBaseObject info in searcher.Get()
                                             let id = int.Parse(info["ProcessId"].ToString())
                                                      let fullPath = (string)info["ExecutablePath"]
                                                                     select new SimpleProcessInfo
                    {
                        path = fullPath,
                        id   = id
                    });
                }

                var options = new EnumerationOptions {
                    ReturnImmediately = false
                };
                using (var searcher =
                           new ManagementObjectSearcher("root\\CIMV2",
                                                        "SELECT * FROM Win32_PerfFormattedData_PerfProc_Process", options))
                {
                    processInformation.AddRange(from ManagementBaseObject queryObj in searcher.Get()
                                                where queryObj != null
                                                let name = (string)queryObj["Name"]
                                                           let processId = int.Parse(queryObj["IDProcess"].ToString())
                                                                           let handles = int.Parse(queryObj["HandleCount"].ToString())
                                                                                         let threads = int.Parse(queryObj["ThreadCount"].ToString())
                                                                                                       let memory = long.Parse(queryObj["WorkingSetPrivate"].ToString())
                                                                                                                    let cpuUsage = int.Parse(queryObj["PercentProcessorTime"].ToString())
                                                                                                                                   let ioReadOperationsPerSec = int.Parse(queryObj["IOReadOperationsPerSec"].ToString())
                                                                                                                                                                let ioWriteOperationsPerSec = int.Parse(queryObj["IOWriteOperationsPerSec"].ToString())
                                                                                                                                                                                              let fullPath                       = ""
                                                                                                                                                                                                                        let icon = ""
                                                                                                                                                                                                                                   select new SystemProcesses
                    {
                        id       = processId,
                        path     = fullPath,
                        name     = name,
                        icon     = icon,
                        ramUsage = memory,
                        cpuUsage = cpuUsage,
                        threads  = threads,
                        handles  = handles,
                        ioWriteOperationsPerSec = ioWriteOperationsPerSec,
                        ioReadOperationsPerSec  = ioReadOperationsPerSec
                    });
                    foreach (var result in processInformation)
                    {
                        foreach (var process in simpleProcesses.Where(process => process.id == result.id))
                        {
                            result.path = process.path;
                            if (!string.IsNullOrEmpty(result.path))
                            {
                                result.icon = Tools.GetIconForProcess(result.path);
                            }
                            else
                            {
                                result.path = "null";
                                result.icon = "null";
                            }
                        }
                    }
                }
            }
            catch (ManagementException e)
            {
                var data = new
                {
                    managementException = true,
                    message             = e.Message
                };
                serializator.Serialize(client, packet.endpoint, packet.syncKey, data);
            }

            return(processInformation);
        }
        /// <summary>
        /// Invoke the "special enumeration" in order to get collection of classes (by filter)
        /// </summary>
        /// <param name="wsmanClient">the client to connect</param>
        /// <param name="EPR">the EPR representing the "main object"</param>
        /// <param name="resultClassName">the class name which will be returned from the enumeration</param>
        /// <param name="associationClassName">the association class name, this class define the relation between the EPR and the result classes</param>
        /// <param name="role">the role name of the "main class"</param>
        /// <param name="resultRole">the role name of the result class</param>
        /// <returns>Collection of the result classes after executing the enumeration</returns>
        private static Collection<CimBaseReferencePair> EnumerateAssociatedImpl(IWSManClient wsmanClient, CimReference EPR, Type resultClass, Type associationClass, string role, string resultRole)
        {
            EnumerationOptions enumOptions = new EnumerationOptions();

            enumOptions.Filter = new AssociatedFilter(
                EPR,
                (resultClass != null) ? resultClass.UnderlyingSystemType.Name : null, // Validate the resultClass property
                role,
                null, // The includeResultProperty is not supported by AMT
                (associationClass != null) ? associationClass.UnderlyingSystemType.Name : null, // Validate the associationClass property
                resultRole);

            Collection<CimBaseReferencePair> objCollection = CimBase.Enumerate(wsmanClient, enumOptions);

            return objCollection;
        }
Example #19
0
        /// <summary>
        /// Gets the properties of an item at the specified path
        /// </summary>
        protected override void BeginProcessing()
        {
            ConnectionOptions options = GetConnectionOption();

            if (this.AsJob)
            {
                RunAsJob("Get-WMIObject");
                return;
            }
            else
            {
                if (List.IsPresent)
                {
                    if (!this.ValidateClassFormat())
                    {
                        ErrorRecord errorRecord = new ErrorRecord(
                            new ArgumentException(
                                string.Format(
                                    Thread.CurrentThread.CurrentCulture,
                                    "Class", this.Class)),
                            "INVALID_QUERY_IDENTIFIER",
                            ErrorCategory.InvalidArgument,
                            null);
                        errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiFilterInvalidClass", this.Class);

                        WriteError(errorRecord);
                        return;
                    }

                    foreach (string name in ComputerName)
                    {
                        if (this.Recurse.IsPresent)
                        {
                            Queue namespaceElement = new Queue();
                            namespaceElement.Enqueue(this.Namespace);
                            while (namespaceElement.Count > 0)
                            {
                                string          connectNamespace = (string)namespaceElement.Dequeue();
                                ManagementScope scope            = new ManagementScope(WMIHelper.GetScopeString(name, connectNamespace), options);
                                try
                                {
                                    scope.Connect();
                                }
                                catch (ManagementException e)
                                {
                                    ErrorRecord errorRecord = new ErrorRecord(
                                        e,
                                        "INVALID_NAMESPACE_IDENTIFIER",
                                        ErrorCategory.ObjectNotFound,
                                        null);
                                    errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiNamespaceConnect", connectNamespace, e.Message);
                                    WriteError(errorRecord);
                                    continue;
                                }
                                catch (System.Runtime.InteropServices.COMException e)
                                {
                                    ErrorRecord errorRecord = new ErrorRecord(
                                        e,
                                        "INVALID_NAMESPACE_IDENTIFIER",
                                        ErrorCategory.ObjectNotFound,
                                        null);
                                    errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiNamespaceConnect", connectNamespace, e.Message);
                                    WriteError(errorRecord);
                                    continue;
                                }
                                catch (System.UnauthorizedAccessException e)
                                {
                                    ErrorRecord errorRecord = new ErrorRecord(
                                        e,
                                        "INVALID_NAMESPACE_IDENTIFIER",
                                        ErrorCategory.ObjectNotFound,
                                        null);
                                    errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiNamespaceConnect", connectNamespace, e.Message);
                                    WriteError(errorRecord);
                                    continue;
                                }

                                ManagementClass namespaceClass = new ManagementClass(scope, new ManagementPath("__Namespace"), new ObjectGetOptions());
                                foreach (ManagementBaseObject obj in namespaceClass.GetInstances())
                                {
                                    if (!IsLocalizedNamespace((string)obj["Name"]))
                                    {
                                        namespaceElement.Enqueue(connectNamespace + "\\" + obj["Name"]);
                                    }
                                }

                                ManagementObjectSearcher searcher = this.GetObjectList(scope);
                                if (searcher == null)
                                {
                                    continue;
                                }
                                foreach (ManagementBaseObject obj in searcher.Get())
                                {
                                    WriteObject(obj);
                                }
                            }
                        }
                        else
                        {
                            ManagementScope scope = new ManagementScope(WMIHelper.GetScopeString(name, this.Namespace), options);
                            try
                            {
                                scope.Connect();
                            }
                            catch (ManagementException e)
                            {
                                ErrorRecord errorRecord = new ErrorRecord(
                                    e,
                                    "INVALID_NAMESPACE_IDENTIFIER",
                                    ErrorCategory.ObjectNotFound,
                                    null);
                                errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiNamespaceConnect", this.Namespace, e.Message);
                                WriteError(errorRecord);
                                continue;
                            }
                            catch (System.Runtime.InteropServices.COMException e)
                            {
                                ErrorRecord errorRecord = new ErrorRecord(
                                    e,
                                    "INVALID_NAMESPACE_IDENTIFIER",
                                    ErrorCategory.ObjectNotFound,
                                    null);
                                errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiNamespaceConnect", this.Namespace, e.Message);
                                WriteError(errorRecord);
                                continue;
                            }
                            catch (System.UnauthorizedAccessException e)
                            {
                                ErrorRecord errorRecord = new ErrorRecord(
                                    e,
                                    "INVALID_NAMESPACE_IDENTIFIER",
                                    ErrorCategory.ObjectNotFound,
                                    null);
                                errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiNamespaceConnect", this.Namespace, e.Message);
                                WriteError(errorRecord);
                                continue;
                            }

                            ManagementObjectSearcher searcher = this.GetObjectList(scope);
                            if (searcher == null)
                            {
                                continue;
                            }
                            foreach (ManagementBaseObject obj in searcher.Get())
                            {
                                WriteObject(obj);
                            }
                        }
                    }

                    return;
                }

                // When -List is not specified and -Recurse is specified, we need the -Class parameter to compose the right query string
                if (this.Recurse.IsPresent && string.IsNullOrEmpty(Class))
                {
                    string      errorMsg = string.Format(CultureInfo.InvariantCulture, WmiResources.WmiParameterMissing, "-Class");
                    ErrorRecord er       = new ErrorRecord(new InvalidOperationException(errorMsg), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                string      queryString = string.IsNullOrEmpty(this.Query) ? GetQueryString() : this.Query;
                ObjectQuery query       = new ObjectQuery(queryString.ToString());

                foreach (string name in ComputerName)
                {
                    try
                    {
                        ManagementScope    scope       = new ManagementScope(WMIHelper.GetScopeString(name, this.Namespace), options);
                        EnumerationOptions enumOptions = new EnumerationOptions();
                        enumOptions.UseAmendedQualifiers = Amended;
                        enumOptions.DirectRead           = DirectRead;
                        ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query, enumOptions);
                        foreach (ManagementBaseObject obj in searcher.Get())
                        {
                            WriteObject(obj);
                        }
                    }
                    catch (ManagementException e)
                    {
                        ErrorRecord errorRecord = null;
                        if (e.ErrorCode.Equals(ManagementStatus.InvalidClass))
                        {
                            string className = GetClassNameFromQuery(queryString);
                            string errorMsg  = string.Format(CultureInfo.InvariantCulture, WmiResources.WmiQueryFailure,
                                                             e.Message, className);
                            errorRecord = new ErrorRecord(new ManagementException(errorMsg), "GetWMIManagementException", ErrorCategory.InvalidType, null);
                        }
                        else if (e.ErrorCode.Equals(ManagementStatus.InvalidQuery))
                        {
                            string errorMsg = string.Format(CultureInfo.InvariantCulture, WmiResources.WmiQueryFailure,
                                                            e.Message, queryString);
                            errorRecord = new ErrorRecord(new ManagementException(errorMsg), "GetWMIManagementException", ErrorCategory.InvalidArgument, null);
                        }
                        else if (e.ErrorCode.Equals(ManagementStatus.InvalidNamespace))
                        {
                            string errorMsg = string.Format(CultureInfo.InvariantCulture, WmiResources.WmiQueryFailure,
                                                            e.Message, this.Namespace);
                            errorRecord = new ErrorRecord(new ManagementException(errorMsg), "GetWMIManagementException", ErrorCategory.InvalidArgument, null);
                        }
                        else
                        {
                            errorRecord = new ErrorRecord(e, "GetWMIManagementException", ErrorCategory.InvalidOperation, null);
                        }

                        WriteError(errorRecord);
                        continue;
                    }
                    catch (System.Runtime.InteropServices.COMException e)
                    {
                        ErrorRecord errorRecord = new ErrorRecord(e, "GetWMICOMException", ErrorCategory.InvalidOperation, null);
                        WriteError(errorRecord);
                        continue;
                    }
                }
            }
        }
        /// <summary>
        /// Invoke the "special enumeration" in order to get collection of association classes (by filter)
        /// </summary>
        /// <param name="wsmanClient">the client to connect</param>
        /// <param name="EPR">the EPR representing the "main object"</param>
        /// <param name="resultClassName">the class name which will be returned from the enumeration</param>
        /// <param name="role">the role name of the "main class"</param>
        /// <returns>Collection of the result classes after executing the enumeration</returns>
        private static Collection<CimBaseReferencePair> EnumerateAssociationImpl(IWSManClient wsmanClient, CimReference EPR, Type resultClass, string role)
        {
            EnumerationOptions enumOptions = new EnumerationOptions();

            enumOptions.Filter = new AssociationFilter(
                EPR,
                resultClass.UnderlyingSystemType.Name,
                role,
                null); // This includeResultProperty is not supported by AMT

            Collection<CimBaseReferencePair> objCollection = CimBase.Enumerate(wsmanClient, enumOptions);

            return objCollection;
        }
	public ManagementObjectSearcher(string scope, string queryString, EnumerationOptions options) {}
Example #22
0
 /// <inheritdoc />
 public IEnumerable <IFileSystemInfo> EnumerateFileSystemInfos(string searchPattern, EnumerationOptions enumerationOptions)
 {
     return(Convert(Implementation.EnumerateFileSystemInfos(searchPattern, enumerationOptions)));
 }
Example #23
0
 public IEnumerable <FileSystemInfo> EnumerateFileSystemInfos(string searchPattern, EnumerationOptions enumerationOptions)
 => InternalEnumerateInfos(FullPath, searchPattern, SearchTarget.Both, enumerationOptions);
Example #24
0
 /// <inheritdoc />
 public IEnumerable <IDirectoryInfo> EnumerateDirectories(string searchPattern, EnumerationOptions enumerationOptions)
 {
     return(Convert(Implementation.EnumerateDirectories(searchPattern, enumerationOptions)));
 }
Example #25
0
 public static string[] GetDirectories(string path, string searchPattern, SearchOption searchOption)
 => GetDirectories(path, searchPattern, EnumerationOptions.FromSearchOption(searchOption));
Example #26
0
 public FileInfo[] GetFiles(string searchPattern, EnumerationOptions enumerationOptions)
 => ((IEnumerable <FileInfo>)InternalEnumerateInfos(FullPath, searchPattern, SearchTarget.Files, enumerationOptions)).ToArray();
Example #27
0
 public static string[] GetFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
 => GetFileSystemEntries(path, searchPattern, EnumerationOptions.FromSearchOption(searchOption));
Example #28
0
 public FileSystemInfo[] GetFileSystemInfos(string searchPattern, SearchOption searchOption)
 => GetFileSystemInfos(searchPattern, EnumerationOptions.FromSearchOption(searchOption));
Example #29
0
 public static List <Error> GetInstances(ManagementScope mgmtScope, EnumerationOptions enumOptions) => GetInstances(mgmtScope, enumOptions, ClassName).Cast <ManagementObject>().Select((mo) => new Error(mo)).ToList();
Example #30
0
 public FileSystemInfo[] GetFileSystemInfos(string searchPattern, EnumerationOptions enumerationOptions)
 => InternalEnumerateInfos(FullPath, searchPattern, SearchTarget.Both, enumerationOptions).ToArray();
Example #31
0
 public DirectoryRecursed(string directory, EnumerationOptions options)
     : base(directory, options)
 {
 }
Example #32
0
 public DirectoryInfo[] GetDirectories(string searchPattern, SearchOption searchOption)
 => GetDirectories(searchPattern, EnumerationOptions.FromSearchOption(searchOption));
Example #33
0
 public FileSystemEnumerable(string directory, FindTransform transform, EnumerationOptions options = null)
     : this(directory, transform, options, isNormalized : false)
 {
 }
Example #34
0
 public DirectoryInfo[] GetDirectories(string searchPattern, EnumerationOptions enumerationOptions)
 => ((IEnumerable <DirectoryInfo>)InternalEnumerateInfos(FullPath, searchPattern, SearchTarget.Directories, enumerationOptions)).ToArray();
        private void UnInstallAndUnMap(string hostName, string serverName)
        {
            try
            {
                StopHostInstances(hostName);
                //Build the HostInstance name
                string hostInstanceName = "Microsoft BizTalk Server" //Name of product
                                          + " " + hostName           //Name of Host of which instance is to be deleted
                                          + " " + serverName;        //Name of Server on which instance is to be deleted

                //Get the options and create a new ManagementClass
                ObjectGetOptions hostInstOptions = new ObjectGetOptions();
                ManagementClass  hostInstClass   = new ManagementClass(string.Format(BIZTALKSCOPE, serverName), "MSBTS_HostInstance", hostInstOptions);
                //Specify the enumeration options and retrieve instances of the HostInstance class
                EnumerationOptions enumOptions = new EnumerationOptions();
                enumOptions.ReturnImmediately = false;
                ManagementObjectCollection hostInstCollection = hostInstClass.GetInstances(enumOptions);

                ManagementObject hostInstance = null;

                //Iterate through the collection and retrieve the specific HostInstance that is required
                foreach (ManagementObject inst in hostInstCollection)
                {
                    if (inst["Name"] != null)
                    {
                        if (inst["Name"].ToString().ToUpper() == hostInstanceName.ToUpper())
                        {
                            hostInstance = inst;
                        }
                    }
                }

                //Stop the HostInstance if it is 'Started' and if it is an InProcess HostInstance
                if (hostInstance != null && hostInstance["HostType"].ToString() != "2" && hostInstance["ServiceState"].ToString() == "4")
                {
                    hostInstance.InvokeMethod("Stop", null);
                }

                // Remove adapter handlers
                DeleteReceiveHandler("WCF-NetTcp", serverName, hostName, HandlerType.Receive);
                DeleteReceiveHandler("WCF-NetTcp", serverName, hostName, HandlerType.Send);

                //Now UnInstall the HostInstance
                if (hostInstance != null)
                {
                    hostInstance.InvokeMethod("UnInstall", null);
                }

                //Create an instance of the ServerHost class using the System.Management namespace
                ObjectGetOptions svrHostOptions = new ObjectGetOptions();
                ManagementClass  svrHostClass   = new ManagementClass(string.Format(BIZTALKSCOPE, serverName), "MSBTS_ServerHost", svrHostOptions);
                ManagementObject svrHostObject  = svrHostClass.CreateInstance();

                //Set the properties of the ServerHost instance
                svrHostObject["ServerName"] = serverName;
                svrHostObject["HostName"]   = hostName;

                //Invoke the UnMap method of the ServerHost object
                try
                {
                    svrHostObject.InvokeMethod("UnMap", null);
                }
                catch { }

                DeleteHost(hostName);
                return;
            }
            catch (Exception excep)
            {
                throw new ApplicationException("Failure during HostInstance deletion", excep);
            }
        }
Example #36
0
 public IEnumerable <DirectoryInfo> EnumerateDirectories(string searchPattern, SearchOption searchOption)
 => EnumerateDirectories(searchPattern, EnumerationOptions.FromSearchOption(searchOption));
Example #37
0
        private static void Stop(string assemblyName, string orchestrationName, Context context)
        {
            var stopped  = false;
            var wmiQuery =
                String.Format("Select * from MSBTS_Orchestration where Name=\"{0}\" and AssemblyName=\"{1}\"", orchestrationName, assemblyName);

            context.LogInfo("Query for Orchestration: {0}", wmiQuery);

            var enumOptions = new EnumerationOptions {
                ReturnImmediately = false
            };
            var orchestrationSearcher = new ManagementObjectSearcher("root\\MicrosoftBizTalkServer", wmiQuery, enumOptions);

            var retryCnt = -1;
            var status   = (UInt32)999;
            var found    = false;

            while (!stopped && (retryCnt < 10))
            {
                retryCnt++;
                if (retryCnt > 0)
                {
                    Thread.Sleep(5000);
                }
                foreach (ManagementObject orchestrationInstance in orchestrationSearcher.Get())
                {
                    found  = true;
                    status = (UInt32)orchestrationInstance.GetPropertyValue("OrchestrationStatus");
                    context.LogInfo("current orchestration status: {0}", status);
                    if (status == (UInt32)OrchestrationStatus.Unbound)
                    {
                        var e = new Exception("Orchestration is unbound");
                        context.LogException(e);
                        throw e;
                    }
                    switch (status)
                    {
                    case (UInt32)OrchestrationStatus.Bound:
                        // We need to Enlist the orchestration first
                        context.LogInfo("Enlisting Orchestration: {0}", orchestrationName);
                        orchestrationInstance.InvokeMethod("Enlist", new object[] { });
                        break;

                    case (UInt32)OrchestrationStatus.Started:
                        context.LogInfo("Stopping Orchestration: {0}", orchestrationName);

                        /*
                         * AutoEnableReceiveLocationFlag
                         * [in] [in] Permissible values for this property are (1) "No auto disable of receive locations related to this Orchestration", or (2) "Disable all receive locations related to this orchestration that are not shared by other orchestration(s)". Note that the integer values must be used in code and script. The default value is 1.
                         * AutoResumeOrchestrationInstanceFlag
                         * [in] Permissible values for this property are (1) "No auto suspend of service instances of this Orchestration", or (2) "Suspend all running service instances of this Orchestration". Note that the integer values must be used in code and script. The default value is 2.
                         */
                        orchestrationInstance.InvokeMethod("Stop", new object[] { 2, 2 });
                        context.LogInfo("Orchestration: {0} was successfully stopped", orchestrationName);
                        stopped = true;
                        break;

                    case (UInt32)OrchestrationStatus.Stopped:
                        context.LogInfo("Orchestration: {0} was already stopped", orchestrationName);
                        stopped = true;
                        break;

                    default:
                        var e = new Exception(string.Format("Unhandled orchestration status: {0}", status));
                        context.LogException(e);
                        throw e;
                    }
                }
                if (!found)
                {
                    retryCnt = 10;
                }
            }

            if (!found)
            {
                throw new Exception(string.Format("Orchestration: \"{0}\" in \"{1}\" not found", orchestrationName, assemblyName));
            }
            if (!stopped)
            {
                throw new Exception(string.Format("Failed to stop the orchestration: \"{0}\" after {1} retries: status={2}", orchestrationName, retryCnt, status));
            }
        }
Example #38
0
 public IEnumerable <DirectoryInfo> EnumerateDirectories(string searchPattern, EnumerationOptions enumerationOptions)
 => (IEnumerable <DirectoryInfo>)InternalEnumerateInfos(FullPath, searchPattern, SearchTarget.Directories, enumerationOptions);
Example #39
0
 protected abstract string[] GetPaths(string directory, string pattern, EnumerationOptions options);
Example #40
0
 public IEnumerable <FileInfo> EnumerateFiles(string searchPattern, EnumerationOptions enumerationOptions)
 => (IEnumerable <FileInfo>)InternalEnumerateInfos(FullPath, searchPattern, SearchTarget.Files, enumerationOptions);
Example #41
0
 protected override string[] GetPaths(string directory, string pattern, EnumerationOptions options)
 {
     return(new DirectoryInfo(directory).GetFiles(pattern, options).Select(i => i.FullName).ToArray());
 }
	public ManagementObjectSearcher(ManagementScope scope, ObjectQuery query, EnumerationOptions options) {}