private void Awake() { if (Instance == null) { Instance = this; } }
// Use this for initialization void Start() { currentReplayStep = new ReplayReader.ReplayStep(); alreadyGenerateStatistic = false; matchResults = new List <uint>(); grid = gameObject.GetComponent <Grid>(); scenarioId = grid.scenarioId; academy = FindObjectOfType(typeof(BombermanAcademy)) as BombermanAcademy; playerManager = ServiceLocator.getManager(scenarioId).GetPlayerManager(); bombManager = ServiceLocator.getManager(scenarioId).GetBombManager(); blocksManager = ServiceLocator.getManager(scenarioId).GetBlocksManager(); playerManager.initInitialPositions(grid); ServiceLocator.getManager(scenarioId).GetLogManager().episodePrint(playerManager.getEpisodeCount()); playerManager.setRandomizeIterationOfAgents(randomizeIterationOfAgents); //Vector3 monitorPosition = transform.position + new Vector3(-3, 4, 1); // scene sem imitação Vector3 monitorPosition = transform.position + new Vector3(-6.72f, 4, -4.51f); myMonitor = Instantiate(monitorPrefab, monitorPosition, Quaternion.identity, transform.parent); Monitor.Log("Last Result:", "draw", myMonitor.transform); Monitor.Log("Iteration:", "0 / " + maxIterationString, myMonitor.transform); Monitor.Log("Episode:", "1", myMonitor.transform); Monitor.Log("Scenario:", transform.parent.gameObject.name, myMonitor.transform); iterationWhereWasCreatedBombs = 0; numberOfBombsByCreation = 1; // replay if (saveReplay) { replayWriter = new ReplayWriter(scenarioId); } if (followReplayFile) { replayReader = new ReplayReader(replayFileName); ReplayReader.ReplayStep rStep = replayReader.readStep(ReplayCommandLine.RCL_Episode); if (rStep.command == ReplayCommandLine.RCL_Episode) { currentReplayStep.epId = rStep.epId; } else { Debug.Log("Nao e pra entrar aqui. Leitura de episódio errada"); } } //Debug.Log("Criando MapController"); createAgents(); initBlocks(); wasInitialized = true; reseting = false; }
public static void loadLevel() { string[] lines; lines = System.IO.File.ReadAllLines(@"Assets/Resources/Levels/level_" + (Data.Session.level + 1).ToString() + ".txt"); int levelWidth = System.Convert.ToInt16(lines[0]); int nLines = 0; int[,] arrayTiles = new int[levelWidth, levelWidth]; for (int i = 1; i < lines.Length; i++) { if ((i - 1) % levelWidth == 0 && i != 1) { nLines++; } arrayTiles[(i - 1) - levelWidth * nLines, nLines] = System.Convert.ToInt16(lines[i]); } for (int i = 0; i < arrayTiles.GetLength(1); i++) { for (int j = 0; j < arrayTiles.GetLength(0); j++) { BlocksManager.createBlock(j, i, arrayTiles [j, i]); } } PlayerManager.setLevelInitialPos(Data.Session.level + 1); }
private void OnSceneGUI() { BlocksManager bm = target as BlocksManager; if (bm.Grid == null) { return; } GUIStyle style = new GUIStyle(); style.normal.textColor = new Color(1, 0, 0, 1); style.fontSize = 20; style.fontStyle = FontStyle.Bold; for (int i = 0; i < bm.Grid.GetLength(0); i++) { for (int j = 0; j < bm.Grid.GetLength(1); j++) { Vector3 offset = (i - GameManager.Instance.Width / 2 - 0.5f) * Vector3.right * BlocksManager.Instance.InitSize + (j - GameManager.Instance.Height / 2 + 0.5f) * Vector3.up * BlocksManager.Instance.InitSize; if (bm.ShowGridColor) { Handles.Label(bm.transform.position + offset, bm.Grid[i, j].ToString(), style); } if (bm.ShowGridIndex) { Handles.Label(bm.transform.position + offset, i + "," + j, style); } } } }
public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData) { Type type = GetType(value); switch (type) { case Type.RottenMeat: BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneBlockMesh, color, 2f * size, ref matrix, environmentData); return; case Type.Oil: color = new Color(30, 30, 30); BlocksManager.DrawCubeBlock(primitivesRenderer, Terrain.ReplaceContents(value, 18), new Vector3(size), ref matrix, color, color, environmentData); return; case Type.OilBucket: BlocksManager.DrawMeshBlock(primitivesRenderer, StandaloneBlockMesh, color, 2f * size, ref matrix, environmentData); return; default: color = Colors[(int)type - 1]; BlocksManager.DrawCubeBlock(primitivesRenderer, Terrain.ReplaceContents(value, 18), new Vector3(size), ref matrix, color, color, environmentData); return; } }
void Awake() { if (instance != null) { Debug.LogError("More than one BlockManager"); } instance = this; }
public Managers(int _id) { id = _id; sLogManager = new LogManager(id); sBombManager = new BombManager(); sBlocksManager = new BlocksManager(); myPlayerManager = new PlayerManager(); }
void Start() { gameManager = FindObjectOfType <GameManager>(); blocksManager = FindObjectOfType <BlocksManager>(); meshRenderer = GetComponent <MeshRenderer>(); meshRenderer.material.EnableKeyword("_EMISSION"); originalColor = meshRenderer.material.GetColor("_EmissionColor"); m_audio = GetComponent <AudioSource>(); }
void Start() { playerController = FindObjectOfType <PlayerController>(); blocksManager = FindObjectOfType <BlocksManager>(); scoreMarker = FindObjectOfType <ScoreMarker>(); currentRoundNum = initRound; StartRound(); m_audio = GetComponent <AudioSource>(); }
public CacheManager(string configPath, string blocksPath, BufferManager bufferManager) { _bufferManager = bufferManager; _blocksManager = new BlocksManager(Path.Combine(configPath, "Blocks"), blocksPath, _bufferManager); _contentInfoManager = new ContentInfosManager(); _settings = new Settings(configPath); _checkTimer = new WatchTimer(this.CheckTimer); }
private void Start() { if (Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; } }
// Start is called before the first frame update void Start() { gameManager = FindObjectOfType <GameManager>(); blocksManager = FindObjectOfType <BlocksManager>(); meshRenderer = GetComponent <MeshRenderer>(); meshRenderer.material.EnableKeyword("_EMISSION"); trailRenderer = GetComponent <TrailRenderer>(); trailRenderer.material.EnableKeyword("_EMISSION"); speed = defaultSpeed; m_audio = GetComponent <AudioSource>(); }
protected override void Dispose(bool isDisposing) { if (_isDisposed) { return; } _isDisposed = true; if (isDisposing) { _removedBlockEventQueue.Dispose(); if (_blocksManager != null) { try { _blocksManager.Dispose(); } catch (Exception) { } _blocksManager = null; } if (_checkTimer != null) { try { _checkTimer.Dispose(); } catch (Exception) { } _checkTimer = null; } if (_checkTimer != null) { try { _checkTimer.Dispose(); } catch (Exception) { } _checkTimer = null; } } }
//private int life; void Start() { Panel = GameObject.Find("Panel"); GameOverText = GameObject.Find("GameOverText"); GameClearText = GameObject.Find("GameClearText"); blocksmanager = GameObject.Find("Blocks").GetComponent <BlocksManager>(); endwallscript = GameObject.Find("GameEndWall").GetComponent <EndWallScript>(); //gameover = false; //life = 3; ResetUI(); }
public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData) { int data = Terrain.ExtractData(value); int clothingColor = GetClothingColor(data); MekClothData clothingData = GetClothingData(data); Matrix matrix2 = m_slotTransforms[(int)clothingData.Slot] * Matrix.CreateScale(size) * matrix; if (clothingData.IsOuter) { BlocksManager.DrawMeshBlock(primitivesRenderer, m_outerMesh, clothingData.Texture, color * SubsystemPalette.GetFabricColor(environmentData, clothingColor), 1f, ref matrix2, environmentData); } else { BlocksManager.DrawMeshBlock(primitivesRenderer, m_innerMesh, clothingData.Texture, color * SubsystemPalette.GetFabricColor(environmentData, clothingColor), 1f, ref matrix2, environmentData); } }
public float ApplyArmorProtection(float attackPower) { float num = m_random.UniformFloat(0f, 1f); ClothingSlot slot = (num < 0.1f) ? ClothingSlot.Feet : ((num < 0.3f) ? ClothingSlot.Legs : ((num < 0.9f) ? ClothingSlot.Torso : ClothingSlot.Head)); float num2 = ((MekClothingBlock)BlocksManager.Blocks[1011]).Durability + 1; List <int> list = new List <int>(GetClothes(slot)); for (int i = 0; i < list.Count; i++) { int value = list[i]; MekClothData clothingData = MekClothingBlock.GetClothingData(Terrain.ExtractData(value)); float x = (num2 - (float)BlocksManager.Blocks[1011].GetDamage(value)) / num2 * clothingData.Sturdiness; float num3 = MathUtils.Min(attackPower * MathUtils.Saturate(clothingData.ArmorProtection), x); if (num3 > 0f) { attackPower -= num3; if (m_subsystemGameInfo.WorldSettings.GameMode != 0) { float x2 = num3 / clothingData.Sturdiness * num2 + 0.001f; int damageCount = (int)(MathUtils.Floor(x2) + (float)(m_random.Bool(MathUtils.Remainder(x2, 1f)) ? 1 : 0)); list[i] = BlocksManager.DamageItem(value, damageCount); } if (!string.IsNullOrEmpty(clothingData.ImpactSoundsFolder)) { m_subsystemAudio.PlayRandomSound(clothingData.ImpactSoundsFolder, 1f, m_random.UniformFloat(-0.3f, 0.3f), m_componentBody.Position, 4f, 0.15f); } } } int num4 = 0; while (num4 < list.Count) { if (Terrain.ExtractContents(list[num4]) != 1011) { list.RemoveAt(num4); m_subsystemParticles.AddParticleSystem(new BlockDebrisParticleSystem(m_subsystemTerrain, m_componentBody.Position + m_componentBody.BoxSize / 2f, 1f, 1f, Color.White, 0)); } else { num4++; } } SetClothes(slot, list); return(MathUtils.Max(attackPower, 0f)); }
public void Start() { bm = GameController.GetComponent <BlocksManager>(); canvasGameOverModel.worldCamera = Camera.main; if (PlayerPrefs.HasKey(Key.GameIsSaved) == true) { Debug.Log("try load"); bm.LoadBlocks(); } else { Debug.Log("nothing to load"); bm.GenerateNewLineOfBlocks(); } bestScore = ReadInteger(Key.BestScore); score = ReadInteger(Key.LastScore); ballsAmount = ReadInteger(Key.BallAmount, InitalBallsAmount); updateBallsAmount(); updateScore(); updateBest(); }
public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData) { BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneBlockMesh, color, 2f * size, ref matrix, environmentData); }
void Awake() { Instance = this; }
void Start() { _background = GetComponentInChildren <SpriteRenderer>(); _label = GetComponentInChildren <TextMesh>(); _manager = GetComponentInParent <BlocksManager>(); }
public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData) { BlocksManager.DrawCubeBlock(primitivesRenderer, value, new Vector3(size), ref matrix, color, color, environmentData); }
public void Update(float dt) { if (m_subsystemGameInfo.WorldSettings.GameMode != 0 && m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled && m_subsystemTime.PeriodicGameTimeEvent(0.5, 0.0)) { foreach (int enumValue in EnumUtils.GetEnumValues(typeof(ClothingSlot))) { bool flag = false; m_clothesList.Clear(); m_clothesList.AddRange(GetClothes((ClothingSlot)enumValue)); int num = 0; while (num < m_clothesList.Count) { int value = m_clothesList[num]; MekClothData clothingData = MekClothingBlock.GetClothingData(Terrain.ExtractData(value)); if ((float)clothingData.PlayerLevelRequired > m_componentPlayer.PlayerData.Level) { m_componentGui.DisplaySmallMessage(string.Format("Must be level {0} to wear {1}", new object[2] { clothingData.PlayerLevelRequired, clothingData.DisplayName }), blinking: true, playNotificationSound: true); m_subsystemPickables.AddPickable(value, 1, m_componentBody.Position, null, null); m_clothesList.RemoveAt(num); flag = true; } else { num++; } } if (flag) { SetClothes((ClothingSlot)enumValue, m_clothesList); } } } if (m_subsystemGameInfo.WorldSettings.GameMode != 0 && m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled && m_subsystemTime.PeriodicGameTimeEvent(2.0, 0.0) && ((m_componentLocomotion.LastWalkOrder.HasValue && m_componentLocomotion.LastWalkOrder.Value != Vector2.Zero) || (m_componentLocomotion.LastSwimOrder.HasValue && m_componentLocomotion.LastSwimOrder.Value != Vector3.Zero) || m_componentLocomotion.LastJumpOrder != 0f)) { if (m_lastTotalElapsedGameTime.HasValue) { foreach (int enumValue2 in EnumUtils.GetEnumValues(typeof(ClothingSlot))) { bool flag2 = false; m_clothesList.Clear(); m_clothesList.AddRange(GetClothes((ClothingSlot)enumValue2)); for (int i = 0; i < m_clothesList.Count; i++) { int value2 = m_clothesList[i]; MekClothData clothingData2 = MekClothingBlock.GetClothingData(Terrain.ExtractData(value2)); float num2 = (m_componentVitalStats.Wetness > 0f) ? (10f * clothingData2.Sturdiness) : (20f * clothingData2.Sturdiness); double num3 = MathUtils.Floor(m_lastTotalElapsedGameTime.Value / (double)num2); if (MathUtils.Floor(m_subsystemGameInfo.TotalElapsedGameTime / (double)num2) > num3 && m_random.UniformFloat(0f, 1f) < 0.75f) { m_clothesList[i] = BlocksManager.DamageItem(value2, 1); flag2 = true; } } int num4 = 0; while (num4 < m_clothesList.Count) { if (Terrain.ExtractContents(m_clothesList[num4]) != 1011) { m_clothesList.RemoveAt(num4); m_subsystemParticles.AddParticleSystem(new BlockDebrisParticleSystem(m_subsystemTerrain, m_componentBody.Position + m_componentBody.BoxSize / 2f, 1f, 1f, Color.White, 0)); m_componentGui.DisplaySmallMessage("Your clothing has worn out", blinking: true, playNotificationSound: true); } else { num4++; } } if (flag2) { SetClothes((ClothingSlot)enumValue2, m_clothesList); } } } m_lastTotalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime; } UpdateRenderTargets(); }
public async Task Run(Guid serverId, string vmMoref = null, CancellationToken ctoken = default) { if (backup != null) { return; } this.ctoken = ctoken; Server = await metaDB.GetVMWareServer(serverId, true); backup = new DBBackup { Server = serverId, StartDate = DateTime.UtcNow, Status = Status.Running, Log = new List <string>() }; backup.Id = await metaDB.AddBackup(backup); var vmBackup = new DBVMwareVM { Backup = backup.Id, Moref = vmMoref, StartDate = DateTime.UtcNow, Valid = false, Server = Server.Id }; vmBackup.Id = await metaDB.AddVMwareVM(vmBackup); var snapRef = string.Empty; try { vim25Proxy = new Proxy(Server.Ip); await vim25Proxy.Login(Server.Username, Server.Password); if (vmMoref == null) { int selected = -1; var vmList = (await vim25Proxy.GetVMs()).OrderBy(vm => vm.Name).ToArray(); do { var i = 1; foreach (var vm in vmList) { Console.WriteLine("{0}\t{1}", i++, vm.Name); } Console.WriteLine("Choose a VM: "); if (!int.TryParse(Console.ReadLine(), out selected) || selected < 1 || selected > vmList.Length) { selected = -1; } } while (selected < 1); vmMoref = vmList[selected - 1].MoRef; } CheckCancelStatus(); // Retrieve backup vm info, usefull for backup type var vmPowerState = await vim25Proxy.GetVMPowerState(vmMoref); var(changeTrackingEnabled, changeTrackingSupported) = await vim25Proxy.GetCBTState(vmMoref); // Check and enable CBT if (!changeTrackingEnabled && changeTrackingSupported) { await vim25Proxy.ConfigureForCBT(vmMoref); } // Create backup snapshot snapRef = await vim25Proxy.CreateSnapshot( vmMoref, "BerBackup", $"Backup started at {DateTime.Now}", false, vmPowerState == VirtualMachinePowerState.poweredOn); // Retrieve full vm config from Snapshot var vmConfig = await vim25Proxy.GetVMConfigFromSnapshot(snapRef); vmBackup.Name = vim25Proxy.GetVMConfigParameter(vmConfig, "name") as string; vmBackup.Config = vim25Proxy.SerializeVMConfig(vmConfig); vmBackup.Id = await metaDB.AddVMwareVM(vmBackup); var previousVMBackup = changeTrackingEnabled ? await metaDB.GetLatestVM(serverId, vmMoref) : null; // Initialize VDDK stuff Environment.SetEnvironmentVariable("PATH", @"C:\Users\bedn\source\repos\backup\x64\Debug;C:\VMware-vix-disklib-6.5.2-6195444.x86_64\bin;%PATH%"); var status = VixDiskLib.VixDiskLib_InitEx(6, 0, null, null, null, @"C:\VMware-vix-disklib-6.5.2-6195444.x86_64", null); var connectParams = new VixDiskLibConnectParams { serverName = Server.Ip, thumbPrint = Server.ThumbPrint, credType = VixDiskLibCredType.VIXDISKLIB_CRED_UID, port = 0, nfcHostPort = 0, vmxSpec = string.Format("moref={0}", vmMoref) }; connectParams.creds.uid.userName = Server.Username; connectParams.creds.uid.password = Server.Password; var vixConnHandle = IntPtr.Zero; var vixDiskHandle = IntPtr.Zero; status = VixDiskLib.VixDiskLib_ConnectEx(connectParams, (char)VixDiskLib.TRUE, snapRef, null, out vixConnHandle); var blocksReadBatch = 2048UL; var vddkReadBuffer = new byte[blocksReadBatch * 512]; foreach (var disk in vim25Proxy.GetDisksFromConfig(vmConfig)) { var diskInfo = vim25Proxy.GetDiskInfo(disk); status = VixDiskLib.VixDiskLib_PrepareForAccess(connectParams, "BackupSoft"); status = VixDiskLib.VixDiskLib_Open(vixConnHandle, diskInfo.Path, (uint)VixDiskLib.VIXDISKLIB_FLAG_OPEN_READ_ONLY, out vixDiskHandle); status = VixDiskLib.VixDiskLib_GetMetadataKeys(vixDiskHandle, null, 1, out uint metaLength); var diskMeta = new byte[metaLength]; status = VixDiskLib.VixDiskLib_GetMetadataKeys(vixDiskHandle, diskMeta, metaLength, out metaLength); var dbDisk = new DBVMDisk { VM = vmBackup.Id, Path = diskInfo.Path, Key = diskInfo.Key, ChangeId = diskInfo.ChangeId, Metadata = diskMeta, Length = diskInfo.Capacity, Valid = false }; dbDisk.Id = await metaDB.AddVMDisk(dbDisk); Console.WriteLine(DateTime.Now); Console.WriteLine($"Backup VM disk : {diskInfo.Path}"); var previousChangeId = "*"; var previousDisk = previousVMBackup != null ? await metaDB.GetVMDisk(previousVMBackup.Id, diskInfo.Key) : null; if (previousDisk != null) { previousChangeId = previousDisk.ChangeId; await metaDB.CopyVMDiskBlocks(previousDisk.VM, dbDisk.Id); } long bytestart = 0; long bytelength = 0; ulong iterations; ulong startsector; ulong lastSectors; BlocksManager.dbBlocks = 0; IList <byte[]> blocks; var totalBlocks = 0; int alignoffset = 0; foreach (var(start, length) in await vim25Proxy.GetDiskChangedAreas(vmMoref, snapRef, diskInfo.Key, bytestart, previousChangeId)) { bytestart = start; var _bytestart = await metaDB.GetPreviousVMDiskOffset(dbDisk.Id, bytestart); if (_bytestart > 0) { bytestart = _bytestart; } var _byteend = await metaDB.GetNextVMDiskOffset(dbDisk.VM, start + length); if (_byteend > 0) { bytelength = _byteend - bytestart; } else { bytelength = length; } iterations = (Convert.ToUInt64(bytelength) / 512) / blocksReadBatch; lastSectors = (Convert.ToUInt64(bytelength) / 512) % blocksReadBatch; startsector = Convert.ToUInt64(bytestart) / 512; alignoffset = Convert.ToInt32(bytestart % 512); var startNotAligned = alignoffset > 0; hasher.Initialize(); for (var pos = 0UL; pos < iterations; pos++) { status = VixDiskLib.VixDiskLib_Read(vixDiskHandle, startsector, blocksReadBatch, vddkReadBuffer); startsector += blocksReadBatch; if (startNotAligned) { blocks = hasher.NextBlock(vddkReadBuffer, alignoffset); startNotAligned = false; } else { blocks = hasher.NextBlock(vddkReadBuffer, 0); } foreach (var block in blocks) { var blockGuid = await BlocksManager.AddBlockToDB(block); await metaDB.AddVMDiskBlock(new DBVMDiskBlock { Block = blockGuid, VMDisk = dbDisk.Id, Offset = bytestart }); bytestart += block.Length; totalBlocks++; } } if (lastSectors > 0UL) { status = VixDiskLib.VixDiskLib_Read(vixDiskHandle, startsector, lastSectors, vddkReadBuffer); startsector += lastSectors; if (startNotAligned) { blocks = hasher.NextBlock(vddkReadBuffer, alignoffset, 512 * Convert.ToInt32(lastSectors)); startNotAligned = false; } else { blocks = hasher.NextBlock(vddkReadBuffer, 0, 512 * Convert.ToInt32(lastSectors)); } foreach (var block in blocks) { var blockGuid = await BlocksManager.AddBlockToDB(block); await metaDB.AddVMDiskBlock(new DBVMDiskBlock { Block = blockGuid, VMDisk = dbDisk.Id, Offset = bytestart }); bytestart += block.Length; totalBlocks++; } } if (hasher.HasRemainingBytes) { var diskSizeInSectors = Convert.ToUInt64(diskInfo.Capacity) / 512; while (startsector < diskSizeInSectors) { var readSize = Math.Min(blocksReadBatch, diskSizeInSectors - startsector); status = VixDiskLib.VixDiskLib_Read(vixDiskHandle, startsector, readSize, vddkReadBuffer); startsector += readSize; if (startNotAligned) { blocks = hasher.NextBlock(vddkReadBuffer, alignoffset, Convert.ToInt32(readSize) * 512); startNotAligned = false; } else { blocks = hasher.NextBlock(vddkReadBuffer, 0, Convert.ToInt32(readSize) * 512); } if (blocks.Count > 0) { var block = blocks[0]; var blockGuid = await BlocksManager.AddBlockToDB(block); await metaDB.AddVMDiskBlock(new DBVMDiskBlock { Block = blockGuid, VMDisk = dbDisk.Id, Offset = bytestart }); bytestart += block.Length; totalBlocks++; break; } } if (startsector >= diskSizeInSectors && hasher.HasRemainingBytes) { var block = hasher.RemainingBytes(); var blockGuid = await BlocksManager.AddBlockToDB(block); await metaDB.AddVMDiskBlock(new DBVMDiskBlock { Block = blockGuid, VMDisk = dbDisk.Id, Offset = bytestart }); bytestart += block.Length; totalBlocks++; } } Console.WriteLine(DateTime.Now); Console.WriteLine("Total blocks : " + totalBlocks); Console.WriteLine("DB blocks : " + BlocksManager.dbBlocks); } Console.WriteLine(DateTime.Now); Console.WriteLine("Total blocks : " + totalBlocks); Console.WriteLine("DB blocks : " + BlocksManager.dbBlocks); dbDisk.Valid = true; await metaDB.AddVMDisk(dbDisk); status = VixDiskLib.VixDiskLib_Close(vixDiskHandle); dbDisk.Valid = true; await metaDB.AddVMDisk(dbDisk); } status = VixDiskLib.VixDiskLib_Disconnect(vixConnHandle); VixDiskLib.VixDiskLib_Exit(); vmBackup.EndDate = DateTime.UtcNow; vmBackup.Valid = true; await metaDB.AddVMwareVM(vmBackup); } catch (Exception e) { Console.WriteLine($"{backup.Id} - Backup failed: {e.Message}"); backup.AppendLog(e.Message); backup.Status = Status.Failed; } finally { if (vim25Proxy.IsConnected) { if (snapRef != string.Empty) { await vim25Proxy.RemoveSnapshot(snapRef, false, true); } await vim25Proxy.Logout(); } } vmBackup.EndDate = DateTime.UtcNow; await metaDB.AddVMwareVM(vmBackup); backup.EndDate = DateTime.UtcNow; await metaDB.AddBackup(backup); }
public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData) { BlocksManager.DrawMeshBlock(primitivesRenderer, drawMesh, texture, Color.White, size + 2f, ref matrix, environmentData); }
private async Task BackupFile(BackupItem file) { var totalBlocks = 0; try { var stream = await agentProxy.GetStream(file.StreamGuid); hasher.Initialize(); var dbFile = new DBFile { Name = file.Name, Backup = backup.Id, LastWriteTime = file.LastWriteTime, Length = file.Length, Valid = false }; currentFileId = await metaDB.AddFile(dbFile); dbFile.Id = currentFileId; var currentFilePos = 0L; var buffer = new byte[1024 * 64]; BlocksManager.dbBlocks = 0; Console.WriteLine($"{DateTime.Now} - Backup file: {file.Name}"); IList <byte[]> newbLocks; var readCount = await stream.ReadAsync(buffer, 0, buffer.Length, ctoken); while (readCount > 0) { CheckCancelStatus(); newbLocks = hasher.NextBlock(buffer, 0, readCount); foreach (var newbLock in newbLocks) { CheckCancelStatus(); var blockGuid = await BlocksManager.AddBlockToDB(newbLock); await metaDB.AddFileBlock(new DBFileBlock { Block = blockGuid, File = currentFileId, Offset = currentFilePos }); currentFilePos += newbLock.Length; totalBlocks++; } readCount = await stream.ReadAsync(buffer, 0, buffer.Length, ctoken); } if (hasher.HasRemainingBytes) { var lastLock = hasher.RemainingBytes(); var blockGuid = await BlocksManager.AddBlockToDB(lastLock); await metaDB.AddFileBlock(new DBFileBlock { Block = blockGuid, File = currentFileId, Offset = currentFilePos }); currentFilePos += lastLock.Length; totalBlocks++; } dbFile.Valid = true; await metaDB.AddFile(dbFile); } catch (OperationCanceledException e) { // re-throws OperationCanceled exceptions throw e; } catch (Exception e) { backup.AppendLog($"Error file: {file.Name} --- {e.Message} "); backupStatus = Status.Warning; await metaDB.AddBackup(backup); // Update backup with error } Console.WriteLine($"{DateTime.Now} - Total blocks: {totalBlocks}"); Console.WriteLine($"{DateTime.Now} - DB blocks: {BlocksManager.dbBlocks}"); }