Пример #1
0
        public OutputWriter(eOutputFormat OutputFormat,
                            eOutputQuality OutputQuality,
                            string OutputFileName,
                            string OutputTimestampFormat,
                            bool ReadRaw,
                            SourceLevels swlvl = SourceLevels.Information)
        {
            _trace.Switch.Level = swlvl;
            _trace.TraceEvent(TraceEventType.Verbose, 0, "Creating OutputWriter.");

            _OutputFormat          = OutputFormat;
            _OutputQuality         = OutputQuality;
            _OutputFileName        = OutputFileName;
            _OutputTimestampFormat = OutputTimestampFormat;
            _ReadRaw = ReadRaw;

            try {
                if (!string.IsNullOrEmpty(_OutputFileName))
                {
                    _writer = new StreamWriter(_OutputFileName);
                }
                else
                {
                    _writer           = new StreamWriter(Console.OpenStandardOutput());
                    _writer.AutoFlush = true;
                    Console.SetOut(_writer);
                }
            } catch (Exception e) {
                _trace.TraceEvent(TraceEventType.Error, 0, "Exception during creating OutputWriter:" + e.ToString());
                Close();
                throw;
            }
        }
Пример #2
0
        // If parsing was unsuccessfull, return false
        static bool ParseCommandLine(string[] args)
        {
            var p = new OptionSet()
            {
                { "n=|node=", "Remote computer name (optional)", v => Host = v },
                { "s=|server=", "OPC HDA server name (required)", v => Server = v },
                { "from=|start=|begin=", "Start time (abs. or relative), default NOW-1H",
                  v => StartTime = v ?? "NOW-1H" },
                { "to=|end=", "End time (abs. or relative), default NOW",
                  v => EndTime = v ?? "NOW" },
                { "a=|agg=", "Aggregate (see spec)", v => Aggregate = Utils.GetHDAAggregate(v) },
                { "r=|resample=", "Resample interval (in seconds), 0 - return just one value (see OPC HDA spec.)",
                  v => ResampleInterval = Int32.Parse(v) },
                { "raw", "Read raw data (if omitted, read processed data) ",
                  v => ReadRaw = v != null },
                { "m=|maxvalues=", "Maximum number of values to load (only for ReadRaw)",
                  v => MaxValues = Int32.Parse(v) },
                { "b|bounds", "Whether the bounding item values should be returned (only for ReadRaw).",
                  v => IncludeBounds = v != null },
                { "t=|tsformat=", "Output timestamp format to use. You can use -t=DateTime to output date and time in separate columns",
                  v => OutputTimestampFormat = v },
                { "f=", "Output format (TABLE, MERGED or RECORD)",
                  v => OutputFormat = Utils.GetOutputFormat(v) },
                { "q=", "Include quality in output data (NONE, DA, HISTORIAN or BOTH)",
                  v => OutputQuality = Utils.GetOutputQuality(v) },
                { "o=|output=", "Output filename (if omitted, output to console)",
                  v => OutputFileName = v },
                { "i=|input=", "Input filename with list of tags (if omitted, tag list must be provided as command line argument)",
                  v => InputFileName = v },
                { "v", "Show extended info", v => ExtendedInfo = v != null },
                { "vv|verbose", "Show debug info", v => Verbose = v != null },
                { "h|?|help", "Show help", v => Help = v != null },
                { "<>", "List of tag names", v => Tagnames.Add(v) },
            };

            try {
                p.Parse(args);
            } catch (OptionException e) {
                Utils.ConsoleWriteColoredLine(ConsoleColor.Red, e.Message);
                Console.WriteLine("Try `HDARead --help' for more information.");
                return(false);
            }

            StringBuilder sb = new StringBuilder();
            TextWriter    tw = new StringWriter(sb);

            if (tw != null)
            {
                p.WriteOptionDescriptions(tw);
                tw.Flush();
                OptionDescription = sb.ToString();
            }
            return(true);
        }
Пример #3
0
 public MergedOutputWriter(eOutputFormat OutputFormat,
                           eOutputQuality OutputQuality,
                           string OutputFileName,
                           string OutputTimestampFormat,
                           bool ReadRaw,
                           SourceLevels swlvl = SourceLevels.Information) : base(OutputFormat,
                                                                                 OutputQuality,
                                                                                 OutputFileName,
                                                                                 OutputTimestampFormat,
                                                                                 ReadRaw,
                                                                                 swlvl)
 {
 }