public void ExecuteCargoShift() { int ballastMass = 123030; if (step) { foreach (IMyInventory ContainerBase in ContainerBases) { foreach (IMyInventory ContainerEnd in ContainerEnds) { ContainerBase.TransferItemFrom(ContainerEnd, 0, 0, true, ballastMass / (ContainerBases.Count * ContainerEnds.Count)); } } } else { foreach (IMyInventory ContainerEnd in ContainerEnds) { foreach (IMyInventory ContainerBase in ContainerBases) { ContainerEnd.TransferItemFrom(ContainerBase, 0, 0, true, ballastMass / (ContainerBases.Count * ContainerEnds.Count)); } } } }
static Publisher() { _trackerBlock = new ActionBlock<ContainerBase>(async tc => { try { ContainerBase trackerContainer = tc; if (_firstTC == null) _firstTC = trackerContainer; else if (_firstTC == trackerContainer && !_trackerBlockCancellationTokenSource.IsCancellationRequested) { try { await Task.Delay(TimeSpan.FromSeconds(15), _trackerBlockCancellationTokenSource.Token) .ConfigureAwait(false); } catch (OperationCanceledException) { Configurator.Configuration.Logger.Info("Task.Delay exiting"); } } foreach ( TrackerData td in trackerContainer.GetTrackerData(_trackerBlockCancellationTokenSource.IsCancellationRequested) ) { _publisherBlock.Post(td); } } catch (Exception ex) { Configurator.Configuration.Logger.Error(ex.Message, ex); } finally { if (!_trackerBlockCancellationTokenSource.IsCancellationRequested) _trackerBlock.Post(tc); else if (_trackerBlock.InputCount == 0) _trackerBlock.Complete(); } }); _publisherBlock = new ActionBlock<TrackerData>(tc => { try { _lastPersistanceComplete = false; Configurator.Configuration.Persister.Persist(tc); _lastPersistanceComplete = true; } catch (Exception ex) { Configurator.Configuration.Logger.Error(ex.Message, ex); _lastPersistanceComplete = true; } }, new ExecutionDataflowBlockOptions {MaxDegreeOfParallelism = 4}); }
public bool IsEndGameSatisfied() { ContainerBase actualEntity = null; // NB. only support an end-game if Peggy is in the same room // (ie. only check the current room for the end-game Character // or container. if (_endGameCondition.Type.Equals("character")) { actualEntity = Peggy.CurrentRoom.GetCharacterByName(_endGameCondition.EntityName); } else if (_endGameCondition.Type.Equals("container")) { actualEntity = Peggy.CurrentRoom.GetContainerByName(_endGameCondition.EntityName); } if (actualEntity == null) { // The end-game Character or Container isn't in Peggy's current room return(false); } foreach (string requiredItem in _endGameCondition.RequiredItems) { if (!actualEntity.HasItemWithId(requiredItem)) { return(false); } } return(true); }
/// <summary> /// Helper function to convert ps backup container model from service response. /// </summary> public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionContainerResource protectionContainer) { ContainerBase containerModel = null; if (protectionContainer != null && protectionContainer.Properties != null) { if (protectionContainer.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.IaaSVMContainer))) { containerModel = new AzureVmContainer(protectionContainer); } else if (protectionContainer.Properties.GetType() == typeof(ServiceClientModel.MabContainer)) { containerModel = new MabContainer(protectionContainer); } else if (protectionContainer.Properties.GetType() == typeof(ServiceClientModel.AzureSqlContainer)) { containerModel = new AzureSqlContainer(protectionContainer); } else if (protectionContainer.Properties.GetType() == typeof(ServiceClientModel.AzureStorageContainer)) { containerModel = new AzureFileShareContainer(protectionContainer); } else if (protectionContainer.Properties.GetType() == typeof(ServiceClientModel.AzureVMAppContainerProtectionContainer)) { containerModel = new AzureVmWorkloadContainer(protectionContainer); } } return(containerModel); }
private bool CheckContainersNotOnGround(ContainerBase mainContainer, LoadingContainer loadingContainer, HashSet <LoadingContainer> loadedContainers) { var ppp = new Dictionary <Vector, bool>(); ppp.Add(loadingContainer.Position.Shift(loadingContainer.ContainerType.Length, 0, 0), false); ppp.Add(loadingContainer.Position.Shift(0, loadingContainer.ContainerType.Width, 0), false); ppp.Add(loadingContainer.Position.Shift(loadingContainer.ContainerType.Length, loadingContainer.ContainerType.Width, 0), false); foreach (var item in loadedContainers) { if (ppp.Values.All(c => c)) { return(true); } foreach (var point in ppp) { if (item.Position.X < point.Key.X && item.Position.X + item.ContainerType.Length < point.Key.X && item.Position.Z < point.Key.Z && item.Position.Z + item.ContainerType.Width < point.Key.Z && item.ContainerType.Height == point.Key.Y) { ppp[point.Key] = true; } } } if (ppp.Values.All(c => c)) { return(true); } return(false); }
public void Load( ContainerBase mainContainer, Dictionary <Container, int> containers ) { HashSet <LoadingContainer> loadedContainers = new HashSet <LoadingContainer>(); IList <Vector> startCoord = new List <Vector> { new Vector(0, 0, 0) }; foreach (var item in containers) { var loadingContainer = new LoadingContainer() { ContainerType = item.Key, Position = GetCoord(startCoord) }; while (item.Value > 0 && TryAddContainer(mainContainer, loadingContainer, loadedContainers)) { loadedContainers.Add(loadingContainer); containers[item.Key]--; startCoord.Add(loadingContainer.Position.Shift(loadingContainer.ContainerType.Length, 0, 0)); startCoord.Add(loadingContainer.Position.Shift(0, loadingContainer.ContainerType.Width, 0)); startCoord.Add(loadingContainer.Position.Shift(loadingContainer.ContainerType.Length, loadingContainer.ContainerType.Width, 0)); startCoord.Add(loadingContainer.Position.Shift(0, 0, loadingContainer.ContainerType.Height)); startCoord.Remove(loadingContainer.Position); } } }
private static void postTrackers(ContainerBase trackerContainer, bool flushAll) { foreach (TrackerData td in trackerContainer.GetTrackerData(flushAll, Configurator.Configuration.Persister.PersistPreAggregatedBuckets)) { _publisherBlock.Post(td); } }
private bool TryAddContainer(ContainerBase mainContainer, LoadingContainer loadingContainer, HashSet <LoadingContainer> loadedContainers) { if (loadingContainer.Position.Y != 0 && CheckContainersNotOnGround(mainContainer, loadingContainer, loadedContainers)) { return(true); } return(false); }
private void PrepCore(App app, Guid entityGuid, string fieldName, bool usePortalRoot) { var tenant = new DnnTenant(Dnn.Portal); AdamAppContext = new AdamAppContext(tenant, app, SxcInstance); ContainerContext = usePortalRoot ? new ContainerOfTenant(AdamAppContext) as ContainerBase : new ContainerOfField(AdamAppContext, entityGuid, fieldName); }
private void PrepCore(App app, Guid entityGuid, string fieldName, bool usePortalRoot) { Log.Add("PrepCore(...)"); var dnn = new DnnHelper(SxcInstance?.EnvInstance); var tenant = new DnnTenant(dnn.Portal); AdamAppContext = new AdamAppContext(tenant, app, SxcInstance, Log); ContainerContext = usePortalRoot ? new ContainerOfTenant(AdamAppContext) as ContainerBase : new ContainerOfField(AdamAppContext, entityGuid, fieldName); }
private static void initialize() { _trackerBlockCancellationTokenSource = new CancellationTokenSource(); _lastPersistanceComplete = false; _firstTC = null; _trackerBlock = new ActionBlock<ContainerBase>((Func<ContainerBase, Task>) measureAccumulator); _publisherBlock = new ActionBlock<TrackerData>((Action<TrackerData>) trackerWriter, new ExecutionDataflowBlockOptions {MaxDegreeOfParallelism = 4}); }
private void PrepCore(IApp app, Guid entityGuid, string fieldName, bool usePortalRoot) { Log.Add("PrepCore(...)"); var dnn = new DnnContext(BlockBuilder?.Container); var tenant = new DnnTenant(dnn.Portal); AdamAppContext = new AdamAppContext(tenant, app, BlockBuilder, 10, Log); ContainerContext = usePortalRoot ? new ContainerOfTenant(AdamAppContext) as ContainerBase : new ContainerOfField(AdamAppContext, entityGuid, fieldName); }
public static void InitN() { System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; HiddenAccessN.init(); LoggerN.IsSafeThread = true; LoggerN.setLogListener(new Logger(true)); HiddenAccessN.randomHelper = new RandomFactory(true); var versionManager = Bridge.Cast <IVersionManagerBase>(ContainerBase.getComponent(IVersionManagerBase_._class)); int currentVersion = versionManager.getVersionAsInt(); RbSerializer.Init(currentVersion); RbSerializerN.Init(currentVersion); RbSerializerN.register(typeof(RobotStatus), RbSerializerN.RobotStatus_TYPE); RbSerializerN.register(typeof(BattleResults), RbSerializerN.BattleResults_TYPE); RbSerializerN.register(typeof(Bullet), RbSerializerN.Bullet_TYPE); RbSerializerN.register(typeof(RobotStatics), RbSerializerN.RobotStatics_TYPE); // events RbSerializerN.register(typeof(RoundEndedEvent), RbSerializerN.RoundEndedEvent_TYPE); RbSerializerN.register(typeof(BattleEndedEvent), RbSerializerN.BattleEndedEvent_TYPE); RbSerializerN.register(typeof(BulletHitBulletEvent), RbSerializerN.BulletHitBulletEvent_TYPE); RbSerializerN.register(typeof(BulletHitEvent), RbSerializerN.BulletHitEvent_TYPE); RbSerializerN.register(typeof(BulletMissedEvent), RbSerializerN.BulletMissedEvent_TYPE); RbSerializerN.register(typeof(DeathEvent), RbSerializerN.DeathEvent_TYPE); RbSerializerN.register(typeof(WinEvent), RbSerializerN.WinEvent_TYPE); RbSerializerN.register(typeof(HitWallEvent), RbSerializerN.HitWallEvent_TYPE); RbSerializerN.register(typeof(RobotDeathEvent), RbSerializerN.RobotDeathEvent_TYPE); RbSerializerN.register(typeof(SkippedTurnEvent), RbSerializerN.SkippedTurnEvent_TYPE); RbSerializerN.register(typeof(ScannedRobotEvent), RbSerializerN.ScannedRobotEvent_TYPE); RbSerializerN.register(typeof(HitByBulletEvent), RbSerializerN.HitByBulletEvent_TYPE); RbSerializerN.register(typeof(HitRobotEvent), RbSerializerN.HitRobotEvent_TYPE); RbSerializerN.register(typeof(KeyPressedEvent), RbSerializerN.KeyPressedEvent_TYPE); RbSerializerN.register(typeof(KeyReleasedEvent), RbSerializerN.KeyReleasedEvent_TYPE); RbSerializerN.register(typeof(KeyTypedEvent), RbSerializerN.KeyTypedEvent_TYPE); RbSerializerN.register(typeof(MouseClickedEvent), RbSerializerN.MouseClickedEvent_TYPE); RbSerializerN.register(typeof(MouseDraggedEvent), RbSerializerN.MouseDraggedEvent_TYPE); RbSerializerN.register(typeof(MouseEnteredEvent), RbSerializerN.MouseEnteredEvent_TYPE); RbSerializerN.register(typeof(MouseExitedEvent), RbSerializerN.MouseExitedEvent_TYPE); RbSerializerN.register(typeof(MouseMovedEvent), RbSerializerN.MouseMovedEvent_TYPE); RbSerializerN.register(typeof(MousePressedEvent), RbSerializerN.MousePressedEvent_TYPE); RbSerializerN.register(typeof(MouseReleasedEvent), RbSerializerN.MouseReleasedEvent_TYPE); RbSerializerN.register(typeof(MouseWheelMovedEvent), RbSerializerN.MouseWheelMovedEvent_TYPE); RbSerializerN.register(typeof(ExecCommands), RbSerializerN.ExecCommands_TYPE); RbSerializerN.register(typeof(BulletCommand), RbSerializerN.BulletCommand_TYPE); RbSerializerN.register(typeof(TeamMessage), RbSerializerN.TeamMessage_TYPE); RbSerializerN.register(typeof(DebugProperty), RbSerializerN.DebugProperty_TYPE); RbSerializerN.register(typeof(ExecResults), RbSerializerN.ExecResults_TYPE); RbSerializerN.register(typeof(BulletStatus), RbSerializerN.BulletStatus_TYPE); }
private static void initialize() { _trackerBlockCancellationTokenSource = new CancellationTokenSource(); _lastPersistanceComplete = false; _firstTC = null; _trackerBlock = new ActionBlock <ContainerBase>((Func <ContainerBase, Task>)measureAccumulator); _publisherBlock = new ActionBlock <TrackerData>((Action <TrackerData>)trackerWriter, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 4 }); }
public void RegisterContainer() { string vaultName = (string)ProviderData[VaultParams.VaultName]; string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; string containerName = (string)ProviderData[ContainerParams.Name]; string backupManagementType = (string)ProviderData[ContainerParams.BackupManagementType]; string workloadType = (string)ProviderData[ContainerParams.ContainerType]; ContainerBase containerBase = (ContainerBase)ProviderData[ContainerParams.Container]; AzureVmWorkloadContainer container = (AzureVmWorkloadContainer)ProviderData[ContainerParams.Container]; ProtectionContainerResource protectionContainerResource = null; //Trigger Discovery ODataQuery <BMSRefreshContainersQueryObject> queryParam = new ODataQuery <BMSRefreshContainersQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureWorkload); AzureWorkloadProviderHelper.RefreshContainer(vaultName, vaultResourceGroupName, queryParam); List <ProtectableContainerResource> unregisteredVmContainers = GetUnRegisteredVmContainers(vaultName, vaultResourceGroupName); ProtectableContainerResource unregisteredVmContainer = unregisteredVmContainers.Find( vmContainer => string.Compare(vmContainer.Name.Split(';').Last(), containerName, true) == 0); if (unregisteredVmContainer != null || container != null) { protectionContainerResource = new ProtectionContainerResource(container != null ? container.Id : unregisteredVmContainer.Id, container != null ? container.Name : unregisteredVmContainer.Name); AzureVMAppContainerProtectionContainer azureVMContainer = new AzureVMAppContainerProtectionContainer( friendlyName: containerName, backupManagementType: backupManagementType, sourceResourceId: container != null ? container.SourceResourceId : unregisteredVmContainer.Properties.ContainerId, workloadType: workloadType.ToString(), operationType: container != null ? OperationType.Reregister : OperationType.Register); protectionContainerResource.Properties = azureVMContainer; AzureWorkloadProviderHelper.RegisterContainer(container != null ? container.Name : unregisteredVmContainer.Name, protectionContainerResource, vaultName, vaultResourceGroupName); } else { throw new ArgumentException(string.Format(Resources.AzureWorkloadAlreadyRegisteredException)); } }
/// <summary> /// Helper function to convert ps backup container model from service response. /// </summary> public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionContainerResource protectionContainer) { ContainerBase containerModel = null; if (protectionContainer != null && protectionContainer.Properties != null) { if (protectionContainer.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureIaaSVMProtectionContainer))) { containerModel = new AzureVmContainer(protectionContainer); } if (protectionContainer.Properties.GetType() == typeof(ServiceClientModel.MabProtectionContainer)) { containerModel = new MabContainer(protectionContainer); } } return(containerModel); }
protected override ContainerBase LinkedItemLoader(string name) { ContainerBase result = null; if (Application != null) { result = Application.Groups[name]; if (result == null) { result = Application.Store.Groups[name]; } } else { result = Store.Groups[name]; } return(result); }
private void Start() { timesUpdated = 0; spriteR = GetComponent <SpriteRenderer>(); allContainers = transform.parent.GetComponentsInChildren <ContainerBase>(); foreach (var t in allContainers) { if (t.tag == "shaftContainerElement") { loadingPosition = t; } else { unloadingPosition = t; } } loadingContainer = loadingPosition; manager = transform.parent.GetComponentInChildren <Manager>(); }
private static async Task measureAccumulator(ContainerBase tc) { try { ContainerBase trackerContainer = tc; if (_firstTC == null) { _firstTC = trackerContainer; } else if (_firstTC == trackerContainer && !_trackerBlockCancellationTokenSource.IsCancellationRequested) { try { await Task.Delay(TimeSpan.FromSeconds(15), _trackerBlockCancellationTokenSource.Token).ConfigureAwait(false); } catch (OperationCanceledException) { Configurator.Configuration.Logger.Info("Task.Delay exiting"); } } postTrackers(trackerContainer, _trackerBlockCancellationTokenSource.IsCancellationRequested); } catch (Exception ex) { Configurator.Configuration.Logger.Error(ex.Message, ex); } finally { if (!_trackerBlockCancellationTokenSource.IsCancellationRequested) { _trackerBlock.Post(tc); } else if (_trackerBlock.InputCount == 0) { _trackerBlock.Complete(); } } }
private WorkloadProtectableItemResource GetAzureFileShareProtectableObject( string azureFileShareName, string storageAccountName, string vaultName = null, string vaultResourceGroupName = null) { //Trigger Discovery ODataQuery <BMSRefreshContainersQueryObject> queryParam = new ODataQuery <BMSRefreshContainersQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureStorage); AzureWorkloadProviderHelper.RefreshContainer(vaultName, vaultResourceGroupName, queryParam); //get registered storage accounts bool isRegistered = false; string storageContainerName = null; List <ContainerBase> registeredStorageAccounts = GetRegisteredStorageAccounts(vaultName, vaultResourceGroupName); ContainerBase registeredStorageAccount = registeredStorageAccounts.Find( storageAccount => string.Compare(storageAccount.Name.Split(';').Last(), storageAccountName, true) == 0); if (registeredStorageAccount != null) { isRegistered = true; storageContainerName = "StorageContainer;" + registeredStorageAccount.Name; } //get unregistered storage account if (!isRegistered) { List <ProtectableContainerResource> unregisteredStorageAccounts = GetUnRegisteredStorageAccounts(vaultName, vaultResourceGroupName); ProtectableContainerResource unregisteredStorageAccount = unregisteredStorageAccounts.Find( storageAccount => string.Compare(storageAccount.Name.Split(';').Last(), storageAccountName, true) == 0); if (unregisteredStorageAccount != null) { //unregistered //check for source Id for storageAccountId in ProtectionContainerResource storageContainerName = unregisteredStorageAccount.Name; ProtectionContainerResource protectionContainerResource = new ProtectionContainerResource(unregisteredStorageAccount.Id, unregisteredStorageAccount.Name); AzureStorageContainer azureStorageContainer = new AzureStorageContainer( friendlyName: storageAccountName, backupManagementType: ServiceClientModel.BackupManagementType.AzureStorage, sourceResourceId: unregisteredStorageAccount.Properties.ContainerId, resourceGroup: vaultResourceGroupName); protectionContainerResource.Properties = azureStorageContainer; AzureWorkloadProviderHelper.RegisterContainer(unregisteredStorageAccount.Name, protectionContainerResource, vaultName, vaultResourceGroupName); } } //inquiry AzureWorkloadProviderHelper.TriggerInquiry(vaultName, vaultResourceGroupName, storageContainerName, ServiceClientModel.WorkloadType.AzureFileShare); //get protectable item WorkloadProtectableItemResource protectableObjectResource = null; protectableObjectResource = GetProtectableItem(vaultName, vaultResourceGroupName, azureFileShareName, storageAccountName); if (protectableObjectResource == null) { // Container is not discovered. Throw exception string errorMessage = string.Format( Resources.AFSDiscoveryFailure, azureFileShareName, vaultResourceGroupName); Logger.Instance.WriteDebug(errorMessage); Logger.Instance.WriteError( new ErrorRecord(new Exception(Resources.FileShareNotDiscovered), string.Empty, ErrorCategory.InvalidArgument, null)); } return(protectableObjectResource); }
/// <summary>Register service method with a service binder with or without implementation. Useful when customizing the service binding logic. /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary> /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static void BindService(grpc::ServiceBinderBase serviceBinder, ContainerBase serviceImpl) { serviceBinder.AddMethod(__Method_GetBindings, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Dolittle.DependencyInversion.Management.GetBindingsRequest, global::Dolittle.DependencyInversion.Management.Bindings>(serviceImpl.GetBindings)); }
/// <summary>Creates service definition that can be registered with a server</summary> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static grpc::ServerServiceDefinition BindService(ContainerBase serviceImpl) { return(grpc::ServerServiceDefinition.CreateBuilder() .AddMethod(__Method_GetBindings, serviceImpl.GetBindings).Build()); }
public ReadonlyFieldsTest(int i, string s, ContainerBase c) { Int = i; String = s; Container = c; }
/// <summary> /// Lists protected items protected by the recovery services vault according to the provider data /// </summary> /// <returns>List of protected items</returns> public List <ItemBase> ListProtectedItems() { ContainerBase container = (ContainerBase)this.ProviderData[ItemParams.Container]; string name = (string)this.ProviderData[ItemParams.AzureVMName]; ItemProtectionStatus protectionStatus = (ItemProtectionStatus)this.ProviderData[ItemParams.ProtectionStatus]; ItemProtectionState status = (ItemProtectionState)this.ProviderData[ItemParams.ProtectionState]; Models.WorkloadType workloadType = (Models.WorkloadType) this.ProviderData[ItemParams.WorkloadType]; ProtectedItemListQueryParam queryParams = new ProtectedItemListQueryParam(); queryParams.DatasourceType = ServiceClientModel.WorkloadType.VM; queryParams.BackupManagementType = ServiceClientModel.BackupManagementType.AzureIaasVM.ToString(); List <ProtectedItemResource> protectedItems = new List <ProtectedItemResource>(); string skipToken = null; PaginationRequest paginationRequest = null; do { var listResponse = ServiceClientAdapter.ListProtectedItem(queryParams, paginationRequest); protectedItems.AddRange(listResponse.ItemList.Value); ServiceClientHelpers.GetSkipTokenFromNextLink(listResponse.ItemList.NextLink, out skipToken); if (skipToken != null) { paginationRequest = new PaginationRequest(); paginationRequest.SkipToken = skipToken; } } while (skipToken != null); // 1. Filter by container if (container != null) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItem.Id); return(containerUri.Contains(container.Name)); }).ToList(); } List <ProtectedItemResponse> protectedItemGetResponses = new List <ProtectedItemResponse>(); // 2. Filter by item's friendly name if (!string.IsNullOrEmpty(name)) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id); return(protectedItemUri.ToLower().Contains(name.ToLower())); }).ToList(); GetProtectedItemQueryParam getItemQueryParams = new GetProtectedItemQueryParam(); getItemQueryParams.Expand = "extendedinfo"; for (int i = 0; i < protectedItems.Count; i++) { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItems[i].Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id); var getResponse = ServiceClientAdapter.GetProtectedItem(containerUri, protectedItemUri, getItemQueryParams); protectedItemGetResponses.Add(getResponse); } } List <ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems); if (!string.IsNullOrEmpty(name)) { for (int i = 0; i < itemModels.Count; i++) { AzureVmItemExtendedInfo extendedInfo = new AzureVmItemExtendedInfo(); var serviceClientExtendedInfo = ((AzureIaaSVMProtectedItem)protectedItemGetResponses[i].Item.Properties).ExtendedInfo; if (serviceClientExtendedInfo.OldestRecoveryPoint.HasValue) { extendedInfo.OldestRecoveryPoint = serviceClientExtendedInfo.OldestRecoveryPoint; } extendedInfo.PolicyState = serviceClientExtendedInfo.PolicyInconsistent.ToString(); extendedInfo.RecoveryPointCount = serviceClientExtendedInfo.RecoveryPointCount; ((AzureVmItem)itemModels[i]).ExtendedInfo = extendedInfo; } } // 3. Filter by item's Protection Status if (protectionStatus != 0) { itemModels = itemModels.Where(itemModel => { return(((AzureVmItem)itemModel).ProtectionStatus == protectionStatus); }).ToList(); } // 4. Filter by item's Protection State if (status != 0) { itemModels = itemModels.Where(itemModel => { return(((AzureVmItem)itemModel).ProtectionState == status); }).ToList(); } // 5. Filter by workload type if (workloadType != 0) { itemModels = itemModels.Where(itemModel => { return(itemModel.WorkloadType == workloadType); }).ToList(); } return(itemModels); }
public List <ItemBase> ListProtectedItems() { string vaultName = (string)ProviderData[VaultParams.VaultName]; string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; ContainerBase container = (ContainerBase)ProviderData[ItemParams.Container]; string itemName = (string)ProviderData[ItemParams.ItemName]; ItemProtectionStatus protectionStatus = (ItemProtectionStatus)ProviderData[ItemParams.ProtectionStatus]; ItemProtectionState status = (ItemProtectionState)ProviderData[ItemParams.ProtectionState]; CmdletModel.WorkloadType workloadType = (CmdletModel.WorkloadType)ProviderData[ItemParams.WorkloadType]; PolicyBase policy = (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy]; // 1. Filter by container List <ProtectedItemResource> protectedItems = AzureWorkloadProviderHelper.ListProtectedItemsByContainer( vaultName, resourceGroupName, container, policy, ServiceClientModel.BackupManagementType.AzureWorkload, DataSourceType.SQLDataBase); List <ProtectedItemResource> protectedItemGetResponses = new List <ProtectedItemResource>(); // 2. Filter by item name List <ItemBase> itemModels = AzureWorkloadProviderHelper.ListProtectedItemsByItemName( protectedItems, itemName, vaultName, resourceGroupName, (itemModel, protectedItemGetResponse) => { AzureWorkloadSQLDatabaseProtectedItemExtendedInfo extendedInfo = new AzureWorkloadSQLDatabaseProtectedItemExtendedInfo(); var serviceClientExtendedInfo = ((AzureVmWorkloadSQLDatabaseProtectedItem)protectedItemGetResponse.Properties).ExtendedInfo; if (serviceClientExtendedInfo.OldestRecoveryPoint.HasValue) { extendedInfo.OldestRecoveryPoint = serviceClientExtendedInfo.OldestRecoveryPoint; } extendedInfo.PolicyState = serviceClientExtendedInfo.PolicyState.ToString(); extendedInfo.RecoveryPointCount = (int)(serviceClientExtendedInfo.RecoveryPointCount.HasValue ? serviceClientExtendedInfo.RecoveryPointCount : 0); ((AzureWorkloadSQLDatabaseProtectedItem)itemModel).LatestRecoveryPoint = ((AzureVmWorkloadSQLDatabaseProtectedItem)protectedItemGetResponse.Properties).LastRecoveryPoint; ((AzureWorkloadSQLDatabaseProtectedItem)itemModel).ExtendedInfo = extendedInfo; }); // 3. Filter by item's Protection Status if (protectionStatus != 0) { itemModels = itemModels.Where(itemModel => { return(((AzureWorkloadSQLDatabaseProtectedItem)itemModel).ProtectionStatus == protectionStatus); }).ToList(); } // 4. Filter by item's Protection State if (status != 0) { itemModels = itemModels.Where(itemModel => { return(((AzureWorkloadSQLDatabaseProtectedItem)itemModel).ProtectionState == status); }).ToList(); } // 5. Filter by workload type if (workloadType != 0) { itemModels = itemModels.Where(itemModel => { return(itemModel.WorkloadType == workloadType); }).ToList(); } return(itemModels); }
public double GetGoalFunctionValue(ContainerBase mainContainer, IDictionary <LoadingContainer, int> containers) { return(criteria.Sum(c => c.Item1 * c.Item2(mainContainer, containers))); }
internal static void Register(ContainerBase trackerContainer) { _trackers.Add(trackerContainer); _trackerBlock.Post(trackerContainer); _trackersRegisted = true; }
public List <ItemBase> GetMABProtectedItems(string vaultName, string resourceGroupName, ContainerBase container = null) { ODataQuery <ProtectedItemQueryObject> queryParams = new ODataQuery <ProtectedItemQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.MAB); List <ProtectedItemResource> protectedItems = ServiceClientAdapter.ListProtectedItem( queryParams, null, vaultName: vaultName, resourceGroupName: resourceGroupName); // filter by Container Name if given if (container != null) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItem.Id); var delimIndex = containerUri.IndexOf(';'); string containerName = containerUri.Substring(delimIndex + 1); return(containerName.ToLower().Equals(container.Name.ToLower())); }).ToList(); } return(ConversionHelpers.GetItemModelList(protectedItems)); }
/// <summary> /// Lists protected items protected by the recovery services vault according to the provider data /// </summary> /// <returns>List of protected items</returns> public List <ItemBase> ListProtectedItems() { ContainerBase container = (ContainerBase)ProviderData[ItemParams.Container]; string name = (string)ProviderData[ItemParams.AzureVMName]; ItemProtectionStatus protectionStatus = (ItemProtectionStatus)ProviderData[ItemParams.ProtectionStatus]; ItemProtectionState status = (ItemProtectionState)ProviderData[ItemParams.ProtectionState]; CmdletModel.WorkloadType workloadType = (CmdletModel.WorkloadType)ProviderData[ItemParams.WorkloadType]; ODataQuery <ProtectedItemQueryObject> queryParams = new ODataQuery <ProtectedItemQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureIaasVM && q.ItemType == DataSourceType.VM); List <ProtectedItemResource> protectedItems = new List <ProtectedItemResource>(); string skipToken = null; var listResponse = ServiceClientAdapter.ListProtectedItem(queryParams, skipToken); protectedItems.AddRange(listResponse); // 1. Filter by container if (container != null) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItem.Id); return(containerUri.Contains(container.Name)); }).ToList(); } List <ProtectedItemResource> protectedItemGetResponses = new List <ProtectedItemResource>(); // 2. Filter by item's friendly name if (!string.IsNullOrEmpty(name)) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id); return(protectedItemUri.ToLower().Contains(name.ToLower())); }).ToList(); ODataQuery <GetProtectedItemQueryObject> getItemQueryParams = new ODataQuery <GetProtectedItemQueryObject>(q => q.Expand == "extendedinfo"); for (int i = 0; i < protectedItems.Count; i++) { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItems[i].Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id); var getResponse = ServiceClientAdapter.GetProtectedItem(containerUri, protectedItemUri, getItemQueryParams); protectedItemGetResponses.Add(getResponse.Body); } } List <ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems); if (!string.IsNullOrEmpty(name)) { for (int i = 0; i < itemModels.Count; i++) { AzureVmItemExtendedInfo extendedInfo = new AzureVmItemExtendedInfo(); var serviceClientExtendedInfo = ((AzureIaaSVMProtectedItem)protectedItemGetResponses[i].Properties).ExtendedInfo; if (serviceClientExtendedInfo.OldestRecoveryPoint.HasValue) { extendedInfo.OldestRecoveryPoint = serviceClientExtendedInfo.OldestRecoveryPoint; } extendedInfo.PolicyState = serviceClientExtendedInfo.PolicyInconsistent.ToString(); extendedInfo.RecoveryPointCount = (int)(serviceClientExtendedInfo.RecoveryPointCount.HasValue ? serviceClientExtendedInfo.RecoveryPointCount : 0); ((AzureVmItem)itemModels[i]).ExtendedInfo = extendedInfo; } } // 3. Filter by item's Protection Status if (protectionStatus != 0) { itemModels = itemModels.Where(itemModel => { return(((AzureVmItem)itemModel).ProtectionStatus == protectionStatus); }).ToList(); } // 4. Filter by item's Protection State if (status != 0) { itemModels = itemModels.Where(itemModel => { return(((AzureVmItem)itemModel).ProtectionState == status); }).ToList(); } // 5. Filter by workload type if (workloadType != 0) { itemModels = itemModels.Where(itemModel => { return(itemModel.WorkloadType == workloadType); }).ToList(); } return(itemModels); }
internal static void Register(ContainerBase trackerContainer) { _trackerBlock.Post(trackerContainer); _trackersRegisted = true; }
static Publisher() { _trackerBlock = new ActionBlock <ContainerBase>(async tc => { try { var trackerContainer = (ContainerBase)tc; if (_firstTC == null) { _firstTC = trackerContainer; } else if (_firstTC == trackerContainer && !_trackerBlockCancellationTokenSource.IsCancellationRequested) { try { await Task.Delay(TimeSpan.FromSeconds(30), _trackerBlockCancellationTokenSource.Token).ConfigureAwait(false); } catch (OperationCanceledException) { System.Diagnostics.Debug.WriteLine("Task.Delay exiting"); } } foreach (var td in trackerContainer.GetTrackerData(_trackerBlockCancellationTokenSource.IsCancellationRequested)) { _publisherBlock.Post(td); } } catch (Exception ex) { Configurator.Configuration.Logger.Error(ex.Message, ex); } finally { if (!_trackerBlockCancellationTokenSource.IsCancellationRequested) { _trackerBlock.Post(tc); } else if (_trackerBlock.InputCount == 0) { _trackerBlock.Complete(); } } }); _publisherBlock = new ActionBlock <Data.TrackerData>(tc => { try { _lastPersistanceComplete = false; Configurator.Configuration.Persister.Persist(tc); _lastPersistanceComplete = true; } catch (Exception ex) { Configurator.Configuration.Logger.Error(ex.Message, ex); _lastPersistanceComplete = true; } }, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 4 }); }
/// <summary> /// Lists protected items protected by the recovery services vault according to the provider data /// </summary> /// <returns>List of protected items</returns> public List <ItemBase> ListProtectedItems() { string vaultName = (string)ProviderData[VaultParams.VaultName]; string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; ContainerBase container = (ContainerBase)ProviderData[ItemParams.Container]; string name = (string)ProviderData[ItemParams.ItemName]; ItemProtectionStatus protectionStatus = (ItemProtectionStatus)ProviderData[ItemParams.ProtectionStatus]; ItemProtectionState status = (ItemProtectionState)ProviderData[ItemParams.ProtectionState]; CmdletModel.WorkloadType workloadType = (CmdletModel.WorkloadType)ProviderData[ItemParams.WorkloadType]; PolicyBase policy = (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy]; ODataQuery <ProtectedItemQueryObject> queryParams = policy != null ? new ODataQuery <ProtectedItemQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureSql && q.ItemType == DataSourceType.AzureSqlDb && q.PolicyName == policy.Name) : new ODataQuery <ProtectedItemQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureSql && q.ItemType == DataSourceType.AzureSqlDb); List <ProtectedItemResource> protectedItems = new List <ProtectedItemResource>(); string skipToken = null; var listResponse = ServiceClientAdapter.ListProtectedItem( queryParams, skipToken, vaultName: vaultName, resourceGroupName: resourceGroupName); protectedItems.AddRange(listResponse); // 1. Filter by container if (container != null) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItem.Id); return(containerUri.Contains(container.Name)); }).ToList(); } List <ProtectedItemResource> protectedItemGetResponses = new List <ProtectedItemResource>(); // 2. Filter by item's friendly name if (!string.IsNullOrEmpty(name)) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id); return(protectedItemUri.ToLower().Contains(name.ToLower())); }).ToList(); ODataQuery <GetProtectedItemQueryObject> getItemQueryParams = new ODataQuery <GetProtectedItemQueryObject>(q => q.Expand == extendedInfo); for (int i = 0; i < protectedItems.Count; i++) { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItems[i].Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id); var getResponse = ServiceClientAdapter.GetProtectedItem( containerUri, protectedItemUri, getItemQueryParams, vaultName: vaultName, resourceGroupName: resourceGroupName); protectedItemGetResponses.Add(getResponse.Body); } } List <ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems); if (!string.IsNullOrEmpty(name)) { for (int i = 0; i < itemModels.Count; i++) { AzureSqlProtectedItem azureSqlProtectedItem = (AzureSqlProtectedItem)protectedItemGetResponses[i].Properties; AzureSqlItemExtendedInfo extendedInfo = new AzureSqlItemExtendedInfo(); var hydraExtendedInfo = azureSqlProtectedItem.ExtendedInfo; if (hydraExtendedInfo.OldestRecoveryPoint.HasValue) { extendedInfo.OldestRecoveryPoint = hydraExtendedInfo.OldestRecoveryPoint; } extendedInfo.PolicyState = hydraExtendedInfo.PolicyState; extendedInfo.RecoveryPointCount = hydraExtendedInfo.RecoveryPointCount; ((AzureSqlItem)itemModels[i]).ExtendedInfo = extendedInfo; } } // 3. Filter by item's Protection Status if (protectionStatus != 0) { throw new Exception( string.Format( Resources.ProtectionStatusNotAllowedForAzureSqlItem, protectionStatus.ToString())); } // 4. Filter by item's Protection State if (status != 0) { if (status != ItemProtectionState.Protected) { throw new Exception( string.Format( Resources.ProtectionStateInvalidForAzureSqlItem, status.ToString())); } itemModels = itemModels.Where(itemModel => { return(((AzureSqlItem)itemModel).ProtectionState == status.ToString()); }).ToList(); } // 5. Filter by workload type if (workloadType != 0) { itemModels = itemModels.Where(itemModel => { return(itemModel.WorkloadType == workloadType); }).ToList(); } return(itemModels); }
internal static void Register(ContainerBase trackerContainer) { _trackerBlock.Post(trackerContainer); }