コード例 #1
0
 public static object Map(this ReadPoint readPoint, long eventId)
 {
     return(new
     {
         EventId = eventId,
         ReadPointId = readPoint.Id
     });
 }
コード例 #2
0
        private Option <Coordinate> ReadValidCoorindate(string label, ReadPoint op)
        {
            var x     = Option <Coordinate> .None;
            int tries = 0;

            do
            {
                Console.Write($"{label}:");
                x = parseInt(Console.ReadLine())
                    .Where(xVal => xVal >= 1 && xVal <= op.Board.Size.Value)
                    .Map(xVal => new Coordinate(xVal));
            } while (x.IsNone && ++tries < 4);
            return(x);
        }
コード例 #3
0
ファイル: ReadZB.cs プロジェクト: SWJ8529/stu
        public void readpoint()
        {
            FilePath = Environment.CurrentDirectory + @"/Point.txt";
            #region 读取文件坐标
            if (!File.Exists(FilePath))//判断文件是否存在
            {
                File.Create(FilePath).Close();
            }
            //Thread.Sleep(200);
            var lines = File.ReadAllLines(FilePath);

            string PointJson = string.Empty;

            foreach (var line in lines)
            {
                if (!string.IsNullOrEmpty(line))
                {
                    PointJson += line;
                }
            }
            ReadPoint rp = JsonConvert.DeserializeObject <ReadPoint>(PointJson);
            if (rp != null)
            {
                point = rp.point;
                if (rp.url != ConfigurationManager.AppSettings["URL"])
                {
                    rp.url = ConfigurationManager.AppSettings["URL"];
                }
                _URL = rp.url;
            }
            else
            {
                FileStream fs = new FileStream(ReadZB.FilePath, FileMode.Open, FileAccess.Write);
                System.IO.File.SetAttributes(ReadZB.FilePath, FileAttributes.Hidden);
                StreamWriter sr = new StreamWriter(fs);
                fs.Seek(0, SeekOrigin.Begin);
                fs.SetLength(0);
                ReadZB.point.Clear();
                sr.WriteLine(JsonConvert.SerializeObject(new ReadZB.ReadPoint()
                {
                    point = ReadZB.point, url = ConfigurationManager.AppSettings["URL"]
                }));                                                                                                                                      //开始写入值
                sr.Close();
                fs.Close();
                _URL = ConfigurationManager.AppSettings["URL"];
            }

            #endregion
        }
コード例 #4
0
        private static bool IsAtCSVQuote(ReadPoint <char> currentReadPoint)
        {
            ReadPoint <char> curr = currentReadPoint;

            for (int i = 0; i < 1; ++i)
            {
                if (curr.Next.AtEnd)
                {
                    return(false);
                }
                if (curr.Next.Value != '\"')
                {
                    return(false);
                }
                curr = curr.Next;
            }
            return(true);
        }
コード例 #5
0
        public static IEnumerable <string> CharsToLines(IEnumerable <char> chars)
        {
            List <char>      accumulator = new List <char>();
            ReadPoint <char> currentChar = Alg.ReadPoint(chars);

            while (!currentChar.AtEnd)
            {
                char c = currentChar.Value;
                if (c == '\n')
                {
                    yield return(Alg.MergedChars(accumulator));

                    accumulator = new List <char>();
                }
                else
                if (c == '\r')
                {       // have to handle '\r'-only case.
                    if (!currentChar.Next.AtEnd)
                    {
                        if (currentChar.Next.Value != '\n')
                        {
                            yield return(Alg.MergedChars(accumulator));

                            accumulator = new List <char>();
                        }
                    }
                }
                else
                {
                    accumulator.Add(c);
                }
                currentChar = currentChar.Next;
            }

            if (accumulator.Count != 0)
            {
                yield return(Alg.MergedChars(accumulator));

                accumulator = new List <char>();
            }
        }
コード例 #6
0
        public static IEnumerable <string> LineToCSFEntries(string line, char delimiter, bool quotesHaveMeaning)
        {
            ReadPoint <char> currentChar        = Alg.ReadPoint(line.ToCharArray());
            List <char>      accumulatedElement = new List <char>();
            bool             inQuote            = false;
            bool             haveSeenAComma     = false;

            while (!currentChar.AtEnd)
            {
                char c = currentChar.Value;
                if (inQuote)
                {
                    if (c == '\"')
                    {   // may be a double-quote
                        if (IsAtCSVQuote(currentChar))
                        {
                            accumulatedElement.Add('\"');
                            currentChar = currentChar.Next; // next add will be done at end of this loop.
                        }
                        else
                        {
                            accumulatedElement.Add(c);
                            inQuote = false;
                        }
                    }
                    else
                    {
                        accumulatedElement.Add(c);
                    }
                }
                else
                {
                    if (c == delimiter)
                    {
                        haveSeenAComma = true;
                        yield return(Alg.MergedChars(accumulatedElement).Trim());

                        accumulatedElement = new List <char>();
                    }
                    else
                    {
                        if (quotesHaveMeaning && (c == '\"'))
                        {
                            inQuote = true;
                            accumulatedElement.Add(c);
                        }
                        else
                        {
                            accumulatedElement.Add(c);
                        }
                    }
                }
                currentChar = currentChar.Next;
            }
            if ((accumulatedElement.Count != 0) || haveSeenAComma)
            {
                yield return(Alg.MergedChars(accumulatedElement).Trim());   // deliberately return "last"

                accumulatedElement = new List <char>();
            }
        }
コード例 #7
0
 public override Validation <string, Point> Work(ReadPoint Op) =>
 from x in ReadValidCoorindate("X", Op).ToValidation("Could not read X point")
 from y in ReadValidCoorindate("Y", Op).ToValidation("Could not read Y point")
 from point in Op.Board.CreateBoardPoint(x, y)
 select point;
コード例 #8
0
 public override Validation <string, Point> Mock(ReadPoint Op) =>
 Op.Board.CreateBoardPoint(new Coordinate(1), new Coordinate(1));