Пример #1
0
        public override void mStart()
        {
            blGo = true;
            try
            {
                intStatus = STATUS_RUNNING;
                if (readSettings())
                {
                    log(MOD_NAME, "Starting interprocess communication process...");
                    server.start();
                    if (server.isRunning())
                    {
                        log(MOD_NAME, " interprocess comm startup: OK");
                    }
                    else
                    {
                        log(MOD_NAME, " interprocess comm startup: FAILED");
                    }

                    ArrayList alMACs = getMacAddress();

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



                    if (strMACList != null && strMACList.Length > 0)
                    {
                        Boolean blConnectOK = false;
                        String  strDta      = "";
                        while (!blConnectOK)
                        {
                            try
                            {
                                log(MOD_NAME, "Attempting to connect to fog server...");
                                WebClient wc      = new WebClient();
                                String    strPath = strURLModuleStatus + "?mac=" + strMACList + "&moduleid=printermanager";
                                strDta      = 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 { }
                            }
                        }

                        strDta = strDta.Trim();
                        Boolean blLoop = false;

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

                        blEnabled = blLoop;
                        if (blLoop)
                        {
                            managePrinters();
                        }
                    }
                }
                else
                {
                    log(MOD_NAME, "Failed to read ini settings.");
                }
            }
            catch
            {
            }
        }