Exemplo n.º 1
0
        /// <summary>
        /// 指定されたパスのファイルからSequenceDataを作成します。拡張子は自動的に付加されます。
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static SequenceData RetrieveState(string path)
        {
            SequenceData ret = new SequenceData();

            if (!File.Exists(path + DefaultExtensionForHeader))
            {
                string ext = Path.GetExtension(path);
                if (ext == DefaultExtensionForHeader || ext == DefaultExtensionForValues || ext == DefaultExtensionForBorder)
                {
                    path = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path));
                    if (!File.Exists(path + DefaultExtensionForHeader))
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            string titlePath    = string.Format("{0}{1}", path, DefaultExtensionForHeader);
            string sequencePath = string.Format("{0}{1}", path, DefaultExtensionForValues);
            string borderPath   = string.Format("{0}{1}", path, DefaultExtensionForBorder);

            using (FileStream titleStream = new FileStream(titlePath, FileMode.Open)) {
                ret.RetrieveDataHeader(titleStream);
            }
            ret.Values        = TimeSeriesValues.Deserialize(sequencePath);
            ret.Borders       = LabelingBorders.Deserialize(borderPath);
            ret.IsDataChanged = false;
            return(ret);
        }
Exemplo n.º 2
0
        /// <summary>
        /// ストリームからデータを復元します
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static SequenceData Deserialize(XmlReader reader)
        {
            SequenceData ret = null;

            reader.ReadStartElement(typeof(SequenceData).Name);
            byte[]          titleBytes = null, sequenceBytes = null;
            LabelingBorders border     = null;
            string          tmp;
            MemoryStream    tmpStream;
            StreamWriter    tmpWriter;

            for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement && reader.NodeType != XmlNodeType.None; reader.MoveToContent())
            {
                if (reader.IsEmptyElement)
                {
                    reader.Skip();
                    continue;
                }
                switch (reader.Name)
                {
                case "Title":
                    tmp       = reader.ReadElementContentAsString();
                    tmpStream = new MemoryStream();
                    tmpWriter = new StreamWriter(tmpStream);
                    tmpWriter.Write(tmp);
                    tmpWriter.Flush();
                    titleBytes = tmpStream.ToArray();
                    break;

                case "Sequence":
                    tmp       = reader.ReadElementContentAsString();
                    tmpStream = new MemoryStream();
                    tmpWriter = new StreamWriter(tmpStream);
                    tmpWriter.Write(tmp);
                    tmpWriter.Flush();
                    sequenceBytes = tmpStream.ToArray();
                    break;

                case "Border":
                    reader.ReadStartElement();
                    border = LabelingBorders.Deserialize(reader.ReadSubtree());
                    for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement && reader.NodeType != XmlNodeType.None; reader.MoveToContent())
                    {
                        reader.Skip();
                    }
                    reader.ReadEndElement();
                    break;

                default:
                    reader.Skip();
                    break;
                }
            }
            reader.ReadEndElement();
            if (titleBytes != null && sequenceBytes != null && border != null)
            {
                ret         = new SequenceData();
                ret.Borders = border;
                using (MemoryStream stream2 = new MemoryStream(sequenceBytes)) {
                    ret.Values = TimeSeriesValues.Deserialize(stream2);
                }
                using (MemoryStream stream2 = new MemoryStream(titleBytes)) {
                    ret.RetrieveDataHeader(stream2);
                }
            }
            return(ret);
        }