Beispiel #1
0
        /// <summary>
        /// Return all the logged users on the computer. Note that local system account will
        /// also be returned
        /// </summary>
        /// <param name="force">True to ignore any cache</param>
        /// <returns>ALl the logged users</returns>
        public async Task <IEnumerable <User> > getAllLoggedUsers(bool force = false)
        {
            TimeSpan diff = DateTime.Now - lastUsersFetch;

            if (force || diff.TotalMilliseconds > maxCacheLife || cachedUsers == null)
            {
                cachedUsers = await WMIExecutor.getLoggedUsers(this);

                lastUsersFetch = DateTime.Now;
            }

            return(cachedUsers);
        }
Beispiel #2
0
        /// <summary>
        /// Return the mac address of the computer
        /// </summary>
        /// <param name="force">True to ignore any cache</param>
        /// <returns>The mac address</returns>
        public async Task <string> getMacAddress(bool force = false)
        {
            TimeSpan diff = DateTime.Now - lastMacAddrFetch;

            if (force || diff.TotalMilliseconds > maxCacheLife || cachedMacAddr == null)
            {
                cachedMacAddr = await WMIExecutor.getMACAddress(this);

                lastMacAddrFetch = DateTime.Now;
            }

            return(cachedMacAddr);
        }
Beispiel #3
0
        /// <summary>
        /// Return all the sofwares installed on the computer.
        /// </summary>
        /// <param name="force">True to ignore any cache</param>
        /// <returns>All the installed sofwares</returns>
        public async Task <IEnumerable <Software> > getInstalledSofwares(bool force = false)
        {
            TimeSpan diff = DateTime.Now - lastSoftwaresFetch;

            if (force || diff.TotalMilliseconds > maxCacheLife || cachedSoftwares == null)
            {
                var results = await Task.WhenAll(
                    Task.Run(() => WMIExecutor.getInstalledSoftwares(this, 32)),
                    Task.Run(() => WMIExecutor.getInstalledSoftwares(this, 64)));

                cachedSoftwares    = results.SelectMany(result => result);
                lastSoftwaresFetch = DateTime.Now;
            }

            return(cachedSoftwares);
        }
Beispiel #4
0
 /// <summary>
 /// Execute a remote action
 /// </summary>
 /// <param name="command">The command</param>
 /// <param name="args">The command arguments</param>
 /// <param name="maxDuration">The maximum duration of the command</param>
 /// <param name="callback">The callback to call after the remote action</param>
 public void exec(string command, string[] args, Action <WMIExecutionResult> callback, Action <WMIException> callbackError = null, long maxDuration = 5000)
 {
     WMIExecutor.exec(this, command, args, maxDuration).ContinueWith(result => {
         if (result.Exception != null)
         {
             if (callbackError != null)
             {
                 callbackError(result.Exception.InnerException as WMIException);
             }
             else
             {
                 callback(result.Result);
             }
         }
     });
 }
Beispiel #5
0
 /// <summary>
 /// Reboot the computer
 /// </summary>
 public async Task reboot()
 {
     await WMIExecutor.reboot(this);
 }
Beispiel #6
0
 /// <summary>
 /// Shutdown the computer
 /// </summary>
 public async Task shutdown()
 {
     await WMIExecutor.shutdown(this);
 }
Beispiel #7
0
 /// <summary>
 /// Execute a remote action
 /// </summary>
 /// <param name="command">The command</param>
 /// <param name="args">The command arguments</param>
 /// <param name="maxDuration">The maximum duration of the command</param>
 /// <returns>The async task of the action</returns>
 public async Task <WMIExecutionResult> exec(string command, string[] args = null, long maxDuration = 5000)
 {
     return(await WMIExecutor.exec(this, command, args, maxDuration));
 }
Beispiel #8
0
 /// <summary>
 /// Return all the logged users on the computer. Note that local system account will
 /// also be returned
 /// </summary>
 /// <returns>ALl the logged users</returns>
 public static async Task <IEnumerable <User> > getAllLoggedUsers(Computer computer)
 {
     return(await WMIExecutor.getLoggedUsers(computer));
 }
Beispiel #9
0
 /// <summary>
 /// Return the logged users on the computed. Note that only real user accounts will
 /// be returned
 /// </summary>
 /// <returns>The logged user</returns>
 public static async Task <IEnumerable <User> > getLoggedUsers(Computer computer)
 {
     return((await WMIExecutor.getLoggedUsers(computer)).Where(u => u.SIDType == 1));
 }