Exemple #1
0
        public void ToUnixEpoch_正常()
        {
            // arrange
            var date = new DateTime(2000, 1, 1);

            // act
            var act = date.ToUnixEpoch();

            // assert
            Assert.AreEqual(946652400000, act);
        }
Exemple #2
0
        public void ToUnixEpoch_小数点以下切り捨て()
        {
            // arrange
            var date = new DateTime(2000, 1, 1, 0, 0, 0, 999);

            // act
            var act = date.ToUnixEpoch();

            // assert
            Assert.AreEqual(946652400999, act);
        }
        /// <include file='.\ISyncService.xml' path='/SyncService/Push/*'/>
        public void Push(Stream stream, string remotePath, int permissions, DateTime timestamp, CancellationToken cancellationToken)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (remotePath == null)
            {
                throw new ArgumentNullException(nameof(remotePath));
            }

            if (remotePath.Length > MaxPathLength)
            {
                throw new ArgumentOutOfRangeException(nameof(remotePath), $"The remote path {remotePath} exceeds the maximum path size {MaxPathLength}");
            }

            this.Socket.SendSyncRequest(SyncCommand.SEND, remotePath, permissions);

            // create the buffer used to read.
            // we read max SYNC_DATA_MAX.
            byte[] buffer = new byte[MaxBufferSize];

            // look while there is something to read
            while (true)
            {
                // check if we're canceled
                cancellationToken.ThrowIfCancellationRequested();

                // read up to SYNC_DATA_MAX
                int read = stream.Read(buffer, 0, MaxBufferSize);

                if (read == 0)
                {
                    // we reached the end of the file
                    break;
                }

                // now send the data to the device
                // first write the amount read
                this.Socket.SendSyncRequest(SyncCommand.DATA, read);
                this.Socket.Send(buffer, read);
            }

            // create the DONE message
            int time = (int)timestamp.ToUnixEpoch();
            this.Socket.SendSyncRequest(SyncCommand.DONE, time);

            // read the result, in a byte array containing 2 ints
            // (id, size)
            var result = this.Socket.ReadSyncResponse();
            var length = this.Socket.ReadSyncLength();

            if (result == SyncCommand.FAIL)
            {
                var message = this.Socket.ReadSyncString(length);

                throw new AdbException(message);
            }
            else if (result != SyncCommand.OKAY)
            {
                throw new AdbException($"The server sent an invali repsonse {result}");
            }
        }
Exemple #4
0
 public void should_convert_utc_date_to_epoch() {
   var date = new DateTime(2014, 9, 24, 0, 0, 0, DateTimeKind.Local)
     .ToUniversalTime();
   long epoch = 1411527600; // 24/09/2014 00:00:00 (dd/mm/yyyy HH:mm:ss)
   Assert.That(date.ToUnixEpoch(), Is.EqualTo(epoch));
 }