Exemplo n.º 1
0
        /// <summary>
        /// Checks the log data for duplicate indexes.
        /// </summary>
        /// <param name="logData">The log data.</param>
        /// <param name="function">The context function</param>
        /// <param name="delimiter">The data delimiter.</param>
        /// <param name="isTimeLog">Is the log a time log.</param>
        /// <param name="mnemonicCount">The count of mnemonics.</param>
        /// <returns><c>true</c> if Log data has duplicates; otherwise, <c>false</c>.</returns>
        public static bool HasDuplicateIndexes(this List <string> logData, Functions function, string delimiter, bool isTimeLog, int mnemonicCount)
        {
            var warnings    = new List <WitsmlValidationResult>();
            var indexValues = new HashSet <double>();

            foreach (var row in logData)
            {
                var values = ChannelDataReader.Split(row, delimiter, mnemonicCount, warnings);
                var value  = values.FirstOrDefault();

                if (isTimeLog)
                {
                    DateTimeOffset dto;

                    if (!DateTimeOffset.TryParse(value, out dto))
                    {
                        var error = new WitsmlException(function.GetNonConformingErrorCode());
                        ChannelDataExtensions.HandleInvalidDataRow(error, warnings);
                        continue;
                    }

                    // TODO: Add compatibility option for DuplicateIndexSetting
                    if (indexValues.Contains(dto.UtcTicks))
                    {
                        return(true);
                    }

                    indexValues.Add(dto.UtcTicks);
                }
                else
                {
                    double doubleValue;

                    if (!double.TryParse(value, out doubleValue))
                    {
                        var error = new WitsmlException(function.GetNonConformingErrorCode());
                        ChannelDataExtensions.HandleInvalidDataRow(error, warnings);
                        continue;
                    }

                    // TODO: Add compatibility option for DuplicateIndexSetting
                    if (indexValues.Contains(doubleValue))
                    {
                        return(true);
                    }

                    indexValues.Add(doubleValue);
                }
            }

            if (warnings.Any())
            {
                WitsmlOperationContext.Current.Warnings.AddRange(warnings);
            }

            return(false);
        }
Exemplo n.º 2
0
        public void ChannelDataExtensions_GetDataDelimiterOrDefault_Returns_Delimter_Correctly()
        {
            var result = ChannelDataExtensions.GetDataDelimiterOrDefault(string.Empty);

            Assert.IsNotNull(result);
            Assert.AreEqual(",", ",");

            result = ChannelDataExtensions.GetDataDelimiterOrDefault("|");
            Assert.IsNotNull(result);
            Assert.AreEqual("|", "|");
        }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the data delimiter for the log or the default data delimiter.
 /// </summary>
 /// <param name="log">The log.</param>
 /// <returns>The data delimiter.</returns>
 public static string GetDataDelimiterOrDefault(this Witsml141.Log log)
 {
     return(ChannelDataExtensions.GetDataDelimiterOrDefault(log?.DataDelimiter));
 }