protected List <AssetSettingsGetDBResponse> BuildAssetSetting(AssetSettingsBase target, List <AssetSettingsGetDBResponse> assetTargets) { List <AssetSettingsGetDBResponse> assetWeeklySettings = new List <AssetSettingsGetDBResponse>(); _loggingService.Debug(string.Format("Call To DB For Extracting AssetWeeklySettingsBased on StartDate : {0} And EndDate : {1}", target.StartDate, target.EndDate.Value), "AssetWeeklySettingsService.SaveAssetSetting"); //var assetTargets = GetAssetSettingsForTargetTypeWithAssetUIDStartDateAndEndDate(target.AssetUID.ToStringWithoutHyphens().WrapCommaSeperatedStringsWithUnhex(), target.StartDate, target.EndDate.Value); var assetTargetsByAssetUID = assetTargets.Where(x => x.AssetUID == target.AssetUID).ToList(); if (!isRecordExists(assetTargetsByAssetUID, _groupType)) { /* * Record Doesn't Exist for the Week.. * Insert a New Record, * publish Inserted AssetConfigWeeklyUID into kafka * Return */ // using (var scope = new TransactionScope()) { _loggingService.Debug("No Records Insert a New Record", "AssetWeeklySettingsService.SaveAssetSetting"); //var response = new List<AssetSettingsGetDBResponse>(); var targets = _Converter.GetCommonResponseFromProductivityTargetsAndAssetTargets(target); // _weekRepo.InsertAssetTargets(targets); targets.ForEach(value => { value.Status = true; value.OperationType = AssetSettingsOperationType.Insert; }); // if (_utils.PublishToKafka(targets)) //scope.Complete(); assetWeeklySettings.AddRange(targets); //return response; } } else { assetWeeklySettings = _assetSettingsOverlap.HandleOverlap(target, assetTargetsByAssetUID, _groupType); } return(assetWeeklySettings); }
/// <summary>Constructs a instance of script context</summary> /// <param name="assetConfig">Configuration settings of processing assets</param> protected AssetContextBase(AssetSettingsBase assetConfig) { this._assetConfig = assetConfig; this._translatorsPool = new Dictionary <string, ITranslator>(); this._translatorsPoolSynchronizer = new object(); this._postProcessorsPool = new Dictionary <string, IPostProcessor>(); this._postProcessorsPoolSynchronizer = new object(); this._minifiersPool = new Dictionary <string, IMinifier>(); this._minifiersPoolSynchronizer = new object(); this._fileExtensionMappings = this.GetFileExtensionMappings(); }
/// <summary> /// Constructs a instance of script context /// </summary> /// <param name="assetConfig">Configuration settings of processing assets</param> protected AssetContextBase(AssetSettingsBase assetConfig) { _assetConfig = assetConfig; _translatorsPool = new Dictionary<string, ITranslator>(); _translatorsPoolSynchronizer = new object(); _postProcessorsPool = new Dictionary<string, IPostProcessor>(); _postProcessorsPoolSynchronizer = new object(); _minifiersPool = new Dictionary<string, IMinifier>(); _minifiersPoolSynchronizer = new object(); _fileExtensionMappings = GetFileExtensionMappings(); }
public List <AssetSettingsGetDBResponse> HandleOverlap(AssetSettingsBase target, List <AssetSettingsGetDBResponse> assetTargets, GroupType groupType) { _loggingService.Debug("No Records Insert a New Record", "AssetSettingsOverlapTemplate.HandleOverlap"); _groupType = groupType; var dates = _assetOverlapHandler.GetStartDateAndEndDate(assetTargets, _groupType); var assetEndDate = dates.Item2; var assetStartDate = dates.Item1; var response = new List <AssetSettingsGetDBResponse>(); //Multiple Overlap Scenarios if ((_groupType == GroupType.AssetTargets && assetTargets.Count > 2) || (_groupType == GroupType.ProductivityTargets && assetTargets.Count > 3)) { _loggingService.Debug("MultipleOverlaps Exists For The Scenario", "AssetSettingsOverlapTemplate.HandleOverlap"); return(HandleMultipleOverlaps(target, assetStartDate, assetTargets)); } _loggingService.Debug("SingleOverlap Exists For The Scenario", "AssetSettingsOverlapTemplate.HandleOverlap"); //Single Overlap Scenarios if (target.StartDate > assetStartDate && target.EndDate >= assetEndDate) { return(HandleSingleOverlapAtEnd(assetTargets, target, _groupType, assetStartDate, assetEndDate)); } if (target.StartDate > assetStartDate && target.EndDate < assetEndDate) { return(HandleSingleOVerlapAtMiddle(assetTargets, target, _groupType, assetStartDate, assetEndDate)); } if (target.StartDate <= assetStartDate && target.EndDate >= assetEndDate) { return(HandleSingleOverallOverlap(assetTargets, target, _groupType, assetStartDate, assetEndDate)); } if (target.StartDate <= assetStartDate && target.EndDate < assetEndDate) { return(HandleSingleOverlapAtStart(assetTargets, target, _groupType, assetStartDate, assetEndDate)); } return(response); }
private List <AssetSettingsGetDBResponse> HandleMultipleOverlaps(AssetSettingsBase target, DateTime startDate, List <AssetSettingsGetDBResponse> assetTargets) { var response = new List <AssetSettingsGetDBResponse>(); var largeAssetEndDate = assetTargets.Select(assetTarget => assetTarget.EndDate).OrderByDescending(assetDate => assetDate).First(); if (target.StartDate > startDate && target.EndDate >= largeAssetEndDate) { return(HandleMultipleOverlapAtEnd(assetTargets, target, _groupType, startDate, largeAssetEndDate)); } if (target.StartDate > startDate && target.EndDate < largeAssetEndDate) { return(HandleMultipleOverlapAtMiddle(assetTargets, target, _groupType, startDate, largeAssetEndDate)); } if (target.StartDate <= startDate && target.EndDate >= largeAssetEndDate) { return(HandleMultipleOverallOverlap(assetTargets, target, _groupType, startDate, largeAssetEndDate)); } if (target.StartDate <= startDate && target.EndDate < largeAssetEndDate) { return(HandleMultipleOverlapAtStart(assetTargets, target, _groupType, startDate, largeAssetEndDate)); } return(response); }
protected abstract List <AssetSettingsGetDBResponse> HandleMultipleOverallOverlap(IEnumerable <AssetSettingsGetDBResponse> assetTargets, AssetSettingsBase targets, GroupType assetTargetType, DateTime startDate, DateTime endDate);
protected abstract List <AssetSettingsGetDBResponse> HandleSingleOVerlapAtMiddle(IEnumerable <AssetSettingsGetDBResponse> assetTargets, AssetSettingsBase targets, GroupType assetTargetType, DateTime startDate, DateTime endDate);
protected override List <AssetSettingsGetDBResponse> HandleSingleOVerlapAtMiddle(IEnumerable <AssetSettingsGetDBResponse> assetTargets, AssetSettingsBase target, GroupType assetTargetType, DateTime startDate, DateTime endDate) { _loggingService.Debug("Single Overlap At The Middle", "AssetSettingsOverlapHandler.HandleSingleOVerlapAtMiddle"); var response = new List <AssetSettingsGetDBResponse>(); var targetEndDate = target.EndDate.Value; var targetStartDate = target.StartDate; var oldAssetEndDate = assetTargets.First().EndDate; var targets = _assetOverlapHandler.UpdateDateForEndDateAndReturn(new List <AssetSettingsGetDBResponse>(assetTargets), targetStartDate, _groupType); targets.ForEach(assetTarget => { assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Update; }); response.AddRange(targets); targets = _assetOverlapHandler.GetCommonResponseFromProductivityTargetsAndAssetTargets(target); targets.ForEach(assetTarget => { assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Insert; }); response.AddRange(targets); targets = _assetOverlapHandler.UpdateDataForStartDate(new List <AssetSettingsGetDBResponse>(assetTargets), targetEndDate, _groupType); targets.ForEach(assetTarget => { assetTarget.EndDate = oldAssetEndDate; assetTarget.AssetWeeklyConfigUID = Guid.NewGuid().ToStringWithoutHyphens(); assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Insert; }); response.AddRange(targets); return(response); }
protected override List <AssetSettingsGetDBResponse> HandleSingleOverlapAtEnd(IEnumerable <AssetSettingsGetDBResponse> assetTargets, AssetSettingsBase target, GroupType assetTargetType, DateTime startDate, DateTime endDate) { _loggingService.Debug("Single Overlap At The End", "AssetSettingsOverlapHandler.HandleSingleOverlapAtEnd"); var response = new List <AssetSettingsGetDBResponse>(); var targets = _assetOverlapHandler.UpdateDateForEndDateAndReturn(assetTargets.ToList().AsReadOnly(), target.StartDate, _groupType); targets.ForEach(assetTarget => { assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Update; }); response.AddRange(targets); targets = _assetOverlapHandler.GetCommonResponseFromProductivityTargetsAndAssetTargets(target); targets.ForEach(assetTarget => { assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Update; }); response.AddRange(targets); return(response); }
protected override List <AssetSettingsGetDBResponse> HandleSingleOverallOverlap(IEnumerable <AssetSettingsGetDBResponse> assetTargets, AssetSettingsBase target, GroupType assetTargetType, DateTime startDate, DateTime endDate) { _loggingService.Debug("SingleOverall Overlap", "AssetSettingsOverlapHandler.HandleSingleOverallOverlap"); var response = new List <AssetSettingsGetDBResponse>(); var assetWeeklyConfigUIDs = string.Join(",", assetTargets.Select(assetTarget => assetTarget.AssetWeeklyConfigUID)).WrapCommaSeperatedStringsWithUnhex(); assetTargets.ToList().ForEach(assestTarget => { assestTarget.Status = false; assestTarget.OperationType = AssetSettingsOperationType.Delete; }); response.AddRange(assetTargets); //Insert the new one var targets = _assetOverlapHandler.GetCommonResponseFromProductivityTargetsAndAssetTargets(target); targets.ForEach(assetTarget => { assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Insert; }); response.AddRange(targets); return(response); }
protected override List <AssetSettingsGetDBResponse> HandleMultipleOverlapAtStart(IEnumerable <AssetSettingsGetDBResponse> assetTargets, AssetSettingsBase target, GroupType assetTargetType, DateTime startDate, DateTime endDate) { _loggingService.Debug("Overall Overlap At The Start", "AssetSettingsOverlapHandler.HandleMultipleOverlapAtStart"); var oldAssetEndDate = assetTargets.First().EndDate; //Delete Middle Records var response = new List <AssetSettingsGetDBResponse>(); var assetWeeklyConfigUidsToBeDeleted = assetTargets.Where(assetTarget => assetTarget.EndDate != endDate).Select(assetTarget => assetTarget.AssetWeeklyConfigUID).ToList(); var targetsDeleted = assetTargets.Where(assetTarget => assetTarget.EndDate != endDate).ToList(); targetsDeleted.ToList().ForEach(assetTarget => { assetTarget.Status = false; assetTarget.OperationType = AssetSettingsOperationType.Delete; }); response.AddRange(targetsDeleted); assetTargets = assetTargets.Where(at => !assetWeeklyConfigUidsToBeDeleted.Contains(at.AssetWeeklyConfigUID)); var targets = _assetOverlapHandler.UpdateDataForStartDate(assetTargets.ToList().AsReadOnly(), target.EndDate.Value, _groupType); targets.ForEach(assetTarget => assetTarget.EndDate = endDate); targets.ForEach(assetTarget => { assetTarget.EndDate = endDate; assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Update; }); response.AddRange(targets); //Insert Targets targets = _assetOverlapHandler.GetCommonResponseFromProductivityTargetsAndAssetTargets(target); targets.ForEach(assetTarget => { assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Update; }); response.AddRange(targets); return(response); }
protected override List <AssetSettingsGetDBResponse> HandleMultipleOverlapAtMiddle(IEnumerable <AssetSettingsGetDBResponse> assetTargets, AssetSettingsBase target, GroupType assetTargetType, DateTime startDate, DateTime endDate) { _loggingService.Debug("Overall Overlap At The Middle", "AssetSettingsOverlapHandler.HandleMultipleOVerlapAtMiddle"); var response = new List <AssetSettingsGetDBResponse>(); var oldAssetEndDate = assetTargets.First().EndDate; { var targetsDeleted = assetTargets.Where(assetTarget => assetTarget.EndDate != endDate && assetTarget.StartDate != startDate); targetsDeleted.ToList().ForEach(assetTarget => { assetTarget.Status = false; assetTarget.OperationType = AssetSettingsOperationType.Delete; }); response.AddRange(targetsDeleted); } //Start Insert var smallStartDateSection = assetTargets.Where(at => at.StartDate == startDate).ToList(); var targets = _assetOverlapHandler.UpdateDateForEndDateAndReturn(smallStartDateSection.AsReadOnly(), target.StartDate, _groupType); targets.ToList().ForEach(assetTarget => { assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Update; }); response.AddRange(targets); //End Insert var largerEndDateSection = assetTargets.Where(at => at.EndDate == endDate).ToList(); targets = _assetOverlapHandler.UpdateDataForStartDate(largerEndDateSection.AsReadOnly(), target.EndDate.Value, _groupType); targets.ForEach(assetTarget => { assetTarget.EndDate = endDate; assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Update; }); response.AddRange(targets); targets = _assetOverlapHandler.GetCommonResponseFromProductivityTargetsAndAssetTargets(target); targets.ForEach(assetTarget => { assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Update; }); response.AddRange(targets); return(response); }
protected override List <AssetSettingsGetDBResponse> HandleMultipleOverlapAtEnd(IEnumerable <AssetSettingsGetDBResponse> assetTargets, AssetSettingsBase target, GroupType assetTargetType, DateTime startDate, DateTime endDate) { _loggingService.Debug("Overall Overlap At The End", "AssetSettingsOverlapHandler.HandleMultipleOverlapAtEnd"); var response = new List <AssetSettingsGetDBResponse>(); var assetUIDsToBeDeleted = string.Join(",", assetTargets.Where(assetTarget => assetTarget.StartDate != startDate).Select(assetTarget => assetTarget.AssetWeeklyConfigUID)).WrapCommaSeperatedStringsWithUnhex(); var targetsDeleted = assetTargets.Where(assetTarget => assetTarget.StartDate != startDate); targetsDeleted.ToList().ForEach(assetTarget => { assetTarget.Status = false; assetTarget.OperationType = AssetSettingsOperationType.Delete; }); response.AddRange(targetsDeleted); var targets = _assetOverlapHandler.UpdateDateForEndDateAndReturn(assetTargets.ToList().AsReadOnly(), target.StartDate, _groupType); targets.ToList().ForEach(assetTarget => { assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Update; }); response.AddRange(targets); targets = _assetOverlapHandler.GetCommonResponseFromProductivityTargetsAndAssetTargets(target); targets.ToList().ForEach(assetTarget => { assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Update; }); response.AddRange(targets); return(response); }
protected override List <AssetSettingsGetDBResponse> HandleSingleOverlapAtStart(IEnumerable <AssetSettingsGetDBResponse> assetTargets, AssetSettingsBase target, GroupType assetTargetType, DateTime startDate, DateTime endDate) { using (var scope = new TransactionScope()) { _loggingService.Debug("Single Overlap At The Start", "AssetSettingsOverlapHandler.HandleSingleOverlapAtStart"); var response = new List <AssetSettingsGetDBResponse>(); var targets = _assetOverlapHandler.GetCommonResponseFromProductivityTargetsAndAssetTargets(target); targets.ForEach(assetTarget => { assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Insert; }); response.AddRange(targets); //InsertintoKafka(targets); targets = _assetOverlapHandler.UpdateDataForStartDate(assetTargets.ToList().AsReadOnly(), target.EndDate.Value, _groupType); targets.ForEach(assetTarget => { assetTarget.Status = true; assetTarget.OperationType = AssetSettingsOperationType.Update; }); response.AddRange(targets); return(response); } }