public void InjectSingleMove(Guid targetDatabase, string batchName, LoadEntity mailbox) { base.CallService(delegate() { this.Channel.InjectSingleMove(targetDatabase, batchName, mailbox); }); }
private void SetCommittedLoads(LoadContainer root) { LoadMetricStorage left = new LoadMetricStorage(); if (root.ContainerType == ContainerType.Database) { foreach (LoadEntity loadEntity in root.Children) { LoadContainer loadContainer = (LoadContainer)loadEntity; left += loadContainer.ConsumedLoad; } using (List <LoadEntity> .Enumerator enumerator2 = root.Children.GetEnumerator()) { while (enumerator2.MoveNext()) { LoadEntity loadEntity2 = enumerator2.Current; LoadContainer loadContainer2 = (LoadContainer)loadEntity2; loadContainer2.CommittedLoad = left - loadContainer2.ConsumedLoad; } return; } } foreach (LoadEntity loadEntity3 in root.Children) { LoadContainer committedLoads = (LoadContainer)loadEntity3; this.SetCommittedLoads(committedLoads); } }
private void ExtractConstraintSetHierarchy(LoadContainer databaseContainer) { DirectoryDatabase directoryDatabase = (DirectoryDatabase)base.DirectoryObject; Dictionary <string, LoadContainer> dictionary = new Dictionary <string, LoadContainer>(); foreach (DirectoryMailbox directoryMailbox in directoryDatabase.GetMailboxes()) { TopologyExtractor extractor = base.ExtractorFactory.GetExtractor(directoryMailbox); IMailboxProvisioningConstraints mailboxProvisioningConstraints = directoryMailbox.MailboxProvisioningConstraints; string text = null; if (mailboxProvisioningConstraints != null) { text = mailboxProvisioningConstraints.HardConstraint.Value; } text = (text ?? string.Empty); if (!dictionary.ContainsKey(text)) { DirectoryIdentity identity = new DirectoryIdentity(DirectoryObjectType.ConstraintSet, Guid.NewGuid(), text, directoryMailbox.Identity.OrganizationId); DirectoryObject directoryObject = new DirectoryObject(base.DirectoryObject.Directory, identity); LoadContainer value = new LoadContainer(directoryObject, ContainerType.ConstraintSet); dictionary.Add(text, value); databaseContainer.AddChild(dictionary[text]); } LoadEntity extractedEntity = extractor.ExtractEntity(); this.AddEntityToContainer(dictionary[text], extractedEntity); } }
public void ValidateAccepted(LoadEntity entity) { foreach (IAllocationConstraint allocationConstraint in this.constraints) { allocationConstraint.ValidateAccepted(entity); } }
public void InjectSingleMove(Guid targetDatabase, string batchName, LoadEntity mailbox) { this.InjectMoves(targetDatabase, batchName, new LoadEntity[] { mailbox }); }
public ConstraintValidationResult Accept(LoadEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } DirectoryMailbox directoryMailbox = entity.DirectoryObject as DirectoryMailbox; if (directoryMailbox == null) { return(new ConstraintValidationResult(this, true)); } if (!(directoryMailbox is NonConnectedMailbox)) { if (!directoryMailbox.PhysicalMailboxes.Any((IPhysicalMailbox pm) => pm.IsQuarantined)) { Guid organizationId = directoryMailbox.OrganizationId; if (this.nonMovableOrganizations.Contains(organizationId)) { return(new ConstraintValidationResult(this, false)); } return(new ConstraintValidationResult(this, true)); } } return(new ConstraintValidationResult(this, false)); }
protected virtual void InjectMoves(LoadContainer database, BatchName batchName, IEnumerable <LoadEntity> mailboxes, bool throwIfNotValid) { IRequestQueue injectorQueue = this.queueManager.GetInjectionQueue((DirectoryDatabase)database.DirectoryObject); IOperationRetryManager operationRetryManager = LoadBalanceOperationRetryManager.Create(this.logger); using (IEnumerator <LoadEntity> enumerator = mailboxes.GetEnumerator()) { while (enumerator.MoveNext()) { LoadEntity mailbox = enumerator.Current; if (mailbox.DirectoryObject == null) { this.logger.Log(MigrationEventType.Warning, "Not injecting move for {0} because its DirectoryObject is null", new object[] { mailbox }); } else { OperationRetryManagerResult operationRetryManagerResult = operationRetryManager.TryRun(delegate { DirectoryObject directoryObject = mailbox.DirectoryObject; ConstraintValidationResult constraintValidationResult = database.Constraint.Accept(mailbox); if (constraintValidationResult.Accepted) { database.CommittedLoad += mailbox.ConsumedLoad; if (directoryObject.SupportsMoving) { DirectoryObject directoryObject2 = database.DirectoryObject; IRequest request = directoryObject.CreateRequestToMove(directoryObject2.Identity, batchName.ToString(), this.logger); injectorQueue.EnqueueRequest(request); return; } if (throwIfNotValid) { throw new ObjectCannotBeMovedException(mailbox.DirectoryObjectIdentity.ObjectType.ToString(), mailbox.DirectoryObjectIdentity.ToString()); } } else { this.logger.Log(MigrationEventType.Warning, "Not injecting move for {0} because it violates the target database constraints: {1}", new object[] { mailbox, constraintValidationResult }); if (throwIfNotValid) { constraintValidationResult.Constraint.ValidateAccepted(mailbox); } } }); if (!operationRetryManagerResult.Succeeded && throwIfNotValid) { throw operationRetryManagerResult.Exception; } } } } }
public ConstraintValidationResult Accept(LoadEntity entity) { LoadMetric exceededMetric; long requestedUnits; long availableUnits; return(new LoadCapacityConstraintValidationResult(this, this.container.AvailableCapacity.SupportsAdditional(entity.ConsumedLoad, out exceededMetric, out requestedUnits, out availableUnits), exceededMetric, availableUnits, requestedUnits)); }
public async Task Success() { var stopData = new LoadStatusStopData() { Events = new List <LoadStatusStopEventData>() { new LoadStatusStopEventData() { StopNumber = 1, EventType = StopEventTypeEnum.Arrival }, new LoadStatusStopEventData() { StopNumber = 2, EventType = StopEventTypeEnum.Departure, EventTime = DateTime.Now } } }; var load = new LoadEntity() { LoadId = VALID_LOAD_ID, LoadStops = new List <LoadStopEntity>() { new LoadStopEntity() { StopNbr = 2, Latitude = 10, Longitude = 20 }, new LoadStopEntity() { StopNbr = 3, Latitude = 20, Longitude = 30 } } }; _carrierWebApiService.Setup(_ => _.Send <InTransitLoadData>(It.IsAny <LoadStatusEvent <InTransitLoadData> >())) .ReturnsAsync(new LoadStatusEvent <CarrierApiResponseMessages> { MessageId = Guid.Parse("44444444-4444-4444-4444-555555555555"), MessageTime = new DateTimeOffset(new DateTime(2020, 2, 11, 12, 13, 14)) }); _svc = CreateService(); var response = await _svc.AddInTransitStopStatus(stopData, load); response.Should().NotBeNull(); response.LoadId.Should().Be(load.LoadId); response.LocationTime.Should().BeSameDateAs(stopData.Events[1].EventTime.Value); response.Latitude.Should().Be(load.LoadStops[0].Latitude); response.Longitude.Should().Be(load.LoadStops[0].Longitude); }
public void ValidateAccepted(LoadEntity entity) { LoadMetric loadMetric; long requestedCapacityUnits; long availableCapacityUnits; if (!this.container.AvailableCapacity.SupportsAdditional(entity.ConsumedLoad, out loadMetric, out requestedCapacityUnits, out availableCapacityUnits)) { throw new NotEnoughDatabaseCapacityPermanentException(this.container.Guid.ToString(), loadMetric.ToString(), requestedCapacityUnits, availableCapacityUnits); } }
public void ValidateAccepted(LoadEntity entity) { if (this.Accept(entity)) { return; } foreach (IAllocationConstraint allocationConstraint in this.constraints) { allocationConstraint.ValidateAccepted(entity); } }
private void AddLoadTransaction(LoadEntity updateLoad, string transactionType) { var transaction = new LoadTransactionEntity() { LoadId = updateLoad.LoadId, TransactionTypeId = transactionType, CreateDtTm = _dateTime.Now // to support unit testing }; updateLoad.LoadTransactions.Add(transaction); _context.Loads.Update(updateLoad); }
public override LoadEntity ExtractEntity() { LoadEntity loadEntity = new LoadEntity(base.DirectoryObject); DirectoryMailbox mailbox = (DirectoryMailbox)base.DirectoryObject; foreach (LoadMetric loadMetric in this.bands.Union(LoadMetricRepository.DefaultMetrics)) { long unitsForMailbox = loadMetric.GetUnitsForMailbox(mailbox); loadEntity.ConsumedLoad[loadMetric] = unitsForMailbox; } return(loadEntity); }
public ConstraintValidationResult Accept(LoadEntity entity) { foreach (IAllocationConstraint allocationConstraint in this.constraints) { ConstraintValidationResult constraintValidationResult = allocationConstraint.Accept(entity); if (!constraintValidationResult.Accepted) { return(constraintValidationResult); } } return(new ConstraintValidationResult(this, true)); }
public static LoadEntityData LoadEntityToData(LoadEntity entity) { var data = new LoadEntityData(); data.LoadId = entity.LoadId; data.LoadNumber = entity.LoadNumber; data.EmployeeId = entity.EmployeeId; data.EmployeeName = entity.Employee.FullName; data.Date = entity.Date.ToString("MM/dd/yyyy"); data.IsActive = entity.IsActive; return(data); }
public void ValidateAccepted(LoadEntity entity) { if (!this.Accept(entity)) { Guid guid = Guid.Empty; Guid guid2 = entity.Guid; DirectoryMailbox directoryMailbox = entity.DirectoryObject as DirectoryMailbox; if (directoryMailbox != null) { guid = directoryMailbox.OrganizationId; } throw new EntityIsNonMovableException(guid.ToString(), guid2.ToString()); } }
private PostLoadsResponse ValidatePostedLoad(PostLoadsResponse response, LoadEntity dbLoad, PostingLoad load, string[] bookedTransTypes, List <ServiceTypeEntity> serviceTypes) { if (dbLoad == null) { response.ModelState.AddModelError($"urn:load:{load.LoadId}", "Load not found"); } else { if (load.ShippersFSC < 0) { response.ModelState.AddModelError($"urn:load:{load.LoadId}:{nameof(load.ShippersFSC)}", $"Shippers FSC value must be positive"); } else if (load.ShippersFSC == 0 && !dbLoad.Customer.AllowZeroFuel && !HasFuelUpdateApi(dbLoad.CustomerId)) { response.ModelState.AddModelError($"urn:load:{load.LoadId}:{nameof(load.ShippersFSC)}", $"Shippers FSC value must be provided"); } if (dbLoad.FuelRate != load.ShippersFSC && !dbLoad.Customer.AllowEditingFuel) { response.ModelState.AddModelError($"urn:load:{load.LoadId}:{nameof(load.ShippersFSC)}", $"User is not allowed to edit Shippers FSC"); } var loadAlreadyBooked = bookedTransTypes.Contains(dbLoad.LatestTransactionTypeId); if (loadAlreadyBooked) { response.ModelState.AddModelError($"urn:load:{load.LoadId}", $"Load cannot be posted because it has already been booked. Current status: {dbLoad.LatestTransactionTypeId}"); } } if (load.LineHaulRate <= 0) { response.ModelState.AddModelError($"urn:load:{load.LoadId}:{nameof(load.LineHaulRate)}", $"Line Haul rate value must be provided"); } if (string.IsNullOrWhiteSpace(load.Commodity)) { response.ModelState.AddModelError($"urn:load:{load.LoadId}:{nameof(load.Commodity)}", $"Commodity is required"); } if (load.ServiceTypeIds != null && load.ServiceTypeIds.Count > 0 && !serviceTypes.Any(x => load.ServiceTypeIds.Contains(x.ServiceTypeId))) { response.ModelState.AddModelError($"urn:load:{load.LoadId}:{nameof(load.ServiceTypeIds)}", $"Invalid service type, not found."); } return(response); }
public async Task <bool> DownloadFile <T>(T t, FileInformation source, string targetPath, string taskId) { string token = t as string; if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } string savePath = Path.Combine(targetPath, source.FileName); string downLoadUrl = ""; try { string host = "graph.microsoft.com"; string path = "/v1.0/me/drive/items/"; path = Path.Combine(path, source.FileId); NetClient netClient = new NetClient(); netClient.AddHeader("SampleID", "uwp-csharp-connect-sample"); netClient.AddHeader("SdkVersion", "Graph-dotnet-1.6.2"); netClient.AddHeader("Authorization", string.Format("Bearer {0}", token)); string result = netClient.GET(host, path, true); IDictionary <string, Object> driveItem = JsonConvert.DeserializeObject <IDictionary <string, Object> >(result); Object obj = ""; driveItem.TryGetValue("@microsoft.graph.downloadUrl", out obj); downLoadUrl = obj.ToString(); LoadEntity loadEntity = new LoadEntity() { Url = downLoadUrl, FileSize = source.FileSize, ChunkSize = 1024 * 1024, TaskId = taskId }; NetUtil netUtil = new NetUtil(); bool isSuccess = await netUtil.LoadAsync(loadEntity, savePath, null, ProgressEvent); return(isSuccess); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task MostRecentStopIsNotDeparture() { var stopData = new LoadStatusStopData() { Events = new List <LoadStatusStopEventData>() { new LoadStatusStopEventData() { StopNumber = 1, EventType = StopEventTypeEnum.Departure }, new LoadStatusStopEventData() { StopNumber = 2, EventType = StopEventTypeEnum.Arrival } } }; var load = new LoadEntity() { LoadId = VALID_LOAD_ID, LoadStops = new List <LoadStopEntity>() { new LoadStopEntity() { StopNbr = 2, Latitude = 10, Longitude = 20 }, new LoadStopEntity() { StopNbr = 3, Latitude = 20, Longitude = 30 } } }; _svc = CreateService(); (await _svc.AddInTransitStopStatus(stopData, load)).Should().BeNull(); }
public virtual void InjectMoveForMailbox(DirectoryMailbox mailbox, BatchName batchName) { if (LoadBalanceADSettings.Instance.Value.UseDatabaseSelectorForMoveInjection) { LoadEntity loadEntity = this.serviceContext.GetTopologyExtractorFactoryContext().GetEntitySelectorFactory().GetExtractor(mailbox).ExtractEntity(); MailboxProvisioningResult database = this.databaseSelector.GetDatabase(new MailboxProvisioningData(mailbox.PhysicalSize, mailbox.MailboxProvisioningConstraints, loadEntity.ConsumedLoad)); database.ValidateSelection(); DirectoryIdentity database2 = database.Database; DirectoryDatabase database3 = (DirectoryDatabase)this.directoryProvider.GetDirectoryObject(database2); using (IInjectorService injectorClientForDatabase = this.clientFactory.GetInjectorClientForDatabase(database3)) { injectorClientForDatabase.InjectSingleMove(database2.Guid, batchName.ToString(), new LoadEntity(mailbox)); return; } } IRequest request = mailbox.CreateRequestToMove(null, batchName.ToString(), this.logger); this.queueManager.MainProcessingQueue.EnqueueRequest(request); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int loadId; PropertiesList.Items.Add(new ListItem("Select property", "-1")); foreach (var accountEntity in _db.Account.OrderBy(a => a.Name)) { PropertiesList.Items.Add(new ListItem(accountEntity.Name, accountEntity.AccountId.ToString())); } loadId = int.Parse(Request["loadId"]); var load = _db.Load.FirstOrDefault(l => l.LoadId == loadId); if (load != null) { Load = load; } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var loadId = Request["loadId"]; ///test if (loadId == null) { loadId = "67"; } if (loadId != null && _db.Load.FirstOrDefault(l => l.LoadId == int.Parse(loadId)) != null) { Load = _db.Load.FirstOrDefault(l => l.LoadId == int.Parse(loadId)); Bales = _db.Bale.Where(b => b.LoadId == Load.LoadId).ToList(); } Properties = _db.Account.OrderBy(a => a.Name).ToList(); RecycleTypesList = _db.RecycleType.OrderBy(a => a.Name).ToList(); } }
public IRequestQueue GetProcessingQueue(LoadEntity loadObject) { return(this.queue); }
public Conn(LoadEntity loadMethod) { Context = new TestDataEntities(); CreateItem = loadMethod; }
protected override void AddEntityToContainer(LoadContainer databaseContainer, LoadEntity extractedEntity) { databaseContainer.AddChild(extractedEntity); base.AddEntityToContainer(databaseContainer, extractedEntity); }
public bool Visit(LoadEntity entity) { return(false); }
public IRequestQueue GetProcessingQueue(LoadEntity loadObject) { return(this.GetProcessingQueue(loadObject.Guid, loadObject.Name)); }
public void ValidateAccepted(LoadEntity entity) { }
public ConstraintValidationResult Accept(LoadEntity entity) { return(new ConstraintValidationResult(this, true)); }
void IInjectorService.InjectSingleMove(Guid targetDatabase, string batchName, LoadEntity mailbox) { this.client.InjectSingleMove(targetDatabase, batchName, mailbox); }