Esempio n. 1
0
        public void WcTest()
        {
            string path = Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\"), @"TestFile.txt");

            Wc wc = new Wc(new List <string> {
                path
            });
            int linesCounter = 0, wordsCounter = 0, bytesCounter = 0;

            string[] lines = File.ReadAllLines(path);
            linesCounter = lines.Length;

            foreach (var i in lines)
            {
                string[] words = i.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                wordsCounter += words.Length;
            }

            byte[] bytes = File.ReadAllBytes(path);
            bytesCounter = bytes.Length;

            wc.Run();

            Assert.AreEqual("wc", wc.Name);
            Assert.AreEqual(path, wc.Input[0]);
            Assert.AreEqual(linesCounter.ToString(), wc.Output[0]);
            Assert.AreEqual(wordsCounter.ToString(), wc.Output[1]);
            Assert.AreEqual(bytesCounter.ToString(), wc.Output[2]);
        }
Esempio n. 2
0
 private void Wx_NewWx(Wc wx)
 {
     Invoke((Action)(() =>
     {
         Wu us = null;
         foreach (var c in fp_wxs.Controls)
         {
             var w = c as Wu;
             if (w == null)
             {
                 continue;
             }
             if (w.wx.cu.uin == wx.cu.uin)
             {
                 us = w; break;
             }
         }
         if (us != null)
         {
             us.Name = "id:" + wx.cu.uin;
             us.Image = base64ToImage(wx.cu.headimg);
             us.nickname = wx.cu.nickname;
             us.SizeMode = PictureBoxSizeMode.StretchImage;
             tip_info.SetToolTip(us, us.nickname);
         }
         Activate();
     }));
 }
Esempio n. 3
0
        public void CrawlWeb_StartingUrl_FirstPageReturnsNoContent_ReturnsOnePage()
        {
            Wc.Setup(obj => obj.DownloadString(It.IsAny <string>())).Returns(@"");
            var nav        = (ICrawler) new QueueCrawler(Loader);
            var pages      = nav.CrawlWeb(NoContentUrl);
            var pagesArray = pages.ToArray();

            Assert.That(pagesArray.Length, Is.EqualTo(1));
        }
Esempio n. 4
0
        public void Add(Wc entity)
        {
            XDocument xDocument = XDocument.Load(_databaseFile);
            XElement  node      = new XElement("WcRecord",
                                               new XElement("Time", entity.Time.ToString(CultureInfo.InvariantCulture)));

            xDocument.Element("Database")?.Element("WcList")?.Add(node);
            xDocument.Save(_databaseFile);
        }
Esempio n. 5
0
        public void CrawlWeb_StartingUrl_FirstPageReturnsNoContent_ReturnedPageHasNoLinks()
        {
            Wc.Setup(obj => obj.DownloadString(It.IsAny <string>())).Returns(@"");

            var nav        = (ICrawler) new QueueCrawler(Loader);
            var pages      = nav.CrawlWeb(NoContentUrl);
            var pagesArray = pages.ToArray();

            Assert.That(pagesArray[0].LinksInPage.Count, Is.EqualTo(0));
        }
Esempio n. 6
0
        public void CrawlWeb_StartingUrl_FirstPageReturnsNoContent_ReturnedPageHasNoErrorCode()
        {
            Wc.Setup(obj => obj.DownloadString(It.IsAny <string>())).Returns(@"");

            var nav        = (ICrawler) new QueueCrawler(Loader);
            var pages      = nav.CrawlWeb(NoContentUrl);
            var pagesArray = pages.ToArray();

            Assert.That(pagesArray[0].HttpErrorCode, Is.Null);
        }
Esempio n. 7
0
        public void WcTest()
        {
            Directory.SetCurrentDirectory("test files");
            string[] args  = { "test.txt", "thisfiledoesntexist.txt" };
            string[] lines = new Wc().RunCommand(args);
            Directory.SetCurrentDirectory("..");

            Assert.AreEqual(lines[0], "test.txt 1 1 0");
            Assert.Pass();
        }
Esempio n. 8
0
        public void Delete(Wc entity)
        {
            XDocument xDocument = XDocument.Load(_databaseFile);
            XElement  node      = xDocument.Descendants("WcRecord").FirstOrDefault(wcRecord => wcRecord.Element("Time")?.Value == entity.Time.ToString(CultureInfo.InvariantCulture));

            if (node != null)
            {
                node.Remove();
                xDocument.Save(_databaseFile);
            }
        }
        public void WcIncorrectArgumentTest()
        {
            var mock = new Mock <IWriter>();

            var returned = new Wc().Run(new string[2] {
                "idonotexist", someTextPath
            }, string.Empty, mock.Object).Split(" ").Where(x => x.Length > 0).ToArray();

            Assert.AreEqual(0, returned.Length);
            mock.Verify(mock => mock.WriteLine(It.IsAny <string>()), Times.Once);
        }
        public void WcZeroArgumentsTest()
        {
            var mock = new Mock <IWriter>();

            var returned = new Wc().Run(new string[0], someInput, mock.Object).Split(" ").Where(x => x.Length > 0).ToArray();

            Assert.AreEqual($"{someInput.Count(x => x == '\n') + 1}", returned[0]);
            Assert.AreEqual($"{someInput.Count(x => x == ' ' || x == '\n') + 1}", returned[1]);
            Assert.AreEqual($"{someInput.Length}", returned[2]);
            mock.Verify(mock => mock.WriteLine(It.IsAny <string>()), Times.Never);
        }
Esempio n. 11
0
        public Wu(ContextMenuStrip cms, Wc wx)
        {
            InitializeComponent();
            SizeMode         = PictureBoxSizeMode.CenterImage;
            Width            = Height = 45;
            ContextMenuStrip = cms;
            Image            = Properties.Resources.loading;
            Margin           = new Padding(0, 0, 5, 5);
            Cursor           = Cursors.Hand;

            this.wx          = wx;
            this.wx.SetCode += Wx_SetCode;
        }
Esempio n. 12
0
        private void RunWx(TcpClient tc)
        {
            new Thread(o =>
            {
                var wx = new Wc(o as TcpClient);

                wx.NewWx += Wx_NewWx;
                wx.Exit  += Wx_Exit;
                wx.Run();

                Invoke((Action)(() => { var us = new Wu(cms_user, wx); fp_wxs.Controls.Add(us); tip_info.SetToolTip(us, "正在获取信息"); }));
            }).Start(tc);
        }
        public void WcCorrectArgumentTest()
        {
            var mock = new Mock <IWriter>();

            var returned = new Wc().Run(new string[1] {
                someTextPath
            }, string.Empty, mock.Object).Split(" ").Where(x => x.Length > 0).ToArray();

            Assert.AreEqual("4", returned[0]);
            Assert.AreEqual("8", returned[1]);
            Assert.AreEqual("43", returned[2]);
            mock.Verify(mock => mock.WriteLine(It.IsAny <string>()), Times.Never);
        }
Esempio n. 14
0
        private void GoToWc()
        {
            //Urination
            Wc wc = new Wc(DateTime.Now);

            if (_wcService.GetAll().Count == 0)
            {
                AddWc(wc);
                PlaySoundEffect();
            }
            else
            {
                if (_wcService.GetAll().Last().Time.ToString("HH:mm:ss") != wc.Time.ToString("HH:mm:ss"))
                {
                    AddWc(wc);
                    PlaySoundEffect();
                }
            }
        }
Esempio n. 15
0
 public void Update(Wc entity)
 {
 }
Esempio n. 16
0
 public void Delete(Wc wc)
 {
     _wcDal.Delete(wc);
 }
Esempio n. 17
0
 private void pb_newwx_Click(object sender, EventArgs e)
 {
     Wc.Start();
 }
Esempio n. 18
0
 public void Add(Wc wc)
 {
     _wcDal.Add(wc);
 }
Esempio n. 19
0
        private static Command CreateCommand(string command, int numberOfCommand)
        {
            string[]      wordsArr = command.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            string        name     = wordsArr[0].ToLower();
            List <string> args     = new List <string>();

            for (int i = 1; i < wordsArr.Length; ++i)
            {
                args.Add(wordsArr[i]);
            }

            switch (name)
            {
            case "echo":
            {
                Command result = new Echo(args, Path.GetTempPath() + "\\tmpResult" + numberOfCommand + ".txt", numberOfCommand == 0);
                if (result.IsCorrectArgs())
                {
                    return(result);
                }
                break;
            }

            case "cat":

            {
                Command result = new Cat(args, Path.GetTempPath() + "\\tmpResult" + numberOfCommand + ".txt", numberOfCommand == 0);
                if (result.IsCorrectArgs())
                {
                    return(result);
                }
                break;
            }

            case "pwd":
            {
                Command result = new Pwd(args, Path.GetTempPath() + "\\tmpResult" + numberOfCommand + ".txt", numberOfCommand == 0);
                if (result.IsCorrectArgs())
                {
                    return(result);
                }
                break;
            }

            case "wc":
            {
                Command result = new Wc(args, Path.GetTempPath() + "\\tmpResult" + numberOfCommand + ".txt",
                                        numberOfCommand == 0);
                if (result.IsCorrectArgs())
                {
                    return(result);
                }

                break;
            }

            case "exit":
            {
                Command result = new Exit(args);
                if (result.IsCorrectArgs())
                {
                    return(result);
                }

                break;
            }
            }
            throw new CommandException("Incorrect command name");
        }
Esempio n. 20
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            List <ValidationResult> errors = new List <ValidationResult>();

            #region machine parameters
            if (!((50 <= P12) && (P12 <= 2e5)))
            {
                errors.Add(new ValidationResult(errorP12));
            }
            if (!((48 <= U1) && (U1 <= 660)))
            {
                errors.Add(new ValidationResult(errorU1));
            }
            if (!((10 <= f1) && (f1 <= 400)))
            {
                errors.Add(new ValidationResult(errorf1));
            }
            //if (p < 0) errors.Add(new ValidationResult("Error p")); //such a state is unattainable. This is used for  Validator.TryValidateObject(..., true)
            if (!((0 <= Pмех) && (Pмех <= PмехBoundRight(P12))))
            {
                errors.Add(new ValidationResult($"Значение параметра Pмех должно принадлежать [0 : {PмехBoundRight(P12)}]."));
            }
            #endregion
            #region stator parameters
            if (!((50 < Di) && (Di <= 800)))
            {
                errors.Add(new ValidationResult(errorDi));
            }
            if ((!(0 <= ΔГ1) && (ΔГ1 <= 0)))
            {
                errors.Add(new ValidationResult(errorΔГ1));
            }
            if ((Z1 < 0) || !int.TryParse(Z1.ToString(), out _))
            {
                errors.Add(new ValidationResult(errorZ1));
            }
            if (!((Get_DaBounds(Di).left <= Da) && (Da < Get_DaBounds(Di).right)))
            {
                errors.Add(new ValidationResult($"Значение параметра Da должно принадлежать [{Math.Round(Get_DaBounds(Di).left, 2)} : {Math.Round(Get_DaBounds(Di).right, 2)})."));
            }
            if ((a1 < 0) || !int.TryParse(a1.ToString(), out _))
            {
                errors.Add(new ValidationResult(errora1));
            }
            if (!int.TryParse(a2.ToString(), out _))
            {
                errors.Add(new ValidationResult(errora2));
            }
            if (!((0 <= a2) && (a2 <= 30)))
            {
                errors.Add(new ValidationResult(errora2));
            }
            if ((W1 < 0) || !int.TryParse(W1.ToString(), out _))
            {
                errors.Add(new ValidationResult(errorW1));
            }
            if (W1 % 2 != 0)
            {
                errors.Add(new ValidationResult(errorW1parity));
            }
            if ((Wc < 0) || !int.TryParse(Wc.ToString(), out _))
            {
                errors.Add(new ValidationResult(errorWc));
            }
            if (!((3 <= Δкр) && (Δкр <= 40)))
            {
                errors.Add(new ValidationResult(errorΔкр));
            }
            if ((dиз < 0) || double.IsNaN(dиз))
            {
                errors.Add(new ValidationResult(errordиз));
            }
            if ((qГ < 0) || double.IsNaN(qГ))
            {
                errors.Add(new ValidationResult(errorqГ));
            }
            if (!((3.5 <= bz1) && (bz1 <= 15)))
            {
                errors.Add(new ValidationResult(errorbz1));
            }
            if (!((0 <= h8) && (h8 <= 20)))
            {
                errors.Add(new ValidationResult(errorh8));
            }
            if (!((0 <= h7) && (h7 <= 2)))
            {
                errors.Add(new ValidationResult(errorh7));
            }
            if (!((0 <= h6) && (h6 <= 20)))
            {
                errors.Add(new ValidationResult(errorh6));
            }
            if (!((0.1 <= h5) && (h5 <= 5)))
            {
                errors.Add(new ValidationResult(errorh5));
            }
            if (!((0 <= h3) && (h3 <= 5)))
            {
                errors.Add(new ValidationResult(errorh3));
            }
            if (!((5 <= h4) && (h4 <= 50)))
            {
                errors.Add(new ValidationResult(errorh4));
            }
            //if (!((dиз < ac) && (ac < 2 * dиз))) errors.Add(new ValidationResult($"Значение параметра расчета ac должно принадлежать ({dиз} : {2 * dиз})."));
            if (!(dиз < ac))
            {
                errors.Add(new ValidationResult($"Значение параметра ac должно быть > {dиз}."));
            }
            if (!((0 <= bПН) && (bПН <= bП1Calc(Di, h8, h7, h6, bz1, Z1))))
            {
                errors.Add(new ValidationResult($"Значение параметра bПН должно принадлежать [0 : {Math.Round(bП1Calc(Di, h8, h7, h6, bz1, Z1), 2)}]."));
            }
            if (h1 < 0 || double.IsNaN(h1))
            {
                errors.Add(new ValidationResult(errorh1));
            }
            if (h2 < 0 || double.IsNaN(h2))
            {
                errors.Add(new ValidationResult(errorh2));
            }
            if (!((0.5 <= li) && (li >= 3)))
            {
                errors.Add(new ValidationResult($"Значение параметра li должно принадлежать [{Get_liBounds(U1, I1(P12, U1), Di).left} : " +
                                                $"{Get_liBounds(U1, I1(P12, U1), Di).right}]."));
            }
            if (!((0 <= cз) && (cз <= 200)))
            {
                errors.Add(new ValidationResult(errorcз));
            }
            if (bП < 0 || double.IsNaN(bП))
            {
                errors.Add(new ValidationResult(errorbП));
            }
            if (bП1 < 0 || double.IsNaN(bП1))
            {
                errors.Add(new ValidationResult(errorbП1));
            }
            //if (!((0.36 <= Kзап) && (Kзап <= 0.76))) errors.Add(new ValidationResult(errorKзап));
            if (!((1 <= y1) && (y1 <= 0.5 * Z1 / Convert.ToDouble(p))))
            {
                errors.Add(new ValidationResult($"Значение параметра расчета y1 должно принадлежать [1 : {0.5 * Z1 / Convert.ToDouble(p)}]."));
            }
            if (!((0.5 <= β) && (β <= 0.95)))
            {
                errors.Add(new ValidationResult(errorβ));
            }
            if ((K2 < 0) || double.IsNaN(K2))
            {
                errors.Add(new ValidationResult(errorK2));
            }
            //if (string.IsNullOrEmpty(PR)) errors.Add(new ValidationResult("Error PR.")); //such a state is unattainable. This is used for  Validator.TryValidateObject(..., true)
            if (!((0 <= d1) && (d1 <= bП1Calc(Di, h8, h7, h6, bz1, Z1))))
            {
                errors.Add(
                    new ValidationResult($"Значение параметра расчета d1 должно принадлежать [0 : {Math.Round(bП1Calc(Di, h8, h7, h6, bz1, Z1), 2)}]."));
            }
            if (!((0.9 <= Kfe1) && (Kfe1 <= 1)))
            {
                errors.Add(new ValidationResult(errorKfe1));
            }
            if (!((0.002 <= ρ1x) && (ρ1x <= 0.05)))
            {
                errors.Add(new ValidationResult(errorρ1x));
            }
            if ((ρРУБ < 0) || double.IsNaN(ρРУБ))
            {
                errors.Add(new ValidationResult(errorρРУБ));
            }
            if (!((ρ1x <= ρ1Г) && (ρ1Г <= 0.1235)))
            {
                errors.Add(new ValidationResult($"Значение параметра расчета ρ1Г должно принадлежать [{ρ1x} : 0.1235]."));
            }
            if (!((0 <= B) && (B <= 20)))
            {
                errors.Add(new ValidationResult(errorB));
            }
            if ((p10_50 < 0) || double.IsNaN(p10_50))
            {
                errors.Add(new ValidationResult(errorp10_50));
            }
            #endregion
            #region rotor parameters
            if (!((0 <= ΔГ2) && (ΔГ2 <= 5)))
            {
                errors.Add(new ValidationResult(errorΔГ2));
            }
            //if (!((DpстBoundCalculation - 5 <= Dpст) && (Dpст < DpстBoundCalculation - 0.1)))
            //    errors.Add(new ValidationResult($"Значение параметра Dp.ст должно принадлежать [{ Math.Round(DpстBoundCalculation - 5, 2) } : { Math.Round(DpстBoundCalculation - 0.1, 2)})."));
            if (double.IsNaN(Dpст) || Dpст < 0)
            {
                errors.Add(new ValidationResult(errorDpст));
            }
            //if (string.IsNullOrEmpty(bСК)) errors.Add(new ValidationResult("Error bСК.")); //such a state is unattainable. This is used for  Validator.TryValidateObject(..., true)
            if ((Z2 < 0) || !int.TryParse(Z2.ToString(), out _))
            {
                errors.Add(new ValidationResult(errorZ2));
            }

            if (!((0.01 <= ρ2Г) && (ρ2Г <= 0.2)))
            {
                errors.Add(new ValidationResult(errorρ2Г));
            }
            if (!((0.9 <= Kfe2) && (Kfe2 <= 1)))
            {
                errors.Add(new ValidationResult(errorKfe2));
            }
            //if (!((0.125 * Get_Dp(Dpст, ΔГ2) <= hp) && (hp <= 0.375 * Get_Dp(Dpст, ΔГ2))))
            //    errors.Add(new ValidationResult($"Значение параметра hp должно принадлежать {Get_hpBounds(Dpст, ΔГ2)}."));
            if (hp < 0 || double.IsNaN(hp))
            {
                errors.Add(new ValidationResult(errorhp));
            }
            #endregion

            return(errors);
        }
Esempio n. 21
0
 private void AddWc(Wc wc)
 {
     _wcService.Add(wc);
     lstWc.Items.Add(wc.Text);
     CalculateSumOfWc();
 }