Пример #1
0
        public void MarkListBinarySerializationTest()
        {
            var stream    = new MemoryStream();
            var formatter = new BinaryFormatter();

            // create a mark list collection, and populate it with 10 marks
            var marks = new MarkList();

            for (int i = 1; i <= 10; i = i + 1)
            {
                marks.Add(new Mark(i));
            }

            try
            {
                formatter.Serialize(stream, marks);

                // no exception thrown, so pass the test
                Assert.IsTrue(true);
            }
            catch (Exception)
            {
                // an exception was thrown, meaning that the serialization
                // failed so fail the test
                Assert.IsTrue(false);
            }
            finally
            {
                stream.Close();
            }
        }
Пример #2
0
 private void MarcRect_MouseUp(object sender, Drawing3d.HandledMouseEventArgs e)
 {
     Selector.SnapInside(MarcRect.Rectangle);
     if (Form.ModifierKeys != Keys.Shift)
     {
         MarkList.Clear();
     }
     for (int i = 0; i < SnappItems.Count; i++)
     {
         if (IndexOfTag(SnappItems[i].Tag) < 0)
         {
             MarkList.Add(SnappItems[i].Tag);
         }
     }
     e.Handled = true;
     MarcRect.OnLogout(false);
 }
Пример #3
0
        private void OnMarkListPack(MsgBase b)
        {
            var selfMsg = (Msg_AgarMarkListPack)b;

            MarkList.Clear();

            foreach (var obj in selfMsg.MarkList)
            {
                if (CircleList.ContainsKey(obj.Key))
                {
                    MarkList.Add(new KeyValuePair <string, int>(CircleList[obj.Key].Name, obj.Value));
                }
                else if (obj.Key == Uid && Player != null)
                {
                    MarkList.Add(new KeyValuePair <string, int>(Player.Name, obj.Value));
                }
            }
            // 暂时只接受数据不显示
        }
Пример #4
0
        /// <summary>
        /// 初始化标记信息
        /// </summary>
        /// <param name="edfFilePath">edf/edfx文件路径</param>
        private void initMarkInfo(String edfFilePath)
        {
            /*
             * this._markInfoList.Clear();
             * this._markInfoDic.Clear();
             */
            this.MarkList.Clear();

            String fileNameWithoutExtension = Path.GetFileNameWithoutExtension(edfFilePath) + "_mark";
            String filePath = Path.GetDirectoryName(edfFilePath) + @"\" + fileNameWithoutExtension + ".txt";

            // 初始化保存标记方法
            SaveMark = () =>
            {
                using (var fs = new FileStream(filePath, FileMode.Create))
                    using (var sw = new StreamWriter(fs))
                    {
                        foreach (var mark in MarkList)
                        {
                            // 计算标记名称长度
                            var length = 30 - (Encoding.Default.GetBytes(mark.Name).Length - mark.Name.Length);

                            // 写入标记信息
                            sw.WriteLine(mark.Name.PadRight(length) + mark.DateTime.ToString("HH:mm:ss.fff  MM/dd/yyyy"));
                        }
                    }
            };

            // 打开标记文件
            FileInfo file = new FileInfo(filePath);

            if (!file.Exists)
            {
                this.formMain.refreshMarkListBox();
                return;
            }

            FileStream   fileStream = null;
            StreamReader reader     = null;

            try
            {
                fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                // reader = new StreamReader(fileStream, Encoding.UTF8);
                reader = new StreamReader(fileStream, true);
                String line = null;
                while ((line = reader.ReadLine()) != null)
                {
                    line = line.TrimEnd();

                    // 分解成字节
                    var bytes = Encoding.Default.GetBytes(line);

                    // 前30个字节为名称
                    var mark = Encoding.Default.GetString(bytes, 0, 30).Trim();

                    // 后面为日期
                    var time = Encoding.Default.GetString(bytes, 30, bytes.Length - 30).Trim();

                    // 转换成DateTime
                    DateTime markTime;
                    {
                        // BIO[12:34:56  01/01/2017]长度为20
                        if (time.Length == 20)
                        {
                            markTime = DateTime.ParseExact(time, "HH:mm:ss  MM/dd/yyyy", CultureInfo.CurrentCulture);
                        }
                        // HM[12:34:56.789  01/01/2017]长度为24
                        else if (time.Length == 24)
                        {
                            markTime = DateTime.ParseExact(time, "HH:mm:ss.fff  MM/dd/yyyy", CultureInfo.CurrentCulture);
                        }
                        // 尝试转换
                        else
                        {
                            markTime = DateTime.Parse(time);
                        }
                    }

                    /*
                     * String[] lines = line.Split('|');
                     *
                     * String mark = null; // 标记信息
                     * DateTime markTime;  // 标记相对时间
                     *
                     * if (lines.Length == 2)
                     * {
                     *  mark = lines[0];
                     *  markTime = Convert.ToDateTime(lines[1]);
                     * }
                     * else if (line.Length > 20) // 12:34:56  01/01/2017 长度为20
                     * {
                     *  String markTimeString = line.Substring(line.Length - 20, 20);
                     *  markTime = Convert.ToDateTime(markTimeString);
                     *  mark = line.Substring(0, line.Length - 20).Trim();
                     * }
                     * else
                     * {
                     *  continue;
                     * }
                     */

                    // 加入列表
                    MarkList.Add(new Mark(mark, markTime));

                    /*
                     * // 标记信息和时间都可能重复,如有重复,则添加 "_i" 用来区分
                     * if (!this._markInfoDic.ContainsKey(mark))
                     * {
                     *  this._markInfoDic.Add(mark, markTime);
                     *  this._markInfoList.Add(mark);
                     * }
                     * else
                     * {
                     *  int i = 2;
                     *  String tmp = mark + "_" + i;
                     *  while (this._markInfoDic.ContainsKey(tmp))
                     *  {
                     *      i++;
                     *      tmp = mark + "_" + i;
                     *  }
                     *  mark = tmp;
                     *  this._markInfoDic.Add(mark, markTime);
                     *  this._markInfoList.Add(mark);
                     * }
                     */
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("标记信息初始化异常:" + ex.Message + "\n详情:" + ex.StackTrace);
            }
            finally
            {
                try
                {
                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
                catch { }
                finally
                {
                    fileStream = null;
                    reader     = null;
                }
            }

            this.formMain.refreshMarkListBox();
        }
Пример #5
0
 public void AddSelectionMark(DateTime start, DateTime end)
 {
     MarkList.Add(start, end);
 }