public void AssignBinToUnit_GivenInValidBinId_ShouldAssignBin() { //Setup var expectedUnit = Builder <StorageUnit> .CreateNew() .With(_ => _.Rows = StorageUnit.FromLayout(3, 3)) .Build(); var expectedBin = Builder <StorageBin> .CreateNew() .Build(); var model = Builder <AssignStorageBinModel> .CreateNew() .With(_ => _.UnitId = expectedUnit.Id.ToString()) .With(_ => _.BinId = expectedBin.Id.ToString()) .Build(); _mockUnitRepository .Setup(mc => mc.FindByIdAsync(It.IsAny <string>())) .ReturnsAsync(expectedUnit); _mockRepository .Setup(mc => mc.FindByIdAsync(It.IsAny <string>())) .Returns(Task.FromResult(default(StorageBin))); //Action Action action = () => _controller.AssignBinToUnit(_mockUnitRepository.Object, model).Wait(); //Assert action.Should().Throw <ArgumentOutOfRangeException>(); }
public AddStorage(StorageUnit l) { InitializeComponent(); tbCode.Enabled = false; S = l; this.Text = "Edit storage"; }
/// <summary> /// Detect normalized value and storage unit. /// </summary> private void SetNormalizedValue() { if (this.DefaultValue < 1024.0) { this.NormalizedType = StorageUnit.Byte; this.NormalizedValue = this.DefaultValue; } else if (this.DefaultValue >= 1024.0 && this.DefaultValue < 1048576L) { this.NormalizedType = StorageUnit.Kb; this.NormalizedValue = this.DefaultValue / 1024.0; } else if (this.DefaultValue >= 1048576L && this.DefaultValue < 1073741824L) { this.NormalizedType = StorageUnit.Mb; this.NormalizedValue = this.DefaultValue / 1024.0 / 1024.0; } else if (this.DefaultValue >= 1073741824L && this.DefaultValue < 1099511627776L) { this.NormalizedType = StorageUnit.Gb; this.NormalizedValue = this.DefaultValue / 1024.0 / 1024.0 / 1024.0; } else { this.NormalizedType = StorageUnit.Tb; this.NormalizedValue = this.DefaultValue / 1024.0 / 1024.0 / 1024.0 / 1024.0; } this.NormalizedValue = Math.Round(this.NormalizedValue, 2); }
public void AssignBin_GivenValidBinAndAddress_ShouldAssignBin() { //Setup var expectedRowIndex = 2; var expectedColumnIndex = 2; var location = Builder <StorageLocation> .CreateNew() .Build(); var bin = Builder <StorageBin> .CreateNew() .Build(); var unit = Builder <StorageUnit> .CreateNew() .With(_ => _.Rows = StorageUnit.FromLayout(3, 3)) .With(_ => _.Location = location.ToReference()) .Build(); //Action var assignedBin = unit.AssignBin(bin, expectedRowIndex, expectedColumnIndex); //Assert assignedBin.StorageBinLocation.Should().NotBeNull(); assignedBin.StorageBinLocation.RowIndex.Should().Be(expectedRowIndex); assignedBin.StorageBinLocation.ColumnIndex.Should().Be(expectedColumnIndex); assignedBin.StorageBinLocation.Unit.Id.Should().Be(unit.Id); assignedBin.StorageBinLocation.Location.Id.Should().Be(location.Id); unit.Rows[expectedRowIndex].StorageColumns[expectedColumnIndex].Bin.Id.Should().Be(bin.Id); }
public static void Postfix(StorageUnit __instance, string __state, List <StorageUnit> ___globalStorages, string value) { if (!Enabled) { return; } try { if (___globalStorages == null) { return; } string oldName = __state, newName = value; if (oldName.EqualsOrdinal(newName)) { return; } if (___globalStorages.Remove(__instance)) { ___globalStorages.Add(__instance); Main.Logger.Debug <SortChestsByName>($"Reinserted chest renamed from [{oldName}] to [{newName}]."); } } catch (Exception exception) { Main.Logger.Exception(exception); } }
/// <summary> /// Normalized value detection and auto detection storage unit. /// </summary> private void SetNormalizedValue() { if (this.defValue < 1024L) { this.NormalizedType = StorageUnit.Byte; this.NormalizedValue = (float)this.defValue; } else if (this.defValue >= 1024L && this.defValue < 1024L * 1024L) { this.NormalizedType = StorageUnit.Kb; this.NormalizedValue = (float)this.defValue / 1024f; } else if (this.defValue >= 1024L * 1024L && this.defValue < 1024L * 1024L * 1024L) { this.NormalizedType = StorageUnit.Mb; this.NormalizedValue = (float)this.defValue / 1024f / 1024f; } else if (this.defValue >= 1024L * 1024L * 1024L && this.defValue < 1024L * 1024L * 1024L * 1024L) { this.NormalizedType = StorageUnit.Gb; this.NormalizedValue = (float)this.defValue / 1024f / 1024f / 1024f; } else { this.NormalizedType = StorageUnit.Tb; this.NormalizedValue = (float)this.defValue / 1024f / 1024f / 1024f / 1024f; } }
private static void Postfix(StorageUnit __instance) { if (!enabled) { return; } Dbgl($"new box, level {__instance.Level}"); int count; switch (__instance.Level) { case 0: count = settings.WoodenStorageSize; break; case 1: count = settings.MetalStorageSize; break; case 2: case -1: count = settings.SafetyBoxSize; break; default: return; } Dbgl($"Changing slots for level {__instance.Level} to {count}"); typeof(StorageUnit).GetMethod("InitStoreage", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { count, count }); }
/// <summary> /// Get the length of the file in specified unit /// </summary> /// <param name="fileSizeUnit">The unit type</param> /// <returns>The size of the file in the specified unit</returns> public double GetFileSize(StorageUnit fileSizeUnit) { var byteSize = GetFileSize(); var power = (int)fileSizeUnit; return(byteSize / Math.Pow(1024, power)); }
public override List <StorageUnit> SelectAll() { // //Method Name : List<StorageUnit> SelectAll() //Purpose : Try to get all the StorageUnit objects from the datastore //Re-use : None //Input : None //Output : - ref List<StorageUnit> // - the list that will contain the StorageUnit objects loaded from datastore // List <StorageUnit> StorageUnits; // will be returned, thus can not be declared in try block try { _sqlCon = new SQLiteConnection(_conStr); // new connection bool bRead = false; StorageUnits = new List <StorageUnit>(); // this ensures that if there are no records, // the returned list will not be null, but // it will be empty (Count = 0) _sqlCon.Open(); // open connection string selectQuery = "SELECT * FROM StorageUnits"; SQLiteCommand sqlCommand = new SQLiteCommand(selectQuery, _sqlCon); // setup command SQLiteDataReader sdr = sqlCommand.ExecuteReader(); bRead = sdr.Read(); // Priming read (must have 2nd read in loop) while (bRead == true) // false indicates no more rows/records4\4 { StorageUnit StorageUnit = new StorageUnit(); //unit.Address = new Address(); //unit.Phone = new Phone(); StorageUnit.UnitId = Convert.ToString(sdr["suID"]); StorageUnit.UnitClassification = Convert.ToString(sdr["suClassification"]); StorageUnit.UnitPrice = Convert.ToDouble(sdr["suPrice"]); StorageUnit.UnitSize = Convert.ToString(sdr["suSize"]); StorageUnit.UnitArrears = (Convert.ToInt16(sdr["suArrears"]) == 1) ? true : false;//First Converts Object to Int16 and then Int16 to Boolean Value StorageUnit.UnitOccupied = (Convert.ToInt16(sdr["suOccupied"]) == 1) ? true : false; StorageUnit.UnitInAdvance = (Convert.ToInt16(sdr["suAdvance"]) == 1) ? true : false; StorageUnit.UnitUpToDate = (Convert.ToInt16(sdr["suUpToDate"]) == 1) ? true : false; StorageUnit.UnitOwnerId = Convert.ToString(sdr["suOwnerID"]); StorageUnits.Add(StorageUnit); bRead = sdr.Read(); // Priming read (must have 1st read before loop) } // end while sdr.Close(); // close reader } // end try catch (Exception ex) { throw ex; } // end catch finally { _sqlCon.Close(); // Close connection } // end finally return(StorageUnits); // Single return } // end method
} // end method public override int SelectStorageUnit(string ID, ref StorageUnit StorageUnit) { // //Method Name : int SelectStorageUnit(string ID, ref StorageUnit StorageUnit) //Purpose : Try to get a single StorageUnit object from the StorageUnit datastore //Re-use : //Input : string ID // - The ID of the StorageUnit to load from the datastore // ref StorageUnit StorageUnit // - The StorageUnit object loaded from the datastore //Output : - int // 0 : StorageUnit loaded from datastore // -1 : no StorageUnit was loaded from the datastore (not found) // int rc = 0; // will be returned, thus can not be declared in try block try { _sqlCon = new SQLiteConnection(_conStr); // new connection bool bRead = false; StorageUnit = new StorageUnit(); _sqlCon.Open(); // open connection string selectQuery = "SELECT * FROM StorageUnits WHERE [suID] = '" + ID + "'"; SQLiteCommand sqlCommand = new SQLiteCommand(selectQuery, _sqlCon); // setup command SQLiteDataReader sdr = sqlCommand.ExecuteReader(); bRead = sdr.Read(); if (bRead == true) // false indicates no row/record read { StorageUnit.UnitId = Convert.ToString(sdr["suID"]); StorageUnit.UnitClassification = Convert.ToString(sdr["suClassification"]); StorageUnit.UnitPrice = Convert.ToDouble(sdr["suPrice"]); StorageUnit.UnitSize = Convert.ToString(sdr["suSize"]); StorageUnit.UnitOwnerId = Convert.ToString(sdr["suOwner"]); StorageUnit.UnitArrears = (Convert.ToInt16(sdr["suArrears"]) == 1) ? true : false; //First Converts Object to Int16 and then Int16 to Boolean Value StorageUnit.UnitOccupied = (Convert.ToInt16(sdr["suOccupied"]) == 1) ? true : false; StorageUnit.UnitInAdvance = (Convert.ToInt16(sdr["suAdvance"]) == 1) ? true : false; StorageUnit.UnitUpToDate = (Convert.ToInt16(sdr["suUpToDate"]) == 1) ? true : false; rc = 0; } // end if else { rc = -1; } // end else sdr.Close(); // close reader } // end try catch (Exception ex) { throw ex; } // end catch finally { _sqlCon.Close(); // Close connection } // end finally return(rc); // single return } // end method
public Storage( int capacity, StorageUnit unit, StorageType type) { Capacity = capacity; Unit = unit; Type = type; }
private double ConvertResultToDesiredUnits(StorageUnit unit, double input) { return(unit switch { StorageUnit.Kilobyte => SystemConverter.BytesToKilobytes(input), StorageUnit.Megabyte => SystemConverter.BytesToMegabytes(input), StorageUnit.Gigabyte => SystemConverter.BytesToGigabytes(input), StorageUnit.Terabyte => SystemConverter.BytesToTerabytes(input), _ => input, });
private double ConvertToOptionsUnit(double bytes, StorageUnit unit) { return(unit switch { StorageUnit.Kilobyte => SystemConverter.BytesToKilobytes(bytes), StorageUnit.Megabyte => SystemConverter.BytesToMegabytes(bytes), StorageUnit.Gigabyte => SystemConverter.BytesToGigabytes(bytes), StorageUnit.Terabyte => SystemConverter.BytesToTerabytes(bytes), _ => bytes, });
static void Prefix(PlayerItemBarCtr __instance) { if (!enabled) { return; } if (KeyDown(settings.ItemBarSwitchKey)) { for (int index = 0; index < 8; index++) { ItemObject itemObject = Module <Player> .Self.bag.itemBar.itemBarItems[index]; ItemObject itemObj = Module <Player> .Self.bag.GetItems(0).GetItemObj(index); Module <Player> .Self.bag.BagExchangeItemBar(index, index, 0); } MethodInfo dynMethod = __instance.GetType().GetMethod("Unequip", BindingFlags.NonPublic | BindingFlags.Instance); dynMethod.Invoke(__instance, new object[] { }); } else if (KeyDown(settings.OpenStorageKey) && UIStateMgr.Instance.currentState.type == UIStateMgr.StateType.Play) { StorageViewer sv = new StorageViewer(); FieldRef <StorageViewer, StorageUnit> suRef = FieldRefAccess <StorageViewer, StorageUnit>("storageUnit"); suRef(sv) = StorageUnit.GetStorageByGlobalIndex(lastStorageIndex); MethodInfo dynMethod = sv.GetType().GetMethod("InteractStorage", BindingFlags.NonPublic | BindingFlags.Instance); dynMethod.Invoke(sv, new object[] { }); } else if (KeyDown(settings.OpenFactoryKey) && UIStateMgr.Instance.currentState.type == UIStateMgr.StateType.Play) { FarmFactory[] factorys = Module <FarmFactoryMgr> .Self.GetAllFactorys(); if (factorys.Length == 0) { return; } FarmFactory factory = factorys[0]; Action <List <IdCount> > action = delegate(List <IdCount> ls) { factory.SetMatList(ls); }; UIStateMgr.Instance.ChangeStateByType(UIStateMgr.StateType.PackageExchangeState, true, new object[] { factory.MatList, TextMgr.GetStr(103440, -1), true, action, 103521, 300 }); } }
public static GameConfiguration FromJSON(string jsonStr) { JSONNode json = JSON.Parse(jsonStr); return(new GameConfiguration( Target.FromArray(json["targets"].AsArray), Device.FromArray(json["devices"].AsArray), StorageUnit.FromArray(json["storage"].AsArray), UpgradeType.FromArray(json["upgrades"]["types"].AsArray), UpgradeTier.FromArray(json["upgrades"]["tiers"].AsArray) )); }
public List <InstanceOfProduct> BackList(StorageUnit s) { List <InstanceOfProduct> l = new List <InstanceOfProduct>(); foreach (InstanceOfProduct i in controler.ListOfProducts) { if (s.Code.Equals(i.RefOfStorage.Code)) { l.Add(i); } } return(l); }
private static bool Prefix(StorageUnit __instance, ref ItemTable ___storage, ref ItemTable __result) { if (!enabled || !settings.UpdateExistingStorages) { return(true); } TableSlot[] slots = (TableSlot[])typeof(ItemTable).GetField("slots", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(___storage); int count = slots.Length; int lcount; switch (__instance.Level) { case 0: lcount = settings.WoodenStorageSize; break; case 1: lcount = settings.MetalStorageSize; break; case 2: case -1: lcount = settings.SafetyBoxSize; break; default: return(true); } if (count == lcount) { return(true); } Dbgl($"Changing slots for level {__instance.Level} from {count} to {lcount}"); TableSlot[] newSlots = new TableSlot[lcount]; Array.Copy(slots, newSlots, lcount > count ? count : lcount); if (lcount > count) { for (int i = 0; i < lcount - count; i++) { newSlots[count + i] = new TableSlot(); } } typeof(ItemTable).GetField("slots", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(___storage, newSlots); typeof(ItemTable).GetField("unlockedCount", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(___storage, newSlots.Length); __result = ___storage; return(false); }
public void AssignBin_GivenNoBin_ShouldThrow() { //Setup var unit = Builder <StorageUnit> .CreateNew() .With(_ => _.Rows = StorageUnit.FromLayout(3, 3)) .Build(); //Action Action action = () => unit.AssignBin(null, 1, 1); //Assert action.Should().Throw <ArgumentNullException>(); }
public async Task AssignBinToUnit_GivenValidModelWithExistingBin_ShouldClearExistingBin_And_AssignNewBin() { //Setup var existingBin = Builder <StorageBin> .CreateNew() .Build(); var expectedUnit = Builder <StorageUnit> .CreateNew() .With(_ => _.Rows = StorageUnit.FromLayout(3, 3)) .Build(); expectedUnit.AssignBin(existingBin, 1, 1); var expectedBin = Builder <StorageBin> .CreateNew() .Build(); var model = Builder <AssignStorageBinModel> .CreateNew() .With(_ => _.UnitId = expectedUnit.Id.ToString()) .With(_ => _.BinId = expectedBin.Id.ToString()) .Build(); _mockUnitRepository .Setup(mc => mc.FindByIdAsync(It.IsAny <string>())) .ReturnsAsync(expectedUnit); _mockRepository .Setup(mc => mc.FindByIdAsync(It.IsAny <string>())) .Returns <string>(binId => Task.FromResult(existingBin.Id.Equals(binId) ? existingBin : expectedBin)); _mockUnitRepository .Setup(mc => mc.ReplaceOneAsync(It.IsAny <StorageUnit>())) .Returns <StorageUnit>(Task.FromResult); _mockRepository .Setup(mc => mc.ReplaceOneAsync(It.IsAny <StorageBin>())) .Returns <StorageBin>(bin => { _logger.LogDebug(JsonConvert.SerializeObject(bin, Formatting.Indented)); return(Task.FromResult(bin)); }); //Action var assignedBin = await _controller.AssignBinToUnit(_mockUnitRepository.Object, model); //Assert assignedBin.StorageBinLocation.Should().NotBeNull(); existingBin.StorageBinLocation.Should().BeNull(); }
public async Task GetStorageAllTestAsync(StorageUnit unit, double input, double expected) { fixture.Customize(new SystemStorageCustomization(unit, input)); SystemController mockController = fixture.Build <SystemController>() .OmitAutoProperties() .Create(); Collection <StorageResult> result = await mockController.GetAllStorageSpacesAsync(); // Value at time of writing was 5. Should always be more than 1. Assert.True(result.Count > 1); // Doesn't matter the result. Set up so they're all the same. Assert.Equal(expected, result[0].TotalSpace); }
public async Task GetStorageDriveTestAsync(StorageUnit unit, double input, double expected) { const string drive = "sda/dev1"; fixture.Customize(new SystemStorageCustomization(unit, input)); SystemController mockController = fixture.Build <SystemController>() .OmitAutoProperties() .Create(); Collection <StorageResult> result = await mockController.GetStorageDriveAsync(drive); // Value at time of writing was 5. Should always be more than 1. Assert.Single(result); Assert.Equal(expected, result[0].TotalSpace); }
public static void Prefix(int ___curStorageGlobalIndex, out StorageUnit __state) { __state = null; if (!Enabled) { return; } try { __state = StorageUnit.GetStorageByGlobalIndex(___curStorageGlobalIndex); } catch (Exception exception) { Main.Logger.Exception(exception); } }
public static void Prefix(StorageUnit __instance, out string __state) { __state = null; if (!Enabled) { return; } try { __state = __instance.StorageName; } catch (Exception exception) { Main.Logger.Exception(exception); } }
private static List <StorageRow> _create3By4(StorageUnit unit, int unitIndex) { return(Builder <StorageRow> .CreateListOfSize(3) .All() .With((_, index) => _.Index = index) .With((_, rowIndex) => _.StorageColumns = Builder <StorageColumn> .CreateListOfSize(4) .All() .With((_, index) => _.Index = index) .Do((_, columnIndex) => _assignBin(rowIndex, columnIndex, unitIndex)) .Build() .ToList() ) .Build().ToList()); }
public void FromLayout_GivenValidInput_ShouldCreateRowsAndColumns() { //Setup var expectedRows = 3; var expectedColumns = 2; // Action var result = StorageUnit.FromLayout(expectedRows, expectedColumns); //Assert result.Count.Should().Be(expectedRows); foreach (var storageRow in result) { storageRow.StorageColumns.Count.Should().Be(expectedColumns); } }
public void GetAssignedBin_GivenInvalidColumnIndex_Should_Throw() { //Setup var expectedRowIndex = 2; var expectedColumnIndex = 2; var unit = Builder <StorageUnit> .CreateNew() .With(_ => _.Rows = StorageUnit.FromLayout(3, 1)) .Build(); //Action Action action = () => unit.GetAssignedBin(expectedRowIndex, expectedColumnIndex); //Assert action.Should().Throw <ArgumentOutOfRangeException>(); }
public ContentResult ToAddAgentApp(FormCollection userform) { string msg = string.Empty; PDAAgentApp app = new PDAAgentApp(); app.Ver = userform["Ver"]; app.AppName = userform["AppName"]; if (userform["IsOK"] != null) { app.IsOK = userform["IsOK"] == "on" ? true : false; } var file = Request.Files[0]; string FilePath = "/File/APP/"; string FileName = ""; string errMsg = ""; if (!FileDeal(Request.Files[0], FilePath, out FileName, out errMsg)) { return(Content(errMsg)); } SizeUnit sizeObj = StorageUnit.AutoConver(Request.Files[0].ContentLength); app.Size = sizeObj.size.ToString() + sizeObj.unit; app.AppName = Request.Files[0].FileName; app.AppPath = FilePath + Request.Files[0].FileName; app.CreatTime = CommonFunc.GetNowTimestamp(); if (app.IsOK) { PDAAgentApp.UpdateIsOK(); } if (app.InsertAndReturnIdentity() > 0) { msg = "ok"; } else { msg = "添加失败!"; } return(Content(msg)); }
private void BtnEditStorage_Click(object sender, EventArgs e) { if (StorageBox.SelectedIndex > -1) { StorageUnit s = (StorageUnit)(StorageBox.SelectedItem); AddStorage As = new AddStorage(s); if (As.ShowDialog() == DialogResult.OK) { ((StorageUnit)StorageBox.SelectedItem).Name = As.S.Name; ((StorageUnit)StorageBox.SelectedItem).CapacityInPieces = As.S.CapacityInPieces; ((StorageUnit)StorageBox.SelectedItem).CapsityInWeight = As.S.CapsityInWeight; UpdateStorageBox(); StorageBox.SelectedIndex = -1; StorageBox.SelectedIndex = StorageBox.Items.IndexOf(s); } } }
public static StorageUnit[] FromArray(JSONArray jsonArr) { StorageUnit[] storageUnits = new StorageUnit[jsonArr.Count]; for (int i = 0; i < storageUnits.Length; i++) { JSONNode json = jsonArr[i]; storageUnits[i] = new StorageUnit( i, json["name"].Value, json["capacity"].AsFloat, json["cost"].AsFloat ); } return(storageUnits); }
public void AssignBin_GivenInvalidColumnIndex_ShouldThrow() { //Setup var bin = Builder <StorageBin> .CreateNew() .Build(); var unit = Builder <StorageUnit> .CreateNew() .With(_ => _.Rows = StorageUnit.FromLayout(3, 1)) .Build(); //Action Action action = () => unit.AssignBin(bin, 1, 2); //Assert action.Should().Throw <ArgumentOutOfRangeException>(); }
public static double ConvertStorageUnit(double unit, StorageUnit convertFromUnit, StorageUnit convertToUnit) { switch (convertFromUnit) { case StorageUnit.Bits: switch (convertToUnit) { case StorageUnit.Bits: return unit; case StorageUnit.Bytes: return unit * 0.125; case StorageUnit.Kilobytes: return unit * 0.0001220703; case StorageUnit.Megabyte: return unit * 0.0000001192; case StorageUnit.GigaBytes: return unit * 0.0000000001; default: throw new NotSupportedException("Cannot convert Bits to " + Enum.GetName(typeof(StorageUnit), convertToUnit)); } case StorageUnit.Bytes: switch (convertToUnit) { case StorageUnit.Bits: return unit * 8; case StorageUnit.Bytes: return unit; case StorageUnit.Kilobytes: return unit * 0.0009765625; case StorageUnit.Megabyte: return unit * 0.0000009536; case StorageUnit.GigaBytes: return unit * 0.0000000009; default: throw new NotSupportedException("Cannot convert Bits to " + Enum.GetName(typeof(StorageUnit), convertToUnit)); } case StorageUnit.Kilobytes: switch (convertToUnit) { case StorageUnit.Bits: return unit * 8192; case StorageUnit.Bytes: return unit * 1024; case StorageUnit.Kilobytes: return unit; case StorageUnit.Megabyte: return unit * 0.0009765625; case StorageUnit.GigaBytes: return unit * 0.0000009536; case StorageUnit.TeraBytes: return unit * 0.0000000009; default: throw new NotSupportedException("Cannot convert Bits to " + Enum.GetName(typeof(StorageUnit), convertToUnit)); } case StorageUnit.Megabyte: switch (convertToUnit) { case StorageUnit.Bits: return unit * 8388608; case StorageUnit.Bytes: return unit * 1048576; case StorageUnit.Kilobytes: return unit * 1024; case StorageUnit.Megabyte: return unit; case StorageUnit.GigaBytes: return unit * 0.0009765625; case StorageUnit.TeraBytes: return unit * 0.0000009536; case StorageUnit.PetaBytes: return unit * 0.0000000009; default: throw new NotSupportedException("Cannot convert Bits to " + Enum.GetName(typeof(StorageUnit), convertToUnit)); } case StorageUnit.GigaBytes: switch (convertToUnit) { case StorageUnit.Bits: return unit * 8589934592; case StorageUnit.Bytes: return unit * 1073741824; case StorageUnit.Kilobytes: return unit * 1048576; case StorageUnit.Megabyte: return unit * 1024; case StorageUnit.GigaBytes: return unit; case StorageUnit.TeraBytes: return unit * 0.0009765625; case StorageUnit.PetaBytes: return unit * 0.0000009536; case StorageUnit.Exabytes: return unit * 0.0000000009; default: throw new NotSupportedException("Cannot convert Bits to " + Enum.GetName(typeof(StorageUnit), convertToUnit)); } case StorageUnit.TeraBytes: switch (convertToUnit) { case StorageUnit.Bits: return unit * 8796093022208; case StorageUnit.Bytes: return unit * 1099511627776; case StorageUnit.Kilobytes: return unit * 1073741824; case StorageUnit.Megabyte: return unit * 1048576; case StorageUnit.GigaBytes: return unit * 1024; case StorageUnit.TeraBytes: return unit; case StorageUnit.PetaBytes: return unit * 0.0009765625; case StorageUnit.Exabytes: return unit * 0.0000009536; case StorageUnit.Zettabytes: return unit * 0.0000000009; default: throw new NotSupportedException("Cannot convert Bits to " + Enum.GetName(typeof(StorageUnit), convertToUnit)); } case StorageUnit.PetaBytes: switch (convertToUnit) { case StorageUnit.Bits: return unit * 9007199254740992; case StorageUnit.Bytes: return unit * 1125899906842624; case StorageUnit.Kilobytes: return unit * 1099511627776; case StorageUnit.Megabyte: return unit * 1073741824; case StorageUnit.GigaBytes: return unit * 1048576; case StorageUnit.TeraBytes: return unit * 1024; case StorageUnit.PetaBytes: return unit; case StorageUnit.Exabytes: return unit * 0.0009765625; case StorageUnit.Zettabytes: return unit * 0.0000009536; default: throw new NotSupportedException("Cannot convert Bits to " + Enum.GetName(typeof(StorageUnit), convertToUnit)); } default: throw new NotSupportedException("Cannot convert from " + Enum.GetName(typeof(StorageUnit), convertFromUnit)); } }