Пример #1
0
        /// <summary>
        ///     스트림에서 설정을 읽어옵니다.
        /// </summary>
        /// <param name="stream">읽어올 스트림입니다.</param>
        public override void Read(Stream stream)
        {
            StreamReader streamReader = new StreamReader(stream, Encoding.UTF8);

            while (!streamReader.EndOfStream)
            {
                string data = streamReader.ReadLine();

                //분할 코드 추출
                DivisionCode currentDivisionCode = AccessibleConfig.GetDivisionCode(data);
                if (currentDivisionCode != DivisionCode.None)
                {
                    string divisionString = AccessibleConfig.GetDivisionString(currentDivisionCode);
                    int    index          = data.IndexOf(divisionString);

                    string   key      = data.Substring(0, index);
                    string   value    = data.Substring(index + divisionString.Length);
                    DataPair dataPair = new DataPair(currentDivisionCode, value);

                    //읽어온 설정을 등록
                    if (this.configData.ContainsKey(key))
                    {
                        this.configData.Remove(key);
                    }
                    this.configData.Add(key, dataPair);
                }
            }
        }
Пример #2
0
        /// <summary>
        ///     스트림으로 설정을 출력합니다.
        /// </summary>
        /// <param name="stream">출력할 스트림입니다.</param>
        public override void Write(Stream stream)
        {
            StreamWriter streamWriter = new StreamWriter(stream, Encoding.UTF8);

            foreach (ConfigDataPair configDataPair in this.configData)
            {
                streamWriter.WriteLine(configDataPair.Key + AccessibleConfig.GetDivisionString(configDataPair.Value.t1) + configDataPair.Value.t2);
            }

            streamWriter.Flush();
        }
Пример #3
0
        /// <summary>
        ///     스트림에서 설정을 읽어옵니다.
        /// </summary>
        /// <param name="stream">읽어올 스트림입니다.</param>
        public override void Read(Stream stream)
        {
            DateTime     currentDateTime = this.nowDateTime;
            StreamReader streamReader    = new StreamReader(stream, Encoding.UTF8);

            while (!streamReader.EndOfStream)
            {
                string data = streamReader.ReadLine();

                //시간 추출
                DateTime dateTime;
                Match    match = Regex.Match(data, this.propertyConfig.DateTimeRegex, RegexOptions.Compiled);
                if (match.Success && DateTime.TryParse(match.Value, out dateTime))
                {
                    currentDateTime = dateTime;
                    continue;
                }

                //분할 코드 추출
                DivisionCode currentDivisionCode = AccessibleConfig.GetDivisionCode(data);
                if (currentDivisionCode != DivisionCode.None)
                {
                    string divisionString = AccessibleConfig.GetDivisionString(currentDivisionCode);
                    int    index          = data.IndexOf(divisionString);

                    string   key      = data.Substring(0, index);
                    string   value    = data.Substring(index + divisionString.Length);
                    DataPair dataPair = new DataPair(currentDivisionCode, value);

                    //읽어온 값의 접근 시간이랑 저장되어있던 값의 접근 시간을 비교 후 가장 최근 접근 시간을 추출
                    DateTime latestDateTime = currentDateTime;
                    foreach (ConfigDatasPair configDatasPair in this.configDatas)
                    {
                        if (configDatasPair.Value.ContainsKey(key))
                        {
                            latestDateTime = DateTime.Compare(latestDateTime, configDatasPair.Key) == 1 ? latestDateTime : configDatasPair.Key;
                            configDatasPair.Value.Remove(key);
                        }
                    }

                    //가장 최근 접근 시간으로 읽어온 설정을 등록
                    ConfigData configData;
                    if (!this.configDatas.TryGetValue(latestDateTime, out configData))
                    {
                        configData = new ConfigData(this.configDataStringComparer);
                        this.configDatas.Add(latestDateTime, configData);
                    }
                    configData.Add(key, dataPair);
                }
            }
        }
Пример #4
0
        /// <summary>
        ///     문자열에 해당하는 분할 코드를 반환합니다.
        /// </summary>
        /// <param name="divisionString">문자열입니다.</param>
        /// <returns>물자열에 해당하는 분할 코드입니다.</returns>
        protected static DivisionCode GetDivisionCode(string divisionString)
        {
            if (divisionString == null)
            {
                throw new ArgumentNullException("divisionString", "Argument can not be null");
            }

            DivisionCode divisionCode = DivisionCode.None;

            divisionCode = divisionString.Contains(AccessibleConfig.GetDivisionString(DivisionCode.Relative)) ? DivisionCode.Relative : divisionCode;
            divisionCode = divisionString.Contains(AccessibleConfig.GetDivisionString(DivisionCode.Absolute)) ? DivisionCode.Absolute : divisionCode;
            divisionCode = divisionString.Contains(AccessibleConfig.GetDivisionString(DivisionCode.Disable)) ? DivisionCode.Disable : divisionCode;
            return(divisionCode);
        }
Пример #5
0
        /// <summary>
        ///     스트림으로 설정을 출력합니다.
        /// </summary>
        /// <param name="stream">출력할 스트림입니다.</param>
        public override void Write(Stream stream)
        {
            StreamWriter streamWriter = new StreamWriter(stream, Encoding.UTF8);

            foreach (ConfigDatasPair configDatasPair in this.configDatas)
            {
                if (configDatasPair.Value.Count != 0)
                {
                    streamWriter.WriteLine(this.GetDateTimeSectionString(configDatasPair.Key));
                    foreach (ConfigDataPair configDataPair in configDatasPair.Value)
                    {
                        streamWriter.WriteLine(configDataPair.Key + AccessibleConfig.GetDivisionString(configDataPair.Value.Key) + configDataPair.Value.Value);
                    }
                }
            }

            streamWriter.Flush();
        }