Beispiel #1
0
        internal DataSet(ProtocolDescriptor protocol, bool populateWithInitialValues)
        {
            if (protocol == null)
            {
                throw new ArgumentNullException(nameof(protocol));
            }

            Issues     = new DataErrorCollection();
            Protocol   = protocol;
            _culture   = CultureInfo.InvariantCulture;
            _evaluator = new ExpressionEvaluator(this);

            // At this stage model error aren't allowed and this dataset is not usable
            Issues.AddModelErrors(protocol.ValidateModel());
            if (Issues.Any())
            {
                _cachedDescriptorsLookUp = new Dictionary <string, ValueDescriptor>();
                Values = new Dictionary <string, DataSetValue>();
            }
            else
            {
                _cachedDescriptorsLookUp = protocol.Sections.VisitAllValues()
                                           .Where(x => !String.IsNullOrWhiteSpace(x.Reference))
                                           .ToDictionary(x => x.Reference, StringComparer.OrdinalIgnoreCase);

                Values = new Dictionary <string, DataSetValue>(_cachedDescriptorsLookUp.Count, StringComparer.OrdinalIgnoreCase);

                // It's done here instead of in Calculate() because external values (included with Add()) may
                // overwrite them but we don't want to overwrite external values with their defaults.
                if (populateWithInitialValues)
                {
                    PopulateInitialValues();
                }
            }
        }
Beispiel #2
0
 public static void Save(string path, Encoding encoding, ProtocolDescriptor protocol)
 {
     using (var writer = new StreamWriter(File.Open(path, FileMode.Create, FileAccess.Write, FileShare.None), encoding))
     {
         Save(writer, protocol);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Creates a new instance of <see cref="DataSetAggregator"/>.
        /// </summary>
        /// <param name="protocol">Protocol for wich the aggregation is calculated.</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="protocol"/> is <see langword="null"/>.
        /// </exception>
        public DataSetAggregator(ProtocolDescriptor protocol)
        {
            if (protocol == null)
            {
                throw new ArgumentNullException(nameof(protocol));
            }

            _protocol    = protocol;
            _accumulator = new DataSetValueAccumulator();
            Options      = new AggregationOptions();
        }
Beispiel #4
0
        public static void Save(TextWriter writer, ProtocolDescriptor protocol)
        {
            if (protocol == null)
            {
                throw new ArgumentNullException(nameof(protocol));
            }

            using (var jsonWriter = new JsonTextWriter(writer))
            {
                CreateSerializer().Serialize(jsonWriter, protocol, typeof(ProtocolDescriptor));
            }
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of <see cref="DataSet"/> for the specified
 /// protocol.
 /// </summary>
 /// <param name="protocol">
 /// The protocol for which data are submitted. Structure and content of this protocol must not be
 /// changed after the creation of this <see cref="DataSet"/> object.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="protocol"/> is <see langword="null"/>.
 /// </exception>
 /// <remarks>
 /// Values with a default are calculated immediately after this object has been constructed
 /// and they're available for inspection. For this reason default values always use invariant culture
 /// if a conversion is required (see <see cref="Culture"/>).
 /// </remarks>
 public DataSet(ProtocolDescriptor protocol)
     : this(protocol, true)
 {
 }
Beispiel #6
0
 /// <summary>
 /// Saves the content of the specified protocol into the specified file using UTF-8 encoding.
 /// </summary>
 /// <param name="path">Full path into which protocol JSON representation should be save to.</param>
 /// <param name="protocol">Protocol to save.</param>
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="path"/> is <see langword="null"/>.
 /// <br/>-or-<br/>
 /// If <paramref name="protocol"/> is <see langword="null"/>.
 /// </exception>
 /// <exception cref="IOException">
 /// If an I/O error occurred while opening or writing the specified file.
 /// </exception>
 /// <exception cref="UnauthorizedAccessException">
 /// If user has not enough privileges to write to the specified file.
 /// <br/>-or-<br/>
 /// If specified file already exists and it is <see cref="FileAttributes.Hidden"/>.
 /// </exception>
 public static void Save(string path, ProtocolDescriptor protocol)
 {
     Save(path, Encoding.UTF8, protocol);
 }