示例#1
0
        public void TestCase_ByteValue()
        {
            byte d = 1;

            var value = new ByteValue();

            Assert.AreEqual(PropertyDefinitionType.Data, value.PropertyDefType);
            Assert.AreEqual(PropertyValueType.Byte, value.Type);
            Assert.True(value.IsNull);
            Assert.Throws <Exception>(() => { var v = value.Value; });
            Assert.Throws <Exception>(() => { var v = value.ValueAsString(); });
            value.Value = d;
            Assert.NotNull(value.Value);
            Assert.AreEqual(d, value.Value);
            Assert.AreEqual("1", value.ValueAsString());
            Assert.False(value.IsNull);

            value = new ByteValue(d);
            Assert.False(value.IsNull);
            Assert.NotNull(value.Value);
            Assert.AreEqual(d, value.Value);

            value.SetNull();
            Assert.True(value.IsNull);
            Assert.Throws <Exception>(() => { var v = value.Value; });
        }
示例#2
0
        private static DataValue ConvertByte(ByteValue src, DataType dataType)
        {
            switch (dataType)
            {
            case DataType.DataType_String:
                return(new StringValue(src.Byte.ToString()));

            case DataType.DataType_Int16:
                return(new Int16Value(Convert.ToInt16(src.Byte)));

            case DataType.DataType_Int32:
                return(new Int32Value(Convert.ToInt32(src.Byte)));

            case DataType.DataType_Int64:
                return(new Int64Value(Convert.ToInt64(src.Byte)));

            case DataType.DataType_Single:
                return(new SingleValue(Convert.ToSingle(src.Byte)));

            case DataType.DataType_Decimal:
                return(new DecimalValue(Convert.ToDouble(src.Byte)));

            case DataType.DataType_Double:
                return(new DoubleValue(Convert.ToDouble(src.Byte)));

            default:
                return(null);
            }
        }
示例#3
0
        // TODO(trinabh): Check ACL stuff here

        internal ByteValue ReadData(IValue valuePath)
        {
            ByteValue byteValue = null;

            if (null != valuePath)
            {
                string     dataFilePath = valuePath.ToString();
                FileStream fout         = new FileStream(dataFilePath,
                                                         FileMode.OpenOrCreate,
                                                         FileAccess.Read,
                                                         FileShare.ReadWrite);
                fout.Seek(0, SeekOrigin.Begin);
                //create new MemoryStream object
                MemoryStream memStream = new MemoryStream();
                byte[]       bytes     = new byte[fout.Length];
                //read file to MemoryStream
                int bytesRead = 0;
                fout.Read(bytes, bytesRead, (int)fout.Length);
                fout.Close();
                memStream.Write(bytes, 0, bytes.Length);
                memStream.SetLength(bytes.Length);
                byteValue = SerializerHelper <ByteValue> .DeserializeFromByteStream(memStream);
            }

            return(byteValue);
        }
        internal Property_QueryX_ExclusiveKey(PropertyRoot owner)
        {
            Owner = owner;
            Value = new ByteValue(this);

            owner.Add(this);
        }
        public void ToDifferenceString()
        {
            var oneMB      = new ByteValue(1024 * 1024);
            var minusOneMB = new ByteValue(-1024 * 1024);
            var zero       = new ByteValue(0);

            Assert.That(oneMB.ToDifferenceString(), Is.EqualTo("+" + oneMB.ToString()));
            Assert.That(minusOneMB.ToDifferenceString(), Is.EqualTo(minusOneMB.ToString()));
            Assert.That(zero.ToDifferenceString(), Is.EqualTo(zero.ToString()));
        }
示例#6
0
 private byte[] Pad(uint recordLength, byte fillByte)
 {
     //if (ByteValue.Length > recordLength)
     //{
     //    throw new InvalidCastException(
     //        $"{IO.FileParser.Properties.Resources.ResourceManager.GetString("InvalidLength")}");
     //}
     ByteValue = ByteValue.PadRight(recordLength.ToInt(), fillByte.Convert(Encoder.SourceEncoding, Encoder.DestinationEncoding), true);
     return(ByteValue);
 }
        public void OperatorPlus()
        {
            var threeMB    = new ByteValue(3 * 1024 * 1024);
            var twoMB      = new ByteValue(2 * 1024 * 1024);
            var oneMB      = new ByteValue(1024 * 1024);
            var minusOneMB = new ByteValue(-1024 * 1024);
            var zero       = new ByteValue(0);

            Assert.That(oneMB + twoMB, Is.EqualTo(threeMB));
            Assert.That(minusOneMB + oneMB, Is.EqualTo(zero));
        }
        public void MegaBytes()
        {
            var zero    = new ByteValue(0);
            var oneByte = new ByteValue(1);
            var oneKB   = new ByteValue(1024);
            var oneMB   = new ByteValue(1024 * 1024);
            var oneGB   = new ByteValue(1024 * 1024 * 1024);

            Assert.That(zero.MegaBytes, Is.EqualTo(0m));
            Assert.That(oneByte.MegaBytes, Is.EqualTo(0.00000095367431640625m));
            Assert.That(oneKB.MegaBytes, Is.EqualTo(0.0009765625m));
            Assert.That(oneMB.MegaBytes, Is.EqualTo(1m));
            Assert.That(oneGB.MegaBytes, Is.EqualTo(1024m));
        }
示例#9
0
 public override int GetHashCode()
 {
     unchecked
     {
         var result = GuidValue.GetHashCode();
         result = (result * 397) ^ (StringValue != null ? StringValue.GetHashCode() : 0);
         result = (result * 397) ^ IntValue;
         result = (result * 397) ^ LongValue.GetHashCode();
         result = (result * 397) ^ BoolValue.GetHashCode();
         result = (result * 397) ^ ByteValue.GetHashCode();
         result = (result * 397) ^ DecimalValue.GetHashCode();
         result = (result * 397) ^ DoubleValue.GetHashCode();
         result = (result * 397) ^ DateTimeValue.GetHashCode();
         result = (result * 397) ^ MaybeMoney.GetHashCode();
         return(result);
     }
 }
示例#10
0
        private void AddPicDataStream(string key, byte[] imageBytes)
        {
            StrKey    strKey  = new StrKey(key);
            ByteValue byteVal = new ByteValue(imageBytes);

            try
            {
                lock (picStreamLock)
                {
                    picStream.Append(strKey, byteVal);
                }
            }
            catch (Exception e)
            {
                logger.Log("Error while writing images to dir stream: {0}", e.ToString());
            }
        }
示例#11
0
        private static Row CreateRow(ByteValue outlineLevel, params Cell[] cells)
        {
            var row = new Row();

            if (outlineLevel != null)
            {
                row.OutlineLevel = outlineLevel;
                row.Hidden       = true;
            }

            row.Collapsed = true;
            foreach (var cell in cells)
            {
                row.AppendChild(cell);
            }

            return(row);
        }
示例#12
0
    public static int Main(string[] args)
    {
        string file   = args[0];
        Reader reader = new Reader();

        reader.SetFileName(file);
        bool ret = reader.Read();

        if (!ret)
        {
            return(1);
        }

        File    f  = reader.GetFile();
        DataSet ds = f.GetDataSet();
        Tag     tencapsulated_stream = new Tag(0x0042, 0x0011); // Encapsulated Document

        if (!ds.FindDataElement(tencapsulated_stream))
        {
            return(1);
        }
        // else
        DataElement de  = ds.GetDataElement(tencapsulated_stream);
        ByteValue   bv  = de.GetByteValue();
        uint        len = bv.GetLength();

        byte[] encapsulated_stream = new byte[len];
        bv.GetBuffer(encapsulated_stream, len);

        // Write out the decompressed bytes
        //System.Console.WriteLine(image.toString());
        using (System.IO.Stream stream =
                   System.IO.File.Open(@"/tmp/dd.pdf",
                                       System.IO.FileMode.Create))
        {
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
            writer.Write(encapsulated_stream);
        }


        return(0);
    }
示例#13
0
        public Disk(string fileName, string drive = "")
        {
            Drive = drive;

            // Get the disk info app
            var diskInfo = QemuApps.Get(imageInfoApp);

            // Throw exception if the qemu-img app can't be found
            if (diskInfo == null)
            {
                throw new FileNotFoundException("Cannot find the qemu-img app", imageInfoApp);
            }

            // Assign the file object
            File = new FileInfo(fileName);

            // Check if the disk exists
            if (Exists)
            {
                // Get the results from the app
                var results = diskInfo.Run(new[] {
                    "info",
                    string.Format("\"{0}\"", File.FullName)
                });

                if (results.IsValid)
                {
                    var infoDictionary = new QemuDictionaryResponse(results.Output);
                    var diskSize       = infoDictionary["disk size"];
                    var virtualSize    = infoDictionary["virtual size"];

                    Info = new StorageInfo(ByteValue.Parse(diskSize), ByteValue.Parse(virtualSize));
                }
            }
            else
            {
                // Set the size and capacity to 0 if the disk isn't found
                Info = new StorageInfo(new ByteValue(0, ByteFormat.B), new ByteValue(0, ByteFormat.B));
            }
        }
示例#14
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = CharValue.GetHashCode();
         hashCode = (hashCode * 397) ^ ByteValue.GetHashCode();
         hashCode = (hashCode * 397) ^ SByteValue.GetHashCode();
         hashCode = (hashCode * 397) ^ ShortValue.GetHashCode();
         hashCode = (hashCode * 397) ^ UShortValue.GetHashCode();
         hashCode = (hashCode * 397) ^ IntValue;
         hashCode = (hashCode * 397) ^ (int)UIntValue;
         hashCode = (hashCode * 397) ^ LongValue.GetHashCode();
         hashCode = (hashCode * 397) ^ ULongValue.GetHashCode();
         hashCode = (hashCode * 397) ^ FloatValue.GetHashCode();
         hashCode = (hashCode * 397) ^ DoubleValue.GetHashCode();
         hashCode = (hashCode * 397) ^ DecimalValue.GetHashCode();
         hashCode = (hashCode * 397) ^ DateTimeValue.GetHashCode();
         hashCode = (hashCode * 397) ^ GuidValue.GetHashCode();
         hashCode = (hashCode * 397) ^ StringValue.GetHashCode();
         return(hashCode);
     }
 }
示例#15
0
        private static Object ParseIntLongByte(String arg, int factor)
        {
            // try to parse as an int first, else try to parse as a long
            try
            {
                return IntValue.ParseString(arg)*factor;
            }
            catch (OverflowException e1)
            {
                try
                {
                    return (Int64) (LongValue.ParseString(arg)*factor);
                }
                catch
                {
                }

                throw;
            }
            catch (FormatException e1)
            {
                try
                {
                    return (Int64) (LongValue.ParseString(arg)*factor);
                }
                catch (Exception)
                {
                    try
                    {
                        return (Byte) (ByteValue.ParseString(arg)*factor);
                    }
                    catch (Exception)
                    {
                        throw e1;
                    }
                }
            }
        }
示例#16
0
 public ByteValueTests()
 {
     SmallValue1 = new ByteValue((byte)10);
     SmallValue2 = new ByteValue((byte)10);
     LargeValue  = new ByteValue((byte)20);
 }
        public LocalNativeRecord(MgReader reader, FixedWKTReader mgReader, MgAgfReaderWriter agfRw, MgWktReaderWriter wktRw)
        {
            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                string name = reader.GetPropertyName(i);

                _ordinalMap[i] = name;

                var pt = (PropertyValueType)reader.GetPropertyType(name);
                switch (pt)
                {
                    case PropertyValueType.Blob:
                        _values[name] = new BlobValue();
                        break;

                    case PropertyValueType.Boolean:
                        _values[name] = new BooleanValue();
                        break;

                    case PropertyValueType.Byte:
                        _values[name] = new ByteValue();
                        break;

                    case PropertyValueType.Clob:
                        _values[name] = new ClobValue();
                        break;

                    case PropertyValueType.DateTime:
                        _values[name] = new DateTimeValue();
                        break;

                    case PropertyValueType.Double:
                        _values[name] = new DoubleValue();
                        break;

                    case PropertyValueType.Feature:
                        _values[name] = new FeatureValue();
                        break;

                    case PropertyValueType.Geometry:
                        _values[name] = new GeometryValue();
                        break;

                    case PropertyValueType.Int16:
                        _values[name] = new Int16Value();
                        break;

                    case PropertyValueType.Int32:
                        _values[name] = new Int32Value();
                        break;

                    case PropertyValueType.Int64:
                        _values[name] = new Int64Value();
                        break;

                    case PropertyValueType.Raster:
                        _values[name] = new RasterValue();
                        break;

                    case PropertyValueType.Single:
                        _values[name] = new SingleValue();
                        break;

                    case PropertyValueType.String:
                        _values[name] = new StringValue();
                        break;
                }
            }

            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                string name = _ordinalMap[i];
                GetByteReaderMethod getblob = () => { return reader.GetBLOB(name); };
                GetByteReaderMethod getclob = () => { return reader.GetCLOB(name); };
                GetByteReaderMethod getgeom = () => { return reader.GetGeometry(name); };
                if (!reader.IsNull(name))
                {
                    var pt = (PropertyValueType)reader.GetPropertyType(name);
                    switch (pt)
                    {
                        case PropertyValueType.Blob:
                            ((BlobValue)_values[name]).Value = Utility.StreamAsArray(new MgReadOnlyStream(getblob));
                            break;

                        case PropertyValueType.Boolean:
                            ((BooleanValue)_values[name]).Value = reader.GetBoolean(name);
                            break;

                        case PropertyValueType.Byte:
                            ((ByteValue)_values[name]).Value = reader.GetByte(name);
                            break;

                        case PropertyValueType.Clob:
                            byte[] b = Utility.StreamAsArray(new MgReadOnlyStream(getclob));
                            ((ClobValue)_values[name]).Value = Encoding.UTF8.GetChars(b);
                            break;

                        case PropertyValueType.DateTime:
                            ((DateTimeValue)_values[name]).Value = Utility.ConvertMgDateTime(reader.GetDateTime(name));
                            break;

                        case PropertyValueType.Double:
                            ((DoubleValue)_values[name]).Value = reader.GetDouble(name);
                            break;
                        //case PropertyValueType.Feature:
                        case PropertyValueType.Geometry:
                            try
                            {
                                //TODO: See if SWIG issues come into play here
                                var geom = agfRw.Read(reader.GetGeometry(name));
                                var wkt = wktRw.Write(geom);
                                ((GeometryValue)_values[name]).Value = mgReader.Read(wkt);
                            }
                            catch //Invalid geometry fail!
                            {
                                ((GeometryValue)_values[name]).SetNull();
                            }
                            break;

                        case PropertyValueType.Int16:
                            ((Int16Value)_values[name]).Value = reader.GetInt16(name);
                            break;

                        case PropertyValueType.Int32:
                            ((Int32Value)_values[name]).Value = reader.GetInt32(name);
                            break;

                        case PropertyValueType.Int64:
                            ((Int64Value)_values[name]).Value = reader.GetInt64(name);
                            break;

                        case PropertyValueType.Single:
                            ((SingleValue)_values[name]).Value = reader.GetSingle(name);
                            break;

                        case PropertyValueType.String:
                            ((StringValue)_values[name]).Value = reader.GetString(name);
                            break;
                    }
                }
            }
        }
示例#18
0
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 /// </returns>
 public override int GetHashCode()
 {
     return(ByteValue?.GetHashCode() ?? 0);
 }
示例#19
0
 /// <summary>
 /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
 /// </summary>
 /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
 /// <returns>
 ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 public override bool Equals(object obj)
 {
     return(ByteValue.ValueEquals(((CryptoKey)obj).ByteValue));
 }
示例#20
0
 private void AddPicDataStream(string key, byte[] imageBytes)
 {
     StrKey strKey = new StrKey(key);
     ByteValue byteVal = new ByteValue(imageBytes);
     try
     {
         picStream = base.CreateDirStream<StrKey, ByteValue>("H2OAlertsPics", true);
         picStream.Append(strKey, byteVal);
        // logger.Log("WaterAlert picture has been written to {0}.", picStream.Get(strKey).ToString());
         picStream.Close();
     }
     catch (Exception e)
     {
         logger.Log("Error while writing images to dir stream: {0}", e.ToString());
     }
 }
示例#21
0
 internal Property_Shape_Radius1(PropertyRoot owner) : base(owner)
 {
     Value = new ByteValue(this);
 }
        /// <summary>
        /// Gets the values.
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, ValueExpression> GetValues()
        {
            Dictionary<string, ValueExpression> values = new Dictionary<string, ValueExpression>();
            foreach (DataGridViewRow row in grdProperties.Rows)
            {
                string name = row.Cells[0].Value.ToString();
                PropertyDefinition propDef = row.Cells[0].Tag as PropertyDefinition;
                if (row.Cells[1].Value != null)
                {
                    string str = row.Cells[1].Value.ToString();
                    if (!string.IsNullOrEmpty(str))
                    {
                        ValueExpression expr = null;
                        if (propDef.PropertyType == PropertyType.PropertyType_DataProperty)
                        {
                            DataPropertyDefinition dp = propDef as DataPropertyDefinition;
                            switch (dp.DataType)
                            {
                                case DataType.DataType_Boolean:
                                    expr = new BooleanValue(Convert.ToBoolean(str));
                                    break;
                                case DataType.DataType_Byte:
                                    expr = new ByteValue(Convert.ToByte(str));
                                    break;
                                case DataType.DataType_DateTime:
                                    expr = new DateTimeValue(Convert.ToDateTime(str));
                                    break;
                                case DataType.DataType_Decimal:
                                    expr = new DecimalValue(Convert.ToDouble(str));
                                    break;
                                case DataType.DataType_Double:
                                    expr = new DoubleValue(Convert.ToDouble(str));
                                    break;
                                case DataType.DataType_Int16:
                                    expr = new Int16Value(Convert.ToInt16(str));
                                    break;
                                case DataType.DataType_Int32:
                                    expr = new Int32Value(Convert.ToInt32(str));
                                    break;
                                case DataType.DataType_Int64:
                                    expr = new Int64Value(Convert.ToInt64(str));
                                    break;
                                case DataType.DataType_Single:
                                    expr = new SingleValue(Convert.ToSingle(str));
                                    break;
                                case DataType.DataType_String:
                                    expr = new StringValue(str);
                                    break;
                                default:
                                    throw new NotSupportedException("Unsupported data type: " + dp.DataType);
                            }
                        }
                        else if (propDef.PropertyType == PropertyType.PropertyType_GeometricProperty)
                        {
                            FdoGeometryFactory fact = FdoGeometryFactory.Instance;
                            OSGeo.FDO.Geometry.IGeometry geom = fact.CreateGeometry(str);
                            byte[] fgf = fact.GetFgf(geom);
                            expr = new GeometryValue(fgf);
                            geom.Dispose();
                        }

                        if (expr != null)
                            values.Add(name, expr);
                    }
                }
            }
            return values;
        }
示例#23
0
        public void Run(string CallerName,
                        string HomeName, string AppName, string StreamName, 
                        string RandName, 
                        long stime, long etime,
                        StreamType stream_type,
                        StreamOperation stream_op,
                        StreamFactory.StreamPhysicalType ptype,
                        CompressionType ctype, int ChunkSize , int ThreadPoolSize, 
                        Byte[] value, int num_operations,
                        SynchronizerType synctype,
                        int max_key = 0,
                        string address = null,
                        bool doCosts= false,
                        bool doRaw = false)
        {
            // Set experiment directory
            CallerInfo ci = new CallerInfo(null, CallerName, CallerName, 1);
            exp_directory = Path.GetFullPath((null != ci.workingDir) ? ci.workingDir : Directory.GetCurrentDirectory());
            exp_directory = exp_directory + "/" + HomeName + "/" + AppName + "/" + StreamName;

            if (max_key == 0)
                max_key = num_operations;

            // Set a description/tag for the experiment
            this.exp_id = "Directory: " + HomeName + "/" + AppName + "/" + StreamName +
                " Caller:" + CallerName
                + " Stream Type:" + stream_type + " Stream Op: " + stream_op + " Stream Ptype: " + ptype + " Compression Type: " + ctype
                + " Value size: " + value.Length
                + " num_operations: " + max_key
                + " actual_num_ops: " + num_operations
                + " Sync type: " + synctype
                + " Do costs? " + doCosts + "Chunk Size: " + ChunkSize+ " ThreadPool Size:" +ThreadPoolSize;

            this.compressed_exp_id =
                " ST:" + stream_type + " OP: " + stream_op + " PT: " + ptype + " CT: " + ctype
                + " VS: " + value.Length
                + " I:" + num_operations
                + " MK:" + max_key
                + " SYNC: " + synctype+ " chsize: "+ChunkSize + " nThreads: "+ThreadPoolSize  ;

            // Set remote storage server account info
            string AzureaccountName = ConfigurationManager.AppSettings.Get("AccountName");
            string AzureaccountKey = ConfigurationManager.AppSettings.Get("AccountSharedKey");

            string S3accountName = ConfigurationManager.AppSettings.Get("S3AccountName");
            string S3accountKey = ConfigurationManager.AppSettings.Get("S3AccountSharedKey");

            LocationInfo Li;
            if (synctype == SynchronizerType.Azure)
                Li = new LocationInfo(AzureaccountName, AzureaccountKey, SynchronizerType.Azure);
            else if (synctype == SynchronizerType.AmazonS3)
                Li = new LocationInfo(S3accountName, S3accountKey, SynchronizerType.AmazonS3);
            else
                Li = null;

            StreamFactory sf = StreamFactory.Instance;

            IStream stream = null;
            FqStreamID streamid = new FqStreamID(HomeName, AppName, StreamName);

            // Set op : R/W
            StreamFactory.StreamOp rw;
            if (stream_op == StreamOperation.RandomKeyRandomValueAppend
                || stream_op == StreamOperation.RandomKeySameValueAppend
                || stream_op == StreamOperation.SameKeyRandomValueAppend
                || stream_op == StreamOperation.SameKeySameValueAppend)
            {
                rw = StreamFactory.StreamOp.Write;
            }
            else
            {
                rw = StreamFactory.StreamOp.Read;
            }

            // Initialize costs
            CostsHelper costhelper = null;
            double baselineStorageKV = 0;
            if (doCosts)
            {
                costhelper = new CostsHelper();
                costhelper.getCurrentCpuUsage();
                costhelper.getNetworkUsage();
            }

            if (stream_type == StreamType.CloudRaw)
            {
                if (!Directory.Exists(exp_directory))
                {
                    Directory.CreateDirectory(exp_directory);
                }
                Logger logger = new Logger();
                Byte[] val = new Byte[value.Length * num_operations];
                // DateTime Date = new DateTime(DateTime.UtcNow.Ticks);
                // string cname = String.Format("CloudRaw-{0}", Date.ToString("yyyy-MM-dd"));
                // string bname = String.Format("{0}", Date.ToString("HH-mm-ss"));
                // string cname = String.Format("cloudraw-{0}", RandomString(4));
                // string bname = String.Format("{0}", RandomString(4));
                string cname = String.Format("cloudraw-{0}", RandName);
                string bname = String.Format("{0}", RandName);

                if (stream_op == StreamOperation.RandomKeyGet ||
                    stream_op == StreamOperation.RandomKeyGetMultipleSegments ||
                    stream_op == StreamOperation.RandomKeyGetAll)
                {
                    doRawCloudPerf(val, SynchronizerType.Azure,
                        SynchronizeDirection.Download, exp_directory, logger, containerName: cname, blobName: bname);
                    logger.Dump(exp_directory + "/log");
                }
                else
                {
                    doRawCloudPerf(val, SynchronizerType.Azure,
                        SynchronizeDirection.Upload, exp_directory, logger, containerName: cname, blobName: bname);
                    logger.Dump(exp_directory + "/log");
                }
                return;
            }

            if (stream_type == StreamType.DiskRaw)
            {
                if (!Directory.Exists(exp_directory))
                {
                    Directory.CreateDirectory(exp_directory);
                }
                Logger logger = doDiskRaw(stream_op, num_operations, value.Length, ptype, exp_directory);
                logger.Dump(exp_directory + "/log");
                return;
            }

            // Are we getting raw disk throughput?
            if (stream_type == StreamType.Raw)
            {
                string ret = doDiskSpeed((value.Length * num_operations)/1000 + "K", value.Length/1000 + "K", rw);
                if (!Directory.Exists(exp_directory))
                {
                    Directory.CreateDirectory(exp_directory);
                }
                File.WriteAllText(exp_directory + "/log", ret);
                return;
            }

            // Populate the keys and the values
            Random random = new Random(DateTime.Now.Millisecond);
            StrKey[] keys = new StrKey[max_key];
            for (int i = 0; i < max_key; ++i)
            {
                keys[i] = new StrKey("" + i);
            }

            /*
            List<ByteValue> vals = new List<ByteValue>(num_operations);
            Byte[][] tmp = new Byte[num_operations][];
            for (int i = 0; i < num_operations; ++i)
            {
                tmp[i] = new Byte[value.Length];
                random.NextBytes(tmp[i]);
            }

            for (int i = 0; i < num_operations; ++i)
            {
                keys[i] = new StrKey("" + i);
                vals.Add(new ByteValue(tmp[i]));
                // vals[i] = new ByteValue(tmp);
            }
            */

            Logger log = new Logger();
            // Open stream for different types of experiments
            if (stream_type == StreamType.Local && ptype == StreamFactory.StreamPhysicalType.File)
            {
                stream = sf.openFileStream<StrKey, ByteValue>(streamid, ci, null, StreamFactory.StreamSecurityType.Plain, ctype, rw, address, ChunkSize, ThreadPoolSize, log);
            }

            else if (stream_type == StreamType.LocalEnc && ptype == StreamFactory.StreamPhysicalType.File)
            {
                stream = sf.openFileStream<StrKey, ByteValue>(streamid, ci, null, StreamFactory.StreamSecurityType.Secure, ctype, rw, address, ChunkSize, ThreadPoolSize, log);
            }

            else if (stream_type == StreamType.Remote && ptype == StreamFactory.StreamPhysicalType.File)
            {
                stream = sf.openFileStream<StrKey, ByteValue>(streamid, ci, Li, StreamFactory.StreamSecurityType.Plain, ctype, rw, address, ChunkSize, ThreadPoolSize, log);
            }

            else if (stream_type == StreamType.RemoteEnc && ptype == StreamFactory.StreamPhysicalType.File)
            {
                stream = sf.openFileStream<StrKey, ByteValue>(streamid, ci, Li, StreamFactory.StreamSecurityType.Secure, ctype, rw, address, ChunkSize, ThreadPoolSize, log);
            }

            else if (stream_type == StreamType.Local && ptype == StreamFactory.StreamPhysicalType.Directory)
            {
                stream = sf.openDirStream<StrKey>(streamid, ci, null, StreamFactory.StreamSecurityType.Plain, ctype, rw, address, ChunkSize, ThreadPoolSize, log);
            }

            else if (stream_type == StreamType.LocalEnc && ptype == StreamFactory.StreamPhysicalType.Directory)
            {
                stream = sf.openDirStream<StrKey>(streamid, ci, null, StreamFactory.StreamSecurityType.Secure, ctype, rw, address, ChunkSize, ThreadPoolSize, log);
            }
            else if (stream_type == StreamType.Remote && ptype == StreamFactory.StreamPhysicalType.Directory)
            {
                stream = sf.openDirStream<StrKey>(streamid, ci, Li, StreamFactory.StreamSecurityType.Plain, ctype, rw, address, ChunkSize, ThreadPoolSize, log);
            }
            else if (stream_type == StreamType.RemoteEnc && ptype == StreamFactory.StreamPhysicalType.Directory)
            {
                stream = sf.openDirStream<StrKey>(streamid, ci, Li, StreamFactory.StreamSecurityType.Secure, ctype, rw, address, ChunkSize, ThreadPoolSize, log);
            }
            else
            {
                return;
            }

            if (stream_op == StreamOperation.RandomKeyRandomValueAppend)
            {
                List<ByteValue> vals = new List<ByteValue>(num_operations);
                Byte[][] tmp = new Byte[num_operations][];
                for (int i = 0; i < num_operations; ++i)
                {
                    tmp[i] = new Byte[value.Length];
                    random.NextBytes(tmp[i]);
                }

                for (int i = 0; i < num_operations; ++i)
                {
                    vals.Add(new ByteValue(tmp[i]));
                }

                for (int i = 0; i < num_operations; ++i)
                {
                    baselineStorageKV += keys[i].Size();
                    baselineStorageKV += vals[i].Size();
                    stream.Append(keys[i], vals[i]);
                }
                stream.Close();
            }

            else if (stream_op == StreamOperation.RandomKeySameValueAppend)
            {
                Byte[] singleval = new Byte[value.Length];
                random.NextBytes(singleval);
                ByteValue singlebv = new ByteValue(singleval);
                for (int i = 0; i < num_operations; ++i)
                {
                    baselineStorageKV += keys[i].Size();
                    baselineStorageKV += value.Length;
                    stream.Append(keys[i], singlebv);
                }
                stream.Close();
            }

            else if (stream_op == StreamOperation.SameKeySameValueAppend)
            {
                StrKey key = new StrKey("ExpKey");
                Byte[] singleval = new Byte[value.Length];
                random.NextBytes(singleval);
                ByteValue singlebv = new ByteValue(singleval);
                for (int i = 0; i < num_operations; ++i)
                {
                    stream.Append(key, singlebv);
                    // System.Threading.Thread.Sleep(10);
                }
                stream.Close();
            }

            else if (stream_op == StreamOperation.RandomKeyGet || stream_op == StreamOperation.RandomKeyGetMultipleSegments)
            {
                for (int i = 0; i < num_operations; ++i)
                {
                    stream.Get(keys[random.Next(0, max_key)]);
                }
                stream.Close();
            }

            else if (stream_op == StreamOperation.RandomKeyGetAll)
            {
                StrKey key = new StrKey("ExpKey");
                for (int i = 0; i < num_operations; )
                {
                    long st = 0;
                    long et = -1;
                    Console.WriteLine(stime + ":" + etime);
                    while (et < st)
                    {
                        st = RandomLong(stime, etime, random);
                        // et = RandomLong(stime, etime, random);
                        et = st + (10 * 10 * TimeSpan.TicksPerMillisecond);
                    }
                    Console.WriteLine(st + ":" + et);
                    IEnumerable<IDataItem> iterator = stream.GetAll(key, st, et);
                    foreach (IDataItem data in iterator)
                    {
                        data.GetVal();
                        ++i;

                        if (i == num_operations)
                            break;
                    }
                }
                stream.Close();
            }

            else if (stream_op == StreamOperation.SameKeyRandomValueAppend)
            {
                StrKey key = new StrKey("ExpKey");
                for (int i = 0; i < num_operations; ++i)
                {
                    baselineStorageKV += key.Size();
                    // baselineStorageKV += vals[i].Size();
                    // stream.Append(key, vals[i]);
                }
                stream.Close();
            }
            else
            {
                for (int i = 0; i < num_operations; ++i)
                {
                    stream.Get(new StrKey("" + random.Next(0,num_operations - 1)));
                }
                stream.Close();
            }

            // Dump the instrumentation logs
            stream.DumpLogs(exp_directory + "/log");

            // Collect costs usage
            List<string> costs = new List<string>();
            if (doCosts)
            {
                costs.Add(DateTime.UtcNow.Ticks + ": CPU: " + costhelper.getCurrentCpuUsage());
                costs.Add(DateTime.UtcNow.Ticks + ": Network: " + costhelper.getNetworkUsage());
                costs.Add(DateTime.UtcNow.Ticks + ": DataRelated Storage: " + costhelper.getStorageUsage(this.exp_directory, dataRelated:true)/1000.0f);
                costs.Add(DateTime.UtcNow.Ticks + ": Constant Storage: " + costhelper.getStorageUsage(this.exp_directory, dataRelated:false)/1000.0f);
                costs.Add(DateTime.UtcNow.Ticks + ": Baseline Storage: " + baselineStorageKV/1000.0f);
            }
            File.AppendAllLines(exp_directory + "/log", costs);

            // sf.deleteStream(streamid, ci);
        }
示例#24
0
        private void Prepare(PropertyValueCollection propVals)
        {
            propVals.Clear();
            currentValues.Clear();

            // I do not trust the long-term stability of the PropertyValueCollection
            //
            // So what we do is load it up once with LiteralValue references and manipulate these
            // outside of the collection (via a cached dictionary). We cache everything from the wrapper API
            // that can be cached in the managed world so that we only have minimal contact with it

            // Omit read-only properties
            using (FdoFeatureService service = _conn.CreateFeatureService())
            {
                ClassDefinition c = service.GetClassByName(this.ClassName);
                foreach (PropertyDefinition p in c.Properties)
                {
                    string        name = p.Name;
                    PropertyValue pv   = new PropertyValue(name, null);
                    if (p.PropertyType == PropertyType.PropertyType_DataProperty)
                    {
                        DataPropertyDefinition d = p as DataPropertyDefinition;
                        if (!d.ReadOnly && !d.IsAutoGenerated)
                        {
                            DataValue dv = null;
                            switch (d.DataType)
                            {
                            case DataType.DataType_BLOB:
                                dv = new BLOBValue();
                                break;

                            case DataType.DataType_Boolean:
                                dv = new BooleanValue();
                                break;

                            case DataType.DataType_Byte:
                                dv = new ByteValue();
                                break;

                            case DataType.DataType_CLOB:
                                dv = new CLOBValue();
                                break;

                            case DataType.DataType_DateTime:
                                dv = new DateTimeValue();
                                break;

                            case DataType.DataType_Decimal:
                                dv = new DecimalValue();
                                break;

                            case DataType.DataType_Double:
                                dv = new DoubleValue();
                                break;

                            case DataType.DataType_Int16:
                                dv = new Int16Value();
                                break;

                            case DataType.DataType_Int32:
                                dv = new Int32Value();
                                break;

                            case DataType.DataType_Int64:
                                dv = new Int64Value();
                                break;

                            case DataType.DataType_Single:
                                dv = new SingleValue();
                                break;

                            case DataType.DataType_String:
                                dv = new StringValue();
                                break;
                            }
                            if (dv != null)
                            {
                                pv.Value = dv;
                                propVals.Add(pv);
                            }
                        }
                    }
                    else if (p.PropertyType == PropertyType.PropertyType_GeometricProperty)
                    {
                        GeometricPropertyDefinition g = p as GeometricPropertyDefinition;
                        if (!g.ReadOnly)
                        {
                            GeometryValue gv = new GeometryValue();
                            pv.Value = gv;
                            propVals.Add(pv);
                        }
                    }
                }
                c.Dispose();
            }

            //Load property values into temp dictionary
            foreach (PropertyValue p in propVals)
            {
                currentValues[p.Name.Name] = p.Value as LiteralValue;
            }

            if (propertySnapshot == null)
            {
                propertySnapshot = new List <string>();
                foreach (PropertyValue p in propVals)
                {
                    propertySnapshot.Add(p.Name.Name);
                }
            }
        }
示例#25
0
 private void AddPicDataStream(string key, byte[] imageBytes)
 {
     StrKey strKey = new StrKey(key);
     ByteValue byteVal = new ByteValue(imageBytes);
     try
     {
         lock (picStreamLock)
         {
             picStream.Append(strKey, byteVal);
         }
     }
     catch (Exception e)
     {
         logger.Log("Error while writing images to dir stream: {0}", e.ToString());
     }
 }
示例#26
0
 private static DataValue ConvertByte(ByteValue src, DataType dataType)
 {
     switch (dataType)
     {
         case DataType.DataType_String:
             return new StringValue(src.Byte.ToString());
         case DataType.DataType_Int16:
             return new Int16Value(Convert.ToInt16(src.Byte));
         case DataType.DataType_Int32:
             return new Int32Value(Convert.ToInt32(src.Byte));
         case DataType.DataType_Int64:
             return new Int64Value(Convert.ToInt64(src.Byte));
         case DataType.DataType_Single:
             return new SingleValue(Convert.ToSingle(src.Byte));
         case DataType.DataType_Decimal:
             return new DecimalValue(Convert.ToDouble(src.Byte));
         case DataType.DataType_Double:
             return new DoubleValue(Convert.ToDouble(src.Byte));
         default:
             return null;
     }
 }
示例#27
0
        public static Expression ParseByDataType(string data, DataType dataType)
        {
            Expression expr    = null;
            bool       bIsNull = false;

            // NOTE: blob parsing doesn't work yet (ever?) in FDO:
            if (dataType != DataType.DataType_BLOB)
            {
                expr = Expression.Parse(data);

                if (expr is BooleanValue)
                {
                    bIsNull = true;
                }
                else
                {
                    bIsNull = false;
                }
            }

            switch (dataType)
            {
            case DataType.DataType_Boolean:
            {
                if (bIsNull)
                {
                    BooleanValue val = new BooleanValue();
                    val.SetNull();
                    expr = val;
                }
                else
                {
                    BooleanValue value = (BooleanValue)(expr);
                    if (value == null)
                    {
                        Debug.Fail("Wrong data type!");
                    }
                }
            }
            break;

            case DataType.DataType_Byte:
            {
                if (bIsNull)
                {
                    ByteValue val = new ByteValue();
                    val.SetNull();
                    expr = val;
                }
                else
                {
                    Int32Value value = (Int32Value)(expr);
                    if (value == null)
                    {
                        Debug.Fail("Wrong data type!");
                    }
                    expr = new ByteValue((byte)value.Int32);
                }
            }
            break;

            case DataType.DataType_Int16:
            {
                if (bIsNull)
                {
                    Int16Value val = new Int16Value();
                    val.SetNull();
                    expr = val;
                }
                else
                {
                    Int32Value value = (Int32Value)(expr);
                    if (value == null)
                    {
                        Debug.Fail("Wrong data type!");
                    }
                    expr = new Int16Value((Int16)value.Int32);
                }
            }
            break;

            case DataType.DataType_Int32:
            {
                if (bIsNull)
                {
                    Int32Value val = new Int32Value();
                    val.SetNull();
                    expr = val;
                }
                else
                {
                    Int32Value value = (Int32Value)(expr);
                    if (value == null)
                    {
                        Debug.Fail("Wrong data type!");
                    }
                }
            }
            break;

            case DataType.DataType_Int64:
            {
                if (bIsNull)
                {
                    Int64Value val = new Int64Value();
                    val.SetNull();
                    expr = val;
                }
                else
                {
                    Int64Value value = (Int64Value)(expr);
                    if (value == null)
                    {
                        Debug.Fail("Wrong data type!");
                    }
                    expr = new Int64Value((Int64)value.Int64);
                }
            }
            break;

            case DataType.DataType_Single:
            {
                if (bIsNull)
                {
                    SingleValue val = new SingleValue();
                    val.SetNull();
                    expr = val;
                }
                else
                {
                    DoubleValue value = (DoubleValue)(expr);
                    if (value == null)
                    {
                        Debug.Fail("Wrong data type!");
                    }
                    expr = new SingleValue((float)value.Double);
                }
            }
            break;

            case DataType.DataType_Double:
            {
                if (bIsNull)
                {
                    DoubleValue val = new DoubleValue();
                    val.SetNull();
                    expr = val;
                }
                else
                {
                    DoubleValue value = (DoubleValue)(expr);
                    if (value == null)
                    {
                        Debug.Fail("Wrong data type!");
                    }
                }
            }
            break;

            case DataType.DataType_DateTime:
            {
                if (bIsNull)
                {
                    DateTimeValue val = new DateTimeValue();
                    val.SetNull();
                    expr = val;
                }
                else
                {
                    DateTimeValue value = (DateTimeValue)expr;
                    if (value == null)
                    {
                        Debug.Fail("Wrong data type!");
                    }
                }
            }
            break;

            case DataType.DataType_Decimal:
            {
                if (bIsNull)
                {
                    DecimalValue val = new DecimalValue();
                    val.SetNull();
                    expr = val;
                }
                else
                {
                    DoubleValue valueDouble = (DoubleValue)expr;
                    if (valueDouble != null)
                    {
                        expr = new DecimalValue((double)valueDouble.Double);
                    }
                    else
                    {
                        Int32Value valueInt32 = (Int32Value)expr;
                        if (valueInt32 != null)
                        {
                            expr = new DecimalValue((double)valueInt32.Int32);
                        }
                        else
                        {
                            Debug.Fail("Wrong data type!");
                        }
                    }
                }
            }
            break;

            case DataType.DataType_String:
            {
                if (bIsNull)
                {
                    StringValue val = new StringValue();
                    val.SetNull();
                    expr = val;
                }
                else
                {
                    StringValue value = (StringValue)expr;
                    if (value == null)
                    {
                        Debug.Fail("Wrong data type!");
                    }
                }
            }
            break;

            default:
                Debug.Fail("Unhandled data type!");
                break;
            }

            return(expr);
        }
示例#28
0
        public Dictionary <string, ValueExpression> GetValues()
        {
            Dictionary <string, ValueExpression> values = new Dictionary <string, ValueExpression>();

            foreach (int idx in _modifiedRowIndices)
            {
                DataGridViewRow    row     = grdProperties.Rows[idx];
                string             name    = row.Cells[0].Value.ToString();
                PropertyDefinition propDef = row.Cells[0].Tag as PropertyDefinition;
                if (row.Cells[1].Value != null)
                {
                    string str = row.Cells[1].Value.ToString();
                    if (!string.IsNullOrEmpty(str))
                    {
                        ValueExpression expr = null;
                        if (propDef.PropertyType == PropertyType.PropertyType_DataProperty)
                        {
                            DataPropertyDefinition dp = propDef as DataPropertyDefinition;
                            switch (dp.DataType)
                            {
                            case DataType.DataType_Boolean:
                                expr = new BooleanValue(Convert.ToBoolean(str));
                                break;

                            case DataType.DataType_Byte:
                                expr = new ByteValue(Convert.ToByte(str));
                                break;

                            case DataType.DataType_DateTime:
                                expr = new DateTimeValue(Convert.ToDateTime(str));
                                break;

                            case DataType.DataType_Decimal:
                                expr = new DecimalValue(Convert.ToDouble(str));
                                break;

                            case DataType.DataType_Double:
                                expr = new DoubleValue(Convert.ToDouble(str));
                                break;

                            case DataType.DataType_Int16:
                                expr = new Int16Value(Convert.ToInt16(str));
                                break;

                            case DataType.DataType_Int32:
                                expr = new Int32Value(Convert.ToInt32(str));
                                break;

                            case DataType.DataType_Int64:
                                expr = new Int64Value(Convert.ToInt64(str));
                                break;

                            case DataType.DataType_Single:
                                expr = new SingleValue(Convert.ToSingle(str));
                                break;

                            case DataType.DataType_String:
                                expr = new StringValue(str);
                                break;

                            default:
                                throw new NotSupportedException("Unsupported data type: " + dp.DataType);
                            }
                        }
                        else if (propDef.PropertyType == PropertyType.PropertyType_GeometricProperty)
                        {
                            FdoGeometryFactory           fact = FdoGeometryFactory.Instance;
                            OSGeo.FDO.Geometry.IGeometry geom = fact.CreateGeometry(str);
                            byte[] fgf = fact.GetFgf(geom);
                            expr = new GeometryValue(fgf);
                            geom.Dispose();
                        }
                        else if (propDef.PropertyType == PropertyType.PropertyType_AssociationProperty)
                        {
                            // TODO: don't assume all values are strings! Use schema.
                            expr = new StringValue(str);
                        }
                        else if (propDef.PropertyType == PropertyType.PropertyType_ObjectProperty)
                        {
                            // TODO: don't assume all values are strings! Use schema.
                            expr = new StringValue(str);
                        }

                        if (expr != null)
                        {
                            values.Add(name, expr);
                        }
                    }
                }
            }
            return(values);
        }
示例#29
0
 private static Row CreateOutlineRow(ByteValue outlineLevel, params string[] cellValues)
 {
     return(CreateRow(outlineLevel, cellValues.ConvertArray(x => x.ToCell())));
 }
示例#30
0
        public LocalNativeRecord(MgReader reader, FixedWKTReader mgReader, MgAgfReaderWriter agfRw, MgWktReaderWriter wktRw)
        {
            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                string name = reader.GetPropertyName(i);

                _ordinalMap[i] = name;

                var pt = (PropertyValueType)reader.GetPropertyType(name);
                switch (pt)
                {
                    case PropertyValueType.Blob:
                        _values[name] = new BlobValue();
                        break;
                    case PropertyValueType.Boolean:
                        _values[name] = new BooleanValue();
                        break;
                    case PropertyValueType.Byte:
                        _values[name] = new ByteValue();
                        break;
                    case PropertyValueType.Clob:
                        _values[name] = new ClobValue();
                        break;
                    case PropertyValueType.DateTime:
                        _values[name] = new DateTimeValue();
                        break;
                    case PropertyValueType.Double:
                        _values[name] = new DoubleValue();
                        break;
                    case PropertyValueType.Feature:
                        _values[name] = new FeatureValue();
                        break;
                    case PropertyValueType.Geometry:
                        _values[name] = new GeometryValue();
                        break;
                    case PropertyValueType.Int16:
                        _values[name] = new Int16Value();
                        break;
                    case PropertyValueType.Int32:
                        _values[name] = new Int32Value();
                        break;
                    case PropertyValueType.Int64:
                        _values[name] = new Int64Value();
                        break;
                    case PropertyValueType.Raster:
                        _values[name] = new RasterValue();
                        break;
                    case PropertyValueType.Single:
                        _values[name] = new SingleValue();
                        break;
                    case PropertyValueType.String:
                        _values[name] = new StringValue();
                        break;
                }
            }

            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                string name = _ordinalMap[i];
                GetByteReaderMethod getblob = () => { return reader.GetBLOB(name); };
                GetByteReaderMethod getclob = () => { return reader.GetCLOB(name); };
                GetByteReaderMethod getgeom = () => { return reader.GetGeometry(name); };
                if (!reader.IsNull(name))
                {
                    var pt = (PropertyValueType)reader.GetPropertyType(name);
                    switch (pt)
                    {
                        case PropertyValueType.Blob:
                            ((BlobValue)_values[name]).Value = Utility.StreamAsArray(new MgReadOnlyStream(getblob));
                            break;
                        case PropertyValueType.Boolean:
                            ((BooleanValue)_values[name]).Value = reader.GetBoolean(name);
                            break;
                        case PropertyValueType.Byte:
                            ((ByteValue)_values[name]).Value = reader.GetByte(name);
                            break;
                        case PropertyValueType.Clob:
                            byte [] b = Utility.StreamAsArray(new MgReadOnlyStream(getclob));
                            ((ClobValue)_values[name]).Value = Encoding.UTF8.GetChars(b);
                            break;
                        case PropertyValueType.DateTime:
                            ((DateTimeValue)_values[name]).Value = Utility.ConvertMgDateTime(reader.GetDateTime(name));
                            break;
                        case PropertyValueType.Double:
                            ((DoubleValue)_values[name]).Value = reader.GetDouble(name);
                            break;
                        //case PropertyValueType.Feature:
                        case PropertyValueType.Geometry:
                            try
                            {
                                //TODO: See if SWIG issues come into play here
                                var geom = agfRw.Read(reader.GetGeometry(name));
                                var wkt = wktRw.Write(geom);
                                ((GeometryValue)_values[name]).Value = mgReader.Read(wkt);
                            }
                            catch //Invalid geometry fail!
                            {
                                ((GeometryValue)_values[name]).SetNull();
                            }
                            break;
                        case PropertyValueType.Int16:
                            ((Int16Value)_values[name]).Value = reader.GetInt16(name);
                            break;
                        case PropertyValueType.Int32:
                            ((Int32Value)_values[name]).Value = reader.GetInt32(name);
                            break;
                        case PropertyValueType.Int64:
                            ((Int64Value)_values[name]).Value = reader.GetInt64(name);
                            break;
                        case PropertyValueType.Single:
                            ((SingleValue)_values[name]).Value = reader.GetSingle(name);
                            break;
                        case PropertyValueType.String:
                            ((StringValue)_values[name]).Value = reader.GetString(name);
                            break;
                    }
                }
            }
        }
示例#31
0
        public XmlRecord(XmlProperty[] properties, FixedWKTReader wktReader, XmlNodeList propertyNodes, string nameElement, string valueElement)
        {
            for (int i = 0; i < properties.Length; i++)
            {
                string name = properties[i].Name;
                _ordinalMap[i] = name;

                switch (properties[i].Type)
                {
                case PropertyValueType.Blob:
                    _values[name] = new BlobValue();
                    break;

                case PropertyValueType.Boolean:
                    _values[name] = new BooleanValue();
                    break;

                case PropertyValueType.Byte:
                    _values[name] = new ByteValue();
                    break;

                case PropertyValueType.Clob:
                    _values[name] = new ClobValue();
                    break;

                case PropertyValueType.DateTime:
                    _values[name] = new DateTimeValue();
                    break;

                case PropertyValueType.Double:
                    _values[name] = new DoubleValue();
                    break;

                case PropertyValueType.Feature:
                    _values[name] = new FeatureValue();
                    break;

                case PropertyValueType.Geometry:
                    _values[name] = new GeometryValue();
                    break;

                case PropertyValueType.Int16:
                    _values[name] = new Int16Value();
                    break;

                case PropertyValueType.Int32:
                    _values[name] = new Int32Value();
                    break;

                case PropertyValueType.Int64:
                    _values[name] = new Int64Value();
                    break;

                case PropertyValueType.Raster:
                    _values[name] = new RasterValue();
                    break;

                case PropertyValueType.Single:
                    _values[name] = new SingleValue();
                    break;

                case PropertyValueType.String:
                    _values[name] = new StringValue();
                    break;
                }
            }

            foreach (XmlNode propNode in propertyNodes)
            {
                var name      = propNode[nameElement].InnerText;
                var valueNode = propNode[valueElement];
                if (valueNode != null)
                {
                    var value = valueNode.InnerText;
                    switch (_values[name].Type)
                    {
                    case PropertyValueType.Blob:
                        ((BlobValue)_values[name]).Value = Encoding.UTF8.GetBytes(value);
                        break;

                    case PropertyValueType.Boolean:
                        ((BooleanValue)_values[name]).Value = XmlConvert.ToBoolean(value);
                        break;

                    case PropertyValueType.Byte:
                        ((ByteValue)_values[name]).Value = XmlConvert.ToByte(value);
                        break;

                    case PropertyValueType.Clob:
                        ((ClobValue)_values[name]).Value = value.ToCharArray();
                        break;

                    case PropertyValueType.DateTime:
                        var dt = ConvertToDateTime(value);
                        if (dt.HasValue)
                        {
                            ((DateTimeValue)_values[name]).Value = dt.Value;
                        }
                        break;

                    case PropertyValueType.Double:
                        ((DoubleValue)_values[name]).Value = XmlConvert.ToDouble(value);
                        break;

                    case PropertyValueType.Feature:
                        ((FeatureValue)_values[name]).Value = ConvertToFeatures(value);
                        break;

                    case PropertyValueType.Geometry:
                        ((GeometryValue)_values[name]).Value = wktReader.Read(value);
                        break;

                    case PropertyValueType.Int16:
                        ((Int16Value)_values[name]).Value = XmlConvert.ToInt16(value);
                        break;

                    case PropertyValueType.Int32:
                        ((Int32Value)_values[name]).Value = XmlConvert.ToInt32(value);
                        break;

                    case PropertyValueType.Int64:
                        ((Int64Value)_values[name]).Value = XmlConvert.ToInt64(value);
                        break;

                    case PropertyValueType.Raster:
                        ((RasterValue)_values[name]).Value = ConvertToRaster(value);
                        break;

                    case PropertyValueType.Single:
                        ((SingleValue)_values[name]).Value = XmlConvert.ToSingle(value);
                        break;

                    case PropertyValueType.String:
                        ((StringValue)_values[name]).Value = value;
                        break;
                    }
                }
            }
        }
示例#32
0
        /// <summary>
        /// Computes this provided <see cref="System.Array">array</see> of bytes using the properties provided.
        /// </summary>
        /// <param name="data">The <see cref="System.Array">array</see> of bytes to process.</param>
        public override void Compute(byte[] data = null)
        {
            if (data != null && data.Length > 0)
            {
                byteValue = data;
            }
            if (ByteValue == null || ByteValue.Length < 1)
            {
                return;
            }
            if (Type == typeof(string))
            {
                Value = StringValue;
                return;
            }
            else if (DataFormat == FileFieldDataFormat.Raw)
            {
                Value = ByteValue.ToObject();
                return;
            }
            else if (Type == typeof(byte) || Type == typeof(byte?))
            {
                switch (DataFormat)
                {
                case FileFieldDataFormat.IBMPacked:
                    Value = ByteValue.First();
                    return;

                case FileFieldDataFormat.String:
                    Value = byte.Parse(StringValue);
                    return;
                }
            }
            else if (Type == typeof(DateTime) || Type == typeof(DateTime?))
            {
                switch (DataFormat)
                {
                case FileFieldDataFormat.IBMPacked:
                    if (Type.IsAssignableFrom(typeof(Nullable)))
                    {
                        Value = ByteValue.FromPackedDate();
                    }
                    else
                    {
                        Value = ByteValue.FromPackedDate().Value;
                    }
                    return;

                case FileFieldDataFormat.String:
                    if (Type.IsAssignableFrom(typeof(Nullable)))
                    {
                        Value = StringValue.ToDateTime(YearFirst);
                    }
                    else
                    {
                        Value = StringValue.ToDateTime(YearFirst).Value;
                    }
                    return;
                }
            }
            else if (Type == typeof(bool) || Type == typeof(bool?))
            {
                switch (DataFormat)
                {
                case FileFieldDataFormat.IBMPacked:
                    Value = ByteValue.Last() > 0;
                    return;

                case FileFieldDataFormat.String:
                    if (Type.IsAssignableFrom(typeof(Nullable)))
                    {
                        Value = StringValue.ToBool();
                    }
                    else
                    {
                        Value = StringValue.ToBool().Value;
                    }
                    return;
                }
            }
            else if (Type == typeof(short) || Type == typeof(short?))
            {
                switch (DataFormat)
                {
                case FileFieldDataFormat.IBMPacked:
                    Value = ByteValue.FromPackedShort();
                    return;

                case FileFieldDataFormat.String:
                    if (Type.IsAssignableFrom(typeof(Nullable)))
                    {
                        if (short.TryParse(StringValue?.Trim(), out short ret))
                        {
                            Value = ret;
                        }
                        else
                        {
                            Value = null;
                        }
                    }
                    else
                    {
                        Value = short.Parse(StringValue.Trim());
                    }
                    return;
                }
            }
            else if (Type == typeof(int) || Type == typeof(int?))
            {
                switch (DataFormat)
                {
                case FileFieldDataFormat.IBMPacked:
                    Value = ByteValue.FromPackedInt();
                    return;

                case FileFieldDataFormat.String:
                    if (Type.IsAssignableFrom(typeof(Nullable)))
                    {
                        if (int.TryParse(StringValue?.Trim(), out int ret))
                        {
                            Value = ret;
                        }
                        else
                        {
                            Value = null;
                        }
                    }
                    else
                    {
                        Value = int.Parse(StringValue.Trim());
                    }
                    return;
                }
            }
            else if (Type == typeof(long) || Type == typeof(long?))
            {
                switch (DataFormat)
                {
                case FileFieldDataFormat.IBMPacked:
                    Value = ByteValue.FromPackedLong();
                    return;

                case FileFieldDataFormat.String:
                    if (Type.IsAssignableFrom(typeof(Nullable)))
                    {
                        if (long.TryParse(StringValue?.Trim(), out long ret))
                        {
                            Value = ret;
                        }
                        else
                        {
                            Value = null;
                        }
                    }
                    else
                    {
                        Value = long.Parse(StringValue.Trim());
                    }
                    return;
                }
            }
            else if (Type == typeof(double) || Type == typeof(double?))
            {
                switch (DataFormat)
                {
                case FileFieldDataFormat.IBMPacked:
                    Value = ByteValue.FromPackedDouble(Precision);
                    return;

                case FileFieldDataFormat.String:
                    if (Type.IsAssignableFrom(typeof(Nullable)))
                    {
                        if (double.TryParse(StringValue?.Trim(), out double ret))
                        {
                            Value = ret;
                        }
                        else
                        {
                            Value = null;
                        }
                    }
                    else
                    {
                        Value = long.Parse(StringValue.Trim());
                    }
                    return;
                }
            }
            else if (Type == typeof(decimal) || Type == typeof(decimal?))
            {
                switch (DataFormat)
                {
                case FileFieldDataFormat.IBMPacked:
                    Value = ByteValue.FromPackedDecimal(Precision);
                    return;

                case FileFieldDataFormat.String:
                    decimal ret;
                    if (Type.IsAssignableFrom(typeof(Nullable)))
                    {
                        if (!decimal.TryParse(StringValue?.Trim(), out ret))
                        {
                            Value = null;
                            return;
                        }
                    }
                    else
                    {
                        ret = decimal.Parse(StringValue.Trim());
                    }
                    if (Precision != 0 && !StringValue.Contains("."))
                    {
                        ret /= (decimal)Math.Pow(10, Precision);
                    }
                    Value = ret;
                    return;
                }
            }
            else if (Type == typeof(float) || Type == typeof(float?))
            {
                switch (DataFormat)
                {
                case FileFieldDataFormat.IBMPacked:
                    Value = ByteValue.FromPackedFloat(Precision);
                    return;

                case FileFieldDataFormat.String:
                    float ret;
                    if (Type.IsAssignableFrom(typeof(Nullable)))
                    {
                        if (!float.TryParse(StringValue?.Trim(), out ret))
                        {
                            Value = null;
                            return;
                        }
                    }
                    else
                    {
                        ret = float.Parse(StringValue.Trim());
                    }
                    if (Precision != 0 && !StringValue.Contains("."))
                    {
                        ret /= (float)Math.Pow(10, Precision);
                    }
                    Value = ret;
                    return;
                }
            }
            else if (Type == typeof(ushort) || Type == typeof(ushort?))
            {
                switch (DataFormat)
                {
                case FileFieldDataFormat.IBMPacked:
                    Value = ByteValue.FromPackedUShort();
                    return;

                case FileFieldDataFormat.String:
                    if (Type.IsAssignableFrom(typeof(Nullable)))
                    {
                        if (ushort.TryParse(StringValue?.Trim(), out ushort ret))
                        {
                            Value = ret;
                        }
                        else
                        {
                            Value = null;
                        }
                    }
                    else
                    {
                        Value = ushort.Parse(StringValue.Trim());
                    }
                    return;
                }
            }
            else if (Type == typeof(uint) || Type == typeof(uint?))
            {
                switch (DataFormat)
                {
                case FileFieldDataFormat.IBMPacked:
                    Value = ByteValue.FromPackedUInt();
                    return;

                case FileFieldDataFormat.String:
                    if (Type.IsAssignableFrom(typeof(Nullable)))
                    {
                        if (uint.TryParse(StringValue?.Trim(), out uint ret))
                        {
                            Value = ret;
                        }
                        else
                        {
                            Value = null;
                        }
                    }
                    else
                    {
                        Value = uint.Parse(StringValue.Trim());
                    }
                    return;
                }
            }
            else if (Type == typeof(ulong) || Type == typeof(ulong?))
            {
                switch (DataFormat)
                {
                case FileFieldDataFormat.IBMPacked:
                    Value = ByteValue.FromPackedULong();
                    return;

                case FileFieldDataFormat.String:
                    if (Type.IsAssignableFrom(typeof(Nullable)))
                    {
                        if (ulong.TryParse(StringValue?.Trim(), out ulong ret))
                        {
                            Value = ret;
                        }
                        else
                        {
                            Value = null;
                        }
                    }
                    else
                    {
                        Value = ulong.Parse(StringValue.Trim());
                    }
                    return;
                }
            }
            Value = ByteValue.Convert(Encoder.SourceEncoding, Encoder.DestinationEncoding).ToObject();
        }
示例#33
0
 // byte
 public ScriptExpression(DatumIndex index, ushort opcode, ushort valType, ScriptExpressionType expType,
                         uint strOffset, short line, byte value) : this(index, opcode, valType, expType, strOffset, line)
 {
     Value = new ByteValue(value);
 }
示例#34
0
 /// <summary>
 /// To the hexadecimal.
 /// </summary>
 /// <returns></returns>
 public string ToHex()
 {
     return(ByteValue.ToHex());
 }
 internal Property_Shape_Rotation(PropertyRoot owner) : base(owner)
 {
     Value = new ByteValue(this);
 }
示例#36
0
        public void OpenXmlSimpleTypeConverterTest()
        {
            // 1. Base64BinaryValue
            Base64BinaryValue base64 = new Base64BinaryValue();

            base64 = "AA3322";
            Assert.True(base64 == "AA3322");
            Assert.Equal("AA3322", base64.Value);
            base64 = Base64BinaryValue.FromString("1234");
            Assert.Equal("1234", base64.ToString());
            Assert.Equal("1234", Base64BinaryValue.ToString(base64));

            // 2. BooleanValue
            BooleanValue booleanValue = new BooleanValue();

            booleanValue = true;
            Assert.True(booleanValue);
            Assert.True(booleanValue.Value);
            booleanValue = BooleanValue.FromBoolean(false);
            Assert.False(booleanValue);
            Assert.False(BooleanValue.ToBoolean(booleanValue));

            // 3. ByteValue
            ByteValue byteValue = new ByteValue();
            byte      bt        = 1;

            byteValue = bt;
            Assert.True(bt == byteValue);
            Assert.Equal(bt, byteValue.Value);
            bt        = 2;
            byteValue = ByteValue.FromByte(bt);
            Assert.Equal(bt, ByteValue.ToByte(byteValue));

            // 4. DateTimeValue
            DateTimeValue dtValue = new DateTimeValue();
            DateTime      dt      = DateTime.Now;

            dtValue = dt;
            Assert.True(dt == dtValue);
            dt      = DateTime.Now.AddDays(1);
            dtValue = DateTimeValue.FromDateTime(dt);
            Assert.Equal(dt, dtValue.Value);
            Assert.Equal(dt, DateTimeValue.ToDateTime(dt));

            // 5. DecimalValue
            DecimalValue decimalValue = new DecimalValue();
            decimal      dcm          = 10;

            decimalValue = dcm;
            Assert.True(dcm == decimalValue);
            decimalValue = DecimalValue.FromDecimal(20);
            Assert.Equal(20, decimalValue.Value);
            Assert.Equal(20, DecimalValue.ToDecimal(decimalValue));

            // 6. DoubleValue
            DoubleValue doubleValue = new DoubleValue();
            double      dbl         = 1.1;

            doubleValue = dbl;
            Assert.True(dbl == doubleValue);
            doubleValue = DoubleValue.FromDouble(2.2);
            Assert.Equal(2.2, doubleValue.Value);
            Assert.Equal(2.2, DoubleValue.ToDouble(doubleValue));

            // 7. HexBinaryValue
            HexBinaryValue hexBinaryValue = new HexBinaryValue();
            string         hex            = "0X99CCFF";

            hexBinaryValue = hex;
            Assert.True(hex == hexBinaryValue);
            hex            = "111111";
            hexBinaryValue = HexBinaryValue.FromString(hex);
            Assert.Equal(hex, hexBinaryValue.Value);
            Assert.Equal(hex, HexBinaryValue.ToString(hexBinaryValue));

            // 8. Int16
            Int16Value int16Value = new Int16Value();
            short      int16      = 16;

            int16Value = int16;
            Assert.True(int16 == int16Value);
            int16      = 17;
            int16Value = Int16Value.FromInt16(int16);
            Assert.Equal(int16, int16Value.Value);
            Assert.Equal(int16, Int16Value.ToInt16(int16Value));

            // 9. Int32
            Int32Value int32Value = new Int32Value();
            int        int32      = 32;

            int32Value = int32;
            Assert.True(int32 == int32Value);
            int32      = 33;
            int32Value = Int32Value.FromInt32(int32);
            Assert.Equal(int32, int32Value.Value);
            Assert.Equal(int32, Int32Value.ToInt32(int32Value));

            // 10. Int64
            Int64Value int64Value = new Int64Value();
            long       int64      = 64;

            int64Value = int64;
            Assert.True(int64 == int64Value);
            int64      = 17;
            int64Value = Int64Value.FromInt64(int64);
            Assert.Equal(int64, int64Value.Value);
            Assert.Equal(int64, Int64Value.ToInt64(int64Value));

            // 11. IntegerValue
            IntegerValue integerValue = new IntegerValue();
            int          integer      = 64;

            integerValue = integer;
            Assert.True(integer == integerValue);
            integer      = 17;
            integerValue = IntegerValue.FromInt64(integer);
            Assert.Equal(integer, integerValue.Value);
            Assert.Equal(integer, IntegerValue.ToInt64(integerValue));

            // 12. OnOffValue
            OnOffValue onOffValue = new OnOffValue();

            onOffValue = true;
            Assert.True(onOffValue);
            onOffValue = OnOffValue.FromBoolean(false);
            Assert.False(onOffValue.Value);
            Assert.False(OnOffValue.ToBoolean(onOffValue));

            // 13. SByteValue
            SByteValue sbyteValue = new SByteValue();
            sbyte      sbt        = sbyte.MaxValue;

            sbyteValue = sbt;
            Assert.True(sbt == sbyteValue);
            sbt        = sbyte.MinValue;
            sbyteValue = SByteValue.FromSByte(sbt);
            Assert.Equal(sbt, sbyteValue.Value);
            Assert.Equal(sbt, SByteValue.ToSByte(sbt));

            // 14. SingleValue
            SingleValue singleValue = new SingleValue();
            float       single      = float.MaxValue;

            singleValue = single;
            Assert.True(single == singleValue);
            single      = float.NaN;
            singleValue = SingleValue.FromSingle(single);
            Assert.Equal(single, singleValue.Value);
            Assert.Equal(single, SingleValue.ToSingle(singleValue));

            // 15. StringValue
            StringValue stringValue = new StringValue();
            string      str         = "Ethan";

            stringValue = str;
            Assert.True(str == stringValue);
            str         = "Yin";
            stringValue = StringValue.FromString(str);
            Assert.Equal(str, stringValue.Value);
            Assert.Equal(str, stringValue.ToString());
            Assert.Equal(str, StringValue.ToString(stringValue));

            // 16. TrueFalseBlankValue
            TrueFalseBlankValue tfbValue = new TrueFalseBlankValue();

            tfbValue = true;
            Assert.True(tfbValue);
            tfbValue = TrueFalseBlankValue.FromBoolean(false);
            Assert.False(tfbValue.Value);
            Assert.False(TrueFalseBlankValue.ToBoolean(tfbValue));

            // 17. TrueFalseValue
            TrueFalseValue tfValue = new TrueFalseValue();

            tfValue = true;
            Assert.True(tfValue);
            tfValue = TrueFalseValue.FromBoolean(false);
            Assert.False(tfValue.Value);
            Assert.False(TrueFalseValue.ToBoolean(tfValue));

            // 18. UInt16Value
            UInt16Value uint16Value = new UInt16Value();
            ushort      uint16      = ushort.MaxValue;

            uint16Value = uint16;
            Assert.True(uint16 == uint16Value);
            uint16      = ushort.MinValue;
            uint16Value = UInt16Value.FromUInt16(uint16);
            Assert.Equal(uint16, uint16Value.Value);
            Assert.Equal(uint16, UInt16Value.ToUInt16(uint16Value));

            // 19. UInt32Value
            UInt32Value uint32Value = new UInt32Value();
            uint        uint32      = uint.MaxValue;

            uint32Value = uint32;
            Assert.True(uint32 == uint32Value);
            uint32      = uint.MinValue;
            uint32Value = UInt32Value.FromUInt32(uint32);
            Assert.Equal(uint32, uint32Value.Value);
            Assert.Equal(uint32, UInt32Value.ToUInt32(uint32Value));

            // 20. UInt64Value
            UInt64Value uint64Value = new UInt64Value();
            ulong       uint64      = ulong.MaxValue;

            uint64Value = uint64;
            Assert.True(uint64 == uint64Value);
            uint64      = ulong.MinValue;
            uint64Value = UInt64Value.FromUInt64(uint64);
            Assert.Equal(uint64, uint64Value.Value);
            Assert.Equal(uint64, UInt64Value.ToUInt64(uint64Value));
        }
        public void OpenXmlSimpleTypeConverterTest()
        {
            // 1. Base64BinaryValue
            Base64BinaryValue base64 = new Base64BinaryValue();
            base64 = "AA3322";
            Assert.True("AA3322" == base64);
            Assert.Equal("AA3322", base64.Value);
            base64 = Base64BinaryValue.FromString("1234");
            Assert.Equal("1234", base64.ToString());
            Assert.Equal("1234", Base64BinaryValue.ToString(base64));

            // 2. BooleanValue
            BooleanValue booleanValue = new BooleanValue();
            booleanValue = true;
            Assert.True(booleanValue);
            Assert.True(booleanValue.Value);
            booleanValue = BooleanValue.FromBoolean(false);
            Assert.False(booleanValue);
            Assert.Equal(false, BooleanValue.ToBoolean(booleanValue));

            // 3. ByteValue
            ByteValue byteValue = new ByteValue();
            Byte bt = 1;
            byteValue = bt;
            Assert.True(bt == byteValue);
            Assert.Equal(bt, byteValue.Value);
            bt = 2;
            byteValue = ByteValue.FromByte(bt);
            Assert.Equal(bt, ByteValue.ToByte(byteValue));

            // 4. DateTimeValue
            DateTimeValue dtValue = new DateTimeValue();
            DateTime dt = DateTime.Now;
            dtValue = dt;
            Assert.True(dt == dtValue);
            dt = DateTime.Now.AddDays(1);
            dtValue = DateTimeValue.FromDateTime(dt);
            Assert.Equal(dt, dtValue.Value);
            Assert.Equal(dt, DateTimeValue.ToDateTime(dt));

            // 5. DecimalValue
            DecimalValue decimalValue = new DecimalValue();
            decimal dcm = 10;
            decimalValue = dcm;
            Assert.True(dcm == decimalValue);
            decimalValue = DecimalValue.FromDecimal(20);
            Assert.Equal(20, decimalValue.Value);
            Assert.Equal(20, DecimalValue.ToDecimal(decimalValue));

            // 6. DoubleValue
            DoubleValue doubleValue = new DoubleValue();
            double dbl = 1.1;
            doubleValue = dbl;
            Assert.True(dbl == doubleValue);
            doubleValue = DoubleValue.FromDouble(2.2);
            Assert.Equal(2.2, doubleValue.Value);
            Assert.Equal(2.2, DoubleValue.ToDouble(doubleValue));

            // 7. HexBinaryValue
            HexBinaryValue hexBinaryValue = new HexBinaryValue();
            string hex = "0X99CCFF";
            hexBinaryValue = hex;
            Assert.True(hex == hexBinaryValue);
            hex = "111111";
            hexBinaryValue = HexBinaryValue.FromString(hex);
            Assert.Equal(hex, hexBinaryValue.Value);
            Assert.Equal(hex, HexBinaryValue.ToString(hexBinaryValue));

            // 8. Int16
            Int16Value int16Value = new Int16Value();
            Int16 int16 = 16;
            int16Value = int16;
            Assert.True(int16 == int16Value);
            int16 = 17;
            int16Value = Int16Value.FromInt16(int16);
            Assert.Equal(int16, int16Value.Value);
            Assert.Equal(int16, Int16Value.ToInt16(int16Value));

            // 9. Int32
            Int32Value int32Value = new Int32Value();
            Int32 int32 = 32;
            int32Value = int32;
            Assert.True(int32 == int32Value);
            int32 = 33;
            int32Value = Int32Value.FromInt32(int32);
            Assert.Equal(int32, int32Value.Value);
            Assert.Equal(int32, Int32Value.ToInt32(int32Value));

            // 10. Int64
            Int64Value int64Value = new Int64Value();
            Int64 int64 = 64;
            int64Value = int64;
            Assert.True(int64 == int64Value);
            int64 = 17;
            int64Value = Int64Value.FromInt64(int64);
            Assert.Equal(int64, int64Value.Value);
            Assert.Equal(int64, Int64Value.ToInt64(int64Value));

            // 11. IntegerValue
            IntegerValue integerValue = new IntegerValue();
            int integer = 64;
            integerValue = integer;
            Assert.True(integer == integerValue);
            integer = 17;
            integerValue = IntegerValue.FromInt64(integer);
            Assert.Equal(integer, integerValue.Value);
            Assert.Equal(integer, IntegerValue.ToInt64(integerValue));

            // 12. OnOffValue
            OnOffValue onOffValue = new OnOffValue();
            onOffValue = true;
            Assert.True(onOffValue);
            onOffValue = OnOffValue.FromBoolean(false);
            Assert.Equal(false, onOffValue.Value);
            Assert.Equal(false, OnOffValue.ToBoolean(onOffValue));

            // 13. SByteValue
            SByteValue sbyteValue = new SByteValue();
            SByte sbt = SByte.MaxValue;
            sbyteValue = sbt;
            Assert.True(sbt == sbyteValue);
            sbt = SByte.MinValue;
            sbyteValue = SByteValue.FromSByte(sbt);
            Assert.Equal(sbt, sbyteValue.Value);
            Assert.Equal(sbt, SByteValue.ToSByte(sbt));

            // 14. SingleValue
            SingleValue singleValue = new SingleValue();
            Single single = Single.MaxValue;
            singleValue = single;
            Assert.True(single == singleValue);
            single = Single.NaN;
            singleValue = SingleValue.FromSingle(single);
            Assert.Equal(single, singleValue.Value);
            Assert.Equal(single, SingleValue.ToSingle(singleValue));

            // 15. StringValue
            StringValue stringValue = new StringValue();
            String str = "Ethan";
            stringValue = str;
            Assert.True(str == stringValue);
            str = "Yin";
            stringValue = StringValue.FromString(str);
            Assert.Equal(str, stringValue.Value);
            Assert.Equal(str, stringValue.ToString());
            Assert.Equal(str, StringValue.ToString(stringValue));

            // 16. TrueFalseBlankValue
            TrueFalseBlankValue tfbValue = new TrueFalseBlankValue();
            tfbValue = true;
            Assert.True(tfbValue);
            tfbValue = TrueFalseBlankValue.FromBoolean(false);
            Assert.Equal(false, tfbValue.Value);
            Assert.Equal(false, TrueFalseBlankValue.ToBoolean(tfbValue));

            // 17. TrueFalseValue
            TrueFalseValue tfValue = new TrueFalseValue();
            tfValue = true;
            Assert.True(tfValue);
            tfValue = TrueFalseValue.FromBoolean(false);
            Assert.Equal(false, tfValue.Value);
            Assert.Equal(false, TrueFalseValue.ToBoolean(tfValue));

            // 18. UInt16Value
            UInt16Value uint16Value = new UInt16Value();
            UInt16 uint16 = UInt16.MaxValue;
            uint16Value = uint16;
            Assert.True(uint16 == uint16Value);
            uint16 = UInt16.MinValue;
            uint16Value = UInt16Value.FromUInt16(uint16);
            Assert.Equal(uint16, uint16Value.Value);
            Assert.Equal(uint16, UInt16Value.ToUInt16(uint16Value));

            // 19. UInt32Value
            UInt32Value uint32Value = new UInt32Value();
            UInt32 uint32 = UInt32.MaxValue;
            uint32Value = uint32;
            Assert.True(uint32 == uint32Value);
            uint32 = UInt32.MinValue;
            uint32Value = UInt32Value.FromUInt32(uint32);
            Assert.Equal(uint32, uint32Value.Value);
            Assert.Equal(uint32, UInt32Value.ToUInt32(uint32Value));

            // 20. UInt64Value
            UInt64Value uint64Value = new UInt64Value();
            UInt64 uint64 = UInt64.MaxValue;
            uint64Value = uint64;
            Assert.True(uint64 == uint64Value);
            uint64 = UInt64.MinValue;
            uint64Value = UInt64Value.FromUInt64(uint64);
            Assert.Equal(uint64, uint64Value.Value);
            Assert.Equal(uint64, UInt64Value.ToUInt64(uint64Value));
        }
示例#38
0
        private void Prepare(PropertyValueCollection propVals)
        {
            propVals.Clear();
            currentValues.Clear();

            // I do not trust the long-term stability of the PropertyValueCollection
            //
            // So what we do is load it up once with LiteralValue references and manipulate these
            // outside of the collection (via a cached dictionary). We cache everything from the wrapper API 
            // that can be cached in the managed world so that we only have minimal contact with it

            // Omit read-only properties
            using (FdoFeatureService service = _conn.CreateFeatureService())
            {
                ClassDefinition c = service.GetClassByName(this.ClassName);
                foreach (PropertyDefinition p in c.Properties)
                {
                    string name = p.Name;
                    PropertyValue pv = new PropertyValue(name, null);
                    if (p.PropertyType == PropertyType.PropertyType_DataProperty)
                    {
                        DataPropertyDefinition d = p as DataPropertyDefinition;
                        if (!d.ReadOnly && !d.IsAutoGenerated) 
                        {
                            DataValue dv = null;
                            switch (d.DataType)
                            {
                                case DataType.DataType_BLOB:
                                    dv = new BLOBValue();
                                    break;
                                case DataType.DataType_Boolean:
                                    dv = new BooleanValue();
                                    break;
                                case DataType.DataType_Byte:
                                    dv = new ByteValue();
                                    break;
                                case DataType.DataType_CLOB:
                                    dv = new CLOBValue();
                                    break;
                                case DataType.DataType_DateTime:
                                    dv = new DateTimeValue();
                                    break;
                                case DataType.DataType_Decimal:
                                    dv = new DecimalValue();
                                    break;
                                case DataType.DataType_Double:
                                    dv = new DoubleValue();
                                    break;
                                case DataType.DataType_Int16:
                                    dv = new Int16Value();
                                    break;
                                case DataType.DataType_Int32:
                                    dv = new Int32Value();
                                    break;
                                case DataType.DataType_Int64:
                                    dv = new Int64Value();
                                    break;
                                case DataType.DataType_Single:
                                    dv = new SingleValue();
                                    break;
                                case DataType.DataType_String:
                                    dv = new StringValue();
                                    break;
                            }
                            if (dv != null)
                            {
                                pv.Value = dv;
                                propVals.Add(pv);
                            }
                        }
                    }
                    else if (p.PropertyType == PropertyType.PropertyType_GeometricProperty)
                    {
                        GeometricPropertyDefinition g = p as GeometricPropertyDefinition;
                        if (!g.ReadOnly)
                        {
                            GeometryValue gv = new GeometryValue();
                            pv.Value = gv;
                            propVals.Add(pv);
                        }
                    }
                }
                c.Dispose();
            }

            //Load property values into temp dictionary
            foreach (PropertyValue p in propVals)
            {
                currentValues[p.Name.Name] = p.Value as LiteralValue;
            }

            if (propertySnapshot == null)
            {
                propertySnapshot = new List<string>();
                foreach (PropertyValue p in propVals)
                {
                    propertySnapshot.Add(p.Name.Name);
                }
            }
        }
示例#39
0
文件: XmlRecord.cs 项目: kanbang/Colt
        public XmlRecord(XmlProperty[] properties, FixedWKTReader wktReader, XmlNodeList propertyNodes, string nameElement, string valueElement)
        {
            for (int i = 0; i < properties.Length; i++)
            {
                string name = properties[i].Name;
                _ordinalMap[i] = name;

                switch (properties[i].Type)
                {
                    case PropertyValueType.Blob:
                        _values[name] = new BlobValue();
                        break;
                    case PropertyValueType.Boolean:
                        _values[name] = new BooleanValue();
                        break;
                    case PropertyValueType.Byte:
                        _values[name] = new ByteValue();
                        break;
                    case PropertyValueType.Clob:
                        _values[name] = new ClobValue();
                        break;
                    case PropertyValueType.DateTime:
                        _values[name] = new DateTimeValue();
                        break;
                    case PropertyValueType.Double:
                        _values[name] = new DoubleValue();
                        break;
                    case PropertyValueType.Feature:
                        _values[name] = new FeatureValue();
                        break;
                    case PropertyValueType.Geometry:
                        _values[name] = new GeometryValue();
                        break;
                    case PropertyValueType.Int16:
                        _values[name] = new Int16Value();
                        break;
                    case PropertyValueType.Int32:
                        _values[name] = new Int32Value();
                        break;
                    case PropertyValueType.Int64:
                        _values[name] = new Int64Value();
                        break;
                    case PropertyValueType.Raster:
                        _values[name] = new RasterValue();
                        break;
                    case PropertyValueType.Single:
                        _values[name] = new SingleValue();
                        break;
                    case PropertyValueType.String:
                        _values[name] = new StringValue();
                        break;
                }
            }

            foreach (XmlNode propNode in propertyNodes)
            {
                var name = propNode[nameElement].InnerText;
                var valueNode = propNode[valueElement];
                if (valueNode != null)
                {
                    var value = valueNode.InnerText;
                    switch (_values[name].Type)
                    {
                        case PropertyValueType.Blob:
                            ((BlobValue)_values[name]).Value = Encoding.UTF8.GetBytes(value);
                            break;
                        case PropertyValueType.Boolean:
                            ((BooleanValue)_values[name]).Value = XmlConvert.ToBoolean(value);
                            break;
                        case PropertyValueType.Byte:
                            ((ByteValue)_values[name]).Value = XmlConvert.ToByte(value);
                            break;
                        case PropertyValueType.Clob:
                            ((ClobValue)_values[name]).Value = value.ToCharArray();
                            break;
                        case PropertyValueType.DateTime:
                            var dt = ConvertToDateTime(value);
                            if (dt.HasValue)
                                ((DateTimeValue)_values[name]).Value = dt.Value;
                            break;
                        case PropertyValueType.Double:
                            ((DoubleValue)_values[name]).Value = XmlConvert.ToDouble(value);
                            break;
                        case PropertyValueType.Feature:
                            ((FeatureValue)_values[name]).Value = ConvertToFeatures(value);
                            break;
                        case PropertyValueType.Geometry:
                            ((GeometryValue)_values[name]).Value = wktReader.Read(value);
                            break;
                        case PropertyValueType.Int16:
                            ((Int16Value)_values[name]).Value = XmlConvert.ToInt16(value);
                            break;
                        case PropertyValueType.Int32:
                            ((Int32Value)_values[name]).Value = XmlConvert.ToInt32(value);
                            break;
                        case PropertyValueType.Int64:
                            ((Int64Value)_values[name]).Value = XmlConvert.ToInt64(value);
                            break;
                        case PropertyValueType.Raster:
                            ((RasterValue)_values[name]).Value = ConvertToRaster(value);
                            break;
                        case PropertyValueType.Single:
                            ((SingleValue)_values[name]).Value = XmlConvert.ToSingle(value);
                            break;
                        case PropertyValueType.String:
                            ((StringValue)_values[name]).Value = value;
                            break;
                    }
                }
            }
        }