Пример #1
0
        public void AddPoint(IHdaPoint point)
        {
            if (point == null)
            {
                throw new ArgumentNullException("point");
            }

            var values = point.GetValues().ToList();

            if (values == null || !values.Any())
            {
                throw new ArgumentException("Точка не содержит значений.");
            }

            var fileGroupId = Guid.NewGuid();

            var rootPath = Path.GetTempPath() + Assembly.GetExecutingAssembly().GetName().Name + "\\" + fileGroupId.ToString() + "\\";

            new FileInfo(rootPath).Directory.Create();

            var blockFiles = CompressedBlocksUtils.SaveToFileByParts(values, "points", rootPath, HDDDataManager.BLOCK_SIZE);

            //Сохраняем заголовок (ссылку на саму точку не храним, ибо она очень много весит)

            AddedPoints.Add(new PointInfo
            {
                Folder      = rootPath,
                Item        = point.Item,
                Description = point.Description,
                EngUnit     = point.EngUnit,
                BlockFiles  = blockFiles,
                ValuesCount = values.Count
            });
        }
Пример #2
0
        public IEnumerable <HdaPointValue> GetValues()
        {
            var values =
                CompressedBlocksUtils.LoadFromParts("points",
                                                    _info.Folder,
                                                    _info.ValuesCount,
                                                    HDDDataManager.BLOCK_SIZE);

            return(values.OfType <HdaPointValue>());
        }
Пример #3
0
        internal void Save(HDDInfinityFileImpl file)
        {
            if (string.IsNullOrWhiteSpace(file.FilePath))
            {
                throw new Exception("FileName is empty.");
            }

            List <string> blockFiles = new List <string>();

            var rootPath = Path.GetTempPath() + Assembly.GetExecutingAssembly().GetName().Name + "\\";

            blockFiles.AddRange(CompressedBlocksUtils.SaveToFileByParts(file.AddedEvents, "events", rootPath, BLOCK_SIZE));
            blockFiles.AddRange(CompressedBlocksUtils.SaveToFileByParts(file.AddedConfigEvents,
                                                                        "configEvents",
                                                                        rootPath,
                                                                        BLOCK_SIZE));

            if (File.Exists(file.FilePath))
            {
                File.Delete(file.FilePath);
            }

            new FileInfo(file.FilePath).Directory.Create();

            var serializer = new BinaryFormatter();

            using (var stream = File.Open(file.FilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                using (var writer = new BinaryWriter(stream))
                {
                    writer.Write(Guid.Parse(Header).ToByteArray());

                    writer.Write(Version);

                    long hashPosition = stream.Position;

                    writer.Write(new byte[16]);

                    writer.Write(file.AddedPoints.Count);
                    writer.Write(file.AddedEvents.Length);
                    writer.Write(file.AddedConfigEvents.Length);

                    foreach (var addedPoint in file.AddedPoints)
                    {
                        serializer.Serialize(writer.BaseStream, addedPoint);
                        foreach (var blockFile in addedPoint.BlockFiles)
                        {
                            using (var blockStream = File.Open(blockFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                            {
                                writer.Write((int)blockStream.Length);
                                blockStream.CopyTo(stream);
                            }
                        }
                    }

                    //Запись для событий и конфигурационных событий
                    foreach (var blockFile in blockFiles)
                    {
                        using (var blockStream = File.Open(blockFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                        {
                            writer.Write((int)blockStream.Length);
                            blockStream.CopyTo(stream);
                        }
                    }

                    stream.Seek(hashPosition + 16, SeekOrigin.Begin);

                    using (var md5 = MD5.Create())
                    {
                        var hash = md5.ComputeHash(stream);

                        stream.Seek(hashPosition, SeekOrigin.Begin);

                        writer.Write(hash);
                    }
                }
            }

            foreach (var blockFile in blockFiles)
            {
                File.Delete(blockFile);
            }
        }