Exemplo n.º 1
0
 /// <summary>
 ///  Create a copy of a String8. Use when the source of the String8s
 ///  will change (like a reader reusing the same byte[] buffer) and
 ///  you need to keep a copy of specific values with minimal object overhead.
 /// </summary>
 /// <param name="source">String8 to copy</param>
 /// <returns>String8 copy which will persist</returns>
 public String8 GetCopy(ITabularValue source)
 {
     if (source is String8TabularValue)
     {
         return(GetCopy(source.ToString8()));
     }
     return(GetCopy(source.ToString()));
 }
Exemplo n.º 2
0
        public static bool ToBoolean(this ITabularValue value)
        {
            bool result;

            if (value.TryToBoolean(out result))
            {
                return(result);
            }
            throw new FormatException(value.ToString());
        }
Exemplo n.º 3
0
        public static int ToInteger(this ITabularValue value)
        {
            int result;

            if (value.TryToInteger(out result))
            {
                return(result);
            }
            throw new FormatException(value.ToString());
        }
Exemplo n.º 4
0
        public static DateTime ToDateTime(this ITabularValue value)
        {
            DateTime result;

            if (value.TryToDateTime(out result))
            {
                return(result);
            }
            throw new FormatException(value.ToString());
        }
Exemplo n.º 5
0
        private static TableMetadata Build(IStreamProvider streamProvider, string tableRootPath)
        {
            TableMetadata metadata       = new TableMetadata();
            string        schemaFilePath = Path.Combine(tableRootPath, SchemaFileName);

            using (ITabularReader sr = TabularFactory.BuildReader(streamProvider.OpenRead(schemaFilePath), SchemaFileName))
            {
                int nameIndex = sr.ColumnIndex("Name");
                int typeIndex = sr.ColumnIndex("Type");

                while (sr.NextRow())
                {
                    metadata.Schema.Add(new ColumnDetails(sr.Current(nameIndex).ToString(), TypeProviderFactory.Get(sr.Current(typeIndex).ToString()).Type));
                }
            }

            using (ITabularReader mr = TabularFactory.BuildReader(streamProvider.OpenRead(Path.Combine(tableRootPath, MetadataFileName)), MetadataFileName))
            {
                int nameIndex    = mr.ColumnIndex("Name");
                int contextIndex = mr.ColumnIndex("Context");
                int valueIndex   = mr.ColumnIndex("Value");

                while (mr.NextRow())
                {
                    String8       name    = mr.Current(nameIndex).ToString8();
                    String8       context = mr.Current(contextIndex).ToString8();
                    ITabularValue value   = mr.Current(valueIndex);

                    if (name.Equals("RowCount"))
                    {
                        metadata.RowCount = value.ToInteger();
                    }
                    else
                    {
                        throw new NotImplementedException($"TableMetadataSerializer.Read doesn't know how to read Metadata '{name}'");
                    }
                }
            }

            metadata.Query = streamProvider.ReadAllText(Path.Combine(tableRootPath, ConfigQueryPath));

            return(metadata);
        }
        private static void ITabularValue_Basics(string value, String8 value8, ITabularValue itv)
        {
            Assert.AreEqual(String.IsNullOrEmpty(value), itv.IsNullOrEmpty());
            Assert.AreEqual(value8, itv.ToString8());
            Assert.AreEqual(value, itv.ToString());

            bool asBoolean;

            if (bool.TryParse(value, out asBoolean))
            {
                Assert.AreEqual(asBoolean, itv.ToBoolean());
            }
            else
            {
                Verify.Exception <FormatException>(() => { var result = itv.ToBoolean(); });
            }

            int asInteger;

            if (int.TryParse(value, out asInteger))
            {
                Assert.AreEqual(asInteger, itv.ToInteger());
            }
            else
            {
                Verify.Exception <FormatException>(() => { var result = itv.ToInteger(); });
            }

            DateTime asDateTime;

            if (DateTime.TryParse(value, CultureInfo.CurrentCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out asDateTime))
            {
                Assert.AreEqual(asDateTime, itv.ToDateTime());
            }
            else
            {
                Verify.Exception <FormatException>(() => { var result = itv.ToDateTime(); });
            }
        }