Exemple #1
0
        /// <summary>
        /// Writes the <paramref name="dataPoint"/> to the <see cref="ArchiveDataBlock"/>.
        /// </summary>
        /// <param name="dataPoint"><see cref="IDataPoint"/> to write.</param>
        /// <param name="exception">Any <see cref="Exception"/> that may have been encountered while writing.</param>
        /// <returns>
        /// <c>true</c> if data point was written; otherwise, <c>false</c>.
        /// </returns>
        public bool Write(IDataPoint dataPoint, out Exception exception)
        {
            exception = null;

            try
            {
                TimeTag value = dataPoint.Time;

                // Do not attempt to write values with a bad timestamp, this will just throw an exception
                if (value.CompareTo(TimeTag.MinValue) < 0 || value.CompareTo(TimeTag.MaxValue) > 0)
                {
                    exception = new TimeTagException("Skipping data write for point: Bad time tag, value must between 01/01/1995 and 01/19/2063");
                }
                else
                {
                    if (SlotsAvailable > 0)
                    {
                        // We have enough space to write the provided point data to the data block.
                        m_lastActivityTime = DateTime.UtcNow;

                        lock (m_parent.FileData)
                        {
                            // Write the data.
                            if (m_writeCursor != m_parent.FileData.Position)
                            {
                                m_parent.FileData.Seek(m_writeCursor, SeekOrigin.Begin);
                            }

                            dataPoint.CopyBinaryImageToStream(m_parent.FileData);

                            // Update the write cursor.
                            m_writeCursor = m_parent.FileData.Position;

                            // Flush the data if configured.
                            if (!m_parent.CacheWrites)
                            {
                                m_parent.FileData.Flush();
                            }
                        }
                    }
                    else
                    {
                        exception = new InvalidOperationException("Skipping data write for point: No slots available for writing new data");
                    }
                }
            }
            catch (Exception ex)
            {
                exception = new InvalidOperationException($"Skipping data write for point: {ex.Message}", ex);
            }

            if ((object)exception == null)
            {
                return(true);
            }

            OnDataWriteException(exception);

            return(false);
        }
        /// <summary>
        /// Writes the <paramref name="dataPoint"/> to the <see cref="ArchiveDataBlock"/>.
        /// </summary>
        /// <param name="dataPoint"><see cref="IDataPoint"/> to write.</param>
        /// <param name="exception">Any <see cref="Exception"/> that may have been encountered while writing.</param>
        /// <returns>
        /// <c>true</c> if data point was written; otherwise, <c>false</c>.
        /// </returns>
        public bool Write(IDataPoint dataPoint, out Exception exception)
        {
            exception = null;

            try
            {
                TimeTag value = dataPoint.Time;

                // Do not attempt to write values with a bad timestamp, this will just throw an exception
                if (value.CompareTo(TimeTag.MinValue) < 0 || value.CompareTo(TimeTag.MaxValue) > 0)
                {
                    exception = new TimeTagException("Skipping data write for point: Bad time tag, value must between 01/01/1995 and 01/19/2063");
                }
                else
                {
                    if (SlotsAvailable > 0)
                    {
                        // We have enough space to write the provided point data to the data block.
                        m_lastActivityTime = DateTime.UtcNow;

                        lock (m_parent.FileData)
                        {
                            // Write the data.
                            if (m_writeCursor != m_parent.FileData.Position)
                                m_parent.FileData.Seek(m_writeCursor, SeekOrigin.Begin);

                            dataPoint.CopyBinaryImageToStream(m_parent.FileData);

                            // Update the write cursor.
                            m_writeCursor = m_parent.FileData.Position;

                            // Flush the data if configured.
                            if (!m_parent.CacheWrites)
                                m_parent.FileData.Flush();
                        }
                    }
                    else
                    {
                        exception = new InvalidOperationException("Skipping data write for point: No slots available for writing new data");
                    }
                }
            }
            catch (Exception ex)
            {
                exception = new InvalidOperationException($"Skipping data write for point: {ex.Message}", ex);
            }

            if ((object)exception == null)
                return true;

            OnDataWriteException(exception);

            return false;
        }