コード例 #1
0
ファイル: Action.cs プロジェクト: DmitryTahoma/Diary
        public Action(string dbStr) : base()
        {
            Regex regex = new Regex("^\b<sa>\b\\d+\b<sa>\b\b<sn>\b\\d+\b<sn>\b[\\s\\S]*\b<sn>\b[\\s\\S]*\b<sn>\b\\d+[,\\d[E\\-\\d]*]*\b<sn>\b\\d+[,\\d[E\\-\\d]*]*\b<sn>\b\b<sa>\b\\d+[,\\d[E\\-\\d]*]*\b<sa>\b\\d+[,\\d[E\\-\\d]*]*\b<sa>\b");

            if (regex.IsMatch(dbStr))
            {
                string[] values = StringsHelper.Split("\b<sa>\b", dbStr);

                Id = int.Parse(values[0]);
                Note baseNote = new Note(values[1]);
                Start = DateTime.MinValue.AddDays(double.Parse(values[2]));
                double endDays = double.Parse(values[3]);
                if (endDays >= 3652058)
                {
                    End = DateTime.MaxValue;
                }
                else
                {
                    End = DateTime.MinValue.AddDays(endDays);
                }

                base.Id      = baseNote.Id;
                StereotypeId = baseNote.StereotypeId;
                Name         = baseNote.Name;
                Text         = baseNote.Text;
                Created      = baseNote.Created;
                LastChanged  = baseNote.LastChanged;
            }
            else
            {
                throw new ArgumentException();
            }
        }
コード例 #2
0
ファイル: Point.cs プロジェクト: DmitryTahoma/Diary
        public Point(string dbStr)
        {
            Regex regex1 = new Regex("^\b<sp>\b\\d+\b<sp>\b[\\s\\S]*\b<sp>\b1\b<sp>\b");
            Regex regex2 = new Regex("^\b<sp>\b\\d+\b<sp>\b[\\s\\S]*\b<sp>\b");

            if (regex2.IsMatch(dbStr))
            {
                string[] values = StringsHelper.Split("\b<sp>\b", dbStr);

                id   = int.Parse(values[0]);
                Text = values[1];
                if (regex1.IsMatch(dbStr))
                {
                    IsChecked = true;
                }
            }
            else
            {
                throw new ArgumentException();
            }
        }
コード例 #3
0
        public Note(string dbStr)
        {
            Regex regex = new Regex("^\b<sn>\b\\d+\b<sn>\b[\\s\\S]*\b<sn>\b[\\s\\S]*\b<sn>\b\\d+[,\\d[E\\-\\d]*]*\b<sn>\b\\d+[,\\d[E\\-\\d]*]*\b<sn>\b");

            if (regex.IsMatch(dbStr))
            {
                string[] values = StringsHelper.Split("\b<sn>\b", dbStr);

                Id           = int.Parse(values[0]);
                Name         = values[1];
                Text         = values[2];
                Created      = DateTime.MinValue.AddDays(double.Parse(values[3]));
                LastChanged  = DateTime.MinValue.AddDays(double.Parse(values[4]));
                isAutoTiming = true;
                InitializeTimer();
                commit = new NoteCommit(name, text);
            }
            else
            {
                throw new ArgumentException();
            }
        }
コード例 #4
0
ファイル: Mission.cs プロジェクト: DmitryTahoma/Diary
        public static IMission CreateNew(string dbStr)
        {
            Regex regexProgress   = new Regex("^\b<sm>\b\\d+\b<sm>\b\b<sa>\b\\d+\b<sa>\b\b<sn>\b\\d+\b<sn>\b[\\s\\S]*\b<sn>\b[\\s\\S]*\b<sn>\b\\d+[,\\d[E\\-\\d]*]*\b<sn>\b\\d+[,\\d[E\\-\\d]*]*\b<sn>\b\b<sa>\b\\d+[,\\d[E\\-\\d]*]*\b<sa>\b\\d+[,\\d[E\\-\\d]*]*\b<sa>\b\b<sm>\b\\d+z\\d+z\\d+z\\d+\b<sm>\b");
            Regex regexParagraph  = new Regex("^\b<sm>\b[-]\\d+\b<sm>\b\b<sa>\b\\d+\b<sa>\b\b<sn>\b\\d+\b<sn>\b[\\s\\S]*\b<sn>\b[\\s\\S]*\b<sn>\b\\d+[,\\d[E\\-\\d]*]*\b<sn>\b\\d+[,\\d[E\\-\\d]*]*\b<sn>\b\b<sa>\b\\d+[,\\d[E\\-\\d]*]*\b<sa>\b\\d+[,\\d[E\\-\\d]*]*\b<sa>\b\b<sm>\b\b<sc>\b\\d+\b<sc>\b\\d+\b<sc>\b[\b<sp>\b\\d+\b<sp>\b[\\s\\S]*\b<sp>\b[1\b<sp>\b]*\b<sc>\b]*\b<sm>\b"),
                  regexParagraph2 = new Regex("^\b<sm>\b[-]\\d+\b<sm>\b\b<sa>\b\\d+\b<sa>\b\b<sn>\b\\d+\b<sn>\b[\\s\\S]*\b<sn>\b[\\s\\S]*\b<sn>\b\\d+[,\\d[E\\-\\d]*]*\b<sn>\b\\d+[,\\d[E\\-\\d]*]*\b<sn>\b\b<sa>\b\\d+[,\\d[E\\-\\d]*]*\b<sa>\b\\d+[,\\d[E\\-\\d]*]*\b<sa>\b\b<sm>\b\b<sc>\b\\d+\b<sc>\b\\d+\b<sc>\b\b<sm>\b");

            if (regexProgress.IsMatch(dbStr))
            {
                string[]        values          = StringsHelper.Split("\b<sm>\b", dbStr);
                Action          action          = new Action(values[1]);
                Progress        progress        = new Progress(values[2]);
                ProgressMission progressMission = new ProgressMission(int.Parse(values[0]), action, progress);
                return(progressMission);
            }
            else if (regexParagraph.IsMatch(dbStr) || regexParagraph2.IsMatch(dbStr))
            {
                string[]         values           = StringsHelper.Split("\b<sm>\b", dbStr);
                Action           action           = new Action(values[1]);
                ParagraphMission paragraphMission = new ParagraphMission(int.Parse(values[0]) * -1, new Paragraph(values[2]), action.Id, action.NoteId, action.StereotypeId, action.Name, action.Text, action.Created, action.LastChanged, action.Start, action.End, true);
                return(paragraphMission);
            }
            throw new ArgumentException();
        }
コード例 #5
0
        public Paragraph(string dbStr)
        {
            Regex regex  = new Regex("^\b<sc>\b\\d+\b<sc>\b\\d+\b<sc>\b[\b<sp>\b\\d+\b<sp>\b[\\s\\S]*\b<sp>\b[1\b<sp>\b]*\b<sc>\b]*"),
                  regex2 = new Regex("^\b<sc>\b\\d+\b<sc>\b\\d+\b<sc>\b");

            if (regex.IsMatch(dbStr) || regex2.IsMatch(dbStr))
            {
                string[] values = StringsHelper.Split("\b<sc>\b", dbStr);
                Id = int.Parse(values[0]);

                Items = new List <Point>();
                if (int.Parse(values[1]) != 0)
                {
                    for (int i = 2; i < values.Length; ++i)
                    {
                        Items.Add(new Point(values[i]));
                    }
                }
            }
            else
            {
                throw new ArgumentException();
            }
        }
コード例 #6
0
        public void GetDayTest(string login, string password, int day, int month, int year)
        {
            GenerateTestNotes();
            string expectedResultString = server.ExecuteCommand("gd", new string[] { login, password, day.ToString(), month.ToString(), year.ToString() });

            try
            {
                List <Note> result = helper.GetDay(login, password, day, month, year);

                List <Note> expectedResult = new List <Note>();
                string[]    erss           = StringsHelper.Split("\b<sgd>\b", expectedResultString);
                for (int i = 0; i < erss.Length; ++i)
                {
                    if (Mission.IsStringMission(erss[i]))
                    {
                        expectedResult.Add((ParagraphMission)Mission.CreateNew(erss[i]));
                    }
                    else
                    {
                        expectedResult.Add(new Note(erss[i]));
                    }
                }

                Assert.AreEqual(expectedResult.Count, result.Count);
                for (int i = 0; i < result.Count; ++i)
                {
                    if (expectedResult[i] is ParagraphMission)
                    {
                        Assert.IsTrue(result[i] is ParagraphMission);
                        ParagraphMission expectedMission = (ParagraphMission)expectedResult[i],
                                         mission         = (ParagraphMission)result[i];

                        Assert.AreEqual(expectedMission.Context.Count, mission.Context.Count);
                        Assert.AreEqual(expectedMission.ContextId, mission.ContextId);
                        for (int j = 0; j < mission.Context.Count; ++j)
                        {
                            Assert.AreEqual(expectedMission.Paragraph.Items[j].Id, mission.Paragraph.Items[j].Id);
                            Assert.AreEqual(expectedMission.Paragraph.Items[j].Text, mission.Paragraph.Items[j].Text);
                            Assert.AreEqual(expectedMission.Paragraph.Items[j].IsChecked, mission.Paragraph.Items[j].IsChecked);
                        }

                        Assert.AreEqual(expectedMission.Id, mission.Id);
                        Assert.AreEqual(expectedMission.ActionId, mission.ActionId);
                        Assert.AreEqual(expectedMission.Start, expectedMission.Start);
                        Assert.AreEqual(expectedMission.End, expectedMission.End);
                    }
                    Assert.AreEqual(expectedResult[i].Id, result[i].Id);
                    Assert.AreEqual(expectedResult[i].Name, result[i].Name);
                    Assert.AreEqual(expectedResult[i].Text, result[i].Text);
                    Assert.AreEqual(expectedResult[i].LastChanged, result[i].LastChanged);
                    Assert.AreEqual(expectedResult[i].Created, result[i].Created);
                    Assert.AreEqual(expectedResult[i].StereotypeId, result[i].StereotypeId);
                }
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(expectedResultString == "ae");
            }
            finally
            {
                server.Stop();
            }
        }