示例#1
0
        public static uint GetDataTypeBytes(StreamDataType d)
        {
            switch (d)
            {
            case StreamDataType.Intel_Int8:
            case StreamDataType.Intel_UInt8:
                return(1);

            case StreamDataType.Intel_Int16:
            case StreamDataType.Intel_UInt16:
            case StreamDataType.Motorola_Int16:
            case StreamDataType.Motorola_UInt16:
            case StreamDataType.Ieee754r_Half:
                return(2);

            case StreamDataType.Intel_Int32:
            case StreamDataType.Intel_UInt32:
            case StreamDataType.Motorola_Int32:
            case StreamDataType.Motorola_UInt32:
            case StreamDataType.Ieee754_Single:
                return(4);

            case StreamDataType.Intel_Int64:
            case StreamDataType.Intel_UInt64:
            case StreamDataType.Ieee754_Double:
                return(8);


            case StreamDataType.Ieee754_Quad:
                return(16);

            default:
                return(0);
            }
        }
示例#2
0
    public void RecevingData(StreamDataType _type, string _dataJson)
    {
        switch (_type)
        {
        //case StreamDataType.Map:
        //    string[,] _mapJson = JsonConvert.DeserializeObject<string[,]>(_dataJson);
        //    map.Maps = new Box[_mapJson.GetLength(0), _mapJson.GetLength(0)];
        //    for (int x = 0; x < _mapJson.GetLength(0); x++)
        //    {
        //        for (int y = 0; y < _mapJson.GetLength(1); y++)
        //        {
        //            map.Maps[x,y] = JsonConvert.DeserializeObject<Box>(_mapJson[x,y]);
        //        }
        //    }
        //    map.UpdateMap();
        //    break;
        case StreamDataType.Players:
            Dictionary <int, string> _plysJson = (Dictionary <int, string>)JsonConvert.DeserializeObject(_dataJson, typeof(Dictionary <int, string>));
            allPlayer.Clear();
            foreach (KeyValuePair <int, string> _v in _plysJson)
            {
                allPlayer.Add(_v.Key, JsonConvert.DeserializeObject <Client>(_v.Value));
                //allPlayer[_v.Key].GetPly().powerUps = (Dictionary<PowerUps, int>)JsonConvert.DeserializeObject(allPlayer[_v.Key].GetPly().powerUpsJson, typeof(Dictionary<PowerUps, int>));
            }
            scoreTable.InitialazePlayerTable();
            break;

        case StreamDataType.Room:
            roomInfo = (RoomInfoClass)JsonConvert.DeserializeObject(_dataJson, typeof(RoomInfoClass));
            break;
        }
    }
示例#3
0
        public StreamRenderer(XElement signalentry, double guisignaldisplaywidth, int imagewidth)
            : base(signalentry)
        {
            this.channels = SignalEntry.GetNumChannels(signalentry);

            switch (SignalEntry.GetFileFormat(signalentry))
            {
            case FileFormat.Bin:
                this.datatype         = SignalEntry.GetBinDataType(signalentry);
                this.samplestructsize = this.channels * (int)SignalEntry.GetDataTypeBytes(this.datatype);
                break;

            case FileFormat.Csv:
                this.datatype         = StreamDataType.Ieee754_Single;
                this.samplestructsize = this.channels * (int)SignalEntry.GetDataTypeBytes(this.datatype);
                break;

            default:
                throw new Exception("Dateiformat noch nicht unterstützt.");
            }

            this.Baseline      = (float)SignalEntry.GetBaseline(signalentry);
            this.Lsbvalue      = (float)SignalEntry.GetLsbValue(signalentry);
            this.Unit          = SignalEntry.GetUnit(signalentry);
            this.samplespersec = SignalEntry.GetSampleRate(signalentry);

            this.imageheight = (int)guisignaldisplaywidth;
            this.imagewidth  = imagewidth;
            //this.imageheight = 100;
            this.dirtyrect = new Int32Rect(0, 0, this.imagewidth, this.imageheight);

            this.physicaldata = new SampleD[this.channels];

            this.ReOpen();
        }
示例#4
0
        public static unsafe void CropBinary(XElement signalentry, double time_start, double time_end)
        {
            StreamDataType datatype         = SignalEntry.GetBinDataType(signalentry);
            int            channels         = SignalEntry.GetNumChannels(signalentry);
            int            samplestructsize = channels * (int)SignalEntry.GetDataTypeBytes(datatype);
            double         samplespersec    = SignalEntry.GetSampleRate(signalentry);



            MapFile mapfile = new MapFile(SignalEntry.GetId(signalentry), false);

            // Hier Dateigröße und Anzahl der Samples nochmal ausrechnen.
            // Kann ja sein, dass die Datei am Ende ein bissel kaputt ist.
            // (Datei wird dann auf ganze Sampleanzahl abgeschnitten)
            Int64 filesamples = mapfile.filesize / samplestructsize;
            Int64 filesize    = filesamples * samplestructsize;


            Int64 sample_start = (Int64)(time_start * samplespersec);
            Int64 sample_end   = (Int64)(time_end * samplespersec);


            if (sample_start >= filesamples)
            {
                return;
            }


            if (sample_end > filesamples)
            {
                sample_end = filesamples;
            }


            Int64 srcoffs = sample_start * samplestructsize;
            Int64 size    = (Int64)((sample_end - sample_start) * samplestructsize);


            // Sampledaten nach vorne kopieren
            if (sample_start > 0)
            {
                mapfile.MemMove(0, (int)srcoffs, (int)size);    // XXX memmove gibts gibts nur als 32bit version??
            }
            mapfile.Dispose();
            mapfile = null;


            // Datei hinten abschneiden (truncate)
            if (size < filesize)
            {
                FileStream fs = new FileStream(SignalEntry.GetId(signalentry), FileMode.Open, FileAccess.Write);
                fs.SetLength(size);
                fs.Close();
                fs.Dispose();
                fs = null;
            }
        }
示例#5
0
 public void SendData(StreamDataType _type, string _data)
 {
     if (_data == null)
     {
         Debug.LogError("Data Is null");
         return;
     }
     if (!streamDatas.ContainsKey(_type))
     {
         streamDatas.Add(_type, _data);
     }
     else
     {
         streamDatas[_type] = _data;
     }
     ClientManager.client.RecevingData(_type, _data);
 }
示例#6
0
        private string GetPath(StreamDataType type)
        {
            string file = null;

            switch (type)
            {
            case StreamDataType.CONNECTION_DEFINITION: file = FILENAME_CONNECTION_DEFINITIONS; break;

            case StreamDataType.AGENT_DEFINITION: file = FILENAME_AGENT_DEFINITIONS; break;

            case StreamDataType.COMPONENT_DEFINITION: file = FILENAME_COMPONENT_DEFINITIONS; break;

            case StreamDataType.DATA_ITEM_DEFINITION: file = FILENAME_DATA_ITEM_DEFINITIONS; break;

            case StreamDataType.DEVICE_DEFINITION: file = FILENAME_DEVICE_DEFINITIONS; break;

            case StreamDataType.ARCHIVED_SAMPLE: file = FILENAME_SAMPLES; break;
            }

            if (file != null)
            {
                // Get the Parent Directory
                string dir = GetDirectory();
                System.IO.Directory.CreateDirectory(dir);

                string filename = Path.ChangeExtension(file, "csv");
                string path     = Path.Combine(dir, filename);

                // Increment Filename until Size is ok
                int i = 1;
                while (!IsFileOk(path))
                {
                    filename = Path.ChangeExtension(file + "_" + i, "csv");
                    path     = Path.Combine(dir, filename);
                    i++;
                }

                return(path);
            }

            return(null);
        }
示例#7
0
 /// <summary>
 /// Initializes static members of the DataTypes class.
 /// </summary>
 static DataTypes()
 {
     Integer = new IntegerDataType();
     Stream = new StreamDataType();
     String = new StringDataType();
     Boolean = new BooleanDataType();
     FixedPoint = new FixedPointDataType();
     FloatingPoint = new FloatingPointDataType();
     DateTime = new DateTimeDataType();
     Binary = new BinaryDataType();
     Guid = new GuidDataType();
     TimeOfDay = new TimeOfDayDataType();
     ComplexType = new ComplexDataType();
     EntityType = new EntityDataType();
     CollectionType = new CollectionDataType();
     ReferenceType = new ReferenceDataType();
     RowType = new RowDataType();
     EnumType = new EnumDataType();
     Spatial = new SpatialDataType();
 }
示例#8
0
        private List <string> WriteToFile(List <IStreamData> streamData, StreamDataType type)
        {
            // Create a list with the list of EntryIds of each successfully written item
            var written = new List <string>();

            try
            {
                do
                {
                    // Get the filepath based on the Type of StreamData being written
                    string path = GetPath(type);

                    // Start Append FileStream
                    using (var fileStream = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Write))
                    {
                        foreach (var item in streamData)
                        {
                            // Write CSV lines
                            string s     = Csv.ToCsv(item) + Environment.NewLine;
                            var    bytes = System.Text.Encoding.ASCII.GetBytes(s);
                            fileStream.Write(bytes, 0, bytes.Length);
                            written.Add(item.EntryId);

                            // Check file size limit
                            if (fileStream.Length >= MaxFileSize)
                            {
                                break;
                            }
                        }
                    }
                } while (written.Count < streamData.Count);
            }
            catch (Exception ex)
            {
                log.Trace(ex);
            }

            return(written);
        }
示例#9
0
        public static string GetQiTypeId(StreamDataType desiredType)
        {
            switch (desiredType)
            {
            case StreamDataType.Integer:
                return(IntegerQiType.Id);

            case StreamDataType.Float:
                return(DoubleQiType.Id);

            case StreamDataType.String:
                return(StringQiType.Id);

            case StreamDataType.Blob:
                return(BlobQiType.Id);

            case StreamDataType.Time:
                return(TimestampQiType.Id);

            default:
                throw new ArgumentOutOfRangeException(nameof(desiredType), desiredType, null);
            }
        }
示例#10
0
    public void StreamSendData(StreamDataType _type)
    {
        switch (_type)
        {
        //case StreamDataType.Map:
        //    if (map.Maps == null)
        //    {
        //        break;
        //    }
        //    string[,] _mapJson = new string[map.Maps.GetLength(0), map.Maps.GetLength(1)];
        //    for (int x = 0; x < map.Maps.GetLength(0); x++)
        //    {
        //        for (int y = 0; y < map.Maps.GetLength(1); y++)
        //        {
        //            _mapJson[x,y] = JsonConvert.SerializeObject(map.Maps[x,y]);
        //        }
        //    }
        //    stream.SendData(StreamDataType.Map, JsonConvert.SerializeObject(_mapJson));
        //    break;
        case StreamDataType.Players:
            Dictionary <int, string> _plysJson = new Dictionary <int, string>();
            foreach (KeyValuePair <int, Client> _ply in allPlayer)
            {
                _plysJson.Add(_ply.Key, _ply.Value.json());
                if (_ply.Value.alive)
                {
                    _ply.Value.GetPly().stream = true;
                }
            }
            stream.SendData(StreamDataType.Players, JsonConvert.SerializeObject(_plysJson));
            break;

        case StreamDataType.Room:
            stream.SendData(StreamDataType.Room, JsonConvert.SerializeObject(roominfo));
            break;
        }
    }
示例#11
0
 /// <summary>
 /// Resolves the specified data type.
 /// </summary>
 /// <param name="dataType">Data type specification.</param>
 /// <returns>Resolved EDM Type.</returns>
 PrimitiveDataType IPrimitiveDataTypeVisitor <PrimitiveDataType> .Visit(StreamDataType dataType)
 {
     return(EdmDataTypes.Stream);
 }
        IEdmPrimitiveTypeReference IPrimitiveDataTypeVisitor <IEdmPrimitiveTypeReference> .Visit(StreamDataType dataType)
        {
            IEdmPrimitiveType typeDefinition = this.GetEdmTypeDefinition(dataType);

            var typeReference = new EdmPrimitiveTypeReference(
                typeDefinition,
                dataType.IsNullable);

            return(typeReference);
        }
示例#13
0
 public void SetStreamDataType(StreamDataType type)
 {
     _streamDataType = type;
 }
示例#14
0
 public SampleData(StreamDataType type)
 {
     EntryId = Guid.NewGuid().ToString();
     _streamDataType = type;
 }
示例#15
0
        /// <summary>
        /// Resolves the specified entity model schema type and returns the Edm model type for it.
        /// </summary>
        /// <param name="model">The model to get the type from.</param>
        /// <param name="schemaType">The entity model schema type to resolve.</param>
        /// <returns>The resolved type for the specified <paramref name="schemaType"/>.</returns>
        public static IEdmTypeReference ResolveEntityModelSchemaType(IEdmModel model, DataType schemaType)
        {
            if (schemaType == null)
            {
                return(null);
            }

            PrimitiveDataType primitiveDataType = schemaType as PrimitiveDataType;

            if (primitiveDataType != null)
            {
                return(GetPrimitiveTypeReference(primitiveDataType));
            }

            if (model == null)
            {
                return(null);
            }

            EntityDataType entityDataType = schemaType as EntityDataType;

            if (entityDataType != null)
            {
                IEdmNamedElement edmType = model.FindType(entityDataType.Definition.FullName);
                ExceptionUtilities.Assert(
                    edmType != null,
                    "The expected entity type '{0}' was not found in the entity model for this test.",
                    entityDataType.Definition.FullName);

                IEdmEntityType entityType = edmType as IEdmEntityType;
                ExceptionUtilities.Assert(
                    entityType != null,
                    "The expected entity type '{0}' is not defined as entity type in the test's metadata.",
                    entityDataType.Definition.FullName);
                return(entityType.ToTypeReference());
            }

            ComplexDataType complexDataType = schemaType as ComplexDataType;

            if (complexDataType != null)
            {
                return(GetComplexType(model, complexDataType));
            }

            CollectionDataType collectionDataType = schemaType as CollectionDataType;

            if (collectionDataType != null)
            {
                DataType          collectionElementType = collectionDataType.ElementDataType;
                PrimitiveDataType primitiveElementType  = collectionElementType as PrimitiveDataType;
                if (primitiveElementType != null)
                {
                    IEdmPrimitiveTypeReference primitiveElementTypeReference = GetPrimitiveTypeReference(primitiveElementType);
                    return(primitiveElementTypeReference.ToCollectionTypeReference());
                }

                ComplexDataType complexElementType = collectionElementType as ComplexDataType;
                if (complexElementType != null)
                {
                    IEdmComplexTypeReference complexElementTypeReference = GetComplexType(model, complexElementType);
                    return(complexElementTypeReference.ToCollectionTypeReference());
                }

                EntityDataType entityElementType = collectionElementType as EntityDataType;
                if (entityElementType != null)
                {
                    IEdmEntityTypeReference entityElementTypeReference = GetEntityType(model, entityElementType);
                    return(entityElementTypeReference.ToCollectionTypeReference());
                }

                throw new NotSupportedException("Collection types only support primitive, complex, and entity element types.");
            }

            StreamDataType streamType = schemaType as StreamDataType;

            if (streamType != null)
            {
                Type systemType = streamType.GetFacet <PrimitiveClrTypeFacet>().Value;
                ExceptionUtilities.Assert(systemType == typeof(Stream), "Expected the system type 'System.IO.Stream' for a stream reference property.");
                return(MetadataUtils.GetPrimitiveTypeReference(systemType));
            }

            throw new NotImplementedException("Unrecognized schema type " + schemaType.GetType().Name + ".");
        }
示例#16
0
        /// <summary>
        /// Crops the binary.
        /// </summary>
        /// <param name="signalentry">The signalentry.</param>
        /// <param name="time_start">The time_start.</param>
        /// <param name="time_end">The time_end.</param>
        private static unsafe void CropBinary(XElement signalentry, double time_start, double time_end)
        {
            String         fileName         = SignalEntry.GetId(signalentry);
            StreamDataType datatype         = SignalEntry.GetBinDataType(signalentry);
            int            channels         = SignalEntry.GetNumChannels(signalentry);
            int            samplestructsize = channels * (int)SignalEntry.GetDataTypeBytes(datatype);
            double         samplespersec    = SignalEntry.GetSampleRate(signalentry);

            FileInfo fileInfo = new FileInfo(fileName);
            // Hier Dateigröße und Anzahl der Samples nochmal ausrechnen.
            // Kann ja sein, dass die Datei am Ende ein bissel kaputt ist.
            // (Datei wird dann auf ganze Sampleanzahl abgeschnitten)
            long filesamples  = fileInfo.Length / samplestructsize;
            long filesize     = filesamples * samplestructsize;
            long sample_start = (long)(time_start * samplespersec);
            long sample_end   = (long)(time_end * samplespersec);

            if (sample_start >= filesamples)
            {
                return;
            }

            if (sample_end > filesamples)
            {
                sample_end = filesamples;
            }

            long size = (long)((sample_end - sample_start) * samplestructsize);

            // Datei vorne abschneiden
            if (sample_start > 0)
            {
                long srcoffs = sample_start * samplestructsize;
                try //Try it first with fast memory mapping
                {
                    MapFile mapfile = new MapFile(fileName, false);
                    mapfile.MemMove(0, (int)srcoffs, (int)size); // XXX memmove gibts gibts nur als 32bit version??
                    mapfile.Dispose();
                    mapfile = null;
                }
                catch (Exception) //If file is too large for memory mapping do it manually
                {
                    FileStream inFile    = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                    FileStream outFile   = new FileStream(fileName + ".tmp", FileMode.OpenOrCreate, FileAccess.Write);
                    int        blocksize = 10240;

                    inFile.Seek(srcoffs, SeekOrigin.Begin);
                    while (true)
                    {
                        byte[] buffer = new byte[blocksize];
                        int    data   = inFile.Read(buffer, 0, blocksize);
                        if (data <= 0)
                        {
                            break; //
                        }
                        outFile.Write(buffer, 0, data);
                        if (data < blocksize)
                        {
                            break;
                        }
                    }
                    inFile.Close();
                    outFile.Close();
                    File.Delete(fileName);
                    File.Move(fileName + ".tmp", fileName);
                }
            }

            // Datei hinten abschneiden (truncate)
            if (size < filesize)
            {
                FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Write);
                fs.SetLength(size);
                fs.Close();
                fs.Dispose();
                fs = null;
            }
        }