public void TestDriveMapping_A_for_Audiobooks() { { StorageDrive d = MyPCSystemConfiguration.StorageDrives.Find(x => x.DriveLetter.ToLower().StartsWith("a:")); Assert.IsTrue(d.DriveMapping.ToLower().Contains("audio")); //TODO: Add check for specific mapping } }
public void TestDriveMapping_H_for_HomeDirectory() { { StorageDrive d = MyPCSystemConfiguration.StorageDrives.Find(x => x.DriveLetter.ToLower().StartsWith("h:")); Assert.IsTrue(d.DriveMapping.ToLower().Contains("jdaniels")); Console.WriteLine("Drive " + d.DriveLetter + " is mapped to " + d.DriveMapping); } }
public async Task <Guid> Upsert(StorageDrive model) { model.Brand = _appContext.Brands.Find(model.Brand.Id); model.Type = _appContext.StorageDriveTypes.Find(model.Type.Id); _appContext.StorageDrives.Update(model); await _appContext.SaveChangesAsync(); return(model.Id.Value); }
void UpdateServerDetails() { if (server == null) { return; } hostname.text = server.hostname; StorageDrive drive = server.hardDrives[0]; newDriveButton.GetComponentInChildren <Text>().text = "Add New Drive ($" + drive.cost + ")"; serverDetailsLeftTextbox.text = server.processorName + "\n" + server.cpuCores + "/" + server.logicalCores + "\n" + server.cpuUsage.ToString("0.#\\%") + "\n" + "n/a" + "\n\n" + server.customers.Count + "\n" + "n/a" + "\n\n" + server.serverCustomerSatisfaction; serverDetailsRightTextbox.text = drive.name + "\n" + drive.totalCapacity + " GB x" + server.hardDrives.Count + "\n" + server.hardDriveCapacity + "\n" + server.diskUsage.ToString("0.#\\") + " GB / " + server.GetTotalDiskSpace + " GB" + "\n" + server.CalculateDiskPercentage().ToString("0.#\\%") + "\n\n\n" + GameDate.GetMonthNameFromInt(server.originalBuildDate["Month"]) + " " + server.originalBuildDate["Day"] + " Year: " + server.originalBuildDate["Year"] + "\n" + "$" + server.originalServerCost; serverDetailsRevenueInfo.text = "$" + server.serverIncome + "/mo\n" + "$" + server.serverCosts + "/mo\n" + "n/a"; serverProfitTextbox.text = "$" + (server.serverIncome - server.serverCosts) + "/mo"; if (server.hardDrives.Count >= server.hardDriveCapacity) { newDriveButton.interactable = false; } else { newDriveButton.interactable = true; } if (server.acceptCustomers) { acceptNewCustomers.isOn = true; } else { acceptNewCustomers.isOn = false; } recommendedCustomersStatic.text = recommendedCustomers.ToString(); }
public void CheckDefaultDrive(StorageDrive drive, Guid?organizationId) { if (drive.IsDefault.Value) { var defaultDrive = _storageDriveRepository.Find(null).Items.Where(q => q.OrganizationId == organizationId && q.IsDefault == true).FirstOrDefault(); if (defaultDrive != null && defaultDrive.Name != drive.Name) { throw new EntityOperationException($"Default drive {defaultDrive.Name} already exists"); } } }
public Automation AddAutomation(AutomationViewModel request) { var drive = new StorageDrive(); if (string.IsNullOrEmpty(request.DriveId)) { drive = _storageDriveRepository.Find(null, q => q.IsDefault == true).Items?.FirstOrDefault(); if (drive == null) { throw new EntityDoesNotExistException("Default drive does not exist or could not be found"); } else { request.DriveId = drive.Id.ToString(); } } else { drive = _storageDriveRepository.GetOne(Guid.Parse(request.DriveId)); } IFormFile[] fileArray = { request.File }; string shortPath = Path.Combine(drive.Name, "Automations"); string path = Path.Combine(shortPath, request.Id.ToString()); var fileView = new FileFolderViewModel() { Files = fileArray, StoragePath = shortPath, FullStoragePath = path, ContentType = fileArray[0].ContentType, IsFile = true }; CheckStoragePathExists(fileView, request, drive.Name); fileView.StoragePath = fileView.FullStoragePath; fileView = _fileManager.AddFileFolder(fileView, request.DriveId)[0]; var automationEngine = GetAutomationEngine(request.AutomationEngine); var automation = new Automation() { Name = request.Name, AutomationEngine = automationEngine, Id = request.Id, FileId = fileView.Id, OriginalPackageName = request.File.FileName }; AddAutomationVersion(request); return(automation); }
public void AddStorageDrive() { StorageDrive drive = server.hardDrives[0]; if (GameManager.gameManager.MakePurchase(drive.cost)) { server.hardDrives.Add(drive); } else { // We couldn't afford to buy the drive, so provide an error message } }
public async Task <StorageDrive> GetDrive(string id) { try { var drive = await _client.Drives[id] .Request() .GetAsync(); var storageDrive = new StorageDrive { Id = drive.Id, Name = drive.Name }; return(storageDrive); } catch (Exception e) { throw e; } }
public static List <StorageDrive> GetDeviceId() { List <StorageDrive> driveList = new List <StorageDrive>(); ManagementClass mc = new ManagementClass("Win32_LogicalDisk"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { StorageDrive drive = new StorageDrive(); drive.DriveType = (DriveType)(uint)mo["DriveType"]; drive.DriveName = (string)mo["DeviceID"]; drive.SerialNumber = (string)mo["VolumeSerialNumber"]; drive.DriveName = (string)mo["VolumeName"]; drive.DriveAvailability = mo["Availability"] == null || (byte)mo["Availability"] == 0x03; driveList.Add(drive); } return(driveList); }
static void Main(string[] args) { Component ram8 = new DynamicMemory("RAM 8 GB", "DDR3 1600 Mhz", 85); Component ram4 = new DynamicMemory("RAM 4 GB", "DDR3 1066 Mhz", 35); Component simpleRam = new DynamicMemory("Simple RAM 2GB", 10); Component gpuGeForce = new GraphicCard("GeForce GPU", "2Gb DDR5", 100); Component gpuAti = new GraphicCard("Ati Radeon GPU", "1Gb DDR5", 70); Component simpleGpu = new GraphicCard("Simple GPU", 15); Component boardGood = new Motherboard("Intel Desktop Board DH55TC", "Intel H55 Express Chipset", 75); Component simpleBoard = new Motherboard("Simple motherboard", 25); Component intelI7 = new Processor("Intel i3 Processor", "3.4 Ghz Cache: 12Mb", 300); Component intelCeleron = new Processor("Intel Celeron", "2.66 Ghz Cache: 1Mb", 89); Component simpleCpu = new Processor("Simple CPU", 49); Component bigScreen = new Screen("HP Z-24", "24 in FULL HD display", 300); Component simpleScreen = new Screen("Simple Screen - 17 in", 80); Component ssd1Tb = new StorageDrive("Crucial M550", "1TB SSD", 400); Component hdd1Tb = new StorageDrive("HDD", "1TB", 150); Component simpleHdd = new StorageDrive("Simple HDD", "320 Gb", 50); Computer goodComp = new Computer("Zverska-Machine", new Component[] { intelI7, ram8, gpuGeForce, ssd1Tb, bigScreen, boardGood }); Computer workComp = new Computer("Work-Horse", new Component[] { intelCeleron, ram4, gpuAti, hdd1Tb, simpleScreen, boardGood }); Computer averageComp = new Computer("FacebookAndYoutubeAreGreat", new Component[] { simpleCpu, simpleRam, simpleGpu, simpleHdd, simpleScreen, simpleBoard }); Computer simplComputer = new Computer("Email-Opener", new Component[] { simpleCpu, simpleRam, simpleHdd, simpleBoard }); Computer[] computers = new Computer[] { goodComp, workComp, averageComp, simplComputer }; foreach (var computer in computers) { Console.WriteLine(computer); } }
public Task <Guid> Upsert(StorageDrive model) { return(_stogareDriveRepository.Upsert(model)); }
public QueueItemViewModel UpdateAttachedFiles(QueueItem queueItem, UpdateQueueItemViewModel request) { if (queueItem == null) { throw new EntityDoesNotExistException("Queue item could not be found or does not exist"); } UpdateItemsStates(queueItem.QueueId.ToString()); queueItem.DataJson = request.DataJson; queueItem.Event = request.Event; queueItem.ExpireOnUTC = request.ExpireOnUTC; queueItem.PostponeUntilUTC = request.PostponeUntilUTC; queueItem.Name = request.Name; queueItem.QueueId = request.QueueId.Value; queueItem.Source = request.Source; queueItem.Type = request.Type; queueItem.State = request.State; if (queueItem.State == "New") { queueItem.StateMessage = null; queueItem.RetryCount = 0; } //if files don't exist in file manager: add file entity, upload file, and add email attachment attachment entity var attachments = _queueItemAttachmentRepository.Find(null, q => q.QueueItemId == queueItem.Id)?.Items; string hash = string.Empty; if (string.IsNullOrEmpty(request.DriveId)) { var drive = new StorageDrive(); if (attachments.Count() > 0) { var fileToCheck = _storageFileRepository.GetOne(attachments[0].Id.Value); drive = _storageDriveRepository.GetOne(fileToCheck.StorageDriveId.Value); } else { drive = _storageDriveRepository.Find(null, q => q.IsDefault == true).Items?.FirstOrDefault(); } request.DriveId = drive.Id.ToString(); } IFormFile[] filesArray = CheckFiles(request.Files, hash, attachments, request.DriveId); var queueItemAttachments = new List <QueueItemAttachment>(); if (filesArray.Length > 0) { queueItemAttachments = AddNewAttachments(queueItem, filesArray, request.DriveId); } _repo.Update(queueItem); //attach new files QueueItemViewModel response = new QueueItemViewModel(); response = response.Map(queueItem); foreach (var attachment in attachments) { queueItemAttachments.Add(attachment); } response.Attachments = queueItemAttachments; return(response); }
public Asset CreateAsset(Asset asset, IFormFile file, string driveId = null) { AssetNameAvailability(asset); if (asset.Type == "Text") { asset.SizeInBytes = System.Text.Encoding.Unicode.GetByteCount(asset.TextValue); } else if (asset.Type == "Number") { asset.SizeInBytes = System.Text.Encoding.Unicode.GetByteCount(asset.NumberValue.ToString()); } else if (asset.Type == "Json") { asset.SizeInBytes = System.Text.Encoding.Unicode.GetByteCount(asset.JsonValue); } else if (asset.Type == "File") { var drive = new StorageDrive(); if (string.IsNullOrEmpty(driveId)) { drive = _storageDriveRepository.Find(null).Items.Where(q => q.IsDefault == true).FirstOrDefault(); } else { drive = _fileManager.GetDriveById(driveId); } if (drive == null) { throw new EntityDoesNotExistException("Default drive could not be found or does not exist"); } else { driveId = drive.Id.ToString(); } if (file != null) { IFormFile[] fileArray = { file }; asset.Id = Guid.NewGuid(); string shortPath = Path.Combine(drive.Name, "Assets"); var fileView = new FileFolderViewModel() { ContentType = file.ContentType, Files = fileArray, StoragePath = shortPath, IsFile = true }; var request = new AgentAssetViewModel(); request = request.Map(asset, file, drive.Id); CheckStoragePathExists(fileView, request, true, drive); fileView.StoragePath = Path.Combine(shortPath, asset.Id.ToString()); CheckStoragePathExists(fileView, request, true, drive); fileView = _fileManager.AddFileFolder(fileView, driveId)[0]; asset.FileId = fileView.Id; asset.SizeInBytes = file.Length; } else { throw new EntityDoesNotExistException("File does not exist"); } } return(asset); }
public FileFolderViewModel CheckStoragePathExists(FileFolderViewModel view, AgentAssetViewModel request, bool getShortPath, StorageDrive drive) { //check if storage path exists; if it doesn't exist, create folder var folder = _fileManager.GetFileFolderByStoragePath(view.StoragePath, drive.Name); if (folder.Name == null) { string storagePath = view.StoragePath; if (getShortPath) { storagePath = _fileManager.GetShortPath(view.StoragePath); } folder.Name = request.AgentId.ToString(); folder.StoragePath = storagePath; folder.IsFile = false; folder.Size = (request.File == null) ? view.Size : request.File.Length; folder = _fileManager.AddFileFolder(folder, drive.Id.ToString())[0]; } return(folder); }
public Asset CreateAgentAsset(AgentAssetViewModel request) { Asset globalAsset = _repo.Find(null, a => a.Name == request.Name && a.AgentId == null).Items?.FirstOrDefault(); Asset agentAsset = new Asset(); if (globalAsset == null) { throw new EntityDoesNotExistException("No global asset exists with the given name"); } agentAsset.Name = request.Name; agentAsset.AgentId = request.AgentId; agentAsset.Type = globalAsset.Type; AssetNameAvailability(agentAsset); switch (agentAsset.Type.ToLower()) { case "text": if (request.TextValue == null) { agentAsset.TextValue = globalAsset.TextValue; } else { agentAsset.TextValue = request.TextValue; } agentAsset = GetSizeInBytes(agentAsset); break; case "number": if (request.NumberValue == null) { agentAsset.NumberValue = globalAsset.NumberValue; } else { agentAsset.NumberValue = request.NumberValue; } agentAsset = GetSizeInBytes(agentAsset); break; case "json": if (request.JsonValue == null) { agentAsset.JsonValue = globalAsset.JsonValue; } else { agentAsset.JsonValue = request.JsonValue; } agentAsset = GetSizeInBytes(agentAsset); break; case "file": var drive = new StorageDrive(); string driveId = request.DriveId.ToString(); if (string.IsNullOrEmpty(driveId)) { drive = _storageDriveRepository.Find(null).Items.Where(q => q.IsDefault == true).FirstOrDefault(); } else { drive = _fileManager.GetDriveById(driveId); } if (drive == null) { throw new EntityDoesNotExistException("Default drive could not be found or does not exist"); } else { driveId = drive.Id.ToString(); } //if file is in request, use file; else, get file from global asset IFormFile[] fileArray; string agentIdStr = request.AgentId.ToString(); string storagePath = Path.Combine(drive.Name, "Assets", globalAsset.Id.ToString(), agentIdStr); if (request.File != null) { fileArray = new IFormFile[] { request.File }; string fullStoragePath = Path.Combine(storagePath, request.File.FileName); var fileView = new FileFolderViewModel() { ContentType = request.File.ContentType, Files = fileArray, StoragePath = storagePath, IsFile = true, FullStoragePath = fullStoragePath }; CheckStoragePathExists(fileView, request, true, drive); fileView = _fileManager.AddFileFolder(fileView, driveId)[0]; agentAsset.FileId = fileView.Id; agentAsset.SizeInBytes = request.File.Length; } else { var fileViewModel = _fileManager.GetFileFolder(globalAsset.FileId.ToString(), driveId, "Files"); fileViewModel.StoragePath = storagePath; var folder = CheckStoragePathExists(fileViewModel, request, true, drive); fileViewModel = _fileManager.CopyFileFolder(fileViewModel.Id.ToString(), folder.Id.ToString(), driveId, "Files"); agentAsset.FileId = fileViewModel.Id; agentAsset.SizeInBytes = fileViewModel.Size; } break; } return(agentAsset); }
public StorageDrive UpdateDrive(string id, StorageDrive drive, string orgId) { Guid organizationId = Guid.Parse(orgId); Guid entityId = Guid.Parse(id); var existingDrive = _storageDriveRepository.Find(null, q => q.Id == entityId && q.OrganizationId == organizationId).Items.FirstOrDefault(); if (existingDrive == null) { throw new EntityDoesNotExistException("Storage drive could not be found or does not exist"); } var existingDriveName = _storageDriveRepository.Find(null, q => q.Name.ToLower() == existingDrive.Name.ToLower() && q.Id != existingDrive.Id).Items.FirstOrDefault(); if (existingDriveName != null) { throw new EntityAlreadyExistsException("Storage drive with same name already exists"); } if (drive.IsDefault == null) { drive.IsDefault = existingDrive.IsDefault; } CheckDefaultDrive(drive, organizationId); var adapterType = drive.FileStorageAdapterType; if (string.IsNullOrEmpty(adapterType)) { adapterType = AdapterType.AzureBlobStorage.ToString(); } //check if updated storage drive can be updated for the current organization long?maxSizeInBytes = drive.MaxStorageAllowedInBytes; //size of updated drive long?organizationStorage = GetTotalOrganizationStorage(organizationId); //sum of all drives for the current organization long?orgMaxSizeInBytes = _organizationManager.GetMaxStorageInBytes(); //max allowed storage for the current organization long?updatedOrgStorage = maxSizeInBytes + (organizationStorage - existingDrive.MaxStorageAllowedInBytes); //sum of updated drive and all existing drives if (orgMaxSizeInBytes != null && maxSizeInBytes > orgMaxSizeInBytes) { throw new EntityOperationException("Drive size would exceed the allowed storage space for this organization"); } existingDrive.IsDefault = drive.IsDefault; if (!string.IsNullOrEmpty(drive.FileStorageAdapterType)) { existingDrive.FileStorageAdapterType = drive.FileStorageAdapterType; } if (drive.MaxStorageAllowedInBytes != null) { existingDrive.MaxStorageAllowedInBytes = drive.MaxStorageAllowedInBytes; } bool existingDriveHasChildren = false; var existingFolders = _storageFolderRepository.Find(null, q => q.ParentFolderId == existingDrive.Id && q.OrganizationId == organizationId).Items; var existingFiles = _storageFileRepository.Find(null, q => q.StorageFolderId == existingDrive.Id && q.OrganizationId == organizationId).Items; if (existingFolders != null && existingFiles != null) { existingDriveHasChildren = true; } if (existingDriveHasChildren && drive.Name != existingDrive.Name) { throw new EntityOperationException("Drive name cannot be changed except when drive is empty"); } else if (existingDrive.Name != drive.Name) { existingDrive.Name = drive.Name; } _storageDriveRepository.Update(existingDrive); _webhookPublisher.PublishAsync("Files.DriveUpdated", drive.Id.ToString(), drive.Name); return(existingDrive); }
public StorageDrive AddStorageDrive(StorageDrive drive) { Guid?organizationId = _organizationManager.GetDefaultOrganization().Id; var existingDrive = _storageDriveRepository.Find(null).Items?.Where(q => q.OrganizationId == organizationId && q.Name.ToLower() == drive.Name.ToLower()).FirstOrDefault(); if (existingDrive != null) { throw new EntityAlreadyExistsException($"Drive {drive.Name} already exists within this organization"); } CheckDefaultDrive(drive, organizationId); var adapterType = drive.FileStorageAdapterType; if (string.IsNullOrEmpty(adapterType)) { adapterType = AdapterType.LocalFileStorage.ToString(); } //check if a new drive can be created for the current organization long?maxSizeInBytes = drive.MaxStorageAllowedInBytes; //size of new drive long?organizationStorage = GetTotalOrganizationStorage(organizationId); //sum of all drives for the current organization long?orgMaxSizeInBytes = _organizationManager.GetMaxStorageInBytes(organizationId); //max allowed storage for the current organization long?updatedOrgStorage = maxSizeInBytes + organizationStorage; //sum of new drive and all existing drives if (orgMaxSizeInBytes != null && maxSizeInBytes > orgMaxSizeInBytes) { throw new EntityOperationException("Drive size would exceed the allowed storage space for this organization"); } if (string.IsNullOrEmpty(drive.StoragePath)) { drive.StoragePath = drive.Name; } if (drive.MaxStorageAllowedInBytes == null) { drive.MaxStorageAllowedInBytes = orgMaxSizeInBytes; } if (string.IsNullOrEmpty(drive.FileStorageAdapterType)) { drive.FileStorageAdapterType = AdapterType.LocalFileStorage.ToString(); } if (drive.IsDefault == null) { drive.IsDefault = false; } var storageDrive = new StorageDrive() { Name = drive.Name, FileStorageAdapterType = drive.FileStorageAdapterType, OrganizationId = organizationId, StoragePath = drive.StoragePath, CreatedBy = _httpContextAccessor.HttpContext.User.Identity.Name, CreatedOn = DateTime.UtcNow, StorageSizeInBytes = drive.StorageSizeInBytes ?? 0, MaxStorageAllowedInBytes = drive.MaxStorageAllowedInBytes, IsDefault = drive.IsDefault }; _storageDriveRepository.Add(storageDrive); _webhookPublisher.PublishAsync("Files.NewDriveCreated", storageDrive.Id.ToString(), storageDrive.Name); return(storageDrive); }