Пример #1
0
        public static void webUpdate()
        {
            if (
                bubble.databaseConnect && DatabaseCredChkCount < databaseTimeOutCount && config.getProfile(bubble.profileInUse).webUpd
                &&
                (
                (webCredsJustChecked || (time.secondsSinceStart() - webUpdLastChecked > config.getProfile(bubble.profileInUse).webPoll))
                || webFirstTimeThru
                )
                )
            {
                teboDebug.writeline(teboDebug.webUpdateVal + 1);
                if (!DatabaseCredentialsCorrect)
                {

                    teboDebug.writeline(teboDebug.webUpdateVal + 2);
                    pulseEvent(null, new EventArgs());

                    logAddLine("Web database not connected checking credentials...");
                    DatabaseCredentialsCorrect = database.credentials_correct(bubble.mysqlDriver, config.getProfile(bubble.profileInUse).webUser, config.getProfile(bubble.profileInUse).webPass);
                    webUpdLastChecked = time.secondsSinceStart();
                    DatabaseCredChkCount++;
                    if (DatabaseCredentialsCorrect)
                    {
                        teboDebug.writeline(teboDebug.webUpdateVal + 3);
                        logAddLine("Web database credentials validated.");
                        webCredsJustChecked = true;
                    }
                    if (DatabaseCredChkCount == databaseTimeOutCount)
                    {
                        teboDebug.writeline(teboDebug.webUpdateVal + 4);
                        logAddLine("Web database credentials checked " + databaseTimeOutCount.ToString() + " times and found to be incorrect!");
                    }
                }
                else
                {

                    //on
                    //activate
                    //off
                    //inactivate
                    //pingon - can use pingon N to ping every N minutes
                    //pingoff
                    //poll N - poll online database every N seconds
                    //log
                    //image
                    //publish N
                    //publish off
                    //shutdown

                    teboDebug.writeline(teboDebug.webUpdateVal + 5);
                    pulseEvent(null, new EventArgs());

                    webCredsJustChecked = false;
                    DatabaseCredChkCount = 0;

                    string user = config.getProfile(bubble.profileInUse).webUser;
                    string instance = config.getProfile(bubble.profileInUse).webInstance;
                    ArrayList data_result = new ArrayList();
                    string update_result = "";

                    //20120331 check for restriction on processing old commands
                    //if a command has been sitting online for longer than a given number of seconds
                    //clear the online command and do not act on it
                    if (config.getProfile(bubble.profileInUse).disCommOnline)
                    {

                        data_result = database.database_get_data(bubble.mysqlDriver, user, instance, "online_request_dt");
                        int timeSinceCommandIssued = time.secondsSinceStart((string)data_result[0]);

                        if (timeSinceCommandIssued > config.getProfile(bubble.profileInUse).disCommOnlineSecs)
                        {

                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";

                        }

                    }

                    data_result = database.database_get_data(bubble.mysqlDriver, user, instance, "online_request");
                    string tmpStr = "";
                    if (data_result.Count >= 1) tmpStr = data_result[0].ToString().Trim();

                    bool securityCode = regex.match("111+$", tmpStr);
                    bool shutDownCmd = regex.match("^shutdown", tmpStr);
                    bool activateCmd = regex.match("^activate$", tmpStr);
                    bool inactivateCmd = regex.match("^inactivate$", tmpStr);
                    bool imageCmd = regex.match("^image$", tmpStr);
                    bool pingonCmd = regex.match("^pingon", tmpStr);
                    bool pingoffCmd = regex.match("^pingoff", tmpStr);
                    bool pollCmd = regex.match("^poll", tmpStr);
                    bool logCmd = regex.match("^log$", tmpStr);
                    bool publishCmd = regex.match("^publish$", tmpStr);
                    bool publishoffCmd = regex.match(@"^publishoff$", tmpStr);

                    data_result = database.database_get_data(bubble.mysqlDriver, user, instance, "email");
                    string email = "";
                    if (data_result.Count >= 1) email = data_result[0].ToString().Trim();

                    if (tmpStr != "NULL" && email == "1")
                    {
                        teboDebug.writeline(teboDebug.webUpdateVal + 6);
                        mail.sendEmail(config.getProfile(bubble.profileInUse).sentBy,
                                       config.getProfile(bubble.profileInUse).sendTo,
                                       "Online Request Confirmation",
                                       @"'" + tmpStr + @"'" + " being actioned.",
                                       config.getProfile(bubble.profileInUse).replyTo,
                                       false,
                                       time.secondsSinceStart(),
                                       config.getProfile(bubble.profileInUse).emailUser,
                                       config.getProfile(bubble.profileInUse).emailPass,
                                       config.getProfile(bubble.profileInUse).smtpHost,
                                       config.getProfile(bubble.profileInUse).smtpPort,
                                       config.getProfile(bubble.profileInUse).EnableSsl
                                       );
                        bubble.logAddLine("Online Request Confirmation email sent.");

                    }

                    //System.Diagnostics.Debug.WriteLine("securityCode " + securityCode.ToString());
                    //System.Diagnostics.Debug.WriteLine("shutDownCmd " + shutDownCmd.ToString());
                    //System.Diagnostics.Debug.WriteLine("activateCmd " + activateCmd.ToString());
                    //System.Diagnostics.Debug.WriteLine("inactivateCmd " + inactivateCmd.ToString());
                    //System.Diagnostics.Debug.WriteLine("imageCmd " + imageCmd.ToString());
                    //System.Diagnostics.Debug.WriteLine("pingonCmd " + pingonCmd.ToString());
                    //System.Diagnostics.Debug.WriteLine("pingoffCmd " + pingoffCmd.ToString());
                    //System.Diagnostics.Debug.WriteLine("pollCmd " + pollCmd.ToString());
                    //System.Diagnostics.Debug.WriteLine("logCmd " + logCmd.ToString());
                    //System.Diagnostics.Debug.WriteLine("publishCmd " + publishCmd.ToString());
                    //System.Diagnostics.Debug.WriteLine("publishoffCmd " + publishoffCmd.ToString());

                    if (webFirstTimeThru)
                    {
                        //update_result = database.database_update_data(user, instance, "on", logForSql()) + " records affected.";

                        teboDebug.writeline(teboDebug.webUpdateVal + 7);

                        if (bubble.Alert.on)
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 8);
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "statusactive", logForSql()) + " records affected.";
                        }
                        else
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 9);
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "statusinactive", logForSql()) + " records affected.";
                        }

                        teboDebug.writeline(teboDebug.webUpdateVal + 10);
                        webFirstTimeThru = false;

                    }

                    teboDebug.writeline(teboDebug.webUpdateVal + 11);
                    update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "poll", time.currentDateTimeSql()) + " records affected.";
                    string tmpDateTime = Convert.ToDateTime(time.currentDateTimeSql()).AddSeconds(config.getProfile(bubble.profileInUse).webPoll).ToString();
                    update_result = "";

                    if (shutDownCmd)
                    {
                        teboDebug.writeline(teboDebug.webUpdateVal + 12);
                        if (securityCode)
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 13);
                            logAddLine("Web request shutdown started...");
                            logAddLine("Motion detection inactivated.");
                            motionDetectionInactivate(null, new EventArgs());
                            bubble.logAddLine("Config data saved.");
                            FileManager.WriteFile("config");

                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "statusoff", logForSql()) + " records affected.";
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";

                            shutDown();
                        }
                        else
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 14);
                            logAddLine("Web request shutdown error - 111 code not issued!");
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";
                        }
                    }

                    if (activateCmd)
                    {
                        teboDebug.writeline(teboDebug.webUpdateVal + 15);
                        logAddLine("Web request motion detection activated.");

                        motionDetectionActivate(null, new EventArgs());

                        update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "statusactive", logForSql()) + " records affected.";
                        update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                        update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";
                    }

                    if (inactivateCmd)
                    {
                        teboDebug.writeline(teboDebug.webUpdateVal + 16);
                        logAddLine("Web request motion detection inactivated.");

                        motionDetectionInactivate(null, new EventArgs());

                        update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "statusinactive", logForSql()) + " records affected.";
                        update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                        update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";
                    }

                    if (pingonCmd)
                    {
                        teboDebug.writeline(teboDebug.webUpdateVal + 17);
                        config.getProfile(bubble.profileInUse).ping = true;
                        bubble.pings = 0;

                        logAddLine("Web request ping activated.");

                        if (tmpStr.Trim().Length > 6)
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 18);
                            string trString = tmpStr.Trim();
                            string Num = LeftRightMid.Right(trString, trString.Length - 6).Trim();
                            if (IsNumeric(Num))
                            {
                                teboDebug.writeline(teboDebug.webUpdateVal + 19);
                                Num = bubble.verifyInt(Num, 1, 9999, config.getProfile(bubble.profileInUse).pingInterval.ToString());
                                logAddLine("Web request ping every " + Num + " minutes.");
                                config.getProfile(bubble.profileInUse).pingInterval = Convert.ToInt32(Num);
                            }
                        }

                        teboDebug.writeline(teboDebug.webUpdateVal + 20);
                        update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                        update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";

                    }

                    if (pingoffCmd)
                    {
                        teboDebug.writeline(teboDebug.webUpdateVal + 21);
                        config.getProfile(bubble.profileInUse).ping = false; ;
                        bubble.pings = 0;

                        logAddLine("Web request ping inactivated.");
                        update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                        update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";
                    }

                    if (pollCmd)
                    {
                        teboDebug.writeline(teboDebug.webUpdateVal + 22);
                        string trString = tmpStr.Trim();
                        string Num = LeftRightMid.Right(trString, trString.Length - 4).Trim();
                        if (IsNumeric(Num))
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 23);
                            Num = bubble.verifyInt(Num, 30, 9999, "30");
                            logAddLine("Web request poll every " + Num + " seconds.");
                            config.getProfile(bubble.profileInUse).webPoll = Convert.ToInt32(Num);
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";
                        }

                    }

                    if (logCmd)
                    {

                        teboDebug.writeline(teboDebug.webUpdateVal + 24);
                        logAddLine("Web log request sent to database.");

                        update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                        update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";
                    }

                    if (imageCmd)
                    {

                        teboDebug.writeline(teboDebug.webUpdateVal + 25);
                        ArrayList tmpRes = database.database_get_data(bubble.mysqlDriver, user, instance, "picloc");
                        string imageLoc = tmpRes[0].ToString();

                        string dateStamp = DateTime.Now.ToString("dd-MMM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
                        string timeStamp = DateTime.Now.ToString("HH:mm", System.Globalization.CultureInfo.InvariantCulture);

                        ImagePubArgs a = new ImagePubArgs();
                        a.option = "onl";
                        a.cam = CameraRig.idxFromButton(camButtons.firstActiveButton());
                        //a.cam = CameraRig.activeCam;

                        try { pubPicture(null, a); }
                        catch { }
                        try
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 26);
                            string pubFile = tmpFolder + config.getProfile(bubble.profileInUse).webImageFileName + ".jpg";
                            ftp.Upload(pubFile, config.getProfile(bubble.profileInUse).webImageRoot, config.getProfile(bubble.profileInUse).webFtpUser, config.getProfile(bubble.profileInUse).webFtpPass);
                            File.Delete(tmpFolder + "pubPicture.jpg");
                            logAddLine("Web image request image published.");
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";

                        }
                        catch { }
                    }

                    //***************************************
                    //***************************************
                    //***************************************

                    if (tmpStr != null && tmpStr.Trim().Length >= 11 && LeftRightMid.Left(tmpStr.ToLower().Trim(), 11) == "image_reset")
                    {

                        teboDebug.writeline(teboDebug.webUpdateVal + 27);
                        bool codeErrror = true;

                        if (tmpStr.Trim().Length > 11)
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 28);
                            string trString = tmpStr.Trim();
                            string Num = LeftRightMid.Right(trString, trString.Length - 11).Trim();
                            if (IsNumeric(Num))
                            {
                                teboDebug.writeline(teboDebug.webUpdateVal + 29);
                                if (Num == "111")
                                {

                                    teboDebug.writeline(teboDebug.webUpdateVal + 30);
                                    codeErrror = false;
                                    logAddLine("Web request image reset started...");

                                }
                            }
                        }
                        if (codeErrror)
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 31);
                            logAddLine("Web request image reset error - 111 code not issued!");
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";
                        }
                    }

                    if (tmpStr != null && tmpStr.Trim().Length >= 9 && LeftRightMid.Left(tmpStr.ToLower().Trim(), 9) == "web_clear")
                    {
                        teboDebug.writeline(teboDebug.webUpdateVal + 32);
                        bool codeErrror = true;

                        if (tmpStr.Trim().Length > 9)
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 33);
                            string trString = tmpStr.Trim();
                            string Num = LeftRightMid.Right(trString, trString.Length - 9).Trim();
                            if (IsNumeric(Num))
                            {
                                teboDebug.writeline(teboDebug.webUpdateVal + 34);
                                if (Num == "111")
                                {

                                    teboDebug.writeline(teboDebug.webUpdateVal + 35);
                                    codeErrror = false;
                                    logAddLine("Web request image reset started...");

                                }
                            }
                        }
                        if (codeErrror)
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 36);
                            logAddLine("Web request image reset error - 111 code not issued!");
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";
                        }
                    }

                    if (tmpStr != null && tmpStr.Trim().Length >= 14 && LeftRightMid.Left(tmpStr.ToLower().Trim(), 14) == "computer_clear")
                    {

                        teboDebug.writeline(teboDebug.webUpdateVal + 37);
                        bool codeErrror = true;

                        if (tmpStr.Trim().Length > 14)
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 38);
                            string trString = tmpStr.Trim();
                            string Num = LeftRightMid.Right(trString, trString.Length - 14).Trim();
                            if (IsNumeric(Num))
                            {
                                teboDebug.writeline(teboDebug.webUpdateVal + 39);
                                if (Num == "111")
                                {

                                    teboDebug.writeline(teboDebug.webUpdateVal + 40);
                                    codeErrror = false;
                                    logAddLine("Web request image reset started...");

                                }
                            }
                        }
                        if (codeErrror)
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 41);
                            logAddLine("Web request image reset error - 111 code not issued!");
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";
                        }
                    }

                    if (tmpStr != null && tmpStr.Trim().Length >= 18 && LeftRightMid.Left(tmpStr.ToLower().Trim(), 18) == "clear_reset_images")
                    {

                        teboDebug.writeline(teboDebug.webUpdateVal + 42);
                        bool codeErrror = true;

                        if (tmpStr.Trim().Length > 18)
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 43);
                            string trString = tmpStr.Trim();
                            string Num = LeftRightMid.Right(trString, trString.Length - 18).Trim();
                            if (IsNumeric(Num))
                            {
                                teboDebug.writeline(teboDebug.webUpdateVal + 44);
                                if (Num == "111")
                                {

                                    teboDebug.writeline(teboDebug.webUpdateVal + 45);
                                    codeErrror = false;
                                    logAddLine("Web request image reset started...");

                                }
                            }
                        }
                        if (codeErrror)
                        {
                            teboDebug.writeline(teboDebug.webUpdateVal + 46);
                            logAddLine("Web request image reset error - 111 code not issued!");
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "log", logForSql()) + " records affected.";
                            update_result = database.database_update_data(bubble.mysqlDriver, user, instance, "reset", time.currentDateTimeSql()) + " records affected.";
                        }
                    }

                    //***************************************
                    //***************************************
                    //***************************************

                    teboDebug.writeline(teboDebug.webUpdateVal + 47);
                    webUpdLastChecked = time.secondsSinceStart();

                    pulseEvent(null, new EventArgs());

                }
            }
        }
Пример #2
0
        public static void publishTestMotion(int testInterval, int cam)
        {
            if (testImagePublishFirst)
            {
                testImagePublishData.Clear();
                testImagePublishCount = 0;
                testImagePublishLast = 0;
            }

            if (testImagePublishFirst || (time.millisecondsSinceStart() - testImagePublishLast) >= testInterval)
            {
                testImagePublishCount++;
                ImagePubArgs a = new ImagePubArgs();
                a.option = "tst" + "motionCalibration" + testImagePublishCount.ToString();
                a.cam = cam;

                try
                {

                    pubPicture(null, a);
                    testImagePublishData.Add(testImagePublishCount);

                    int motLevel = Convert.ToInt32((int)Math.Floor(CameraRig.getCam(cam).MotionDetector.MotionDetectionAlgorithm.MotionLevel * 100));
                    int reportLevel = motLevel >= 0 ? motLevel : 0;

                    testImagePublishData.Add(reportLevel);
                    testImagePublishData.Add(statistics.lowestValTime(cam, 2000, bubble.profileInUse, time.millisecondsSinceStart()));
                    testImagePublishData.Add(LeftRightMid.Right(a.option + ".jpg", a.option.Length + 1));
                    testImagePublishData.Add(CameraRig.getCam(cam).name);
                    testImagePublishData.Add(time.millisecondsSinceStart());

                    testImagePublishFirst = false;
                    testImagePublishLast = time.millisecondsSinceStart();

                }
                catch
                {

                    if (testImagePublishData.Count == testImagePublishCount)
                    {

                        testImagePublishData.RemoveAt(testImagePublishData.Count - 1);
                        testImagePublishCount--;

                    }

                }

            }
        }
Пример #3
0
        public static void take_picture_publish(object sender, ImagePubArgs e)
        {
            haveTheFlag = true;

            string fName = "";
            string stamp = "";
            stamp = e.option;

            bool online = false;
            bool publish = false;
            bool test = false;

            if (stamp.Length >= 3)
            {
                publish = stamp == "pub";
                online = stamp == "onl";
                test = LeftRightMid.Left(stamp, 3) == "tst";
            }

            try
            {

                Bitmap imgBmp = null;
                int compression = 100;

                if (online)
                {
                    fName = config.getProfile(bubble.profileInUse).webImageFileName + ".jpg";

                    imageText stampArgs = new imageText();
                    stampArgs.bitmap = (Bitmap)CameraRig.getCam(e.cam).pubFrame.Clone();
                    stampArgs.type = "Online";
                    stampArgs.backingRectangle = config.getProfile(profileInUse).onlineTimeStampRect;

                    imgBmp = bubble.timeStampImage(stampArgs);
                    compression = config.getProfile(bubble.profileInUse).onlineCompression;
                }

                if (publish)
                {
                    fName = "pubPicture.jpg";

                    imageText stampArgs = new imageText();
                    stampArgs.bitmap = (Bitmap)CameraRig.getCam(e.cam).pubFrame.Clone();
                    stampArgs.type = "Publish";
                    stampArgs.backingRectangle = config.getProfile(profileInUse).publishTimeStampRect;
                    stampArgs.stats = e.lst;

                    imgBmp = bubble.timeStampImage(stampArgs);
                    compression = config.getProfile(bubble.profileInUse).publishCompression;
                }

                if (test)
                {
                    fName = LeftRightMid.Mid(stamp, 3, stamp.Length - 3) + ".jpg";

                    imgBmp = (Bitmap)CameraRig.getCam(e.cam).pubFrame.Clone();
                    compression = config.getProfile(bubble.profileInUse).alertCompression;
                }

                ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
                System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
                EncoderParameters myEncoderParameters = new EncoderParameters(1);
                EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, compression);

                myEncoderParameters.Param[0] = myEncoderParameter;
                imgBmp.Save(bubble.tmpFolder + fName, jgpEncoder, myEncoderParameters);

                if (!test)
                {
                    Bitmap thumb = bubble.GetThumb(imgBmp);
                    thumb.Save(bubble.tmpFolder + bubble.tmbPrefix + fName, ImageFormat.Jpeg);
                    thumb.Dispose();
                }

                imgBmp.Dispose();
                bubble.logAddLine("Image saved: " + fName);
                bubble.pubError = false;
                haveTheFlag = false;

            }
            catch (Exception)
            {
                haveTheFlag = false;
                bubble.pubError = true;
                bubble.logAddLine("Error in saving image: " + fName);
            }
        }
Пример #4
0
        public static void publishImage()
        {
            if (keepPublishing)
            {

                foreach (rigItem item in CameraRig.rig)
                {

                    bool pubToWeb = Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.publishWeb).ToString());
                    bool pubToLocal = Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.publishLocal).ToString());
                    bool pubThisOne = true;

                    //publish from this camera
                    if (pubThisOne && (pubToWeb || pubToLocal))
                    {

                        int timeMultiplier = 0;
                        int PubInterval = 0;
                        bool secs = (bool)CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubSecs);
                        bool mins = Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubMins).ToString());
                        bool hrs = Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubHours).ToString());

                        if (secs) timeMultiplier = 1;
                        if (mins) timeMultiplier = 60;
                        if (hrs) timeMultiplier = 3600;

                        PubInterval = timeMultiplier * Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubTime).ToString());

                        if (
                            Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.publishFirst).ToString())
                            || (time.secondsSinceStart() - Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.lastPublished).ToString())) >= PubInterval
                            )
                        {

                            pulseEvent(null, new EventArgs());

                            CameraRig.updateInfo(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.publishFirst, false);

                            List<string> lst = new List<string>();

                            if (config.getProfile(bubble.profileInUse).publishStatsStamp)
                            {

                                statistics.movementResults stats = new statistics.movementResults();
                                stats = statistics.statsForCam(item.cam.cam, bubble.profileInUse, "Publish");

                                lst.Add(stats.avgMvStart.ToString());
                                lst.Add(stats.avgMvLast.ToString());
                                lst.Add(stats.mvNow.ToString());
                                lst.Add(item.cam.alarmActive ? "On" : "Off");

                                switch (timeMultiplier)
                                {
                                    case 1:
                                        lst.Add(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubTime).ToString() + " Secs");
                                        break;
                                    case 60:
                                        lst.Add(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubTime).ToString() + " Mins");
                                        break;
                                    case 3600:
                                        lst.Add(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubTime).ToString() + " Hours");
                                        break;
                                    default:
                                        lst.Add(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubTime).ToString() + " Secs");
                                        break;
                                }

                            }

                            ImagePubArgs a = new ImagePubArgs();

                            a.option = "pub";
                            a.cam = item.cam.cam;
                            a.lst = lst;

                            try { pubPicture(null, a); }
                            catch { }

                            if (!pubError)
                                try
                                {

                                    teboDebug.writeline(teboDebug.publishImageVal + 3);
                                    pulseEvent(null, new EventArgs());

                                    string pubFile = "";

                                    if (pubToLocal)
                                    {

                                        teboDebug.writeline(teboDebug.publishImageVal + 4);
                                        string locFile = "";

                                        long tmpCycleLoc = new long();
                                        tmpCycleLoc = Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.currentCyclePubLoc).ToString());

                                        string cameraPubLoc = CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.fileDirPubLoc).ToString();
                                        if (!Directory.Exists(cameraPubLoc))
                                        {
                                            Directory.CreateDirectory(cameraPubLoc);
                                        }

                                        //locFile = bubble.imageFolder +
                                        locFile = cameraPubLoc +
                                                  fileNameSet(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.filenamePrefixPubLoc).ToString(),
                                                                                   Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.cycleStampCheckedPubLoc).ToString()),
                                                                                   Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.startCyclePubLoc).ToString()),
                                                                                   Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.endCyclePubLoc).ToString()),
                                                                                   ref tmpCycleLoc,
                                                                                   Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.stampAppendPubLoc).ToString()));

                                        CameraRig.updateInfo(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.currentCyclePubLoc, Convert.ToInt32(tmpCycleLoc));

                                        teboDebug.writeline(teboDebug.publishImageVal + 5);
                                        File.Copy(tmpFolder + "pubPicture.jpg", locFile, true);
                                        pubFile = locFile;

                                    }

                                    if (pubToWeb)
                                    {
                                        teboDebug.writeline(teboDebug.publishImageVal + 6);

                                        string webFile = "";

                                        long tmpCycleWeb = new long();
                                        tmpCycleWeb = Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.currentCyclePubWeb).ToString());

                                        webFile = fileNameSet(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.filenamePrefixPubWeb).ToString(),
                                                              Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.cycleStampCheckedPubWeb).ToString()),
                                                              Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.startCyclePubWeb).ToString()),
                                                              Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.endCyclePubWeb).ToString()),
                                                              ref tmpCycleWeb,
                                                              Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.stampAppendPubWeb).ToString()));

                                        CameraRig.updateInfo(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.currentCyclePubWeb, Convert.ToInt32(tmpCycleWeb));

                                        File.Copy(tmpFolder + "pubPicture.jpg", tmpFolder + webFile, true);
                                        ftp.DeleteFTP(webFile, config.getProfile(bubble.profileInUse).pubFtpRoot, config.getProfile(bubble.profileInUse).pubFtpUser, config.getProfile(bubble.profileInUse).pubFtpPass);
                                        ftp.Upload(tmpFolder + webFile, config.getProfile(bubble.profileInUse).pubFtpRoot, config.getProfile(bubble.profileInUse).pubFtpUser, config.getProfile(bubble.profileInUse).pubFtpPass);
                                        pubFile = webFile;

                                    }

                                    teboDebug.writeline(teboDebug.publishImageVal + 7);
                                    File.Delete(tmpFolder + "pubPicture.jpg");
                                    CameraRig.updateInfo(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.lastPublished, time.secondsSinceStart());
                                    logAddLine("Webcam image " + pubFile + " published.");

                                    pulseEvent(null, new EventArgs());

                                }

                                catch
                                {
                                    teboDebug.writeline(teboDebug.publishImageVal + 8);
                                    CameraRig.updateInfo(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.lastPublished, time.secondsSinceStart());
                                }

                        }

                    }//if (pubToWeb || pubToLocal)

                }//foreach (rigItem item in CameraRig.rig)

            }// if (keepPublishing)
        }