示例#1
0
        public void TestPropertyNavigation()
        {
            var parser = new SpelExpressionParser();

            // Inventions Array
            var teslaContext = TestScenarioCreator.GetTestEvaluationContext();

            // teslaContext.SetRootObject(tesla);
            // Evaluates to "Induction motor"
            var invention = parser.ParseExpression("Inventions[3]").GetValue <string>(teslaContext);

            Assert.Equal("Induction motor", invention);

            // Members List
            var societyContext = new StandardEvaluationContext();
            var ieee           = new IEEE();

            ieee.Members[0] = Tesla;
            societyContext.SetRootObject(ieee);

            // Evaluates to "Nikola Tesla"
            var name = parser.ParseExpression("Members[0].Name").GetValue <string>(societyContext);

            Assert.Equal("Nikola Tesla", name);

            // List and Array navigation
            // Evaluates to "Wireless communication"
            invention = parser.ParseExpression("Members[0].Inventions[6]").GetValue <string>(societyContext);
            Assert.Equal("Wireless communication", invention);
        }
示例#2
0
 private void CreateCommChunk()
 {
     this.writer.Write(Encoding.UTF8.GetBytes("COMM"));
     this.writer.Write(this.SwapEndian(18));
     this.writer.Write(this.SwapEndian((short)this.format.Channels));
     this.commSampleCountPos = this.outStream.Position;
     this.writer.Write(0);
     this.writer.Write(this.SwapEndian((short)this.format.BitsPerSample));
     this.writer.Write(IEEE.ConvertToIeeeExtended((double)this.format.SampleRate));
 }
示例#3
0
 private void CreateCommChunk()
 {
     this.writer.Write(System.Text.Encoding.UTF8.GetBytes("COMM"));
     this.writer.Write(SwapEndian((int)18));
     this.writer.Write(SwapEndian((short)format.Channels));
     commSampleCountPos = this.outStream.Position;;
     this.writer.Write((int)0);  // placeholder for total number of samples
     this.writer.Write(SwapEndian((short)format.BitsPerSample));
     this.writer.Write(IEEE.ConvertToIeeeExtended(format.SampleRate));
 }
示例#4
0
    public void DataFromIEEE()
    {
        if (Session["index"] == null)
        {
            index = 8;
        }
        else
        {
            index = Convert.ToInt32(Session["index"]);
        }
        IEEE          ieee = new IEEE();
        List <string> res  = ieee.GetArticleTerms("Dynamic thermal management for high-performance microprocessors");

        lbl_name.Text = res.ToString();
        //GET IEEE DATA YA NOOB
    }
        double readTemp()
        {
            string strWrite, strRead;
            int    status;
            int    len;

            //Select a GPIB interface card
            int GPIBoard  = 0;
            int GPIB_addr = 19;

            //Select a GPIB interface card
            IEEE.boardselect(GPIBoard);
            if (IEEE.gpib_board_present() == 1)
            {
                //Open and initialize the GPIB interface card
                IEEE.initialize(GPIBoard, 0);
            }
            else
            {
                MessageBox.Show("Invalid GPIB interface card.");
                return(0);
            }

            strWrite = "MEASURE?";
            //Write a string to the instrument with the specific address
            IEEE.send(GPIB_addr, strWrite, out status);
            if (status != 0)
            {
                MessageBox.Show("Error in writing the string command to the GPIB instrument.");
                return(0);
            }

            //Read the response string from the instrument with specific address
            IEEE.enter(out strRead, 100, out len, GPIB_addr, out status);
            if (status != 0)
            {
                MessageBox.Show("Error in reading the response string from the GPIB instrument.");
                return(0);
            }
            strRead = strRead.Substring(0, strRead.IndexOf('C') - 1);
            //MessageBox.Show(new TimeSpan(prev.Ticks- DateTime.Now.Ticks).TotalSeconds.ToString());
            return(Convert.ToDouble(strRead, new CultureInfo("en-US")));
        }
示例#6
0
        /// <summary>
        /// Ensures valid AIFF header and then finds data offset.
        /// </summary>
        /// <param name="stream">The stream, positioned at the start of audio data</param>
        /// <param name="format">The format found</param>
        /// <param name="dataChunkPosition">The position of the data chunk</param>
        /// <param name="dataChunkLength">The length of the data chunk</param>
        /// <param name="chunks">Additional chunks found</param>
        public static void ReadAiffHeader(System.IO.Stream stream, out WaveFormatProvider format, out long dataChunkPosition, out int dataChunkLength, List <AiffChunk> chunks)
        {
            dataChunkPosition = -1;
            format            = null;
            BinaryReader br = new BinaryReader(stream);

            if (ReadChunkName(br) != "FORM")
            {
                throw new FormatException("Not an AIFF file - no FORM header.");
            }
            uint   fileSize = ConvertInt(br.ReadBytes(4));
            string formType = ReadChunkName(br);

            if (formType != "AIFC" && formType != "AIFF")
            {
                throw new FormatException("Not an AIFF file - no AIFF/AIFC header.");
            }

            dataChunkLength = 0;

            while (br.BaseStream.Position < br.BaseStream.Length)
            {
                AiffChunk nextChunk = ReadChunkHeader(br);
                if (nextChunk.ChunkName == "COMM")
                {
                    short  numChannels     = ConvertShort(br.ReadBytes(2));
                    uint   numSampleFrames = ConvertInt(br.ReadBytes(4));
                    short  sampleSize      = ConvertShort(br.ReadBytes(2));
                    double sampleRate      = IEEE.ConvertFromIeeeExtended(br.ReadBytes(10));

                    format = new WaveFormatProvider((int)sampleRate, (int)sampleSize, (int)numChannels);

                    if (nextChunk.ChunkLength > 18 && formType == "AIFC")
                    {
                        // In an AIFC file, the compression format is tacked on to the COMM chunk
                        string compress = new string(br.ReadChars(4)).ToLower();
                        if (compress != "none")
                        {
                            throw new FormatException("Compressed AIFC is not supported.");
                        }
                        br.ReadBytes((int)nextChunk.ChunkLength - 22);
                    }
                    else
                    {
                        br.ReadBytes((int)nextChunk.ChunkLength - 18);
                    }
                }
                else if (nextChunk.ChunkName == "SSND")
                {
                    uint offset    = ConvertInt(br.ReadBytes(4));
                    uint blockSize = ConvertInt(br.ReadBytes(4));
                    dataChunkPosition = nextChunk.ChunkStart + 16 + offset;
                    dataChunkLength   = (int)nextChunk.ChunkLength - 8;

                    br.ReadBytes((int)nextChunk.ChunkLength - 8);
                }
                else
                {
                    if (chunks != null)
                    {
                        chunks.Add(nextChunk);
                    }
                    br.ReadBytes((int)nextChunk.ChunkLength);
                }

                if (nextChunk.ChunkName == "\0\0\0\0")
                {
                    break;
                }
            }

            if (format == null)
            {
                throw new FormatException("Invalid AIFF file - No COMM chunk found.");
            }
            if (dataChunkPosition == -1)
            {
                throw new FormatException("Invalid AIFF file - No SSND chunk found.");
            }
        }
示例#7
0
		public static void ReadAiffHeader(Stream stream, out WaveFormat format, out long dataChunkPosition, out int dataChunkLength, List<AiffFileReader.AiffChunk> chunks)
		{
			dataChunkPosition = -1L;
			format = null;
			BinaryReader binaryReader = new BinaryReader(stream);
			if (AiffFileReader.ReadChunkName(binaryReader) != "FORM")
			{
				throw new FormatException("Not an AIFF file - no FORM header.");
			}
			AiffFileReader.ConvertInt(binaryReader.ReadBytes(4));
			string a = AiffFileReader.ReadChunkName(binaryReader);
			if (a != "AIFC" && a != "AIFF")
			{
				throw new FormatException("Not an AIFF file - no AIFF/AIFC header.");
			}
			dataChunkLength = 0;
			while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
			{
				AiffFileReader.AiffChunk aiffChunk = AiffFileReader.ReadChunkHeader(binaryReader);
				if (aiffChunk.ChunkName == "\0\0\0\0" || binaryReader.BaseStream.Position + (long)((ulong)aiffChunk.ChunkLength) > binaryReader.BaseStream.Length)
				{
					break;
				}
				if (aiffChunk.ChunkName == "COMM")
				{
					short channels = AiffFileReader.ConvertShort(binaryReader.ReadBytes(2));
					AiffFileReader.ConvertInt(binaryReader.ReadBytes(4));
					short bits = AiffFileReader.ConvertShort(binaryReader.ReadBytes(2));
					double num = IEEE.ConvertFromIeeeExtended(binaryReader.ReadBytes(10));
					format = new WaveFormat((int)num, (int)bits, (int)channels);
					if (aiffChunk.ChunkLength > 18u && a == "AIFC")
					{
						if (new string(binaryReader.ReadChars(4)).ToLower() != "none")
						{
							throw new FormatException("Compressed AIFC is not supported.");
						}
						binaryReader.ReadBytes((int)(aiffChunk.ChunkLength - 22u));
					}
					else
					{
						binaryReader.ReadBytes((int)(aiffChunk.ChunkLength - 18u));
					}
				}
				else if (aiffChunk.ChunkName == "SSND")
				{
					uint num2 = AiffFileReader.ConvertInt(binaryReader.ReadBytes(4));
					AiffFileReader.ConvertInt(binaryReader.ReadBytes(4));
					dataChunkPosition = (long)((ulong)(aiffChunk.ChunkStart + 16u + num2));
					dataChunkLength = (int)(aiffChunk.ChunkLength - 8u);
					binaryReader.BaseStream.Position += (long)((ulong)(aiffChunk.ChunkLength - 8u));
				}
				else
				{
					if (chunks != null)
					{
						chunks.Add(aiffChunk);
					}
					binaryReader.BaseStream.Position += (long)((ulong)aiffChunk.ChunkLength);
				}
			}
			if (format == null)
			{
				throw new FormatException("Invalid AIFF file - No COMM chunk found.");
			}
			if (dataChunkPosition == -1L)
			{
				throw new FormatException("Invalid AIFF file - No SSND chunk found.");
			}
		}
示例#8
0
    public void IntegrateIntoUser(int suId, int uId)
    {
        //get ScholarUser object
        ScholarUser scholarUser = GetUserById(suId);
        User        user        = new User().GetUserById(uId);

        user.ImagePath = scholarUser.Image;
        user.FixNulls();
        //user.Id = uId;
        db.UpdateUser(user);
        //db.InsertUser(user);
        //get User uId from db
        user = db.GetUserByName(user.FirstName, user.MiddleName, user.LastName);
        //get user publications
        List <ScholarPublication> publications = GetUserPublications(scholarUser.Id);
        List <Article>            articles     = new List <Article>();

        //insert user articles
        foreach (ScholarPublication pub in publications)
        {
            Article a = (new Article(0, pub.Title, pub.EPrint));
            a.UpdateUsers(new List <User>()
            {
                user
            });
            if (pub.Publisher.Contains("IEEE"))
            {
                try
                {
                    List <string>  terms           = new IEEE().GetArticleTerms(pub.Title);
                    List <Keyword> articleKeywords = new List <Keyword>();
                    foreach (var item in terms)
                    {
                        articleKeywords.Add(new Keyword(0, item));
                    }
                    a.UpdateKeywords(articleKeywords);
                }
                catch (Exception ex)
                {
                    continue;
                }
            }
            db.FullArticleInsert(a);
        }

        //add interests
        scholarUser.Interests = GetUserInterests(scholarUser.Id);
        foreach (var item in scholarUser.Interests)
        {
            db.InsertInterest(user.Id, item);
        }

        Institute        scholarInstitute = GetEmailAffiliation(scholarUser.Email);
        Institute        emailInstitute   = GetEmailAffiliation(user.Email);
        List <Institute> institutes       = new List <Institute>()
        {
            scholarInstitute
        };

        if (emailInstitute != scholarInstitute)
        {
            institutes.Add(emailInstitute);
        }
        user.UpdateAffiliations(institutes);

        //return;
    }
示例#9
0
    public void IntegrateNewUser(int suId)
    {
        //get ScholarUser object
        ScholarUser scholarUser = GetUserById(suId);

        //Make User object
        string[] names = scholarUser.Name.Split(' ');
        User     user  = new User();

        if (names.Length == 2)
        {
            user.FirstName  = names[0];
            user.MiddleName = "";
            user.LastName   = names[1];
        }
        else if (names.Length == 3)
        {
            user.FirstName  = names[0];
            user.MiddleName = names[1];
            user.LastName   = names[2];
        }
        else
        {
            LogManager.Report("trying to add scholar user with 1 name", scholarUser);
            return;
        }
        //Insert User Object to db

        user.ImagePath = scholarUser.Image;
        user.FixNulls();
        db.InsertUser(user);
        //get User uId from db
        user = db.GetUserByName(user.FirstName, user.MiddleName, user.LastName);
        //get user publications
        List <ScholarPublication> publications = GetUserPublications(scholarUser.Id);
        List <Article>            articles     = new List <Article>();

        //insert user articles
        foreach (ScholarPublication pub in publications)
        {
            Article a = (new Article(0, pub.Title, pub.EPrint));
            a.UpdateUsers(new List <User>()
            {
                user
            });
            if (pub.Publisher.Contains("IEEE"))
            {
                List <string>  terms           = new IEEE().GetArticleTerms(pub.Title);
                List <Keyword> articleKeywords = new List <Keyword>();
                foreach (var item in terms)
                {
                    articleKeywords.Add(new Keyword(0, item));
                }
                a.UpdateKeywords(articleKeywords);
            }
            db.FullArticleInsert(a);
        }

        //add interests
        scholarUser.Interests = GetUserInterests(scholarUser.Id);
        foreach (var item in scholarUser.Interests)
        {
            db.InsertInterest(user.Id, item);
        }

        //return;
    }
示例#10
0
 public static string DoubleToBinTest(this double number)
 => IEEE.DoubleToBin(number);
示例#11
0
        public bool Read(string filePath)
        {
            if (File.Exists(filePath))
            {
                string fileName = Path.GetFileNameWithoutExtension(filePath);
                PresetName = fileName;

                BinaryFile bFile = new BinaryFile(filePath, BinaryFile.ByteOrder.BigEndian);

                string firstChunkID = bFile.ReadString(4); // chunk ID	= "FORM"
                int    ckSize       = bFile.ReadInt32();
                string formType     = bFile.ReadString(4);

                // read first data chunk
                string chunkID = bFile.ReadString(4);

                // if chunkID == "COMT" then CommentsChunk
                if (chunkID.Equals("COMT"))
                {
                    long curposTmpComt = bFile.GetPosition();
                    bFile.Seek(curposTmpComt - 4);

                    // CommentsChunk
                    string chunkIDComt    = bFile.ReadString(4); // chunk ID	= "COMT"
                    int    chunkSizeComt  = bFile.ReadInt32();
                    int    numComments    = bFile.ReadUInt16();
                    long   curposTmpComt2 = bFile.GetPosition();

                    for (int i = 0; i < numComments; i++)
                    {
                        int    commentTimestamp = (int)bFile.ReadUInt32();
                        string marker           = bFile.ReadString(4);
                        int    count            = (int)bFile.ReadByte();
                        comments.Add(bFile.ReadString(count));
                    }

                    bFile.Seek(curposTmpComt2 + chunkSizeComt - 2);
                }

                string chunkID2 = bFile.ReadString(4);

                // if chunkID2 == "COMM" then CommonChunk
                if (chunkID2.Equals("COMM"))
                {
                    long curposTmpComm = bFile.GetPosition();
                    bFile.Seek(curposTmpComm - 4);

                    // CommonChunk
                    string chunkIDComm   = bFile.ReadString(4); // chunk ID = "COMM"
                    int    chunkSizeComm = bFile.ReadInt32();

                    channels        = bFile.ReadInt16();
                    numSampleFrames = (int)bFile.ReadUInt32();
                    bitsPerSample   = bFile.ReadInt16();

                    // read IEEE 80-bit extended double precision
                    byte[] sampleRateBytes  = bFile.ReadBytes(0, 10, BinaryFile.ByteOrder.LittleEndian);
                    double sampleRateDouble = IEEE.ConvertFromIeeeExtended(sampleRateBytes);
                    sampleRate = (int)sampleRateDouble;
                }

                string chunkID3 = bFile.ReadString(4);

                // if chunkID3 == "SSND" then SoundDataChunk
                if (chunkID3.Equals("SSND"))
                {
                    long curposTmpSsnd = bFile.GetPosition();
                    bFile.Seek(curposTmpSsnd - 4);

                    // SoundDataChunk
                    string chunkIDSsnd   = bFile.ReadString(4); // chunk ID = "SSND"
                    int    chunkSizeSsnd = bFile.ReadInt32();

                    int    offset    = (int)bFile.ReadUInt32();
                    int    blocksize = (int)bFile.ReadUInt32();
                    byte[] data      = bFile.ReadBytes(offset, chunkSizeSsnd - 8, BinaryFile.ByteOrder.LittleEndian);

                    // swap waveform data
                    WaveformData = SwapAiffEndian(data);
                }

                bFile.Close();
                return(true);
            }
            else
            {
                return(false);
            }
        }