/// <summary> /// /// </summary> /// <param name="serialNumber"></param> /// <returns></returns> public static Boolean Load(Int32 serialNumber) { if (_fileManager == null) { throw new InvalidOperationException("Progress class not initialized"); } try { // Get the storage device for the player IStorageDevice storage = _fileManager.GetStorageDevice(FileLocationContainer.Player); // Wait until storage container is ready and load the file if (SpinWait.SpinUntil(() => { Thread.MemoryBarrier(); return(storage.IsReady); }, Progress.FileOperationTimeout)) { if (storage.FileExists(".", String.Format(DefaultFileName, serialNumber))) { storage.Load(".", String.Format(DefaultFileName, serialNumber), Load); return(true); } } } catch (Exception) { // Load default if nothing was loaded LoadDefault(serialNumber); } return(false); }
public Init( ILogger logger, IStorageDevice storageDevice) { _logger = logger; _storageDevice = storageDevice; }
/// <summary> /// /// </summary> public static Boolean Save() { if (_fileManager == null) { throw new InvalidOperationException("Progress class not initialized"); } // Get the storage device for the player try { IStorageDevice storage = _fileManager.GetStorageDevice(FileLocationContainer.Player); // Wait until storage container is ready and save the file if (SpinWait.SpinUntil(() => { Thread.MemoryBarrier(); return(storage.IsReady); }, Progress.FileOperationTimeout)) { storage.Save(".", String.Format(DefaultFileName, _current.SerialNumber), Save); return(true); } } catch (Exception) { } return(false); }
public Server(Cpu cpu, Ram ram, IStorageDevice hardDrives, VideoCard videoCard) : base(cpu, ram, hardDrives, videoCard) { if (videoCard.IsMonochrome == false) { throw new ArgumentException("Cannot initialise server with colourful video card"); } }
public void Save(IStorageDevice storageDevice, string path) { using (var stream = storageDevice.Open(path, System.IO.FileMode.Create)) using (var bw = new System.IO.BinaryWriter(stream, Encoding.UTF8, true)) { RecursiveWriteStream(bw, _root); } }
public Computer(Cpu cpu, Ram ram, IStorageDevice storage, VideoCard videoCard) { this.CPU = cpu; this.Ram = ram; this.StorageDevice = storage; this.VideoCard = videoCard; this.motherboard = new Motherboard(this.CPU, this.Ram, VideoCard); }
/// <summary> /// Loads the settings from file /// </summary> /// <param name="name"></param> public static Boolean Load() { if (_fileManager == null) { throw new InvalidOperationException("Settings class not initialized"); } try { #if SILVERLIGHT // Get the storage device for the player IStorageDevice storage = _fileManager.GetStorageDevice(FileLocationContainer.Isolated); // Wait until storage container is ready and save the file Boolean timeout = false; Timer timer = new Timer((a) => timeout = true, null, Settings.FileOperationTimeout, System.Threading.Timeout.Infinite); while (!storage.IsReady && !timeout) { Thread.SpinWait(1000); Thread.MemoryBarrier(); } if (timeout) { throw new Exception("Timeout"); } if (storage.FileExists(".", DefaultFileName)) { storage.Load(".", Settings.DefaultFileName, Load); return(true); } #else // Get the storage device for the player IStorageDevice storage = _fileManager.GetStorageDevice(FileLocationContainer.Player); // Wait until storage container is ready and save the file if (SpinWait.SpinUntil(() => { Thread.MemoryBarrier(); return(storage.IsReady); }, Settings.FileOperationTimeout)) { if (storage.FileExists(".", DefaultFileName)) { storage.Load(".", Settings.DefaultFileName, Load); return(true); } } #endif } catch (Exception) { // Load default if nothing was loaded LoadDefault(); } return(false); }
public StorageManager() { #if WINDOWS_PHONE_7 _storageDevice = new XnaPhoneStorageDevice(); #elif WINDOWS_STOREAPP || WINDOWS_PHONE_8 _storageDevice = new XnaStorageDevice(); #elif UNSUPPORTED _storageDevice = new DummyStorageDevice(); #else _storageDevice = new BasicStorageDevice(); #endif }
public BitRepository( ILogger logger, IStorageDevice storageDevice) { _logger = logger; _storageDevice = storageDevice; if (Utilities.TryFindFolder(Constants.BitFolderName, out string bit_path)) // the full path to .bit folder { _repositoryPath = Path.GetDirectoryName(bit_path); } }
private void SD2toSD1_Click(object sender, RoutedEventArgs e) { if (CannotCopy(SD2s)) { return; } TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Indeterminate; IStorageDevice sd = storageDevices[StorageDevice2.SelectedIndex]; SaveMeta currentmeta = sd2Saves[SD2s.SelectedIndex]; NamedStream[] files = sd.ReadSave(currentmeta.directory); CopySave(currentmeta, GetMetaFromID(sd1Saves, GetGameID(currentmeta.directory)), files, storageDevices[StorageDevice1.SelectedIndex], 1); }
public void CanFindDevice() { //InitialiseTestData(); AzureStorage storage = new AzureStorage(); OverlordIdentity.InitializeUserIdentity(TestData.user_02_id, TestData.user_02_token, new string[0]); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser); IStorageUser user = storage.FindUser(TestData.user_01_id.UrnToGuid(), TestData.user_01_token); Assert.NotNull(user); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindDevice); IStorageDevice device = storage.FindDevice(TestData.device_01_id.UrnToGuid(), TestData.device_01_token); Assert.NotNull(device); }
public static async Task <Tuple <string, string, IList <string> > > AuthenticateDeviceAsync(string id, string token) { AzureStorage storage = new AzureStorage(); IStorageDevice device = await storage.AuthenticateAnonymousDeviceAsync(id.UrnToId(), token); if (device == null) { return(null); } else { return(new Tuple <string, string, IList <string> >(device.Id.ToUrn(), device.Token, device.Sensors.Select(s => s.Key).ToList())); } }
/// <summary> /// /// </summary> public static Boolean Save() { if (_fileManager == null) { throw new InvalidOperationException("Progress class not initialized"); } #if SILVERLIGHT // Get the storage device for the player IStorageDevice storage = _fileManager.GetStorageDevice(FileLocationContainer.Isolated); Boolean timeout = false; Timer timer = new Timer((a) => timeout = true, null, PlayerProgress.FileOperationTimeout, System.Threading.Timeout.Infinite); while (!storage.IsReady && !timeout) { Thread.SpinWait(1000); Thread.MemoryBarrier(); } if (timeout) { return(false); } storage.Save(".", String.Format(DefaultFileName, _current.SerialNumber), Save); return(true); #else try { // Get the storage device for the player IStorageDevice storage = _fileManager.GetStorageDevice(FileLocationContainer.Player); // Wait until storage container is ready and save the file if (SpinWait.SpinUntil(() => { Thread.MemoryBarrier(); return(storage.IsReady); }, PlayerProgress.FileOperationTimeout)) { storage.Save(".", String.Format(DefaultFileName, _current.SerialNumber), Save); return(true); } } catch (Exception) { } return(false); #endif }
private void SD2Delete_Click(object sender, RoutedEventArgs e) { if (SD2s.SelectedIndex == -1) { return; } SaveMeta srcMeta = sd2Saves[SD2s.SelectedIndex]; IStorageDevice sd = storageDevices[StorageDevice2.SelectedIndex]; MessageBoxResult a = MessageBox.Show($"Delete {GetGameID(srcMeta.directory)} save file from {sd.GetDeviceName()}?", "Warning", MessageBoxButton.YesNo); if (a == MessageBoxResult.Yes) { sd.DeleteSave(GetGameID(srcMeta.directory)); MessageBox.Show("Save file deleted"); UpdateStorageDeviceItems(); } }
public void CanAddDeviceReadingParallel() { Dictionary <int, IStorageDevice> devices = new Dictionary <int, IStorageDevice>(); OverlordIdentity.InitializeAnonymousIdentity(); AzureStorage storage = new AzureStorage(); storage.AuthenticateAnonymousUser(TestData.user_02_id.UrnToId(), TestData.user_02_token); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser); IStorageUser user = storage.GetCurrentUser(); for (int i = 0; i <= 5; i++) { OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDevice); IStorageDevice device = storage.AddDevice(user, "xUnit_CanAddDevicereadingParallel_Device_" + i.ToString(), "xUnit_CanAddDevicereadingParallel_Device_Token", null, null); devices.Add(i, device); } OverlordIdentity.InitializeAnonymousIdentity(); Parallel.For(0, devices.Count, d => { Log.Partition(); storage.AuthenticateAnonymousDevice(devices[d].Id.ToUrn(), devices[0].Token); IDictionary <string, object> sensor_values = TestData.GenerateRandomSensorData(10); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading); storage.AddDeviceReading(TestData.GenerateRandomTime(null, null, null, null), sensor_values); //Sleep for a random interval Thread.Sleep(TestData.GenerateRandomInteger(0, 1000)); //Add another set of sensor data OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading); storage.AddDeviceReading(TestData.GenerateRandomTime(null, null, null, null), TestData.GenerateRandomSensorData(sensor_values)); //Sleep for a random interval Thread.Sleep(TestData.GenerateRandomInteger(0, 1000)); //Add another set of sensor data OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading); storage.AddDeviceReading(TestData.GenerateRandomTime(null, null, null, null), TestData.GenerateRandomSensorData(sensor_values)); }); }
public static FileList FromRepositoryIndex(IStorageDevice storageDevice, string path) { path = System.IO.Path.GetFullPath(path); var fileList = new FileList(); if (System.IO.File.Exists(path)) { using (var stream = storageDevice.Open(path, System.IO.FileMode.Open)) using (var br = new System.IO.BinaryReader(stream, Encoding.UTF8, true)) { RecursiveReadStream(br, fileList._root); } } return(fileList); }
/// <summary> /// /// </summary> public static Boolean Save() { if (_fileManager == null) { throw new InvalidOperationException("Settings class not initialized"); } // Get the storage device for the player IStorageDevice storage = _fileManager.GetStorageDevice(FileLocationContainer.Player); // Wait until storage container is ready and save the file if (SpinWait.SpinUntil(() => { Thread.MemoryBarrier(); return(storage.IsReady); }, Settings.FileOperationTimeout)) { storage.Save(".", Settings.DefaultFileName, Save); return(true); } return(false); }
public void CanAddDeviceReading() { OverlordIdentity.InitializeAnonymousIdentity(); AzureStorage storage = new AzureStorage(); storage.AuthenticateAnonymousDevice(TestData.device_01_id.UrnToId(), TestData.device_01_token); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindDevice); IStorageDevice device = storage.GetCurrentDevice(); IDictionary <string, object> sensor_values = TestData.GenerateRandomSensorData(10); foreach (KeyValuePair <string, object> s in sensor_values) { OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddSensor); storage.AddSensor(s.Key, "CanAddDeviceReading_Test", null, null); } OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading); storage.AddDeviceReading(DateTime.Now, sensor_values); }
public void CanAddDevice() { AzureStorage storage = new AzureStorage(); OverlordIdentity.InitializeUserIdentity(TestData.user_02_id, TestData.user_02_token, new string[0]); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser); IStorageUser user = storage.FindUser(TestData.user_02_id.UrnToGuid(), TestData.user_02_token); Assert.NotNull(user); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDevice); IStorageDevice device = storage.AddDevice(user, "xUnit_CanAddDeviceTest_Name", "xUnit_CanAddDeviceTest_Token", null); Assert.NotNull(device.Id); Assert.Equal("xUnit_CanAddDeviceTest_Name", device.Name); Assert.Equal("xUnit_CanAddDeviceTest_Token", device.Token); Assert.True(user.Devices.Contains(device.Id)); }
private void InitialiseTestData() { AzureStorage storage = new AzureStorage(); OverlordIdentity.InitializeUserIdentity(TestData.user_02_id, TestData.user_02_token, new string[0]); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser); IStorageUser user = storage.FindUser(TestData.user_02_id.UrnToGuid(), TestData.user_02_token); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDevice); IStorageDevice device_01 = storage.AddDevice(user, TestData.device_01_name, TestData.device_01_token, null, TestData.device_01_id); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser); //user = storage.FindUser(AzureStorageTests.user_02_id.UrnToGuid(), AzureStorageTests.user_02_token); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDevice); IStorageDevice device_02 = storage.AddDevice(user, TestData.device_02_name, TestData.device_02_token, null, TestData.device_02_id); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser); //user = storage.FindUser(AzureStorageTests.user_02_id.UrnToGuid(), AzureStorageTests.user_02_token); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDevice); IStorageDevice device_03 = storage.AddDevice(user, TestData.device_03_name, TestData.device_03_token, null, TestData.device_03_id); }
public Laptop(Cpu cpu, Ram ram, IStorageDevice hardDrives, VideoCard videoCard, LaptopBattery battery) : base(cpu, ram, hardDrives, videoCard) { this.battery = battery; }
public void CopySave(SaveMeta srcMeta, SaveMeta otherMeta, NamedStream[] files, IStorageDevice dest, int updateDevice) { SetMgrEnabled(false); string id = GetGameID(srcMeta.directory); if (dest.HasSave(id)) { if (otherMeta == null) { MessageBoxResult a = MessageBox.Show("Save data in destination directory is corrupted (no PARAM.SFO file). Overwrite?", "", MessageBoxButton.YesNo); if (a == MessageBoxResult.Yes) { dest.DeleteSave(GetGameID(srcMeta.directory)); dest.WriteSave(GetGameID(srcMeta.directory), files); MessageBox.Show("Copied"); } SetMgrEnabled(true); } else { CompareWindow a = new CompareWindow(otherMeta, srcMeta, dest.GetDeviceName(), delegate { try { dest.DeleteSave(GetGameID(srcMeta.directory)); dest.WriteSave(GetGameID(srcMeta.directory), files); MessageBox.Show("Copied"); } catch (IOException) { MessageBox.Show("Copy operation failed"); } foreach (NamedStream b in files) { b.stream.Dispose(); } }, delegate { TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None; SetMgrEnabled(true); UpdateStorageDeviceItems(updateDevice); }); a.Show(); } /*MessageBoxResult a = MessageBox.Show($"Destination already has a {GetGameID(srcMeta.directory)} save file. Overwrite?", "Warning", MessageBoxButton.YesNo); * if (a == MessageBoxResult.No) * { * SD1s.IsEnabled = true; * SD2s.IsEnabled = true; * return; * } * else * { * dest.DeleteSave(GetGameID(srcMeta.directory)); * }*/ } else { try { dest.WriteSave(GetGameID(srcMeta.directory), files); MessageBox.Show("Copied"); } catch (IOException) { MessageBox.Show("Copy operation failed"); } foreach (NamedStream b in files) { b.stream.Dispose(); } TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None; SetMgrEnabled(true); UpdateStorageDeviceItems(updateDevice); } }
public PC(Cpu cpu, Ram ram, IStorageDevice hardDrives, VideoCard videoCard) : base(cpu, ram, hardDrives, videoCard) { }
public StorageManager(IStorageDevice storageDevice) { _storageDevice = storageDevice; }
private void CreateDeviceReadings() { IList <IStorageChannel> channels = CreateSensorChannels(); Dictionary <int, IStorageDevice> devices = new Dictionary <int, IStorageDevice>(); OverlordIdentity.InitializeAnonymousIdentity(); AzureStorage storage = new AzureStorage(); storage.AuthenticateAnonymousUser(TestData.user_02_id.UrnToId(), TestData.user_02_token); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser); IStorageUser user = storage.GetCurrentUser(); for (int i = 0; i <= 5; i++) { OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDevice); IStorageDevice device = storage.AddDevice(user, "xUnit_IngestTests_Device_" + i.ToString(), "xUnit_IngestTests_Device_Token", null, null); devices.Add(i, device); } IDictionary <int, IDictionary <string, object> > sensor_values = new Dictionary <int, IDictionary <string, object> >(6); for (int d = 0; d <= 5; d++) { sensor_values[d] = TestData.GenerateRandomSensorData(10); foreach (string s in sensor_values[d].Keys) { IStorageSensor sensor = new IStorageSensor() { DeviceId = devices[d].Id, Name = s, Channels = new List <Guid>() }; List <IStorageAlert> alerts = new List <IStorageAlert>(); foreach (IStorageChannel channel in channels.Where(c => c.SensorType.ToSensorType() == sensor.Name.ToSensorType())) { sensor.Channels.Add(channel.Id); } OverlordIdentity.AddClaim(Resource.Storage, StorageAction.UpdateDevice); devices[d].Sensors.Add(new KeyValuePair <string, IStorageSensor>(s, sensor)); devices[d] = storage.UpdateDevice(devices[d]); } } OverlordIdentity.InitializeAnonymousIdentity(); storage.AuthenticateAnonymousDevice(devices[0].Id.ToUrn(), devices[0].Token); for (int d = 0; d < devices.Count(); d++) { //Log.Partition(); OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading); storage.AddDeviceReading(devices[d], TestData.GenerateRandomTime(null, null, null, null), sensor_values[d]); //Sleep for a random interval Thread.Sleep(TestData.GenerateRandomInteger(0, 1000)); //Add another set of sensor data OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading); storage.AddDeviceReading(devices[d], TestData.GenerateRandomTime(null, null, null, null), TestData.GenerateRandomSensorData(sensor_values[d])); //Sleep for a random interval Thread.Sleep(TestData.GenerateRandomInteger(0, 1000)); //Add another set of sensor data OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading); storage.AddDeviceReading(devices[d], TestData.GenerateRandomTime(null, null, null, null), TestData.GenerateRandomSensorData(sensor_values[d])); } }