Пример #1
0
        /// <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);
        }
Пример #2
0
 public Init(
     ILogger logger,
     IStorageDevice storageDevice)
 {
     _logger        = logger;
     _storageDevice = storageDevice;
 }
Пример #3
0
        /// <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);
        }
Пример #4
0
 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");
     }
 }
Пример #5
0
 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);
         }
 }
Пример #6
0
        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);
        }
Пример #7
0
        /// <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);
        }
Пример #8
0
        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
        }
Пример #9
0
        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);
            }
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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
        }
Пример #14
0
        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();
            }
        }
Пример #15
0
        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));
            });
        }
Пример #16
0
        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);
        }
Пример #17
0
        /// <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);
        }
Пример #18
0
        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);
        }
Пример #19
0
        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));
        }
Пример #20
0
        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);
        }
Пример #21
0
 public Laptop(Cpu cpu, Ram ram, IStorageDevice hardDrives, VideoCard videoCard, LaptopBattery battery)
     : base(cpu, ram, hardDrives, videoCard)
 {
     this.battery = battery;
 }
Пример #22
0
        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);
            }
        }
Пример #23
0
 public PC(Cpu cpu, Ram ram, IStorageDevice hardDrives, VideoCard videoCard)
     : base(cpu, ram, hardDrives, videoCard)
 {
 }
Пример #24
0
 public StorageManager(IStorageDevice storageDevice)
 {
     _storageDevice = storageDevice;
 }
Пример #25
0
        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]));
            }
        }