protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataSpace.Text = ByteSizeFormatter.Format(MyDBDataset.Statistics.DataSpace); UsedSpace.Text = ByteSizeFormatter.Format(MyDBDataset.Statistics.UsedSpace); LogSpace.Text = ByteSizeFormatter.Format(MyDBDataset.Statistics.LogSpace); var used = (double)MyDBDataset.Statistics.UsedSpace / MyDBDataset.Statistics.DataSpace; var free = 1 - used; if (used == 0) { ProgressUsed.Visible = false; } else { ProgressUsed.Width = String.Format(CultureInfo.InvariantCulture, "{0}%", used * 100.0); } if (free == 0) { ProgressFree.Visible = false; } else { ProgressFree.Width = String.Format(CultureInfo.InvariantCulture, "{0}%", free * 100.0); } ProgressUsedLabel.Text = String.Format(CultureInfo.InvariantCulture, "{0:p}", free); RequestSpaceLink.NavigateUrl = Jhu.Graywulf.Web.Feedback.GetSpaceRequestUrl(); } }
protected override void UpdateForm() { base.UpdateForm(); FileGroup.EntityReference.Value = Item.FileGroup; Partition.EntityReference.Value = Item.Partition; AllocatedSpace.Text = ByteSizeFormatter.Format(Item.AllocatedSpace); UsedSpace.Text = ByteSizeFormatter.Format(Item.UsedSpace); // TODO ReservedSpace.Text = ByteSizeFormatter.Format(Item.ReservedSpace); // TODO }
public SMBItemViewModel(SMBItem smbItem) { IsDirectory = smbItem.IsDirectory; FileName = smbItem.Name; FilePath = smbItem.Path; LastWriteTime = smbItem.Info.LastWriteTime.ToLocalTime(); CreationTime = smbItem.Info.CreationTime.ToLocalTime(); Size = IsDirectory ? string.Empty : ByteSizeFormatter.Format((ulong)smbItem.Size); SMBItem = smbItem; }
public void Format_correctly_formats_size_with_decimal_convention(long size, string expected) { var formatter = new ByteSizeFormatter { Culture = CultureInfo.InvariantCulture, Convention = ByteSizeConvention.Decimal }; var actual = formatter.Format(size); Assert.Equal(expected, actual); }
protected override void UpdateForm() { base.UpdateForm(); FileGroupType.Text = Item.FileGroupType.ToString(); LayoutType.Text = Item.LayoutType.ToString(); AllocationType.Text = Item.AllocationType.ToString(); DiskVolumeType.Text = Item.DiskVolumeType.ToString(); FileGroupName.Text = Item.FileGroupName; AllocatedSpace.Text = ByteSizeFormatter.Format(Item.AllocatedSpace); FileCount.Text = Item.FileCount.ToString(); }
protected override void OnUpdateForm() { base.OnUpdateForm(); fileGroupTypeList.SelectedValue = Item.FileGroupType.ToString(); LayoutType.SelectedValue = Item.LayoutType.ToString(); allocationTypeList.SelectedValue = Item.AllocationType.ToString(); diskVolumeTypeList.SelectedValue = Item.DiskVolumeType.ToString(); FileGroupName.Text = Item.FileGroupName; AllocatedSpace.Text = ByteSizeFormatter.Format(Item.AllocatedSpace); FileCount.Text = Item.FileCount.ToString(); }
protected override void UpdateForm() { base.UpdateForm(); DiskVolume.EntityReference.Value = Item.DiskVolume; DatabaseFileType.Text = Item.DatabaseFileType.ToString(); LogicalName.Text = Item.LogicalName; filename.Text = Item.GetFullUncFilename(); filename.NavigateUrl = String.Format("file:{0}", Item.GetFullUncFilename().Replace('\\', '/')); AllocatedSpace.Text = ByteSizeFormatter.Format(Item.AllocatedSpace); UsedSpace.Text = ByteSizeFormatter.Format(Item.UsedSpace); ReservedSpace.Text = ByteSizeFormatter.Format(Item.ReservedSpace); }
protected override void OnUpdateForm() { base.OnUpdateForm(); RefreshDiskVolumeList(); DiskVolume.SelectedValue = Item.DiskVolumeReference.Guid.ToString(); DatabaseFileType.SelectedValue = Item.DatabaseFileType.ToString(); LogicalName.Text = Item.LogicalName; Filename.Text = Item.Filename; AllocatedSpace.Text = ByteSizeFormatter.Format(Item.AllocatedSpace); UsedSpace.Text = ByteSizeFormatter.Format(Item.UsedSpace); ReservedSpace.Text = ByteSizeFormatter.Format(Item.ReservedSpace); }
public string FormatSize(double size) { var formatter = new ByteSizeFormatter { Convention = ByteSizeConvention.Binary, DecimalPlaces = 1, NumberFormat = "#,##0.###", MinUnit = ByteSizeUnit.Kilobyte, MaxUnit = ByteSizeUnit.Gigabyte, RoundingRule = ByteSizeRounding.Closest, UseFullWordForBytes = true, }; return(formatter.Format((long)size)); }
protected override void OnUpdateForm() { base.OnUpdateForm(); foreach (ListItem li in DiskVolumeType.Items) { li.Selected = ((Item.DiskVolumeType & (DiskVolumeType)Enum.Parse(typeof(DiskVolumeType), li.Value)) > 0); } LocalPath.Text = Item.LocalPath.Value; UncPath.Text = Item.UncPath.Value; FullSpace.Text = ByteSizeFormatter.Format(Item.FullSpace); AllocatedSpace.Text = ByteSizeFormatter.Format(Item.AllocatedSpace); ReservedSpace.Text = ByteSizeFormatter.Format(Item.ReservedSpace); Speed.Text = (Item.Speed / 100000.0).ToString("0.00"); }
protected override void UpdateForm() { base.UpdateForm(); DiskVolumeType.Text = Item.DiskVolumeType.ToString(); LocalPath.Text = String.Format("{0} ({1})", Item.LocalPath.Value, Item.LocalPath.ResolvedValue); UncPath.Text = String.Format("{0} ({1})", Item.UncPath.Value, Item.UncPath.ResolvedValue); FullSpace.Text = ByteSizeFormatter.Format(Item.FullSpace); AllocatedSpace.Text = ByteSizeFormatter.Format(Item.AllocatedSpace); ReservedSpace.Text = ByteSizeFormatter.Format(Item.ReservedSpace); Speed.Text = (Item.Speed / 100000.0).ToString("0.00"); Usage.Values.Clear(); Usage.Values.Add((double)Item.AllocatedSpace / Item.FullSpace); Usage.Values.Add((double)Item.ReservedSpace / Item.FullSpace); }
public void FormatByteSize() { XAssert.AreEqual( "1 B", ByteSizeFormatter.Format(1)); XAssert.AreEqual( "1.00 KB", ByteSizeFormatter.Format(1024)); XAssert.AreEqual( "1.50 MB", ByteSizeFormatter.Format((1024 * 1024) + (512 * 1024) + 1)); XAssert.AreEqual( "999.00 GB", ByteSizeFormatter.Format(999L * 1024 * 1024 * 1024)); }
public R <(string, Thread, TimeSpan?), LocalStr> StreamSongToPipeHandle(string spotifyTrackUri) { var trackId = SpotifyApi.UriToTrackId(spotifyTrackUri); if (!trackId.Ok) { return(new LocalStr("Cannot stream this URI from spotify.")); } if (state == State.NotSetUp) { return(new LocalStr("Spotify API access was not set up correctly. Cannot play from spotify.")); } if (state != State.Idle) { throw new InvalidOperationException( $"Tried to stream spotify song while the system was not idle (current state: {state})." ); } // Launch Librespot. state = State.LaunchingLibrespot; Log.Debug("Launching Librespot..."); var processOption = LaunchLibrespot(); if (!processOption.Ok) { return(processOption.Error); } void Fail(string msg) { Log.Debug("Failed to start song on spotify: " + msg); } TimeSpan duration = default; for (var i = 0; i < SongStartRetries; i++) { Log.Debug($"Starting to play song on spotify, try {i}..."); // Start song. var playResult = api.Request( () => api.Client.Player.ResumePlayback(new PlayerResumePlaybackRequest { DeviceId = deviceId, Uris = new List <string> { spotifyTrackUri } }) ); if (!playResult.Ok) { Fail(playResult.Error.ToString()); continue; } // Check if the song actually started playing. for (var j = 0; j < 2; j++) { if (j == 1) { // Wait before the second check. Thread.Sleep(SongStartRecheckAfter); } var checkResult = api.Request(() => api.Client.Player.GetCurrentPlayback()); if (!checkResult.Ok) { Fail(checkResult.Error.ToString()); continue; } var currentlyPlaying = checkResult.Value; if (currentlyPlaying.CurrentlyPlayingType != "track") { Fail("No track is currently playing."); continue; } var track = (FullTrack)currentlyPlaying.Item; if ( currentlyPlaying.IsPlaying && currentlyPlaying.Device.Id == deviceId && track.Id == trackId.Value ) { duration = TimeSpan.FromMilliseconds(track.DurationMs); state = State.StreamRunning; break; } Fail( $"Song not playing yet on spotify." + $" IsPlaying: {currentlyPlaying.IsPlaying}," + $" DeviceId: {currentlyPlaying.Device.Id} (should be {deviceId})," + $" TrackId: {track.Id} (should be {trackId.Value})." ); } if (state == State.StreamRunning) { Log.Trace("Song is playing on spotify now."); break; } } // Start audio streaming to ffmpeg. Log.Debug("Starting stream..."); var pipeServer = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable); var handle = "pipe:" + pipeServer.GetClientHandleAsString(); var totalBytesSent = 0; void ExitLibrespot(string message, bool stats = true) { pipeServer.Dispose(); if (!process.HasExitedSafe()) { process.Kill(); } process.Close(); state = State.Idle; var msg = message; if (stats) { msg += $" Sent {byteSizeFormatter.Format(totalBytesSent)} bytes in total."; } Log.Debug(msg); } if (state != State.StreamRunning) { var msg = $"Song did not start playing after {SongStartRetries} retries."; ExitLibrespot(msg, false); return(new LocalStr(msg)); } var byteReaderThread = new Thread(() => { var buffer = new byte[BytesPerChunk]; while (true) { int bytesRead; try { bytesRead = process.StandardOutput.BaseStream.Read(buffer, 0, BytesPerChunk); } catch (IOException e) { ExitLibrespot($"Reading from Librespot failed: {e}."); return; } if (bytesRead == 0) { // Librespot exited, no more data coming. ExitLibrespot("All spotify streaming data sent to ffmpeg."); return; } try { pipeServer.Write(buffer, 0, bytesRead); } catch (IOException) { ExitLibrespot("Ffmpeg went away before all spotify stream data was sent."); return; } if (totalBytesSent == 0) { // Necessary to dispose the handle after ffmpeg connected to receive notice when ffmpeg exits. pipeServer.DisposeLocalCopyOfClientHandle(); } totalBytesSent += bytesRead; } }) { IsBackground = true }; return(handle, byteReaderThread, duration); }
public void WhenDataLessThanKilobyte_ThenVolumeShownAsB() { var volume = 765ul; Assert.AreEqual("765 B", ByteSizeFormatter.Format(volume)); }
public void WhenDataExceedsKilobyte_ThenVolumeShownAsKB() { var volume = 2ul * 1024 + 200; Assert.AreEqual("2.2 KB", ByteSizeFormatter.Format(volume)); }
public void WhenDataExceedsMegabyte_ThenVolumeShownAsMB() { var volume = 2ul * 1024 * 1024; Assert.AreEqual("2 MB", ByteSizeFormatter.Format(volume)); }