Ejemplo n.º 1
0
        public void Start()
        {
            Strategy newStrategy    = null;
            int      strategyChoice = random.Next(0, Enum.GetValues(typeof(Strategy.StrategyType)).Length);

            switch ((Strategy.StrategyType)strategyChoice)
            {
            case Strategy.StrategyType.ValidFileOpen:
                newStrategy = new ValidFileOpen();
                break;

            case Strategy.StrategyType.WhiteNoise:
                newStrategy = new WhiteNoise();
                break;

            case Strategy.StrategyType.SymbolGenerator:
                newStrategy = new SymbolGenerator();
                break;

            case Strategy.StrategyType.KeywordGenerator:
                newStrategy = new KeywordGenerator();
                break;
            }

            InitializeStrategy(newStrategy);
            OnDispatchTimer();
        }
Ejemplo n.º 2
0
        public void Start()
        {
            Strategy newStrategy = null;
            int strategyChoice = random.Next(0, Enum.GetValues(typeof(Strategy.StrategyType)).Length);

            switch ((Strategy.StrategyType)strategyChoice)
            {
                case Strategy.StrategyType.ValidFileOpen:
                    newStrategy = new ValidFileOpen();
                    break;
                case Strategy.StrategyType.WhiteNoise:
                    newStrategy = new WhiteNoise();
                    break;
                case Strategy.StrategyType.SymbolGenerator:
                    newStrategy = new SymbolGenerator();
                    break;
                case Strategy.StrategyType.KeywordGenerator:
                    newStrategy = new KeywordGenerator();
                    break;
            }

            InitializeStrategy(newStrategy);
            OnDispatchTimer();
        }
Ejemplo n.º 3
0
        private void InitializeStrategy(Strategy strategy)
        {
            KeywordGenerator keywordStrategy = new KeywordGenerator();
            SymbolGenerator  symbolStrategy  = new SymbolGenerator();

            Strategy.StrategyType strategyType = strategy.GetStrategyType();
            int    numberOfActions             = 0;
            Action nextAction = new Action();

            byte[] endlineChar = BitConverter.GetBytes('\n');

            if (strategyType == Strategy.StrategyType.ValidFileOpen)
            {
                nextAction = strategy.GetNextAction();
                Action.ActionType type       = nextAction.Type;
                byte[]            actionData = nextAction.Data;

                using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(currentFilePath, FileMode.Create)))
                {
                    binaryWriter.Write(Convert.ToInt32(nextAction.Type));
                    binaryWriter.Write(actionData.Length);
                    binaryWriter.Write(actionData);

                    binaryWriter.Close();
                }
            }
            else
            {
                FileStream fileStream = File.Open(currentFilePath, FileMode.Create);
                using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
                {
                    while (numberOfActions < maxActions)
                    {
                        if (strategyType == Strategy.StrategyType.SymbolGenerator || strategyType == Strategy.StrategyType.KeywordGenerator)
                        {
                            int choice = random.Next(0, 2); // Choose between whether to insert a symbol or a keyword
                            if (choice == 0)
                            {
                                nextAction = keywordStrategy.GetNextAction();
                            }
                            else
                            {
                                nextAction = symbolStrategy.GetNextAction();
                            }
                        }
                        else
                        {
                            nextAction = strategy.GetNextAction();
                        }

                        Action.ActionType type       = nextAction.Type;
                        byte[]            actionData = nextAction.Data;


                        if (numberOfActions % 10 == 0) // To insert an endline character after every 100 insertions
                        {
                            binaryWriter.Write(Convert.ToInt32(Action.ActionType.InsertSymbol));
                            binaryWriter.Write(endlineChar.Length);
                            binaryWriter.Write(endlineChar);
                        }

                        binaryWriter.Write(Convert.ToInt32(nextAction.Type));
                        binaryWriter.Write(actionData.Length);
                        binaryWriter.Write(actionData);

                        numberOfActions++;
                    }

                    binaryWriter.Close();
                }
            }
        }
Ejemplo n.º 4
0
        private void InitializeStrategy(Strategy strategy)
        {
            KeywordGenerator keywordStrategy = new KeywordGenerator();
            SymbolGenerator symbolStrategy = new SymbolGenerator();

            Strategy.StrategyType strategyType = strategy.GetStrategyType();
            int numberOfActions = 0;
            Action nextAction = new Action();
            byte[] endlineChar = BitConverter.GetBytes('\n');

            if (strategyType == Strategy.StrategyType.ValidFileOpen)
            {
                nextAction = strategy.GetNextAction();
                Action.ActionType type = nextAction.Type;
                byte[] actionData = nextAction.Data;

                using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(currentFilePath, FileMode.Create)))
                {
                    binaryWriter.Write(Convert.ToInt32(nextAction.Type));
                    binaryWriter.Write(actionData.Length);
                    binaryWriter.Write(actionData);

                    binaryWriter.Close();
                }
            }
            else
            {
                FileStream fileStream = File.Open(currentFilePath, FileMode.Create);
                using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
                {
                    while (numberOfActions < maxActions)
                    {
                        if (strategyType == Strategy.StrategyType.SymbolGenerator || strategyType == Strategy.StrategyType.KeywordGenerator)
                        {

                            int choice = random.Next(0, 2); // Choose between whether to insert a symbol or a keyword
                            if (choice == 0)
                                nextAction = keywordStrategy.GetNextAction();
                            else
                                nextAction = symbolStrategy.GetNextAction();
                        }
                        else
                            nextAction = strategy.GetNextAction();

                        Action.ActionType type = nextAction.Type;
                        byte[] actionData = nextAction.Data;

                        if (numberOfActions % 10 == 0) // To insert an endline character after every 100 insertions
                        {
                            binaryWriter.Write(Convert.ToInt32(Action.ActionType.InsertSymbol));
                            binaryWriter.Write(endlineChar.Length);
                            binaryWriter.Write(endlineChar);
                        }

                        binaryWriter.Write(Convert.ToInt32(nextAction.Type));
                        binaryWriter.Write(actionData.Length);
                        binaryWriter.Write(actionData);

                        numberOfActions++;
                    }

                    binaryWriter.Close();
                }
            }
        }