Example #1
0
        /// <summary>
        /// Sends a file to the xbox.
        /// </summary>
        /// <param name="localName">PC file name.</param>
        /// <param name="remoteName">Xbox file name.</param>
        public void SendFile(string localName, string remoteName)
        {
            using (var fs = new FileStream(localName, FileMode.Open))
                using (var xfs = new XboxFileStream(this, remoteName, FileMode.Create))
                {
                    byte[] data = new byte[(int)fs.Length];
                    fs.Read(data, 0, data.Length);
                    xfs.Write(data, 0, data.Length);
                }

            //System.IO.FileStream lfs = new System.IO.FileStream(localName, FileMode.Open);
            //byte[] fileData = new byte[connection.Client.SendBufferSize];
            //SendCommand("sendfile name=\"{0}\" length={1}", remoteName, lfs.Length);

            //int mainIterations = (int)lfs.Length / connection.Client.SendBufferSize;
            //int remainder = (int)lfs.Length % connection.Client.SendBufferSize;

            //for (int i = 0; i < mainIterations; i++)
            //{
            //    lfs.Read(fileData, 0, fileData.Length);
            //    SendBinaryData(fileData);
            //}
            //lfs.Read(fileData, 0, remainder);
            //SendBinaryData(fileData, remainder);

            //lfs.Close();
        }
Example #2
0
        /// <summary>
        /// Benchmark utility function best when ran with xdk dash.  Lower memory situations will yeild lower speeds.
        /// </summary>
        /// <returns></returns>
		public string StreamTest()
		{
			float toMegs = 1.0f / (1024.0f * 1024.0f);

			int fileBufferSize = 0x40000;   // 256kb
			uint memBufferSize = 0x20000;   // 128kb

			if (MemoryStatistics.AvailablePages * 0x1000 < memBufferSize)
			{
				SetFileCacheSize(1);
				if (MemoryStatistics.AvailablePages * 0x1000 < memBufferSize)
					return "Need at least 128kb of available memory";
			}

            // memory tests
			uint TestBuffer = AllocateMemory(memBufferSize); //64kb
			byte[] membuf = new byte[memBufferSize];

			Stopwatch memReadTimer = Stopwatch.StartNew();
			for (int i = 0; i < 400; i++)
				membuf = GetMemory(TestBuffer, memBufferSize);
			memReadTimer.Stop();
			string memReadSpeed = ((400.0f * (float)memBufferSize * toMegs) / (float)memReadTimer.Elapsed.TotalSeconds).ToString();

			Stopwatch memWriteTimer = Stopwatch.StartNew();
            for (int i = 0; i < 400; i++)
                MemoryStream.Write(TestBuffer, (int)membuf.Length, membuf, 0);
			memWriteTimer.Stop();
			string memWriteSpeed = ((400.0f * (float)memBufferSize * toMegs) / (float)memWriteTimer.Elapsed.TotalSeconds).ToString();

			FreeMemory(TestBuffer);

			// filestream tests
			string fileWriteSpeed, fileReadSpeed;
            using(XboxFileStream xbfs = new XboxFileStream(this, "E:\\test.bin"))
			using(BinaryReader br = new BinaryReader(xbfs))
			using (BinaryWriter bw = new BinaryWriter(xbfs))
			{
				byte[] filebuf = new byte[fileBufferSize];

				Stopwatch fileWriteTimer = Stopwatch.StartNew();
				for (int i = 0; i < 16; i++)
				{
					xbfs.Position = 0;
					bw.Write(filebuf, 0, fileBufferSize);
				}
				fileWriteTimer.Stop();
				fileWriteSpeed = ((16.0f * (float)fileBufferSize * toMegs) / (float)fileWriteTimer.Elapsed.TotalSeconds).ToString();

				Stopwatch fileReadTimer = Stopwatch.StartNew();
				for (int i = 0; i < 16; i++)
				{
					xbfs.Position = 0;
					filebuf = br.ReadBytes(fileBufferSize);
				}
				fileReadTimer.Stop();
				fileReadSpeed = ((16.0f * (float)fileBufferSize * toMegs) / (float)fileReadTimer.Elapsed.TotalSeconds).ToString();
			}
			DeleteFile("E:\\test.bin");

            // determine link speed
            //byte[] bigbuffer = new byte[fileBufferSize];
            //DateTime linkSpeedStart = DateTime.Now;
            //for (int i = 0; i < 100; i++)
            //{
            //    this.Connection.Client.Send(bigbuffer);
            //}
            //TimeSpan linkSpeedElapse = DateTime.Now - linkSpeedStart;
            //string linkSpeed = (((float)100 * (float)fileBufferSize * toMegs) / (float)linkSpeedElapse.TotalSeconds).ToString();

            // get speed
            float linkSpeed;
            if ((LinkStatus & LinkStatus.Speed100Mbps) == LinkStatus.Speed100Mbps) linkSpeed = 100.0f / 8;
            else linkSpeed = 10.0f / 8;
            if ((LinkStatus & LinkStatus.HalfDuplex) == LinkStatus.HalfDuplex) linkSpeed /= 2;

			StringBuilder results = new StringBuilder();
            results.AppendFormat("Max Theoretical Link Speed: {0}MB/s\n", linkSpeed);
			results.AppendFormat("Memory Read: {0}MB/s\n", memReadSpeed);
			results.AppendFormat("Memory Write: {0}MB/s\n", memWriteSpeed);
			results.AppendFormat("File Read: {0}MB/s\n", fileReadSpeed);
			results.AppendFormat("File Write: {0}MB/s\n", fileWriteSpeed);

			return results.ToString();
		}
Example #3
0
        /// <summary>
        /// Sends a file to the xbox.
        /// </summary>
        /// <param name="localName">PC file name.</param>
        /// <param name="remoteName">Xbox file name.</param>
        public void SendFile(string localName, string remoteName)
        {
			using (var fs = new FileStream(localName, FileMode.Open))
			using (var xfs = new XboxFileStream(this, remoteName, FileMode.Create))
			{
				byte[] data = new byte[(int)fs.Length];
				fs.Read(data, 0, data.Length);
				xfs.Write(data, 0, data.Length);
			}

            //System.IO.FileStream lfs = new System.IO.FileStream(localName, FileMode.Open);
            //byte[] fileData = new byte[connection.Client.SendBufferSize];
            //SendCommand("sendfile name=\"{0}\" length={1}", remoteName, lfs.Length);

            //int mainIterations = (int)lfs.Length / connection.Client.SendBufferSize;
            //int remainder = (int)lfs.Length % connection.Client.SendBufferSize;

            //for (int i = 0; i < mainIterations; i++)
            //{
            //    lfs.Read(fileData, 0, fileData.Length);
            //    SendBinaryData(fileData);
            //}
            //lfs.Read(fileData, 0, remainder);
            //SendBinaryData(fileData, remainder);

            //lfs.Close();
        }