Esempio n. 1
0
        private void doWork()
        {
            try
            {
                log(MOD_NAME, "Starting display manager process...");
                switch (System.Environment.OSVersion.Version.Major)
                {
                case 5:
                    break;

                case 6:
                    break;

                case 7:
                    break;

                default:
                    log(MOD_NAME, "This module has only been tested on Windows XP, Vista and 7!");
                    break;
                }

                ArrayList alMACs  = getMacAddress();
                String    macList = null;
                if (alMACs != null && alMACs.Count > 0)
                {
                    String[] strMacs = (String[])alMACs.ToArray(typeof(String));
                    macList = String.Join("|", strMacs);
                }

                // First check and see if the module is active
                //
                Boolean blLoop = false;
                if (macList != null && macList.Length > 0)
                {
                    Boolean blConnectOK = false;
                    String  strData     = "";
                    while (!blConnectOK)
                    {
                        try
                        {
                            log(MOD_NAME, "Attempting to connect to fog server...");
                            WebClient wc      = new WebClient();
                            String    strPath = strURLModuleStatus + "?mac=" + macList + "&moduleid=displaymanager";
                            strData     = wc.DownloadString(strPath);
                            blConnectOK = true;
                        }
                        catch (Exception exp)
                        {
                            log(MOD_NAME, "Failed to connect to fog server!");
                            log(MOD_NAME, exp.Message);
                            log(MOD_NAME, exp.StackTrace);
                            log(MOD_NAME, "Sleeping for 1 minute.");
                            try
                            {
                                System.Threading.Thread.Sleep(60000);
                            }
                            catch { }
                        }
                    }

                    strData = strData.Trim();
                    if (strData.StartsWith("#!ok", true, null))
                    {
                        log(MOD_NAME, "Module is active...");
                        blLoop = true;
                    }
                    else if (strData.StartsWith("#!db", true, null))
                    {
                        log(MOD_NAME, "Database error.");
                    }
                    else if (strData.StartsWith("#!im", true, null))
                    {
                        log(MOD_NAME, "Invalid MAC address format.");
                    }
                    else if (strData.StartsWith("#!ng", true, null))
                    {
                        log(MOD_NAME, "Module is disabled globally on the FOG Server.");
                    }
                    else if (strData.StartsWith("#!nh", true, null))
                    {
                        log(MOD_NAME, "Module is disabled on this host.");
                    }
                    else if (strData.StartsWith("#!um", true, null))
                    {
                        log(MOD_NAME, "Unknown Module ID passed to server.");
                    }
                    else
                    {
                        log(MOD_NAME, "Unknown error, module will exit.");
                    }


                    if (blLoop)
                    {
                        Boolean blLgIn = isLoggedIn();
                        int     X      = -1;
                        int     Y      = -1;
                        int     R      = -1;
                        try
                        {
                            WebClient wc     = new WebClient();
                            String    strRes = wc.DownloadString(strURLDisplay + "?mac=" + macList);
                            strRes = strRes.Trim();
                            if (strRes != null)
                            {
                                String strDisplaySettings = decode64(strRes);
                                if (strDisplaySettings != null)
                                {
                                    String[] strParts = strDisplaySettings.Split('x');
                                    if (strParts.Length == 3)
                                    {
                                        try
                                        {
                                            X = int.Parse(strParts[0]);
                                        }
                                        catch
                                        {
                                            blGo = false;
                                            log(MOD_NAME, "Unable to convert width into a valid integer.");
                                        }

                                        try
                                        {
                                            Y = int.Parse(strParts[1]);
                                        }
                                        catch
                                        {
                                            blGo = false;
                                            log(MOD_NAME, "Unable to convert height into a valid integer.");
                                        }

                                        try
                                        {
                                            R = int.Parse(strParts[2]);
                                        }
                                        catch
                                        {
                                            blGo = false;
                                            log(MOD_NAME, "Unable to convert refresh rate into a valid integer.");
                                        }
                                    }
                                    else
                                    {
                                        blGo = false;
                                        log(MOD_NAME, "Invalid server response.");
                                    }
                                }
                                else
                                {
                                    blGo = false;
                                    log(MOD_NAME, "Unable to determine screen resolution settings.");
                                }
                            }
                            else
                            {
                                blGo = false;
                                log(MOD_NAME, "Server response was null.");
                            }
                        }
                        catch (Exception exp)
                        {
                            log(MOD_NAME, exp.Message);
                            log(MOD_NAME, exp.StackTrace);
                            blGo = false;
                        }


                        log(MOD_NAME, "Starting display manager monitoring loop...");
                        Boolean        blFirst = true;
                        DisplayChanger display = new DisplayChanger();
                        while (blGo)
                        {
                            Boolean blCurLgIn = isLoggedIn();

                            // if this is the first iteration of the loop
                            // and no one is logged in, then attempt to
                            // do a cleanup.  This will cleanup users on a reboot
                            if (blFirst)
                            {
                                log(MOD_NAME, "Changing Display Setting to " + X + " x " + Y + " x " + R + " .");
                                if (!display.changeDisplaySettings(X, Y, R, 0))
                                {
                                    log(MOD_NAME, "Failed to change display settings.");
                                }
                                else
                                {
                                    log(MOD_NAME, "Display settings changed.");
                                }
                                blFirst = false;
                            }


                            if (blLgIn != blCurLgIn)
                            {
                                if (blCurLgIn)
                                {
                                    log(MOD_NAME, "Login detected, taking action...");
                                    log(MOD_NAME, "Changing Display Setting to " + X + " x " + Y + " x " + R + ".");

                                    try
                                    {
                                        System.Threading.Thread.Sleep(20000);
                                    }
                                    catch (Exception)
                                    {
                                    }

                                    if (!display.changeDisplaySettings(X, Y, R, 0))
                                    {
                                        log(MOD_NAME, "Failed to change display settings.");
                                    }
                                    else
                                    {
                                        log(MOD_NAME, "Display settings changed.");
                                    }
                                }
                                blLgIn = blCurLgIn;
                            }

                            try
                            {
                                System.Threading.Thread.Sleep(30000);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        log(MOD_NAME, "Module has finished work and will now exit.");
                    }
                }
                else
                {
                    log(MOD_NAME, "Unable to continue, MAC is null!");
                }
            }
            catch (Exception e)
            {
                pushMessage("FOG DisplayManager error:\n" + e.Message);
                log(MOD_NAME, e.Message);
                log(MOD_NAME, e.StackTrace);
            }
            finally
            {
            }
            intStatus = STATUS_TASKCOMPLETE;
        }
Esempio n. 2
0
        private void doWork()
        {
            try
            {
                log(MOD_NAME, "Starting display manager process...");
                switch (System.Environment.OSVersion.Version.Major)
                {
                    case 5:
                        break;
                    case 6:
                        break;
                    case 7:
                        break;
                    default:
                        log(MOD_NAME, "This module has only been tested on Windows XP, Vista and 7!");
                        break;
                }

                ArrayList alMACs = getMacAddress();
                String macList = null;
                if (alMACs != null && alMACs.Count > 0)
                {
                    String[] strMacs = (String[])alMACs.ToArray(typeof(String));
                    macList = String.Join("|", strMacs);
                }

                // First check and see if the module is active
                //
                Boolean blLoop = false;
                if (macList != null && macList.Length > 0)
                {
                    Boolean blConnectOK = false;
                    String strData = "";
                    while (!blConnectOK)
                    {
                        try
                        {
                            log(MOD_NAME, "Attempting to connect to fog server...");
                            WebClient wc = new WebClient();
                            String strPath = strURLModuleStatus + "?mac=" + macList + "&moduleid=displaymanager";
                            strData = wc.DownloadString(strPath);
                            blConnectOK = true;
                        }
                        catch (Exception exp)
                        {
                            log(MOD_NAME, "Failed to connect to fog server!");
                            log(MOD_NAME, exp.Message);
                            log(MOD_NAME, exp.StackTrace);
                            log(MOD_NAME, "Sleeping for 1 minute.");
                            try
                            {
                                System.Threading.Thread.Sleep(60000);
                            }
                            catch { }
                        }
                    }

                    strData = strData.Trim();
                    if (strData.StartsWith("#!ok", true, null))
                    {
                        log(MOD_NAME, "Module is active...");
                        blLoop = true;
                    }
                    else if (strData.StartsWith("#!db", true, null))
                    {
                        log(MOD_NAME, "Database error.");
                    }
                    else if (strData.StartsWith("#!im", true, null))
                    {
                        log(MOD_NAME, "Invalid MAC address format.");
                    }
                    else if (strData.StartsWith("#!ng", true, null))
                    {
                        log(MOD_NAME, "Module is disabled globally on the FOG Server.");
                    }
                    else if (strData.StartsWith("#!nh", true, null))
                    {
                        log(MOD_NAME, "Module is disabled on this host.");
                    }
                    else if (strData.StartsWith("#!um", true, null))
                    {
                        log(MOD_NAME, "Unknown Module ID passed to server.");
                    }
                    else
                    {
                        log(MOD_NAME, "Unknown error, module will exit.");
                    }

                    if (blLoop)
                    {
                        Boolean blLgIn = isLoggedIn();
                        int X = -1;
                        int Y = -1;
                        int R = -1;
                        try
                        {
                            WebClient wc = new WebClient();
                            String strRes = wc.DownloadString(strURLDisplay + "?mac=" + macList);
                            strRes = strRes.Trim();
                            if (strRes != null)
                            {
                                String strDisplaySettings = decode64(strRes);
                                if (strDisplaySettings != null)
                                {
                                    String[] strParts = strDisplaySettings.Split('x');
                                    if (strParts.Length == 3)
                                    {
                                        try
                                        {
                                            X = int.Parse(strParts[0]);
                                        }
                                        catch
                                        {
                                            blGo = false;
                                            log(MOD_NAME, "Unable to convert width into a valid integer.");
                                        }

                                        try
                                        {
                                            Y = int.Parse(strParts[1]);
                                        }
                                        catch
                                        {
                                            blGo = false;
                                            log(MOD_NAME, "Unable to convert height into a valid integer.");
                                        }

                                        try
                                        {
                                            R = int.Parse(strParts[2]);
                                        }
                                        catch
                                        {
                                            blGo = false;
                                            log(MOD_NAME, "Unable to convert refresh rate into a valid integer.");
                                        }
                                    }
                                    else
                                    {
                                        blGo = false;
                                        log(MOD_NAME, "Invalid server response.");
                                    }
                                }
                                else
                                {
                                    blGo = false;
                                    log(MOD_NAME, "Unable to determine screen resolution settings.");
                                }
                            }
                            else
                            {
                                blGo = false;
                                log(MOD_NAME, "Server response was null.");
                            }
                        }
                        catch (Exception exp)
                        {
                            log(MOD_NAME, exp.Message);
                            log(MOD_NAME, exp.StackTrace);
                            blGo = false;
                        }

                        log(MOD_NAME, "Starting display manager monitoring loop...");
                        Boolean blFirst = true;
                        DisplayChanger display = new DisplayChanger();
                        while (blGo)
                        {
                            Boolean blCurLgIn = isLoggedIn();

                            // if this is the first iteration of the loop
                            // and no one is logged in, then attempt to
                            // do a cleanup.  This will cleanup users on a reboot
                            if (blFirst )
                            {
                                log(MOD_NAME, "Changing Display Setting to " + X + " x " + Y + " x " + R + " .");
                                if (!display.changeDisplaySettings(X, Y, R, 0))
                                {
                                    log(MOD_NAME, "Failed to change display settings.");
                                }
                                else
                                {
                                    log(MOD_NAME, "Display settings changed.");
                                }
                                blFirst = false;
                            }

                            if (blLgIn != blCurLgIn)
                            {
                                if (blCurLgIn)
                                {
                                    log(MOD_NAME, "Login detected, taking action...");
                                    log(MOD_NAME, "Changing Display Setting to " + X + " x " + Y + " x " + R + ".");

                                    try
                                    {
                                        System.Threading.Thread.Sleep(20000);
                                    }
                                    catch (Exception)
                                    {

                                    }

                                    if (!display.changeDisplaySettings(X, Y, R, 0))
                                    {
                                        log(MOD_NAME, "Failed to change display settings.");
                                    }
                                    else
                                    {
                                        log(MOD_NAME, "Display settings changed.");
                                    }
                                }
                                blLgIn = blCurLgIn;
                            }

                            try
                            {
                                System.Threading.Thread.Sleep(30000);
                            }
                            catch (Exception )
                            {

                            }
                        }
                        log(MOD_NAME, "Module has finished work and will now exit.");
                    }
                }
                else
                {
                    log(MOD_NAME, "Unable to continue, MAC is null!");
                }

            }
            catch (Exception e)
            {
                pushMessage("FOG DisplayManager error:\n" + e.Message);
                log(MOD_NAME, e.Message);
                log(MOD_NAME, e.StackTrace);
            }
            finally
            {
            }
            intStatus = STATUS_TASKCOMPLETE;
        }