コード例 #1
0
        public static void Create(IEnumerable <IBlock> blocks, string path, PortalPlc owningPlc)
        {
            if (blocks == null)
            {
                throw new ArgumentNullException(nameof(blocks));
            }
            IEnumerable <DataBlock> dataBlocks;

            if ((dataBlocks = blocks.OfType <DataBlock>())?.Count() <= 0)
            {
                throw new ArgumentException("Blocks does not contain any valid DataBlocks.", nameof(blocks));
            }

            KepwareConfiguration.CreateInternal(dataBlocks, path, owningPlc);
        }
コード例 #2
0
        private static void CreateInternal(IEnumerable <DataBlock> blocks, string path, PortalPlc parentPlc)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (!FileHelpers.IsValidFilePath(path, ".csv"))
            {
                throw new ArgumentException(path + " is not a valid path.", nameof(path));
            }

            try
            {
                using (var file = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                {
                    var writer = new StreamWriter(file);

                    KepwareConfiguration.WriteHeaders(writer);

                    foreach (var block in blocks)
                    {
                        if (block == null)
                        {
                            throw new ArgumentNullException(nameof(block));
                        }
                        if (block.Children?.Count <= 0)
                        {
                            throw new ArgumentException("Block '" + block.Name + "' contains no data", nameof(block));
                        }

                        KepwareConfiguration.ExportDataBlockToFile(block, writer, parentPlc);
                    }

                    writer.Flush();
                }
            }
            catch (Exception e)
            {
                throw new SiemensException("Could not write Kepware configuration", e);
            }
        }
コード例 #3
0
 public static void Create(DataBlock block, string path, PortalPlc owningPlc)
 {
     KepwareConfiguration.CreateInternal(new[] { block }, path, owningPlc);
 }