Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
             }
         }
     });
 }
Esempio n. 5
0
 /// <summary>
 /// Reboot the computer
 /// </summary>
 public async Task reboot()
 {
     await WMIExecutor.reboot(this);
 }
Esempio n. 6
0
 /// <summary>
 /// Shutdown the computer
 /// </summary>
 public async Task shutdown()
 {
     await WMIExecutor.shutdown(this);
 }
Esempio n. 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));
 }
Esempio n. 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));
 }
Esempio n. 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));
 }