private static Stream /*!*/ GetStream(ConversionStorage <MutableString> /*!*/ toStr, RespondToStorage /*!*/ respondTo, object port) { var toStrSite = toStr.GetSite(TryConvertToStrAction.Make(toStr.Context)); MutableString str = toStrSite.Target(toStrSite, port); if (str != null) { return(new MutableStringStream(str)); } IOWrapper wrapper = RubyIOOps.CreateIOWrapper(respondTo, port, FileAccess.Read); if (!wrapper.CanRead) { throw RubyExceptions.CreateTypeError("instance of IO needed"); } return(wrapper); }
public static object Dump(RubyModule /*!*/ self, object obj, object io, [Optional] int?limit) { Stream stream = null; if (io != null) { stream = new IOWrapper(self.Context, io, FileAccess.Write); } if (stream == null || !stream.CanWrite) { throw RubyExceptions.CreateTypeError("instance of IO needed"); } BinaryWriter writer = new BinaryWriter(stream); MarshalWriter dumper = new MarshalWriter(writer, self.Context, limit); dumper.Dump(obj); return(io); }
static async Task RunAsync(Configuration config) { using var timer = SyncHistogram.NewTimer(); using var activity = Tracing.Trace(nameof(RunAsync)); var fileHandler = new IOWrapper(); var db = new DbClient(config, fileHandler); var pelotonApiClient = new Peloton.ApiClient(config.Peloton.Email, config.Peloton.Password, config.Observability.Prometheus.Enabled); var peloton = new PelotonService(config, pelotonApiClient, db, fileHandler); await peloton.DownloadLatestWorkoutDataAsync(); var fitConverter = new FitConverter(config, db, fileHandler); fitConverter.Convert(); var tcxConverter = new TcxConverter(config, db, fileHandler); tcxConverter.Convert(); var garminUploader = new GarminUploader(config, db); try { await garminUploader.UploadToGarminAsync(); Health.Set(HealthStatus.Healthy); fileHandler.Cleanup(config.App.DownloadDirectory); fileHandler.Cleanup(config.App.UploadDirectory); foreach (var file in Directory.GetFiles(config.App.WorkingDirectory)) { File.Delete(file); } } catch (GarminUploadException e) { Log.Error(e, "Garmin upload returned an error code. Failed to upload workouts."); Log.Warning("GUpload failed to upload files. You can find the converted files at {@Path} \n You can manually upload your files to Garmin Connect, or wait for P2G to try again on the next sync job.", config.App.OutputDirectory); Health.Set(HealthStatus.UnHealthy); } }
public CSVFileFinder(IOWrapper ioWrapper, string folderPath) { this.ioWrapper = ioWrapper; this.folderPath = folderPath; }
private async void btnFormat_Click(object sender, EventArgs e) { DiskDrive dd = (DiskDrive)lstDiskDrive.SelectedItem; if (dd == null) { MessageBox.Show("Choose valid SD drive first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (MessageBox.Show("All data on SD card will be lost during format. Are you sure?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No) { return; } SetButtons(false); //if (dd.Volumes.Count() == 0) { var handle = dd.CreateHandle(FileAccess.ReadWrite); var x = IOWrapper.DiskGetDriveLayoutEx(handle); IOWrapper.DiskCreateDiskMBR(handle, 0xa5a5a5); IOWrapper.DiskUpdateProperties(handle); x = IOWrapper.DiskGetDriveLayoutEx(handle); x.PartitionEntry[0].PartitionNumber = 1; x.PartitionEntry[0].StartingOffset = 4 * 512; x.PartitionEntry[0].PartitionLength = (long)dd.GetDriveSize() - x.PartitionEntry[0].StartingOffset; x.PartitionEntry[0].RewritePartition = true; x.PartitionEntry[0].Mbr.PartitionType = (byte)IOWrapper.Partition.FAT32; IOWrapper.DiskSetDriveLayoutEx(handle, x); IOWrapper.DiskUpdateProperties(handle); x = IOWrapper.DiskGetDriveLayoutEx(handle); //IOWrapper.StorageLoadMedia(handle); handle.Close(); var driveID = dd.ID; WmiInfo.LoadDiskInfo(); dd = dd.CreationContext.DiskDrives.FirstOrDefault(z => z.ID == driveID); } this.Text += " (Formatting)"; lblSpeed.Text = "Windows is formatting the drive..."; cts = new CancellationTokenSource(); progress.Value = 0; progress.Maximum = 100; //await Task.Run(() => dd.Format(ProgressHandler, cts.Token)); try { var vol = dd.Volumes.FirstOrDefault(); if (vol != null) { vol.Mount(); await Task.Run(() => dd.Volumes.First().Format("FAT32", true), cts.Token); } } catch (Exception ex) { if (!(ex is OperationCanceledException)) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } cts.Cancel(); } ResetProgress(); FillDriveList(); if (!cts.IsCancellationRequested) { MessageBox.Show("Formatting complete.", "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information); } cts = null; }
internal static void CreateFolderInUploads(Guid newGuid) { var path = Path.Combine(Configurations.UploadsFolder, newGuid.ToString()); IOWrapper.CreateFolderIfNotExists(path); }
public ActionResult Delete(string id) { IOWrapper.DeleteFileFromUploads(id); return(RedirectToAction("Index")); }