예제 #1
0
        public List <string> Deserialize(int wordLength)
        {
            if (!_fileSystem.File.Exists(_filePath))
            {
                throw new FileNotFoundException();
            }

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

            using (StreamReader reader = new StreamReader(_fileSystem.File.OpenRead(_filePath)))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    string word = line.Replace("\n", "").Replace("\r", "");
                    if (char.IsUpper(word[0]))
                    {
                        continue;
                    }

                    word = WordFormatter.Format(word);
                    if (WordIsAllowed(wordLength, word))
                    {
                        words.Add(word);
                    }
                }
            }

            return(words);
        }
예제 #2
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            if (Directory.Exists(directoryPath))
            {
                colorizer = ColorizerSerializer.Deserialize(directoryPath + @"\default.xml");
                formatter = WordFormatterSerializer.Deserialize(directoryPath + @"\basicformat.xml");
                formatter.Initialize(colorizer, this.Application);
            }
            else // if it's the first starting of this version of the Add-In with this user
            {
                Directory.CreateDirectory(directoryPath);

                colorizer = new Colorizer();
                colorizer.LoadPredefinedLanguages();
                colorizer.Initialize();

                formatter = new WordFormatter();
                formatter.Initialize(colorizer, this.Application);
                formatter.SetToDefault();
            }

            indentFixer = new WordIndentFixer(this.Application);
            codecleaner = new CodeCleaner(this.Application);

            Globals.Ribbons.WordCodeEditorToolsRibbon.InitializeAddIn(this);
        }
예제 #3
0
        private List <string> OnCalcWordList(List <BaseFormulaNode> nodes, VariablesSource variables)
        {
            // Rent
            using var idContainer = GetIdContainer();

            // Calculate with internal struct
            List <string> res = CalcInternal(nodes, variables, idContainer);

            return(WordFormatter.Format(res));
        }
예제 #4
0
        public void TestRead()
        {
            WordDocument doc = null;

            using (MemoryStream ms = new MemoryStream(WORD.ToByteArrayFromBase64String()))
            {
                doc = WordDocument.OpenDocument(ms);
            }

            WordFormatter formatter = doc.GetAllSections()[0].GetAllParagraphs()[0].Formatter;

            Assert.AreEqual(Color.FromArgb(0, 255, 0, 0), formatter.Background);
            Assert.AreEqual(Color.FromArgb(0, 255, 255, 0), formatter.Foreground);

            doc.Dispose();
        }
예제 #5
0
        public void TestWrite()
        {
            string file = Path.GetTempFileName() + ".doc";

            using (WordDocument doc = WordDocument.CreateDocument())
            {
                WordSection section = doc.GetAllSections()[0];

                WordParagraph paragraph = section.CreateParagraph();
                paragraph.Text = "Hello World";

                WordFormatter formatter = paragraph.Formatter;
                formatter.Background = Color.Red;
                formatter.Foreground = Color.Yellow;
                formatter.Font       = new Font("Courier New", 12, FontStyle.Underline | FontStyle.Bold);

                Assert.AreEqual(Color.FromArgb(0, 255, 0, 0), formatter.Background);
                Assert.AreEqual(Color.FromArgb(0, 255, 255, 0), formatter.Foreground);

                doc.Save(file);
            }
        }
예제 #6
0
        static void Main(string[] args)
        {
            var options = new Options();

            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                if (!File.Exists(options.DiffFile))
                {
                    Console.WriteLine("ERROR: diff file does not exist");
                }

                if (options.Verbose)
                {
                    Console.WriteLine("Processing {0}", options.DiffFile);
                }

                var reader = new DiffReader(options.DiffFile);
                var diff   = reader.Read();

                if (!String.IsNullOrEmpty(options.WordOutput))
                {
                    if (options.Verbose)
                    {
                        Console.WriteLine("Creating word output {0}", options.WordOutput);
                    }

                    var wordOutput = new WordFormatter(options.WordOutput)
                    {
                        Title   = options.Title,
                        Summary = options.Summary,
                        ShowDeletedFileContents = options.ShowDeleteFileContents,
                        ShowCreatedFileContents = options.ShowCreatedFileContents
                    };
                    wordOutput.Execute(diff);
                }

                if (!String.IsNullOrEmpty(options.HtmlOutput))
                {
                    if (options.Verbose)
                    {
                        Console.WriteLine("Creating html output {0}", options.HtmlOutput);
                    }

                    var htmlOutput = new HtmlFormatter(options.HtmlOutput)
                    {
                        Title   = options.Title,
                        Summary = options.Summary,
                        ShowDeletedFileContents = options.ShowDeleteFileContents,
                        ShowCreatedFileContents = options.ShowCreatedFileContents
                    };
                    htmlOutput.Execute(diff);
                }

                if (options.Verbose || (String.IsNullOrEmpty(options.WordOutput) && String.IsNullOrEmpty(options.HtmlOutput)))
                {
                    var consoleOutput = new ConsoleFormatter();
                    consoleOutput.Execute(diff);
                }
            }



            if (options.Verbose)
            {
                Console.Write("Press enter to quit: ");
                Console.ReadKey();
            }
        }
예제 #7
0
        public WordInputViewModel(List <string> words, Settings settings, Random random, WordGameViewModel wordGameViewModel)
        {
            _words             = words;
            _settings          = settings;
            _random            = random;
            _wordGameViewModel = wordGameViewModel;

            CandidateWord = GetRandomWord();

            var gameIsOngoing = this.WhenAnyValue(x => x.StateInfo.State, (state) => state == WordGameState.Ongoing);

            var canAccept = this.WhenAnyValue(
                x => x.WordInputtedByUser, x => x.StateInfo.State, (word, state) =>
                !string.IsNullOrEmpty(word) &&
                state == WordGameState.Ongoing &&
                WordFormatter.Format(word).Length == settings.WordSize);


            Accept         = ReactiveCommand.Create(() => new Unit(), canAccept);
            Reject         = ReactiveCommand.Create(() => new Unit(), gameIsOngoing);
            TimeOut        = ReactiveCommand.Create(() => new Unit(), gameIsOngoing);
            AddRow         = ReactiveCommand.Create(() => new Unit(), this.WhenAnyValue(x => x.StateInfo.Flags, (switchTeamFlags) => (switchTeamFlags & SwitchTeamFlags.AddRow) == SwitchTeamFlags.AddRow));
            AddBonusLetter = ReactiveCommand.Create(() => new Unit(), this.WhenAnyValue(x => x.StateInfo.Flags, (switchTeamFlags) => (switchTeamFlags & SwitchTeamFlags.AddBonusLetter) == SwitchTeamFlags.AddBonusLetter));
            ClearRow       = ReactiveCommand.Create(() => new Unit(), this.WhenAnyValue(x => x.StateInfo.Flags, (flags) => (flags & SwitchTeamFlags.ClearRow) == SwitchTeamFlags.ClearRow));

            GenerateWord = ReactiveCommand.Create(() =>
            {
                CandidateWord = GetRandomWord();
                return(new Unit());
            });

            NewGame = ReactiveCommand.CreateFromTask(async() =>
            {
                var cancel    = CancelCountDownAndGetNewToken();
                CurrentWord   = CandidateWord;
                CandidateWord = GetRandomWord();
                await wordGameViewModel.StartWordGame(CurrentWord);
                StateInfo = new WordGameStateInfo(WordGameState.Ongoing);
                StartCountDown(cancel.Token);
                return(Unit.Default);
            });

            ShowWord = ReactiveCommand.Create(() => new Unit(),
                                              this.WhenAnyValue(x => x.StateInfo.State, (state) => state == WordGameState.Lost));

            this.WhenAnyValue(x => x.WordInputtedByUser)
            .Where(x => !string.IsNullOrWhiteSpace(x))
            .Subscribe(onNext => wordGameViewModel.SetWord(WordFormatter.Format(onNext)));

            this.Accept.Subscribe(async onNext =>
            {
                var cancel         = CancelCountDownAndGetNewToken();
                WordInputtedByUser = null;
                StateInfo          = await wordGameViewModel.AcceptWord();

                if (StateInfo.State == WordGameState.SwitchTeam && StateInfo.Flags == SwitchTeamFlags.Normal)
                {
                    StateInfo = new WordGameStateInfo(WordGameState.Ongoing);
                }

                if (StateInfo.State == WordGameState.Ongoing)
                {
                    StartCountDown(cancel.Token);
                }
            });
            this.Reject.Subscribe(async onNext =>
            {
                var cancel         = CancelCountDownAndGetNewToken();
                WordInputtedByUser = null;
                StateInfo          = await wordGameViewModel.RejectWord();
                if (StateInfo.State == WordGameState.Ongoing)
                {
                    StartCountDown(cancel.Token);
                }
            });
            this.TimeOut.Subscribe(async onNext =>
            {
                var cancel         = CancelCountDownAndGetNewToken();
                WordInputtedByUser = null;
                StateInfo          = await wordGameViewModel.TimeOut();
                StartCountDown(cancel.Token);
            });
            this.AddRow.Subscribe(async onNext =>
            {
                var cancel = CancelCountDownAndGetNewToken();
                await wordGameViewModel.AddRow();
                if (StateInfo.State == WordGameState.SwitchTeam)
                {
                    if ((StateInfo.Flags & SwitchTeamFlags.AddBonusLetter) != SwitchTeamFlags.AddBonusLetter)
                    {
                        StateInfo = new WordGameStateInfo(WordGameState.Ongoing);
                    }
                }

                StartCountDown(cancel.Token);
            });
            this.AddBonusLetter.Subscribe(async onNext =>
            {
                var cancel = CancelCountDownAndGetNewToken();
                await wordGameViewModel.AddBonusLetter();
                StateInfo = new WordGameStateInfo(WordGameState.Ongoing);
                StartCountDown(cancel.Token);
            });

            this.ClearRow.Subscribe(async x =>
            {
                await wordGameViewModel.ClearRow();
                if ((StateInfo.Flags & SwitchTeamFlags.AddBonusLetter) != SwitchTeamFlags.AddBonusLetter)
                {
                    StateInfo = new WordGameStateInfo(WordGameState.Ongoing);
                }
            });

            this.ShowWord.Subscribe(onNext =>
            {
                CancelCountDownAndGetNewToken();
                wordGameViewModel.ShowWord(CurrentWord);
            });
        }