Example #1
0
        public void sendChangeLangCmd(string langfileName)
        {
            CMD newcmd = new CMD()
            {
                State = CmdStates.ORDERED,
                TargetId = -10,
                Comment = langfileName,
                Purpose = CmdPurposes.CHANGELANG
            };

            if (!SendCmd(newcmd, true, true)){ // sending command failure
                appHandler.OnLanguageChangingCancelled(false, "NOTFREECMDID");
            }
        }
Example #2
0
        private bool SendCmd(CMD newcmd, bool open, bool startTransaction)
        {
            newcmd.ID = -1;

            if(open)
            {
                sqlClient.getConn().Open();
            }

            MySqlCommand cmd;
            if (startTransaction)
            {
                cmd = new MySqlCommand("START TRANSACTION", sqlClient.getConn());
                cmd.ExecuteNonQuery();
            }

            // послать команду на выполнение
            cmd = new MySqlCommand(String.Format(@"
                INSERT INTO `ssmm_cmdstack` 
                (
                    `CmdPurpose`, 
                    `CmdTargetId`,
                    `CmdState`,
                    `CmdComment`
                ) VALUES (
                    '{0}', 
                    '{1}',
                    '{2}',
                    '{3}'
                )",
                newcmd.Purpose.ToString(),
                newcmd.TargetId,
                newcmd.State.ToString(),
                newcmd.Comment
            ),
            sqlClient.getConn());
            cmd.ExecuteNonQuery();

            cmd = new MySqlCommand("SELECT MAX(CmdID) FROM `ssmm_cmdstack`", sqlClient.getConn());
            newcmd.ID = (int)cmd.ExecuteScalar();

            switch(newcmd.ID)
            {
                case -1:
                    {
                        if (startTransaction)
                        {
                            cmd = new MySqlCommand("ROLLBACK", sqlClient.getConn());
                            cmd.ExecuteNonQuery();
                        }
                        break;
                    }
                default:
                    {
                        if (startTransaction)
                        {
                            cmd = new MySqlCommand("COMMIT", sqlClient.getConn());
                            cmd.ExecuteNonQuery();
                        }
                        ActiveCMDs.Add(newcmd);
                        break;
                    }
            }


            if (open)
            {
                sqlClient.getConn().Close();
            }

            if (newcmd.ID == -1) return false;
            else return true;
        }
Example #3
0
        public void sendRemoveCommand(int mapId)
        {
            CMD newcmd = new CMD(){
                State = CmdStates.ORDERED,
                TargetId = mapId,
                Comment = "-",
                Purpose = CmdPurposes.REMOVE
            };

            if(!SendCmd(newcmd, true, true)){ // sending command failure
                appHandler.OnMapRemovingCancelled(mapId, false, "NOTFREECMDID"); 
            }
            else // cmd is adopted
            {
                appHandler.OnMapRemovingCommandAdopted(mapId); // it deletes this map' headers from MySQL
            }
        }
Example #4
0
        public void sendInstallCommand(int mapId, bool isAutoEnabled, bool openConnection, bool startTransaction)
        {
            CMD newcmd = new CMD(){
                State = CmdStates.ORDERED,
                TargetId = mapId,
                Comment = isAutoEnabled == true ? "DEF_ENABLED" : "-",
                Purpose = CmdPurposes.INSTALL
            };

            if (!SendCmd(newcmd, openConnection, startTransaction)){ // sending command failure
                appHandler.OnMapProposingCancelled(mapId, false/*, "NOTFREECMDID"*/);
                //return false;
            }
            else
            {
                appHandler.OnMapProposingCancelled(mapId, true);
            }
            //return true;
        }
Example #5
0
        public void sendDisableCommand(int mapId)
        {
            CMD newcmd = new CMD(){
                State = CmdStates.ORDERED,
                TargetId = mapId,
                Comment = "-",
                Purpose = CmdPurposes.DISABLE
            };

            if (!SendCmd(newcmd, true, true)){ // sending command failure
                appHandler.OnMapDisablingCancelled(mapId, false, "NOTFREECMDID");
            }
        }
Example #6
0
 private void OnCmdFinished(CMD cmd)
 {
     // delete this command from cmdstack
     sqlClient.SendCommand(String.Format("DELETE FROM `ssmm_cmdstack` WHERE `CmdID` = '{0}'", cmd.ID));
 }
Example #7
0
        private void CmdTimer_Tick(object sender, EventArgs e)
        {
            Collection<CMD> cmdsToRemove = new Collection<CMD>();
            foreach (CMD cmd in ActiveCMDs)
            {
                Dictionary<string, string> RESULT = sqlClient.Select("ssmm_cmdstack", String.Format("`CmdID` = '{0}'", cmd.ID));

                CMD performed = new CMD(); // new state of a command
                performed = cmd;


                // loads the new state of this cmd
                foreach (KeyValuePair<string, string> entry in RESULT)
                {
                    switch (entry.Key)
                    {
                        case "CmdState":
                        {
                            performed.State = CMDManager.returnCmdStateByString(entry.Value);
                            break;
                        }
                        case "CmdPurpose":
                        {
                            performed.Purpose = CMDManager.returnCmdPurposeByString(entry.Value);
                            break;
                        }
                        case "CmdComment":
                        {
                            performed.Comment = entry.Value;
                            break;
                        }
                    }
                }

                bool _break = false;
                switch (performed.State)
                {
                    case CmdStates.COMPLETE:
                    case CmdStates.ABORTED:
                        {
                            OnCmdFinished(cmd);
                            cmdsToRemove.Add(cmd);
                            break;
                        }
                    default: // if is not aborted and not competed it means this cmd isn't received by ssmm_checker.amx yet 
                        {
                            _break = true;
                            break;
                        }
                }

                if (_break == true) break; // breaks the loop

                switch (performed.Purpose)
                {
                    case CmdPurposes.DISABLE: { appHandler.OnMapDisablingCancelled(cmd.TargetId, performed.State == CmdStates.COMPLETE ? true : false, cmd.Comment); break; }
                    case CmdPurposes.ENABLE: { appHandler.OnMapEnablingCancelled(cmd.TargetId, performed.State == CmdStates.COMPLETE ? true : false, cmd.Comment); break; }
                    case CmdPurposes.INSTALL: { appHandler.OnMapInstallingCancelled(cmd.TargetId, performed.State == CmdStates.COMPLETE ? true : false, cmd.Comment); break; }
                    case CmdPurposes.REMOVE: { appHandler.OnMapRemovingCancelled(cmd.TargetId, performed.State == CmdStates.COMPLETE ? true : false, cmd.Comment); break; }
                    case CmdPurposes.CHANGELANG: { appHandler.OnLanguageChangingCancelled(performed.State == CmdStates.COMPLETE ? true : false, cmd.Comment); break; } 
                }
                
            }
            // remove all received commands
            foreach (CMD cmd in cmdsToRemove)
            {
                ActiveCMDs.Remove(cmd);
            }
        }