Пример #1
0
        public static async void Timer_Tick(object?state)
        {
            // If we're still uploading, don't double-start
            if (_uploading)
            {
                return;
            }
            _uploading = true;

            Debug.Assert(_client != null);
            Debug.Assert(_dataDirectory != null);
            Debug.Assert(_gazeDevice != null);

            if (_salt == null)
            {
                _salt = await ReadSalt();

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

            var dataDirectory = new DirectoryInfo(_dataDirectory);

            foreach (var fileInfo in dataDirectory.GetFiles())
            {
                if (FileNaming.IsInProgress(fileInfo.FullName))
                {
                    // Skip uploading in-progress file.
                    continue;
                }

                var putRequest = new PutObjectRequest
                {
                    BucketName = BUCKET_NAME,
                    Key        = $"observer_data/{SCHEMA_VERSION}/{FileNaming.CloudStoragePath(fileInfo, _gazeDevice, _salt)}"
                };

                PutObjectResponse putResponse;
                using (var inputStream = fileInfo.OpenRead())
                {
                    putRequest.InputStream = inputStream;
                    putResponse            = await _client.PutObjectAsync(putRequest);
                }

                if (putResponse.HttpStatusCode == HttpStatusCode.OK)
                {
                    fileInfo.Delete();
                }
            }

            _uploading = false;
        }
Пример #2
0
 /**
  * If a FlacWriter object currently exists, stops it and removes the
  * InProgress suffix from its file name.
  */
 private void MaybeEndCurrentFlacWriter()
 {
     lock (flacLock)
     {
         if (flacWriter == null)
         {
             return;
         }
         flacWriter.EndStream();
         flacStream.Close();
         File.Move(
             flacFilePath,
             FileNaming.RemoveInProgressSuffix(flacFilePath));
         flacFilePath = null;
         flacStream   = null;
         flacWriter   = null;
     }
 }
Пример #3
0
        /** Creates a FlacWriter object if none currently exists. */
        private void MaybeCreateFlacWriter()
        {
            if (flacWriter != null)
            {
                return;
            }
            flacFilePath = flacFilePath = FileNaming.AddInProgressSuffix(
                FileNaming.GetMicWavInFilePath(dataDir));
            flacStream = File.Create(flacFilePath);
            flacWriter = new FlacWriter(flacStream);
            FlacStreaminfo streamInfo = new()
            {
                ChannelsCount = AUDIO_NUM_CHANNELS,
                BitsPerSample = AUDIO_BITS_PER_SAMPLE,
                SampleRate    = AUDIO_SAMPLE_RATE_HZ,
                MaxBlockSize  = AUDIO_SAMPLE_RATE_HZ,
            };

            flacWriter.StartStream(streamInfo);
        }