Example #1
0
            private void ExecuteEvents(TimelineHandler handler)
            {
                try
                {
                    foreach (var timelineEvent in handler.TimeLineEvents)
                    {
                        var path = GetSavePath(typeof(LightExcelHandler), handler, timelineEvent, "docx");

                        var list = RandomText.GetDictionary.GetDictionaryList();
                        var rt   = new RandomText(list.ToArray());
                        rt.AddSentence(5);

                        var title = rt.Content;
                        rt.AddContentParagraphs(2, 3, 5, 7, 22);
                        var paragraph = rt.Content;

                        Domain.Code.Office.Word.Write(path, title, paragraph);

                        FileListing.Add(path);
                        this.Report(handler.HandlerType.ToString(), timelineEvent.Command,
                                    timelineEvent.CommandArgs[0].ToString());
                    }
                }
                catch (Exception e)
                {
                    _log.Error(e);
                }
            }
Example #2
0
        public ActionResult GetPosts()
        {
            var text = new RandomText();

            text.AddContentParagraphs(RandomGenerator.GenerateLockedRandom(1, 10),
                                      1,
                                      RandomGenerator.GenerateLockedRandom(10, 20),
                                      RandomGenerator.GenerateLockedRandom(1, 10),
                                      RandomGenerator.GenerateLockedRandom(10, 30));

            var model = new PostViewModel()
            {
                PostedOn    = DateTime.Now.AddSeconds(-90),
                PostedBy    = _defaultHelper.GetUser(User.Identity.GetUserId()),
                Title       = new RandomText().GetNewSentence(5),
                Description = text.Content,
                Rate        = RandomGenerator.GenerateLockedRandom(20, 400),
                PostImages  = new List <ImageViewModel>()
                {
                    new ImageViewModel()
                    {
                        ImageUrl = $"/images/postimages/image{RandomGenerator.GenerateLockedRandom(1, 14)}.jpg"
                    }
                }
            };

            return(PartialView(@"~\Views\Index\_PostDetail.cshtml", model));
        }
        public static string GetRandomText()
        {
            string[] words = { "salmon", "a", "bass", "the", "lingcod", "and", "trout", "with", "rockfish", "made", "true cod", "mean", "lobster", "for", "dungeness crab", "part", "eating", "learn", "smelt", "think", "sardine", "peace", "herring", "for", "shark", "late", "anchovy", "seal" };
            RandomText text = new RandomText(words);
            text.AddContentParagraphs(2, 2, 4, 5, 12);

            return text.Content;
        }
Example #4
0
        string GenerateRandomText()
        {
            string[]   words = { "anemone", "wagstaff",  "man",    "the",      "for",        "and",   "a", "with", "bird", "fox", "Sand", "Air", "Live", "This", "",
                                 "Private ",  "sentence ", "itself", "methods ", "separated ", "words", "create " };
            RandomText text = new RandomText(words);

            text.AddContentParagraphs(2, 2, 4, 5, 12);
            return(text.Content);
        }
Example #5
0
        public void NUGET_AddContentParagraphsTest2()
        {
            var target = new RandomText();
            const int numberParagraphs = 1;
            const int minSentences = 4;
            const int maxSentences = minSentences;
            const int minWords = 4;
            const int maxWords = minWords;
            target.AddContentParagraphs(numberParagraphs, minSentences, maxSentences, minWords, maxWords);
            string actualOutput = target.ToString().Replace("\n\n", string.Empty).Trim();

            int numberOfSentances = actualOutput.Split('.').Length - 1;
            int numberOfWords = actualOutput.Split(' ').Length / numberOfSentances;

            Assert.AreEqual(minSentences, numberOfSentances, "Incorrect number of sentances generated.");
            Assert.AreEqual(minWords, numberOfWords, "Incorrect number of words generated");
        }
Example #6
0
        private void ExecuteEvents(Timeline timeline, TimelineHandler handler)
        {
            try
            {
                foreach (TimelineEvent timelineEvent in handler.TimeLineEvents)
                {
                    try
                    {
                        _log.Trace($"Word event - {timelineEvent}");
                        WorkingHours.Is(handler);

                        if (timelineEvent.DelayBefore > 0)
                        {
                            Thread.Sleep(timelineEvent.DelayBefore);
                        }

                        if (timeline != null)
                        {
                            System.Collections.Generic.List <int> pids = ProcessManager.GetPids(ProcessManager.ProcessNames.Word).ToList();
                            if (pids.Count > timeline.TimeLineHandlers.Count(o => o.HandlerType == HandlerType.Word))
                            {
                                return;
                            }
                        }

                        // start word and turn off msg boxes
                        Word.Application wordApplication = new Word.Application
                        {
                            DisplayAlerts = WdAlertLevel.wdAlertsNone,
                            Visible       = true
                        };

                        // add a new document
                        Word.Document newDocument = wordApplication.Documents.Add();

                        try
                        {
                            wordApplication.WindowState = WdWindowState.wdWindowStateMinimize;
                            foreach (Word.Document item in wordApplication.Documents)
                            {
                                item.Windows[1].WindowState = WdWindowState.wdWindowStateMinimize;
                            }
                        }
                        catch (Exception e)
                        {
                            _log.Trace($"Could not minimize: {e}");
                        }

                        // insert some text
                        System.Collections.Generic.List <string> list = RandomText.GetDictionary.GetDictionaryList();
                        RandomText rt = new RandomText(list.ToArray());
                        rt.AddContentParagraphs(1, 1, 1, 10, 50);
                        wordApplication.Selection.TypeText(rt.Content);

                        int writeSleep = ProcessManager.Jitter(100);
                        Thread.Sleep(writeSleep);

                        wordApplication.Selection.HomeKey(WdUnits.wdLine, WdMovementType.wdExtend);
                        wordApplication.Selection.Font.Color = WdColor.wdColorSeaGreen;
                        wordApplication.Selection.Font.Bold  = 1;
                        wordApplication.Selection.Font.Size  = 18;

                        string rand = RandomFilename.Generate();

                        string dir = timelineEvent.CommandArgs[0].ToString();
                        if (dir.Contains("%"))
                        {
                            dir = Environment.ExpandEnvironmentVariables(dir);
                        }

                        if (Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        string path = $"{dir}\\{rand}.docx";

                        //if directory does not exist, create!
                        _log.Trace($"Checking directory at {path}");
                        DirectoryInfo f = new FileInfo(path).Directory;
                        if (f == null)
                        {
                            _log.Trace($"Directory does not exist, creating directory at {f.FullName}");
                            Directory.CreateDirectory(f.FullName);
                        }

                        try
                        {
                            if (File.Exists(path))
                            {
                                File.Delete(path);
                            }
                        }
                        catch (Exception e)
                        {
                            _log.Debug(e);
                        }

                        newDocument.Saved = true;
                        newDocument.SaveAs(path);
                        Report(handler.HandlerType.ToString(), timelineEvent.Command, timelineEvent.CommandArgs[0].ToString());

                        FileListing.Add(path);

                        if (timelineEvent.DelayAfter > 0)
                        {
                            //sleep and leave the app open
                            _log.Trace($"Sleep after for {timelineEvent.DelayAfter}");
                            Thread.Sleep(timelineEvent.DelayAfter - writeSleep);
                        }

                        wordApplication.Quit();
                        wordApplication.Dispose();
                        wordApplication = null;

                        try
                        {
                            Marshal.ReleaseComObject(wordApplication);
                        }
                        catch { }

                        try
                        {
                            Marshal.FinalReleaseComObject(wordApplication);
                        }
                        catch { }

                        GC.Collect();
                    }
                    catch (Exception e)
                    {
                        _log.Debug(e);
                    }
                    finally
                    {
                        Thread.Sleep(5000);
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
            finally
            {
                KillApp();
                _log.Trace($"Word closing...");
            }
        }
Example #7
0
            public void run(int port)
            {
                // Create and start a server and client.
                TcpListener server = null;
                TcpClient client = null;

                try
                {
                    server = new TcpListener(IPAddress.Any, port);
                    server.Start();
                    client = new TcpClient("localhost", port);

                    // Obtain the sockets from the two ends of the connection.  We are using the blocking AcceptSocket()
                    // method here, which is OK for a test case.
                    Socket serverSocket = server.AcceptSocket();
                    Socket clientSocket = client.Client;

                    // Wrap the two ends of the connection into StringSockets
                    StringSocket sendSocket = new StringSocket(serverSocket, new UTF8Encoding());
                    StringSocket receiveSocket = new StringSocket(clientSocket, new UTF8Encoding());

                    // This will coordinate communication between the threads of the test cases
                    mre1 = new ManualResetEvent(false);
                    mre2 = new ManualResetEvent(false);

                    // Make two receive requests
                    receiveSocket.BeginReceive(CompletedReceive1, 1);
                    receiveSocket.BeginReceive(CompletedReceive2, 2);

                    List<string> sentences = new List<string>();
                    string[] words = { "?", "wagstaff", "nicol", "the", "for",
                "and", "a", "with", "naruto", "fox", "23", "mao" };
                    for (int i = 0; i < 2; i++)
                    {
                        RandomText text = new RandomText(words);
                        text.AddContentParagraphs(1, 2, 4, 200, 200);
                        sentences.Add(text.Content);
                    }
                    String msg = sentences[0] + "\n" + sentences[1] + "\n";

                    foreach (char c in msg)
                    {
                        sendSocket.BeginSend(c.ToString(), (e, o) => { }, null);
                    }

                    // Make sure the lines were received properly.
                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual(sentences[0], s1);
                    Assert.AreEqual(1, p1);

                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2");
                    Assert.AreEqual(sentences[1], s2);
                    Assert.AreEqual(2, p2);
                }
                finally
                {
                    server.Stop();
                    client.Close();
                }
            }