Ejemplo n.º 1
0
        /// <summary>
        /// Function to export current strategy into extern file
        /// </summary>
        /// <param name="Filename">File to write</param>
        /// <param name="PatternFilename">Pattern to use for writting the file</param>
        /// <returns></returns>
        public bool WriteFile(string Filename, string PatternFilename)
        {
            bool Ret = false;
            List <StructuredFileKey> ExportFile           = new List <StructuredFileKey>();
            StructuredFile           OutputStructuredFile = null;

            // First, we have to create the StrucuredFileKey in order to create a Strucutred File
            // Create items that are not included into Loop
            ExportFile.Add(new StructuredFileKey(-1, 0, "PATTERN_STRATEGY_NAME", _StrategyName));
            ExportFile.Add(new StructuredFileKey(-1, 0, "PATTERN_DEFAULT_SPEED", _DefaultSpeed));

            // Store initial cmd (setpos)
            ExportFile.Add(new StructuredFileKey(-1, 1, "PATTERN_INIT_CMD", Command.GetCmdToString(_InitialCmd.Cmd)));
            ExportFile.Add(new StructuredFileKey(-1, 1, "PATTERN_INIT_CMD_TYPE", Command.GetCmdTypeToString(_InitialCmd.CmdType)));
            ExportFile.Add(new StructuredFileKey(-1, 1, "PATTERN_INIT_POS_X", _InitialCmd.Param2));
            ExportFile.Add(new StructuredFileKey(-1, 1, "PATTERN_INIT_POS_Y", _InitialCmd.Param3));
            ExportFile.Add(new StructuredFileKey(-1, 1, "PATTERN_INIT_POS_ANGLE", _InitialCmd.Param4));
            ExportFile.Add(new StructuredFileKey(-1, 1, "PATTERN_INIT_ACTIVE_SENSORS", Command.GetSensorsFlagToString(_InitialCmd.ActiveSensors)));

            if (_Strategy != null)
            {
                // Create Loops
                foreach (StrategyItem Item in _Strategy)
                {
                    ExportFile.Add(new StructuredFileKey(Item.LoopID, Item.GID, "PATTERN_CMD", Command.GetCmdToString(Item.Cmd.Cmd)));
                    ExportFile.Add(new StructuredFileKey(Item.LoopID, Item.GID, "PATTERN_CMD_TYPE", Command.GetCmdTypeToString(Item.Cmd.CmdType)));
                    ExportFile.Add(new StructuredFileKey(Item.LoopID, Item.GID, "PATTERN_ACTIVE_SENSORS_FLAG", Command.GetSensorsFlagToString(Item.Cmd.ActiveSensors)));
                    ExportFile.Add(new StructuredFileKey(Item.LoopID, Item.GID, "PATTERN_PARAMS", Item.Cmd.ExportParamsIntoString()));
                    ExportFile.Add(new StructuredFileKey(Item.LoopID, Item.GID, "PATTERN_NEXT_ACTION_ID", Item.NextActionID.ToString()));
                    ExportFile.Add(new StructuredFileKey(Item.LoopID, Item.GID, "PATTERN_TIMEOUT_ID", Item.TimeoutID.ToString()));
                }
            }
            OutputStructuredFile = new StructuredFile(ExportFile);
            OutputStructuredFile.WriteFile(Filename, PatternFilename);


            return(Ret);
        }