コード例 #1
0
        public void RemoveByName()
        {
            ManagerDictionary dictionary    = GetDictionary();
            DriverManager     managerToKeep = GetManager();

            dictionary.Add(managerToKeep);
            dictionary.Add(string.Empty, GetManager());
            dictionary.Remove(string.Empty);

            Assert.AreEqual(((WebServiceDriverManager)managerToKeep).Get(), dictionary.GetDriver <EventFiringWebServiceDriver, WebServiceDriverManager>());
        }
コード例 #2
0
        public void RemoveByType()
        {
            ManagerDictionary dictionary    = GetDictionary();
            DriverManager     managerToKeep = GetManager();

            dictionary.Add(GetManager());
            dictionary.Add(string.Empty, managerToKeep);
            dictionary.Remove(typeof(WebServiceDriverManager));

            Assert.AreEqual(managerToKeep, dictionary[string.Empty]);
        }
コード例 #3
0
        public void ManagersMap()
        {
            ManagerDictionary dictionary     = GetDictionary();
            DriverManager     managerToKeep  = GetManager();
            DriverManager     managerToKeep2 = GetManager();

            dictionary.Add(managerToKeep);
            dictionary.Add(string.Empty, managerToKeep2);

            Assert.AreEqual(((WebServiceDriverManager)managerToKeep).Get(), dictionary.GetDriver <EventFiringWebServiceDriver, WebServiceDriverManager>());
            Assert.AreEqual(managerToKeep2, dictionary[string.Empty]);
        }
コード例 #4
0
        public void FindWords(string text, string prefix, string trueListWords)
        {
            IGenericRepository <DictionaryWord> repo = new FakeRepository();
            ManagerDictionary manager = new ManagerDictionary(repo);


            manager.CreateDictionary(text);

            List <DictionaryWord> words = manager.FindWords(prefix).ToList();


            StringBuilder result = new StringBuilder();

            foreach (var word in words)
            {
                result.Append(word.Word).Append(" ");
            }

            NUnit.Framework.Assert.AreEqual(result.ToString(), trueListWords);
        }
コード例 #5
0
        [TestCase("жил жил  ", "жил жил ", "")]                       //0 + 0
        public void UpdateDictionary(string text1, string text2, string trueResult)
        {
            IGenericRepository <DictionaryWord> repo = new FakeRepository();
            ManagerDictionary manager = new ManagerDictionary(repo);


            manager.CreateDictionary(text1);

            manager.UpdateDictionary(text2);


            StringBuilder result = new StringBuilder();

            foreach (var word in repo.Get())
            {
                result.Append(word.Word).Append(" ").Append(word.Frequency).Append(" ");
            }

            NUnit.Framework.Assert.AreEqual(result.ToString(), trueResult);
        }
コード例 #6
0
        public void DeleteDictionary(string text, string trueResult)
        {
            DBDictionaryWord dbContext = new DBDictionaryWord();
            IGenericRepository <DictionaryWord> repo = new GenericRepository <DictionaryWord>(dbContext);
            BaseManagerDictionary manager            = new ManagerDictionary(repo);

            if (repo.Get().Any())
            {
                manager.DeleteDictionary();
            }

            manager.CreateDictionary(text);

            manager.DeleteDictionary();

            StringBuilder result = new StringBuilder();

            foreach (var word in repo.Get())
            {
                result.Append(word.Word).Append(" ").Append(word.Frequency).Append(" ");
            }

            NUnit.Framework.Assert.AreEqual(result.ToString(), trueResult);
        }
コード例 #7
0
        public void EmptyCountZero()
        {
            ManagerDictionary dictionary = GetDictionary();

            Assert.AreEqual(0, dictionary.Count);
        }
コード例 #8
0
 private void vlButtonManage_Click(object sender, EventArgs e)
 {
     Button button = (Button)sender;
     ManagerInstance formInstance;
     ManagerList formList;
     ManagerDictionary formDictionary;
     MetaInstanceVariable metaInstanceVariable;
     switch (this.value.Type.CategoryType)
     {
         case ECategoryType.Integral:
             // can't happen
             break;
         case ECategoryType.Enum:
             // can't happen (for now)
             break;
         case ECategoryType.Class:
             for (int i = 0; i < this.value.Instance.InstanceVariables.Count; i++)
             {
                 metaInstanceVariable = this.value.Instance.InstanceVariables[i];
                 if (button.Name == metaInstanceVariable.ToString())
                 {
                     MetaValue value = metaInstanceVariable.Value;
                     switch (value.Type.CategoryType)
                     {
                         case ECategoryType.Integral:
                             // can't happen
                             break;
                         case ECategoryType.Class:
                             formInstance = new ManagerInstance(this.repository, value.Type, value, metaInstanceVariable.Variable.Nullable);
                             formInstance.Text = metaInstanceVariable.ToString();
                             formInstance.ShowDialog();
                             metaInstanceVariable.Value = formInstance.Value;
                             break;
                         case ECategoryType.List:
                             formList = new ManagerList(this.repository, value.Type.SubType1, value.List);
                             formList.Text = metaInstanceVariable.ToString();
                             formList.ShowDialog();
                             value.List = formList.ListValues;
                             break;
                         case ECategoryType.Dictionary:
                             formDictionary = new ManagerDictionary(this.repository, value.Type.SubType1, value.Type.SubType2, value.Dictionary);
                             formDictionary.Text = metaInstanceVariable.ToString();
                             formDictionary.ShowDialog();
                             value.Dictionary = formDictionary.DictionaryValues;
                             break;
                     }
                     this.RefreshData();
                     break;
                 }
             }
             break;
         case ECategoryType.List:
             formList = new ManagerList(this.repository, this.value.Type.SubType1, this.value.List);
             formList.Text = this.value.Type.GetNameWithModule();
             formList.ShowDialog();
             this.value.List = formList.ListValues;
             break;
         case ECategoryType.Dictionary:
             formList = new ManagerList(this.repository, this.value.Type.SubType1, this.value.List);
             formList.Text = this.value.Type.GetNameWithModule();
             formList.ShowDialog();
             this.value.List = formList.ListValues;
             break;
     }
 }
コード例 #9
0
        private void vlButtonManage_Click(object sender, EventArgs e)
        {
            Button               button = (Button)sender;
            ManagerInstance      formInstance;
            ManagerList          formList;
            ManagerDictionary    formDictionary;
            MetaInstanceVariable metaInstanceVariable;

            switch (this.value.Type.CategoryType)
            {
            case ECategoryType.Integral:
                // can't happen
                break;

            case ECategoryType.Enum:
                // can't happen (for now)
                break;

            case ECategoryType.Class:
                for (int i = 0; i < this.value.Instance.InstanceVariables.Count; i++)
                {
                    metaInstanceVariable = this.value.Instance.InstanceVariables[i];
                    if (button.Name == metaInstanceVariable.ToString())
                    {
                        MetaValue value = metaInstanceVariable.Value;
                        switch (value.Type.CategoryType)
                        {
                        case ECategoryType.Integral:
                            // can't happen
                            break;

                        case ECategoryType.Class:
                            formInstance      = new ManagerInstance(this.repository, value.Type, value, metaInstanceVariable.Variable.Nullable);
                            formInstance.Text = metaInstanceVariable.ToString();
                            formInstance.ShowDialog();
                            metaInstanceVariable.Value = formInstance.Value;
                            break;

                        case ECategoryType.List:
                            formList      = new ManagerList(this.repository, value.Type.SubType1, value.List);
                            formList.Text = metaInstanceVariable.ToString();
                            formList.ShowDialog();
                            value.List = formList.ListValues;
                            break;

                        case ECategoryType.Dictionary:
                            formDictionary      = new ManagerDictionary(this.repository, value.Type.SubType1, value.Type.SubType2, value.Dictionary);
                            formDictionary.Text = metaInstanceVariable.ToString();
                            formDictionary.ShowDialog();
                            value.Dictionary = formDictionary.DictionaryValues;
                            break;
                        }
                        this.RefreshData();
                        break;
                    }
                }
                break;

            case ECategoryType.List:
                formList      = new ManagerList(this.repository, this.value.Type.SubType1, this.value.List);
                formList.Text = this.value.Type.GetNameWithModule();
                formList.ShowDialog();
                this.value.List = formList.ListValues;
                break;

            case ECategoryType.Dictionary:
                formList      = new ManagerList(this.repository, this.value.Type.SubType1, this.value.List);
                formList.Text = this.value.Type.GetNameWithModule();
                formList.ShowDialog();
                this.value.List = formList.ListValues;
                break;
            }
        }
コード例 #10
0
        /// <summary>
        /// Настройка команд для идентификации ввода в консоли cmd.exe.
        /// </summary>
        /// <param name="args"> аргументы сонсоли cmd.exe</param>
        /// <returns>Настроенный экземпляр реализации команд консоли cmd.exe</returns>
        public static CommandLineApplication InitCommandLine(string[] args)
        {
            CommandLineApplication commandLineApplication = new CommandLineApplication(throwOnUnexpectedArg: false);

            CommandOption createDictionary = commandLineApplication.Option(
                "--create | -c",
                "The command to create a dictionary, you must specify the name of the file with the text. A dictionary will be created from the text.",
                CommandOptionType.SingleValue);

            var updateDictionary = commandLineApplication.Option(
                "--update | -u",
                "The command to update the dictionary, you must specify the name of the file with the text." +
                " New words will be added from the text, and existing words in the dictionary will be updated.",
                CommandOptionType.SingleValue);

            var deleteDictionary = commandLineApplication.Option(
                "--delete | -d",
                "The command to delete the dictionary.",
                CommandOptionType.NoValue);

            commandLineApplication.HelpOption("-? | -h | --help");


            commandLineApplication.OnExecute(() =>
            {
                //одновременно должна выполняться только одна команда
                int numberInsertCommand = 0; //счетчик команд

                foreach (var command in commandLineApplication.GetOptions())
                {
                    if (command.HasValue())
                    {
                        numberInsertCommand++;
                    }
                }

                if (numberInsertCommand > 1) //команд больше чем одна
                {
                    Console.WriteLine("You can specify only one command-line parameter at a time (commands)");
                    Environment.Exit(0);
                    return(0);
                }


                DBDictionaryWord dbContext;
                IGenericRepository <DictionaryWord> repo;
                ManagerDictionary manager;

                dbContext = new DBDictionaryWord();
                repo      = new GenericRepository <DictionaryWord>(dbContext);
                manager   = new ManagerDictionary(repo);

                //обработка команд
                //команда создания словаря
                if (createDictionary.HasValue())
                {
                    if (IsUTF8(createDictionary.Value()))
                    {
                        string text = "";
                        text        = File.ReadAllText(createDictionary.Value(), Encoding.Default);
                        manager.CreateDictionary(text);
                    }
                    else
                    {
                        Console.WriteLine("Error: The file format is not UTF8.");
                    }
                }

                //команда обновления словаря
                if (updateDictionary.HasValue())
                {
                    if (IsUTF8(updateDictionary.Value()))
                    {
                        string text = "";
                        text        = File.ReadAllText(updateDictionary.Value(), Encoding.Default);
                        manager.UpdateDictionary(text);
                    }
                    else
                    {
                        Console.WriteLine("Error: The file format is not UTF8.");
                    }
                }

                //команда удаления словаря
                if (deleteDictionary.HasValue())
                {
                    manager.DeleteDictionary();
                }
                Environment.Exit(0);
                return(0);
            });
            return(commandLineApplication);
        }
コード例 #11
0
        static void Main(string[] args)
        {
            /* IUnityContainer container = new UnityContainer();
             * container.RegisterType<DetectEncodingType>(new ContainerControlledLifetimeManager());
             * container.RegisterType<DetectEncodingTypeUTF8>(new ContainerControlledLifetimeManager());
             * container.RegisterType<DBDictionaryWord> (new ContainerControlledLifetimeManager());
             * container.RegisterType<IGenericRepository<DictionaryWord>, GenericRepository<DictionaryWord>>();
             * container.RegisterType<BaseManagerDictionary, ManagerDictionary>(new ContainerControlledLifetimeManager());*/



            if (args.Length != 0)
            {
                //Если есть команды
                try
                {
                    var commandLineApplication = InitCommandLine(args);
                    commandLineApplication.Execute(args);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Environment.Exit(0);
                    return;
                }
            }

            //без параметров командной строки, при этом оно должно автоматически переходить в режим ввода, стандартный поток ввода – с клавиатуры
            StringBuilder  prefix = new StringBuilder();
            ConsoleKeyInfo info;

            while (true)
            {
                info = Console.ReadKey(true);
                Console.Write(info.KeyChar);

                if (info.Key == ConsoleKey.Enter && prefix.Length == 0 || info.Key == ConsoleKey.Escape)//выход при нажатии Esc или ввода пустой строки
                {
                    Environment.Exit(0);
                    break;
                }
                else
                if (info.Key == ConsoleKey.Enter && prefix.Length > 0)//ввели не пустую строку
                {
                    List <DictionaryWord> arrayWords;
                    try
                    {
                        DBDictionaryWord dbContext = new DBDictionaryWord();
                        IGenericRepository <DictionaryWord> repo = new GenericRepository <DictionaryWord>(dbContext);
                        BaseManagerDictionary manager            = new ManagerDictionary(repo);

                        //  var manager=container.Resolve<ManagerDictionary>();
                        arrayWords = manager.FindWords(prefix.ToString()).ToList();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Environment.Exit(0);
                        return;
                    }

                    Console.WriteLine();

                    foreach (var word in arrayWords)
                    {
                        Console.WriteLine("- " + word.Word);
                    }
                    prefix.Clear();
                }
                else
                {
                    prefix.Append(info.KeyChar);//собираем символы ввода не esc и не enter
                }
            }
        }