示例#1
0
        public async Task MachineIdsExecutor_RaptorJohnDoe_UnableToResolve()
        {
            var projectIds  = new ProjectIDs(999, Guid.NewGuid());
            var customerUid = Guid.NewGuid();
            var assetId     = 777;
            var machineName = "MachineName2";
            var isJohnDoe   = true;

            GetRaptorMachineIdsMock(new[] { new TMachineDetail {
                                                Name = machineName, ID = assetId, IsJohnDoeMachine = isJohnDoe
                                            } },
                                    projectIds.ProjectId, raptorClient);

            // trex call to assetMatch on JohnDoe assets
            GetTRexMachineIdsMock(new List <MachineStatus>(0), projectIds.ProjectUid, configStore, false, false, tRexProxy);

            var executor = RequestExecutorContainerFactory
                           .Build <GetMachineIdsExecutor>(logger, raptorClient.Object, configStore: configStore.Object,
                                                          trexCompactionDataProxy: tRexProxy.Object,
                                                          customHeaders: _customHeaders, customerUid: customerUid.ToString());
            var result = await executor.ProcessAsync(projectIds) as MachineExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(1, result.MachineStatuses.Count, "Wrong machine count");
            Assert.AreEqual(assetId, result.MachineStatuses[0].AssetId, "Wrong machine Id");
            Assert.IsNull(result.MachineStatuses[0].AssetUid, "Wrong assetUid");
            Assert.AreEqual(machineName, result.MachineStatuses[0].MachineName, "Wrong machine name");
        }
示例#2
0
        public async Task MachineIdsExecutor_RaptorJohnDoe_TRexCallUnavailable()
        {
            var projectIds  = new ProjectIDs(999, Guid.NewGuid());
            var customerUid = Guid.NewGuid();
            var assetId     = 777;
            var machineName = "MachineName2";
            var isJohnDoe   = true;

            GetRaptorMachineIdsMock(new[] { new TMachineDetail {
                                                Name = machineName, ID = assetId, IsJohnDoeMachine = isJohnDoe
                                            } },
                                    projectIds.ProjectId, raptorClient);

            // trex call to assetMatch on JohnDoe assets - trex throws exception
            var exception = new ServiceException(HttpStatusCode.InternalServerError,
                                                 new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError));

            tRexProxy.Setup(x => x.SendDataGetRequest <MachineExecutionResult>(projectIds.ProjectUid.ToString(),
                                                                               It.IsAny <string>(), It.IsAny <IDictionary <string, string> >(), It.IsAny <IDictionary <string, string> >()))
            .ThrowsAsync(exception);
            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_MACHINES")).Returns(false);
            configStore.Setup(x => x.GetValueBool("TREX_IS_AVAILABLE")).Returns(true);

            var executor = RequestExecutorContainerFactory
                           .Build <GetMachineIdsExecutor>(logger, raptorClient.Object, configStore: configStore.Object,
                                                          trexCompactionDataProxy: tRexProxy.Object,
                                                          customHeaders: _customHeaders, customerUid: customerUid.ToString());
            await Assert.ThrowsExceptionAsync <ServiceException>(async() => await executor.ProcessAsync(projectIds));
        }
示例#3
0
        public async Task MachineIdsExecutor_Raptor_Success()
        {
            var projectIds  = new ProjectIDs(999, Guid.NewGuid());
            var customerUid = Guid.NewGuid();
            var assetId     = 777;
            var assetUid    = Guid.NewGuid();
            var machineName = "MachineName2";
            var isJohnDoe   = false;

            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_MACHINES")).Returns(false);

            GetRaptorMachineIdsMock(new[] { new TMachineDetail {
                                                Name = machineName, ID = assetId, IsJohnDoeMachine = isJohnDoe
                                            } },
                                    projectIds.ProjectId, raptorClient);

            var assetMatches = new List <KeyValuePair <Guid, long> > {
                new KeyValuePair <Guid, long>(assetUid, assetId)
            };

            assetProxy.Setup(x => x.GetMatchingAssets(It.IsAny <List <long> >(), It.IsAny <IDictionary <string, string> >()))
            .ReturnsAsync(assetMatches);

            var executor = RequestExecutorContainerFactory
                           .Build <GetMachineIdsExecutor>(logger, raptorClient.Object, configStore: configStore.Object,
                                                          assetResolverProxy: assetProxy.Object,
                                                          customHeaders: _customHeaders, customerUid: customerUid.ToString());
            var result = await executor.ProcessAsync(projectIds) as MachineExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(1, result.MachineStatuses.Count, "Wrong machine count");
            Assert.AreEqual(assetId, result.MachineStatuses[0].AssetId, "Wrong machine Id");
            Assert.AreEqual(assetUid, result.MachineStatuses[0].AssetUid, "Wrong assetUid");
            Assert.AreEqual(machineName, result.MachineStatuses[0].MachineName, "Wrong machine name");
        }
示例#4
0
        public async Task MachineIdsExecutor_TRex_Success()
        {
            var projectIds  = new ProjectIDs(1, Guid.NewGuid());
            var customerUid = Guid.NewGuid();
            var assetUid    = Guid.NewGuid();
            var assetId     = assetUid.ToLegacyId();
            var machineName = "MachineName";
            var isJohnDoe   = false;

            GetTRexMachineIdsMock(new List <MachineStatus>(1)
            {
                new MachineStatus(NULL_ASSETID, machineName, isJohnDoe, assetUid: assetUid)
            },
                                  projectIds.ProjectUid, configStore, true, false, tRexProxy);

            var executor = RequestExecutorContainerFactory
                           .Build <GetMachineIdsExecutor>(logger, configStore: configStore.Object,
                                                          trexCompactionDataProxy: tRexProxy.Object,
                                                          customHeaders: _customHeaders, customerUid: customerUid.ToString());

            var result = await executor.ProcessAsync(projectIds) as MachineExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(1, result.MachineStatuses.Count, "Wrong asset count");
            Assert.AreEqual(assetUid, result.MachineStatuses[0].AssetUid, "Wrong asset Uid");
            Assert.AreEqual(assetId, result.MachineStatuses[0].AssetId, "Wrong asset Id");
            Assert.AreEqual(machineName, result.MachineStatuses[0].MachineName, "Wrong machine name");
        }
示例#5
0
        private async Task PairUpAssetIdentifiers(ProjectIDs projectIds, List <AssetOnDesignPeriod> assetOnDesignPeriods)
        {
            if (assetOnDesignPeriods == null || assetOnDesignPeriods.Count == 0)
            {
                return;
            }

            if (await RequestExecutorContainerFactory.Build <GetMachineIdsExecutor>(loggerFactory,
#if RAPTOR
                                                                                    raptorClient,
#endif
                                                                                    configStore: configStore, trexCompactionDataProxy: trexCompactionDataProxy,
                                                                                    customHeaders: customHeaders, customerUid: customerUid,
                                                                                    userId: userId, fileImportProxy: fileImportProxy)
                .ProcessAsync(projectIds) is MachineExecutionResult machineExecutionResult && machineExecutionResult.MachineStatuses.Count > 0)
            {
                foreach (var assetMatch in machineExecutionResult.MachineStatuses)
                {
                    foreach (var assetOnDesignPeriod in assetOnDesignPeriods.FindAll(a => a.AssetUid == assetMatch.AssetUid))
                    {
                        assetOnDesignPeriod.MachineId = assetMatch.AssetId;
                    }
                }
            }
        }
示例#6
0
        public async Task MachineIdsExecutor_Raptor_MultiAsset()
        {
            var  projectIds            = new ProjectIDs(999, Guid.NewGuid());
            var  customerUid           = Guid.NewGuid();
            var  assetUid1Good         = Guid.NewGuid();
            long assetId1Good          = 777;
            var  assetUid1Expected     = assetUid1Good;
            var  machineName1          = "MachineName1";
            long assetId2Invalid       = 0; // johnDoe?
            Guid?assetUid2ExpectedNull = null;
            var  machineName2          = "MachineName2";
            var  assetUid3Good         = Guid.NewGuid();
            long assetId3Good          = 888;
            var  assetUid3Expected     = assetUid3Good;
            var  machineName3          = "MachineName3";

            var tMachines = new[]
            {
                new TMachineDetail {
                    Name = machineName1, ID = assetId1Good, IsJohnDoeMachine = false
                },
                new TMachineDetail {
                    Name = machineName2, ID = assetId2Invalid, IsJohnDoeMachine = false
                },
                new TMachineDetail {
                    Name = machineName3, ID = assetId3Good, IsJohnDoeMachine = false
                }
            };

            GetRaptorMachineIdsMock(tMachines, projectIds.ProjectId, raptorClient);

            var assetMatches = new List <KeyValuePair <Guid, long> >
            {
                new KeyValuePair <Guid, long>(assetUid1Good, assetId1Good),
                new KeyValuePair <Guid, long>(assetUid3Good, assetId3Good)
            };

            assetProxy.Setup(x => x.GetMatchingAssets(It.IsAny <List <long> >(), It.IsAny <IDictionary <string, string> >()))
            .ReturnsAsync(assetMatches);

            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_MACHINES")).Returns(false);

            var executor = RequestExecutorContainerFactory
                           .Build <GetMachineIdsExecutor>(logger, raptorClient.Object, configStore: configStore.Object,
                                                          assetResolverProxy: assetProxy.Object,
                                                          customHeaders: _customHeaders, customerUid: customerUid.ToString());
            var result = await executor.ProcessAsync(projectIds) as MachineExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(3, result.MachineStatuses.Count, "Wrong machine count");
            Assert.AreEqual(assetId1Good, result.MachineStatuses[0].AssetId, "Wrong machine Id (0)");
            Assert.AreEqual(assetUid1Expected, result.MachineStatuses[0].AssetUid, "Wrong assetUid (0)");
            Assert.AreEqual(assetId2Invalid, result.MachineStatuses[1].AssetId, "Wrong machine Id (1)");
            Assert.AreEqual(assetUid2ExpectedNull, result.MachineStatuses[1].AssetUid, "Wrong assetUid (1)");
            Assert.AreEqual(assetId3Good, result.MachineStatuses[2].AssetId, "Wrong machine Id (2)");
            Assert.AreEqual(assetUid3Expected, result.MachineStatuses[2].AssetUid, "Wrong assetUid (2)");
        }
示例#7
0
        public void ProjectIDsRequest_Invalid(int projectId, string projectUid, string errorMessage)
        {
            var request = new ProjectIDs(projectId, Guid.Parse(projectUid));
            var ex      = Assert.ThrowsException <ServiceException>(() => request.Validate());

            Assert.IsNotNull(ex, "should be exception");
            Assert.AreEqual(HttpStatusCode.BadRequest, ex.Code, "Invalid HttpStatusCode.");
            Assert.AreEqual(ContractExecutionStatesEnum.ValidationError, ex.GetResult.Code, "Invalid executionState.");
            Assert.AreEqual(errorMessage, ex.GetResult.Message, "Invalid error message.");
        }
示例#8
0
        public async Task GetAssetOnDesignLayerPeriodsExecutor_TRexJohnDoe_Success()
        {
            var  projectIds        = new ProjectIDs(777, Guid.NewGuid());
            var  customerUid       = Guid.NewGuid();
            var  assetUid          = Guid.NewGuid();
            var  assetId           = NULL_ASSETID;
            long layerId           = 444;
            var  machineDesignName = "The machine design name";
            var  machineName       = "MachineName2";
            var  isJohnDoe         = true;

            // for GetAssetOnDesignLayerPeriodsExecutor
            var expectedAssetOnDesignLayerPeriodsExecutionResult = new AssetOnDesignLayerPeriodsExecutionResult
                                                                   (
                new List <AssetOnDesignLayerPeriod>(1)
            {
                new AssetOnDesignLayerPeriod(NULL_ASSETID, NULL_RAPTOR_MACHINE_DESIGN_ID, layerId, DateTime.UtcNow.AddDays(-50), DateTime.UtcNow.AddDays(-40), assetUid, machineDesignName)
            }
                                                                   );

            tRexProxy.Setup(x => x.SendDataGetRequest <AssetOnDesignLayerPeriodsExecutionResult>(projectIds.ProjectUid.ToString(),
                                                                                                 It.IsAny <string>(), It.IsAny <IHeaderDictionary>(), It.IsAny <IHeaderDictionary>()))
            .ReturnsAsync(expectedAssetOnDesignLayerPeriodsExecutionResult);
            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_LAYERS")).Returns(true);

            // for GetMachineIdsExecutor
            GetTRexMachineIdsMock(new List <MachineStatus>(1)
            {
                new MachineStatus(NULL_ASSETID, machineName, isJohnDoe, assetUid: assetUid)
            },
                                  projectIds.ProjectUid, configStore, true, false, tRexProxy);

            // for GetMachineIdsExecutor, raptor call to assetMatch on JohnDoe assets
            GetRaptorMachineIdsMock(new[] { new TMachineDetail {
                                                Name = machineName, ID = assetId, IsJohnDoeMachine = isJohnDoe
                                            } },
                                    projectIds.ProjectId, raptorClient);

            // GetAssetOnDesignLayerPeriodsExecutor will call GetMachineIdsExecutor
            var executor = RequestExecutorContainerFactory
                           .Build <GetAssetOnDesignLayerPeriodsExecutor>(logger, configStore: configStore.Object,
                                                                         raptorClient: raptorClient.Object, trexCompactionDataProxy: tRexProxy.Object,
                                                                         customHeaders: _customHeaders, customerUid: customerUid.ToString());

            var result = await executor.ProcessAsync(projectIds) as AssetOnDesignLayerPeriodsExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(1, result.AssetOnDesignLayerPeriods.Count, "Wrong layer count");
            Assert.AreEqual(assetUid, result.AssetOnDesignLayerPeriods[0].AssetUid, "Wrong machine Uid");
            Assert.AreEqual(assetId, result.AssetOnDesignLayerPeriods[0].AssetId, "Wrong legacyAssetId");
            Assert.AreEqual(NULL_RAPTOR_MACHINE_DESIGN_ID, result.AssetOnDesignLayerPeriods[0].OnMachineDesignId, "Wrong design OnMachineDesignId");
            Assert.AreEqual(machineDesignName, result.AssetOnDesignLayerPeriods[0].OnMachineDesignName, "Wrong design OnMachineDesignName");

            Assert.AreEqual(layerId, result.AssetOnDesignLayerPeriods[0].LayerId, "Wrong layer id");
        }
示例#9
0
        public async Task GetAssetOnDesignPeriodsExecutor_TRex_Success()
        {
            var projectIds  = new ProjectIDs(99, Guid.NewGuid());
            var customerUid = Guid.NewGuid();
            var assetUid    = Guid.NewGuid();
            var assetId     = assetUid.ToLegacyId();
            var machineName = "MachineName2";
            var isJohnDoe   = false;

            // for GetAssetOnDesignPeriodsExecutor
            var expectedGetAssetOnDesignPeriodsExecutorResult = new MachineDesignsExecutionResult
                                                                (
                new List <AssetOnDesignPeriod>
            {
                new AssetOnDesignPeriod("The NameOf Design1", NULL_RAPTOR_MACHINE_DESIGN_ID, NULL_ASSETID, DateTime.UtcNow.AddDays(-50),
                                        DateTime.UtcNow.AddDays(-40), assetUid)
            }
                                                                );

            tRexProxy.Setup(x => x.SendDataGetRequest <MachineDesignsExecutionResult>(projectIds.ProjectUid.ToString(),
                                                                                      It.IsAny <string>(),
                                                                                      It.IsAny <IHeaderDictionary>(),
                                                                                      It.IsAny <List <KeyValuePair <string, string> > >()))
            .ReturnsAsync(expectedGetAssetOnDesignPeriodsExecutorResult);
            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_MACHINEDESIGNS")).Returns(true);

            // for GetMachineIdsExecutor
            GetTRexMachineIdsMock(new List <MachineStatus>(1)
            {
                new MachineStatus(NULL_ASSETID, machineName, isJohnDoe, assetUid: assetUid)
            },
                                  projectIds.ProjectUid, configStore, true, false, tRexProxy);

            // GetAssetOnDesignPeriodsExecutor will call GetMachineIdsExecutor
            var executor = RequestExecutorContainerFactory
                           .Build <GetAssetOnDesignPeriodsExecutor>(logger, configStore: configStore.Object,
                                                                    trexCompactionDataProxy: tRexProxy.Object,
                                                                    customHeaders: _customHeaders, customerUid: customerUid.ToString());

            var result = await executor.ProcessAsync(projectIds) as MachineDesignsExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(1, result.AssetOnDesignPeriods.Count, "Wrong design count");
            Assert.AreEqual(expectedGetAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].AssetUid, result.AssetOnDesignPeriods[0].AssetUid,
                            "Wrong asset Uid");
            Assert.AreEqual(assetId, result.AssetOnDesignPeriods[0].MachineId, "Wrong legacyAssetId");
            Assert.AreEqual(expectedGetAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].StartDate, result.AssetOnDesignPeriods[0].StartDate,
                            "Wrong StartDate");
            Assert.AreEqual(NULL_RAPTOR_MACHINE_DESIGN_ID, result.AssetOnDesignPeriods[0].OnMachineDesignId, "Wrong onMachineDesignId");
            Assert.AreEqual(expectedGetAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].OnMachineDesignName, result.AssetOnDesignPeriods[0].OnMachineDesignName, "Wrong onMachineDesignName");

            // there's some funny giggery-pokery in the executor to join up any dis-jointed periods
            Assert.IsTrue(result.AssetOnDesignPeriods[0].EndDate > expectedGetAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].EndDate,
                          "Wrong EndDate");
        }
示例#10
0
        /// <summary>
        /// Matches up the legacy asset ID with the corresponding asset UID.
        /// </summary>
        protected async Task <Guid?> GetAssetUid(ProjectIDs projectIds, long?assetId)
        {
            if (assetId.HasValue)
            {
                var machineExecutionResult = await GetMachines(projectIds) as MachineExecutionResult;

                return(machineExecutionResult?.MachineStatuses?.FirstOrDefault(a => a.AssetId == assetId.Value)?.AssetUid);
            }

            return(null);
        }
示例#11
0
        /// <summary>
        /// Gets the list of machines from Raptor/TRex
        /// </summary>
        private Task <ContractExecutionResult> GetMachines(ProjectIDs projectIds)
        {
            return(RequestExecutorContainerFactory.Build <GetMachineIdsExecutor>(
                       loggerFactory,
#if RAPTOR
                       raptorClient,
#endif
                       configStore: configStore,
                       trexCompactionDataProxy: trexCompactionDataProxy,
                       customHeaders: customHeaders,
                       customerUid: customerUid,
                       userId: userId, fileImportProxy: fileImportProxy)
                   .ProcessAsync(projectIds));
        }
示例#12
0
        public async Task <MachineLayerIdsExecutionResult> GetMachineLiftsByDateRange([FromRoute] Guid projectUid,
                                                                                      [FromQuery] string startUtc = null, [FromQuery] string endUtc = null)
        {
            _log.LogInformation($"{nameof(GetMachineLiftsByDateRange)} Request. projectUid: {projectUid} startUtc: {startUtc} endUtc: {endUtc}");

            var projectIds = new ProjectIDs(await((RaptorPrincipal)User).GetLegacyProjectId(projectUid), projectUid);

            projectIds.Validate();

            var response = await GetMachineLiftsWith(projectIds, startUtc, endUtc);

            _log.LogDebug($"{nameof(GetMachineLiftsByDateRange)} Response: {JsonConvert.SerializeObject(response)}");
            return(response);
        }
示例#13
0
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            try
            {
                var request = CastRequestObjectTo <GetEditDataRequest>(item);
#if RAPTOR
                if (UseTRexGateway("ENABLE_TREX_GATEWAY_EDIT_DATA"))
                {
#endif
                var projectIds = new ProjectIDs(request.ProjectId.Value, request.ProjectUid.Value);
                projectIds.Validate();
                var assetUid = await GetAssetUid(projectIds, request.assetId);

                var parameters = new Dictionary <string, string>
                {
                    { "projectUid", request.ProjectUid.Value.ToString() }
                }
                ;
                if (assetUid.HasValue)
                {
                    parameters.Add("assetUid", assetUid.ToString());
                }
                var queryParams = $"?{new System.Net.Http.FormUrlEncodedContent(parameters).ReadAsStringAsync().Result}";
                var results     = await trexCompactionDataProxy.SendDataGetRequest <TRexEditDataResult>(request.ProjectUid.Value.ToString(), $"/productiondataedit{queryParams}", customHeaders);

                var assetMatches = await GetAssetIds(projectIds, results.DataEdits.Select(d => d.AssetUid).ToList());

                var convertedResults = from d in results.DataEdits select ProductionDataEdit.CreateProductionDataEdit(assetMatches[d.AssetUid], d.StartUtc, d.EndUtc, d.MachineDesignName, d.LiftNumber);

                return(EditDataResult.CreateEditDataResult(convertedResults.ToList()));

#if RAPTOR
            }

            return(ProcessWithRaptor(request));
#endif
            }
            finally
            {
                ContractExecutionStates.ClearDynamic();
            }
        }
示例#14
0
        public async Task MachineIdsExecutor_TRexJohnDoe_Success()
        {
            var projectIds  = new ProjectIDs(1, Guid.NewGuid());
            var customerUid = Guid.NewGuid();
            var assetUid    = Guid.NewGuid();
            var assetId     = NULL_ASSETID;
            var machineName = "MachineName";
            var isJohnDoe   = true;

            GetTRexMachineIdsMock(new List <MachineStatus>(1)
            {
                new MachineStatus(NULL_ASSETID, machineName, isJohnDoe, assetUid: assetUid)
            },
                                  projectIds.ProjectUid, configStore, true, false, tRexProxy);

            // to assetMatch on VSS assets
            var assetMatches = new List <KeyValuePair <Guid, long> > {
                new KeyValuePair <Guid, long>(assetUid, assetId)
            };

            assetProxy.Setup(x => x.GetMatchingAssets(It.IsAny <List <Guid> >(), It.IsAny <IDictionary <string, string> >()))
            .ReturnsAsync(assetMatches);

            // raptor call to assetMatch on JohnDoe assets
            GetRaptorMachineIdsMock(new[] { new TMachineDetail {
                                                Name = machineName, ID = assetId, IsJohnDoeMachine = isJohnDoe
                                            } },
                                    projectIds.ProjectId, raptorClient);

            var executor = RequestExecutorContainerFactory
                           .Build <GetMachineIdsExecutor>(logger, configStore: configStore.Object,
                                                          trexCompactionDataProxy: tRexProxy.Object, assetResolverProxy: assetProxy.Object, raptorClient: raptorClient.Object,
                                                          customHeaders: _customHeaders, customerUid: customerUid.ToString());

            var result = await executor.ProcessAsync(projectIds) as MachineExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(1, result.MachineStatuses.Count, "Wrong asset count");
            Assert.AreEqual(assetUid, result.MachineStatuses[0].AssetUid, "Wrong asset Uid");
            Assert.AreEqual(assetId, result.MachineStatuses[0].AssetId, "Wrong asset Id");
            Assert.AreEqual(machineName, result.MachineStatuses[0].MachineName, "Wrong machine name");
        }
示例#15
0
        public async Task <MachineExecutionResult> GetMachinesOnProjectTbc([FromRoute] long projectId)
        {
            _log.LogInformation($"{nameof(GetMachinesOnProjectTbc)} Request. projectId: {projectId}");

            var projectIds = new ProjectIDs(projectId, await((RaptorPrincipal)User).GetProjectUid(projectId));

            projectIds.Validate();

            var response = await RequestExecutorContainerFactory.Build <GetMachineIdsExecutor>(_logger,
#if RAPTOR
                                                                                               _raptorClient,
#endif
                                                                                               configStore : _configStore, trexCompactionDataProxy : _trexCompactionDataProxy,
                                                                                               customHeaders : CustomHeaders, customerUid : CustomerUid,
                                                                                               userId : UserId, fileImportProxy : FileImportProxy)
                           .ProcessAsync(projectIds) as MachineExecutionResult;

            _log.LogInformation($"{nameof(GetMachinesOnProjectTbc)} Response: {JsonConvert.SerializeObject(response)}");
            return(response);
        }
示例#16
0
        /// <summary>
        /// TimeEntryを追加
        /// </summary>
        /// <param name="appData"></param>
        public void SetTimeEntry(AppDataObject appData)
        {
            int       duration = (int)(appData.LastRunningTime - appData.LaunchedTime).TotalSeconds;
            TimeEntry te       = new TimeEntry()
            {
                IsBillable  = true,
                CreatedWith = "TogglAPI.Net",
                Description = appData.DisplayedName,
                Duration    = duration,
                Start       = appData.LaunchedTime.ToIsoDateStr(),
                Stop        = appData.LastRunningTime.ToIsoDateStr(),

                WorkspaceId = defaultWorkspaceID
            };

            if (ProjectIDs.ContainsKey(appData.LinkedProjectName))
            {
                te.ProjectId = ProjectIDs[appData.LinkedProjectName];
            }

            if (!string.IsNullOrEmpty(appData.LinkedTag))
            {
                te.TagNames = new List <string>()
                {
                    appData.LinkedTag
                };
            }

            try
            {
                if (te != null)
                {
                    timeEntryService.Add(te);
                    Console.WriteLine($"sended:{te}");
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
            }
        }
示例#17
0
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            try
            {
                var request = CastRequestObjectTo <EditDataRequest>(item);
                //Note: request.dataEdit should only be null for a global undo. This is checked in request model validation
                //so the following should never happen. But just in case...
                if (request.dataEdit == null && !request.undo)
                {
                    return(new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, "No data edit to perform"));
                }

#if RAPTOR
                if (UseTRexGateway("ENABLE_TREX_GATEWAY_EDIT_DATA"))
                {
#endif
                var projectIds = new ProjectIDs(request.ProjectId.Value, request.ProjectUid.Value);
                projectIds.Validate();
                var assetUid = await GetAssetUid(projectIds, request.dataEdit.assetId);

                var trexRequest = new TRexEditData(assetUid ?? Guid.Empty, request.dataEdit.startUTC, request.dataEdit.endUTC, request.dataEdit.onMachineDesignName, request.dataEdit.liftNumber);
                var trexResult  = await trexCompactionDataProxy.SendDataDeleteRequest <ContractExecutionResult, TRexEditData>(trexRequest, "/productiondataedit", customHeaders, true);

                if (trexResult.Code != ContractExecutionStatesEnum.ExecutedSuccessfully)
                {
                    throw new ServiceException(HttpStatusCode.BadRequest, trexResult);
                }

                return(trexResult);

#if RAPTOR
            }

            return(ProcessWithRaptor(request));
#endif
            }
            finally
            {
                ContractExecutionStates.ClearDynamic();
            }
        }
示例#18
0
        public async Task <ContractExecutionResult> GetMachineOnProject([FromRoute] Guid projectUid, [FromRoute] Guid machineUid)
        {
            _log.LogInformation($"{nameof(GetMachineOnProject)} Request. projectUid: {projectUid} machineUid: {machineUid}");

            var projectIds = new ProjectIDs(await((RaptorPrincipal)User).GetLegacyProjectId(projectUid), projectUid);

            projectIds.Validate();

            var response = await RequestExecutorContainerFactory.Build <GetMachineIdsExecutor>(_logger,
#if RAPTOR
                                                                                               _raptorClient,
#endif
                                                                                               configStore : _configStore, trexCompactionDataProxy : _trexCompactionDataProxy,
                                                                                               customHeaders : CustomHeaders, customerUid : CustomerUid,
                                                                                               userId : UserId, fileImportProxy : FileImportProxy)
                           .ProcessAsync(projectIds) as MachineExecutionResult;

            _log.LogInformation($"{nameof(GetMachineOnProject)} Response: machineUidFilter {machineUid} responsePreFilter {JsonConvert.SerializeObject(response)}");
            response?.FilterByMachineUid(machineUid);

            return(response);
        }
示例#19
0
        public async Task <MachineDesignsResult> GetMachineDesigns([FromRoute] Guid projectUid)
        {
            _log.LogInformation($"{nameof(GetMachineDesigns)} Request. projectUid: {projectUid}");

            var projectIds = new ProjectIDs(await((RaptorPrincipal)User).GetLegacyProjectId(projectUid), projectUid);

            projectIds.Validate();

            var result = await RequestExecutorContainerFactory.Build <GetAssetOnDesignPeriodsExecutor>(_logger,
#if RAPTOR
                                                                                                       _raptorClient,
#endif
                                                                                                       configStore : _configStore, trexCompactionDataProxy : _trexCompactionDataProxy,
                                                                                                       customHeaders : CustomHeaders, customerUid : CustomerUid,
                                                                                                       userId : UserId, fileImportProxy : FileImportProxy)
                         .ProcessAsync(projectIds) as MachineDesignsExecutionResult;

            _log.LogDebug($"{nameof(GetMachineDesigns)} MachineDesignsExecutionResult: {result}");
            var response = CreateUniqueMachineDesignList(result);

            _log.LogDebug($"{nameof(GetMachineDesigns)} Response: {response}");
            return(response);
        }
示例#20
0
        public async Task MachineIdsExecutor_TRex_MultiAssetUid()
        {
            var projectIds       = new ProjectIDs(1, Guid.NewGuid());
            var customerUid      = Guid.NewGuid();
            var assetUid1Good    = Guid.NewGuid();
            var assetId1Expected = assetUid1Good.ToLegacyId();
            var assetUid2Good    = Guid.NewGuid();
            var assetId2Expected = assetUid2Good.ToLegacyId();
            var assetUid3Good    = Guid.NewGuid();
            var assetId3Expected = assetUid3Good.ToLegacyId();

            var machines = new List <MachineStatus>(3)
            {
                new MachineStatus(NULL_ASSETID, "MachineName2", false, assetUid: assetUid1Good),
                new MachineStatus(NULL_ASSETID, "MachineName3", false, assetUid: assetUid2Good),
                new MachineStatus(NULL_ASSETID, "MachineName4", false, assetUid: assetUid3Good)
            };

            GetTRexMachineIdsMock(machines, projectIds.ProjectUid, configStore, true, false, tRexProxy);

            var executor = RequestExecutorContainerFactory
                           .Build <GetMachineIdsExecutor>(logger, configStore: configStore.Object,
                                                          trexCompactionDataProxy: tRexProxy.Object,
                                                          customHeaders: _customHeaders, customerUid: customerUid.ToString());

            var result = await executor.ProcessAsync(projectIds) as MachineExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(3, result.MachineStatuses.Count, "Wrong design count");
            Assert.AreEqual(assetUid1Good, result.MachineStatuses[0].AssetUid, "Wrong asset1 Uid (0)");
            Assert.AreEqual(assetId1Expected, result.MachineStatuses[0].AssetId, "Wrong legacyAssetId1 (0)");
            Assert.AreEqual(assetUid2Good, result.MachineStatuses[1].AssetUid, "Wrong asset1 Uid (1)");
            Assert.AreEqual(assetId2Expected, result.MachineStatuses[1].AssetId, "Wrong legacyAssetId1 (1)");
            Assert.AreEqual(assetUid3Good, result.MachineStatuses[2].AssetUid, "Wrong asset2 Uid (2)");
            Assert.AreEqual(assetId3Expected, result.MachineStatuses[2].AssetId, "Wrong legacyAssetId2 (2)");
        }
示例#21
0
        protected async Task PairUpAssetIdentifiers(Guid projectUid, FilterResult filter1, FilterResult filter2 = null)
        {
            // filters coming from TBC can have only the legacy assetId
            if ((filter1 == null || filter1.ContributingMachines == null || filter1.ContributingMachines.Count == 0 || filter1.ContributingMachines.All(m => m.AssetUid != null)) &&
                (filter2 == null || filter2.ContributingMachines == null || filter2.ContributingMachines.Count == 0 || filter2.ContributingMachines.All(m => m.AssetUid != null)))
            {
                return;
            }

            var projectIds = new ProjectIDs(-1, projectUid);

            if (await RequestExecutorContainerFactory.Build <GetMachineIdsExecutor>(loggerFactory,
                                                                                    configStore: configStore, trexCompactionDataProxy: trexCompactionDataProxy,
                                                                                    customHeaders: customHeaders, customerUid: customerUid,
                                                                                    userId: userId, fileImportProxy: fileImportProxy)
                .ProcessAsync(projectIds) is MachineExecutionResult machineExecutionResult && machineExecutionResult.MachineStatuses.Count > 0)
            {
                foreach (var assetMatch in machineExecutionResult.MachineStatuses)
                {
                    if ((filter1 != null && filter1.ContributingMachines != null && filter1.ContributingMachines.Count > 0))
                    {
                        foreach (var machine in filter1.ContributingMachines.FindAll(a => a.AssetId == assetMatch.AssetId && a.AssetUid == null))
                        {
                            machine.AssetUid = assetMatch.AssetUid;
                        }
                    }
                    if ((filter2 != null && filter2.ContributingMachines != null && filter2.ContributingMachines.Count > 0))
                    {
                        foreach (var machine in filter2.ContributingMachines.FindAll(a => a.AssetId == assetMatch.AssetId && a.AssetUid == null))
                        {
                            machine.AssetUid = assetMatch.AssetUid;
                        }
                    }
                }
            }
        }
示例#22
0
        public async Task GetAssetOnDesignPeriodsExecutor_RaptorJohnDoe_Success()
        {
            var projectIds        = new ProjectIDs(999, Guid.NewGuid());
            var customerUid       = Guid.NewGuid();
            var assetUid          = Guid.NewGuid();
            var assetId           = 777;
            var machineName       = "MachineName2";
            var isJohnDoe         = true;
            var designId          = 888;
            var machineDesignName = "The machine design name";

            // GetAssetOnDesignPeriodsExecutor
            var expectedAssetOnDesignPeriodsExecutorResult = new MachineDesignsExecutionResult
                                                             (
                new List <AssetOnDesignPeriod>
            {
                new AssetOnDesignPeriod(machineDesignName, designId, assetId, DateTime.UtcNow.AddDays(-5),
                                        DateTime.UtcNow.AddDays(-1))
            }
                                                             );

            var tMachineDesigns = new[]
            {
                new TDesignName
                {
                    FID        = (int)expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].OnMachineDesignId,
                    FName      = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].OnMachineDesignName,
                    FStartDate = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].StartDate,
                    FEndDate   = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].EndDate,
                    FMachineID = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].MachineId
                }
            };

            raptorClient
            .Setup(x => x.GetOnMachineDesignEvents(projectIds.ProjectId))
            .Returns(tMachineDesigns);
            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_MACHINEDESIGNS")).Returns(false);

            // for GetMachineIdsExecutor
            GetRaptorMachineIdsMock(new[] { new TMachineDetail {
                                                Name = machineName, ID = assetId, IsJohnDoeMachine = isJohnDoe
                                            } },
                                    projectIds.ProjectId, raptorClient);

            // GetMachineIdsExecutor trex call to assetMatch on JohnDoe assets
            GetTRexMachineIdsMock(new List <MachineStatus>(1)
            {
                new MachineStatus(NULL_ASSETID, machineName, isJohnDoe, assetUid: assetUid)
            },
                                  projectIds.ProjectUid, configStore, false, true, tRexProxy);

            var executor = RequestExecutorContainerFactory
                           .Build <GetAssetOnDesignPeriodsExecutor>(logger, raptorClient.Object, configStore: configStore.Object,
                                                                    trexCompactionDataProxy: tRexProxy.Object,
                                                                    customHeaders: _customHeaders, customerUid: customerUid.ToString());

            var result = await executor.ProcessAsync(projectIds) as MachineDesignsExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(1, result.AssetOnDesignPeriods.Count, "Wrong design count");
            Assert.AreEqual(assetUid, result.AssetOnDesignPeriods[0].AssetUid, "Wrong assetUid");
            Assert.AreEqual(assetId, result.AssetOnDesignPeriods[0].MachineId, "Wrong legacyAssetId");
            Assert.AreEqual(designId, result.AssetOnDesignPeriods[0].OnMachineDesignId, "Wrong DesignId");
            Assert.AreEqual(machineDesignName, result.AssetOnDesignPeriods[0].OnMachineDesignName, "Wrong DesignName");
            Assert.AreEqual(expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].StartDate, result.AssetOnDesignPeriods[0].StartDate,
                            "Wrong StartDate");

            // the final design change is considered current
            Assert.IsTrue(result.AssetOnDesignPeriods[0].EndDate > expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].EndDate,
                          "Wrong EndDate");
        }
示例#23
0
        public async Task GetAssetOnDesignPeriodsExecutor_Raptor_MultiAssetUid()
        {
            var  projectIds        = new ProjectIDs(999, Guid.NewGuid());
            var  customerUid       = Guid.NewGuid();
            var  assetUid1Good     = Guid.NewGuid();
            long assetId1Good      = 777;
            var  assetUid1Expected = assetUid1Good;
            long assetId2Invalid   = 0; // johnDoe?
            Guid?assetUid2Expected = null;
            var  assetUid3Good     = Guid.NewGuid();
            long assetId3Good      = 888;
            var  assetUid3Expected = assetUid3Good;
            var  designId          = 888;

            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_MACHINEDESIGNS")).Returns(false);
            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_MACHINES")).Returns(false);
            configStore.Setup(x => x.GetValueBool("TREX_IS_AVAILABLE")).Returns(false);

            // GetAssetOnDesignPeriodsExecutor
            var expectedAssetOnDesignPeriodsExecutorResult = new MachineDesignsExecutionResult
                                                             (
                new List <AssetOnDesignPeriod>
            {
                new AssetOnDesignPeriod("The NameOf Design1", designId, assetId1Good, DateTime.UtcNow.AddDays(-5),
                                        DateTime.UtcNow.AddDays(-4)),
                new AssetOnDesignPeriod("The NameOf Design1", designId, assetId2Invalid, DateTime.UtcNow.AddDays(-3),
                                        DateTime.UtcNow.AddDays(-2)),
                new AssetOnDesignPeriod("The NameOf Design1", designId, assetId3Good, DateTime.UtcNow.AddDays(-2),
                                        DateTime.UtcNow.AddDays(-1)),
                new AssetOnDesignPeriod("The NameOf Design1", designId, assetId1Good, DateTime.UtcNow.AddDays(-10),
                                        DateTime.UtcNow.AddDays(-9)),
                new AssetOnDesignPeriod("The NameOf Design1", designId, assetId2Invalid, DateTime.UtcNow.AddDays(-10),
                                        DateTime.UtcNow.AddDays(-9)),
                new AssetOnDesignPeriod("The NameOf Design1", designId, assetId3Good, DateTime.UtcNow.AddDays(-10),
                                        DateTime.UtcNow.AddDays(-9))
            }
                                                             );

            var tMachineDesigns = new[]
            {
                new TDesignName
                {
                    FID        = (int)expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].OnMachineDesignId,
                    FName      = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].OnMachineDesignName,
                    FStartDate = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].StartDate,
                    FEndDate   = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].EndDate,
                    FMachineID = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].MachineId
                },
                new TDesignName
                {
                    FID        = (int)expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[1].OnMachineDesignId,
                    FName      = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[1].OnMachineDesignName,
                    FStartDate = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[1].StartDate,
                    FEndDate   = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[1].EndDate,
                    FMachineID = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[1].MachineId
                },
                new TDesignName
                {
                    FID        = (int)expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[2].OnMachineDesignId,
                    FName      = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[2].OnMachineDesignName,
                    FStartDate = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[2].StartDate,
                    FEndDate   = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[2].EndDate,
                    FMachineID = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[2].MachineId
                },
                new TDesignName
                {
                    FID        = (int)expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[3].OnMachineDesignId,
                    FName      = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[3].OnMachineDesignName,
                    FStartDate = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[3].StartDate,
                    FEndDate   = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[3].EndDate,
                    FMachineID = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[3].MachineId
                },
                new TDesignName
                {
                    FID        = (int)expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[4].OnMachineDesignId,
                    FName      = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[4].OnMachineDesignName,
                    FStartDate = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[4].StartDate,
                    FEndDate   = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[4].EndDate,
                    FMachineID = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[4].MachineId
                },
                new TDesignName
                {
                    FID        = (int)expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[5].OnMachineDesignId,
                    FName      = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[5].OnMachineDesignName,
                    FStartDate = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[5].StartDate,
                    FEndDate   = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[5].EndDate,
                    FMachineID = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[5].MachineId
                }
            };

            raptorClient
            .Setup(x => x.GetOnMachineDesignEvents(projectIds.ProjectId))
            .Returns(tMachineDesigns);

            // for GetMachineIdsExecutor
            var tMachines = new[]
            {
                new TMachineDetail {
                    Name = "blahblah1", ID = assetId1Good, IsJohnDoeMachine = false
                },
                new TMachineDetail {
                    Name = "blahblah2", ID = assetId3Good, IsJohnDoeMachine = false
                }
            };

            GetRaptorMachineIdsMock(tMachines, projectIds.ProjectId, raptorClient);

            // for GetMachineIdsExecutor
            var assetMatches = new List <KeyValuePair <Guid, long> >
            {
                new KeyValuePair <Guid, long>(assetUid1Good, assetId1Good),
                new KeyValuePair <Guid, long>(assetUid3Good, assetId3Good)
            };

            assetProxy.Setup(x => x.GetMatchingAssets(It.IsAny <List <long> >(), It.IsAny <HeaderDictionary>()))
            .ReturnsAsync(assetMatches);

            var executor = RequestExecutorContainerFactory
                           .Build <GetAssetOnDesignPeriodsExecutor>(logger, raptorClient.Object, configStore: configStore.Object,
                                                                    assetResolverProxy: assetProxy.Object,
                                                                    customHeaders: _customHeaders, customerUid: customerUid.ToString());

            var result = await executor.ProcessAsync(projectIds) as MachineDesignsExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(6, result.AssetOnDesignPeriods.Count, "Wrong design count");
            Assert.AreEqual(assetUid1Expected, result.AssetOnDesignPeriods[0].AssetUid, "Wrong asset1 Uid (0)");
            Assert.AreEqual(assetId1Good, result.AssetOnDesignPeriods[0].MachineId, "Wrong legacyAssetId1 (0)");
            Assert.AreEqual(expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].OnMachineDesignId, result.AssetOnDesignPeriods[0].OnMachineDesignId, "Wrong onMachineDesignId (0)");
            Assert.AreEqual(expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].OnMachineDesignName, result.AssetOnDesignPeriods[0].OnMachineDesignName, "Wrong onMachineDesignName (0)");
            Assert.AreEqual(assetUid1Expected, result.AssetOnDesignPeriods[1].AssetUid, "Wrong asset1 Uid (1)");
            Assert.AreEqual(assetId1Good, result.AssetOnDesignPeriods[1].MachineId, "Wrong legacyAssetId1 (1)");

            Assert.AreEqual(assetUid2Expected, result.AssetOnDesignPeriods[2].AssetUid, "Wrong asset2 Uid (2)");
            Assert.AreEqual(assetId2Invalid, result.AssetOnDesignPeriods[2].MachineId, "Wrong legacyAssetId2 (2)");
            Assert.AreEqual(assetUid2Expected, result.AssetOnDesignPeriods[3].AssetUid, "Wrong asset2 Uid (3)");
            Assert.AreEqual(assetId2Invalid, result.AssetOnDesignPeriods[3].MachineId, "Wrong legacyAssetId2 (3)");

            Assert.AreEqual(assetUid3Expected, result.AssetOnDesignPeriods[4].AssetUid, "Wrong asset3 Uid (4)");
            Assert.AreEqual(assetId3Good, result.AssetOnDesignPeriods[4].MachineId, "Wrong legacyAssetId3 (4)");
            Assert.AreEqual(assetUid3Expected, result.AssetOnDesignPeriods[5].AssetUid, "Wrong asset3 Uid (5)");
            Assert.AreEqual(assetId3Good, result.AssetOnDesignPeriods[5].MachineId, "Wrong legacyAssetId3 (5)");
        }
示例#24
0
        public async Task GetAssetOnDesignPeriodsExecutor_Raptor_Success()
        {
            var projectIds  = new ProjectIDs(999, Guid.NewGuid());
            var customerUid = Guid.NewGuid();
            var assetUid    = Guid.NewGuid();
            var assetId     = 777;
            var designId    = 888;
            var machineName = "MachineName2";
            var isJohnDoe   = false;

            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_MACHINEDESIGNS")).Returns(false);
            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_MACHINES")).Returns(false);
            configStore.Setup(x => x.GetValueBool("TREX_IS_AVAILABLE")).Returns(false);

            // GetAssetOnDesignPeriodsExecutor
            var expectedAssetOnDesignPeriodsExecutorResult = new MachineDesignsExecutionResult
                                                             (
                new List <AssetOnDesignPeriod>
            {
                new AssetOnDesignPeriod("The NameOf Design", designId, assetId, DateTime.UtcNow.AddDays(-5),
                                        DateTime.UtcNow.AddDays(-1))
            }
                                                             );

            var tMachineDesigns = new[]
            {
                new TDesignName
                {
                    FID        = (int)expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].OnMachineDesignId,
                    FName      = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].OnMachineDesignName,
                    FStartDate = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].StartDate,
                    FEndDate   = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].EndDate,
                    FMachineID = expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].MachineId
                }
            };

            raptorClient
            .Setup(x => x.GetOnMachineDesignEvents(projectIds.ProjectId))
            .Returns(tMachineDesigns);

            // for GetMachineIdsExecutor
            GetRaptorMachineIdsMock(new[] { new TMachineDetail {
                                                Name = machineName, ID = assetId, IsJohnDoeMachine = isJohnDoe
                                            } },
                                    projectIds.ProjectId, raptorClient);

            // for GetMachineIdsExecutor
            var assetMatches = new List <KeyValuePair <Guid, long> > {
                new KeyValuePair <Guid, long>(assetUid, assetId)
            };

            assetProxy.Setup(x => x.GetMatchingAssets(It.IsAny <List <long> >(), It.IsAny <HeaderDictionary>()))
            .ReturnsAsync(assetMatches);

            var executor = RequestExecutorContainerFactory
                           .Build <GetAssetOnDesignPeriodsExecutor>(logger, raptorClient.Object, configStore: configStore.Object,
                                                                    assetResolverProxy: assetProxy.Object,
                                                                    customHeaders: _customHeaders, customerUid: customerUid.ToString());

            var result = await executor.ProcessAsync(projectIds) as MachineDesignsExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(1, result.AssetOnDesignPeriods.Count, "Wrong design count");
            Assert.AreEqual(assetMatches[0].Key, result.AssetOnDesignPeriods[0].AssetUid, "Wrong assetUid");
            Assert.AreEqual(expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].MachineId, result.AssetOnDesignPeriods[0].MachineId,
                            "Wrong legacyAssetId");
            Assert.AreEqual(expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].OnMachineDesignId, result.AssetOnDesignPeriods[0].OnMachineDesignId, "Wrong DesignId");
            Assert.AreEqual(expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].OnMachineDesignName, result.AssetOnDesignPeriods[0].OnMachineDesignName, "Wrong DesignName");
            Assert.AreEqual(expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].StartDate, result.AssetOnDesignPeriods[0].StartDate,
                            "Wrong StartDate");

            // the final design change is considered current
            Assert.IsTrue(result.AssetOnDesignPeriods[0].EndDate > expectedAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].EndDate,
                          "Wrong EndDate");
        }
示例#25
0
        public async Task GetAssetOnDesignPeriodsExecutor_TRex_MultiAssetUid()
        {
            var projectIds       = new ProjectIDs(99, Guid.NewGuid());
            var customerUid      = Guid.NewGuid();
            var assetUid1Good    = Guid.NewGuid();
            var assetId1Expected = assetUid1Good.ToLegacyId();
            var assetUid2Good    = Guid.NewGuid();
            var assetId2Expected = assetUid2Good.ToLegacyId();
            var assetUid3Good    = Guid.NewGuid();
            var assetId3Expected = assetUid3Good.ToLegacyId();

            // for GetAssetOnDesignPeriodsExecutor
            var expectedGetAssetOnDesignPeriodsExecutorResult = new MachineDesignsExecutionResult
                                                                (
                new List <AssetOnDesignPeriod>
            {
                new AssetOnDesignPeriod("The NameOf Design1", NULL_RAPTOR_MACHINE_DESIGN_ID, NULL_ASSETID, DateTime.UtcNow.AddDays(-5), DateTime.UtcNow.AddDays(-4),
                                        assetUid1Good),
                new AssetOnDesignPeriod("The NameOf Design1", NULL_RAPTOR_MACHINE_DESIGN_ID, NULL_ASSETID, DateTime.UtcNow.AddDays(-3), DateTime.UtcNow.AddDays(-2),
                                        assetUid2Good),
                new AssetOnDesignPeriod("The NameOf Design1", NULL_RAPTOR_MACHINE_DESIGN_ID, NULL_ASSETID, DateTime.UtcNow.AddDays(-2), DateTime.UtcNow.AddDays(-1),
                                        assetUid3Good),
                new AssetOnDesignPeriod("The NameOf Design1", NULL_RAPTOR_MACHINE_DESIGN_ID, NULL_ASSETID, DateTime.UtcNow.AddDays(-10),
                                        DateTime.UtcNow.AddDays(-9), assetUid1Good),
                new AssetOnDesignPeriod("The NameOf Design1", NULL_RAPTOR_MACHINE_DESIGN_ID, NULL_ASSETID, DateTime.UtcNow.AddDays(-10),
                                        DateTime.UtcNow.AddDays(-9), assetUid2Good),
                new AssetOnDesignPeriod("The NameOf Design1", NULL_RAPTOR_MACHINE_DESIGN_ID, NULL_ASSETID, DateTime.UtcNow.AddDays(-10),
                                        DateTime.UtcNow.AddDays(-9), assetUid3Good)
            }
                                                                );

            tRexProxy.Setup(x => x.SendDataGetRequest <MachineDesignsExecutionResult>(projectIds.ProjectUid.ToString(),
                                                                                      It.IsAny <string>(),
                                                                                      It.IsAny <HeaderDictionary>(),
                                                                                      It.IsAny <List <KeyValuePair <string, string> > >()))
            .ReturnsAsync(expectedGetAssetOnDesignPeriodsExecutorResult);
            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_MACHINEDESIGNS")).Returns(true);

            // for GetMachineIdsExecutor
            var machines = new List <MachineStatus>(3)
            {
                new MachineStatus(NULL_ASSETID, "MachineName1", false, assetUid: assetUid1Good),
                new MachineStatus(NULL_ASSETID, "MachineName2", false, assetUid: assetUid2Good),
                new MachineStatus(NULL_ASSETID, "MachineName3", false, assetUid: assetUid3Good)
            };

            GetTRexMachineIdsMock(machines, projectIds.ProjectUid, configStore, true, false, tRexProxy);

            // GetAssetOnDesignPeriodsExecutor will call GetMachineIdsExecutor
            var executor = RequestExecutorContainerFactory
                           .Build <GetAssetOnDesignPeriodsExecutor>(logger, configStore: configStore.Object,
                                                                    trexCompactionDataProxy: tRexProxy.Object,
                                                                    customHeaders: _customHeaders, customerUid: customerUid.ToString());

            var result = await executor.ProcessAsync(projectIds) as MachineDesignsExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(6, result.AssetOnDesignPeriods.Count, "Wrong design count");
            Assert.AreEqual(assetUid1Good, result.AssetOnDesignPeriods[0].AssetUid, "Wrong asset1 Uid (0)");
            Assert.AreEqual(assetId1Expected, result.AssetOnDesignPeriods[0].MachineId, "Wrong legacyAssetId1 (0)");
            Assert.AreEqual(NULL_RAPTOR_MACHINE_DESIGN_ID, result.AssetOnDesignPeriods[0].OnMachineDesignId, "Wrong onMachineDesignId (0)");
            Assert.AreEqual(expectedGetAssetOnDesignPeriodsExecutorResult.AssetOnDesignPeriods[0].OnMachineDesignName, result.AssetOnDesignPeriods[0].OnMachineDesignName, "Wrong onMachineDesignName (0)");
            Assert.AreEqual(assetUid1Good, result.AssetOnDesignPeriods[1].AssetUid, "Wrong asset1 Uid (1)");
            Assert.AreEqual(assetId1Expected, result.AssetOnDesignPeriods[1].MachineId, "Wrong legacyAssetId1 (1)");

            Assert.AreEqual(assetUid2Good, result.AssetOnDesignPeriods[2].AssetUid, "Wrong asset2 Uid (2)");
            Assert.AreEqual(assetId2Expected, result.AssetOnDesignPeriods[2].MachineId, "Wrong legacyAssetId2 (2)");
            Assert.AreEqual(assetUid2Good, result.AssetOnDesignPeriods[3].AssetUid, "Wrong asset2 Uid (3)");
            Assert.AreEqual(assetId2Expected, result.AssetOnDesignPeriods[3].MachineId, "Wrong legacyAssetId2 (3)");

            Assert.AreEqual(assetUid3Good, result.AssetOnDesignPeriods[4].AssetUid, "Wrong asset3 Uid (4)");
            Assert.AreEqual(assetId3Expected, result.AssetOnDesignPeriods[4].MachineId, "Wrong legacyAssetId3 (4)");
            Assert.AreEqual(assetUid3Good, result.AssetOnDesignPeriods[5].AssetUid, "Wrong asset3 Uid (5)");
            Assert.AreEqual(assetId3Expected, result.AssetOnDesignPeriods[5].MachineId, "Wrong legacyAssetId3 (5)");
        }
示例#26
0
        public async Task GetAssetOnDesignLayerPeriodsExecutor_Raptor_MultiAssetUid()
        {
            var  projectIds        = new ProjectIDs(999, Guid.NewGuid());
            var  customerUid       = Guid.NewGuid();
            var  assetUid1Good     = Guid.NewGuid();
            long assetId1Good      = 777;
            var  machineName1      = "MachineName2";
            var  isJohnDoe1        = false;
            var  assetUid1Expected = assetUid1Good;
            long assetId2Invalid   = 0; // johnDoe?
            var  assetUid2Good     = Guid.NewGuid();
            Guid?assetUid2Expected = null;
            Guid?assetUid3NotFound = null;
            long assetId3NotFound  = 888;
            Guid?assetUid3Expected = null;
            var  designId          = 888;
            var  layerId           = 999;

            // for GetAssetOnDesignLayerPeriodsExecutor
            var expectedAssetOnDesignLayerPeriodsExecutionResult = new AssetOnDesignLayerPeriodsExecutionResult
                                                                   (
                new List <AssetOnDesignLayerPeriod>(1)
            {
                new AssetOnDesignLayerPeriod(assetId1Good, designId, layerId, DateTime.UtcNow.AddDays(-50), DateTime.UtcNow.AddDays(-49)),
                new AssetOnDesignLayerPeriod(assetId2Invalid, designId, layerId, DateTime.UtcNow.AddDays(-48), DateTime.UtcNow.AddDays(-47)),
                new AssetOnDesignLayerPeriod(assetId3NotFound, designId, layerId, DateTime.UtcNow.AddDays(-46), DateTime.UtcNow.AddDays(-45)),
                new AssetOnDesignLayerPeriod(assetId1Good, designId, layerId, DateTime.UtcNow.AddDays(-44), DateTime.UtcNow.AddDays(-43)),
                new AssetOnDesignLayerPeriod(assetId2Invalid, designId, layerId, DateTime.UtcNow.AddDays(-42), DateTime.UtcNow.AddDays(-41)),
                new AssetOnDesignLayerPeriod(assetId3NotFound, designId, layerId, DateTime.UtcNow.AddDays(-40), DateTime.UtcNow.AddDays(-38))
            }
                                                                   );

            var tLayers = new[]
            {
                new TDesignLayer
                {
                    FAssetID   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].AssetId,
                    FDesignID  = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].OnMachineDesignId,
                    FLayerID   = (int)expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].LayerId,
                    FStartTime = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].StartDate,
                    FEndTime   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].EndDate
                },
                new TDesignLayer
                {
                    FAssetID   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[1].AssetId,
                    FDesignID  = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[1].OnMachineDesignId,
                    FLayerID   = (int)expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[1].LayerId,
                    FStartTime = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[1].StartDate,
                    FEndTime   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[1].EndDate
                },
                new TDesignLayer
                {
                    FAssetID   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[2].AssetId,
                    FDesignID  = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[2].OnMachineDesignId,
                    FLayerID   = (int)expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[2].LayerId,
                    FStartTime = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[2].StartDate,
                    FEndTime   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[2].EndDate
                },
                new TDesignLayer
                {
                    FAssetID   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[3].AssetId,
                    FDesignID  = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[3].OnMachineDesignId,
                    FLayerID   = (int)expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[3].LayerId,
                    FStartTime = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[3].StartDate,
                    FEndTime   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[3].EndDate
                },
                new TDesignLayer
                {
                    FAssetID   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[4].AssetId,
                    FDesignID  = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[4].OnMachineDesignId,
                    FLayerID   = (int)expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[4].LayerId,
                    FStartTime = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[4].StartDate,
                    FEndTime   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[4].EndDate
                },
                new TDesignLayer
                {
                    FAssetID   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[5].AssetId,
                    FDesignID  = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[5].OnMachineDesignId,
                    FLayerID   = (int)expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[5].LayerId,
                    FStartTime = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[5].StartDate,
                    FEndTime   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[5].EndDate
                }
            };

            raptorClient
            .Setup(x => x.GetOnMachineLayers(projectIds.ProjectId, out tLayers))
            .Returns(0);
            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_LAYERS")).Returns(false);

            // for GetMachineIdsExecutor
            GetRaptorMachineIdsMock(new[] { new TMachineDetail {
                                                Name = machineName1, ID = assetId1Good, IsJohnDoeMachine = isJohnDoe1
                                            } },
                                    projectIds.ProjectId, raptorClient);

            // for GetMachineIdsExecutor
            var assets = new List <KeyValuePair <Guid, long> >
            {
                new KeyValuePair <Guid, long>(assetUid1Good, assetId1Good),
                new KeyValuePair <Guid, long>(assetUid2Good, assetId2Invalid)
            };

            assetProxy.Setup(x => x.GetMatchingAssets(It.IsAny <List <long> >(), It.IsAny <IHeaderDictionary>()))
            .ReturnsAsync(assets);
            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_MACHINES")).Returns(false);

            // GetAssetOnDesignLayerPeriodsExecutor will call GetMachineIdsExecutor
            var executor = RequestExecutorContainerFactory
                           .Build <GetAssetOnDesignLayerPeriodsExecutor>(logger, raptorClient.Object, configStore: configStore.Object,
                                                                         assetResolverProxy: assetProxy.Object,
                                                                         customHeaders: _customHeaders, customerUid: customerUid.ToString());
            var result = await executor.ProcessAsync(projectIds) as AssetOnDesignLayerPeriodsExecutionResult;

            Assert.AreEqual(6, result.AssetOnDesignLayerPeriods.Count, "Wrong design count");
            Assert.AreEqual(assetUid1Expected, result.AssetOnDesignLayerPeriods[0].AssetUid, "Wrong asset1 Uid (0)");
            Assert.AreEqual(assetId1Good, result.AssetOnDesignLayerPeriods[0].AssetId, "Wrong legacyAssetId1 (0)");
            Assert.AreEqual(designId, result.AssetOnDesignLayerPeriods[0].OnMachineDesignId, "Wrong onMachineDesignID (0)");
            Assert.IsNull(result.AssetOnDesignLayerPeriods[0].OnMachineDesignName, "Wrong onMachineDesignName (0)");
            Assert.AreEqual(assetUid2Expected, result.AssetOnDesignLayerPeriods[1].AssetUid, "Wrong asset2 Uid (1)");
            Assert.AreEqual(assetId2Invalid, result.AssetOnDesignLayerPeriods[1].AssetId, "Wrong legacyAssetId2 (1)");
            Assert.AreEqual(designId, result.AssetOnDesignLayerPeriods[1].OnMachineDesignId, "Wrong onMachineDesignID (1)");
            Assert.IsNull(result.AssetOnDesignLayerPeriods[1].OnMachineDesignName, "Wrong onMachineDesignName (1)");
            Assert.AreEqual(assetUid3Expected, result.AssetOnDesignLayerPeriods[2].AssetUid, "Wrong asset3 Uid (2)");
            Assert.AreEqual(assetId3NotFound, result.AssetOnDesignLayerPeriods[2].AssetId, "Wrong legacyAssetId3 (2)");

            Assert.AreEqual(assetUid1Expected, result.AssetOnDesignLayerPeriods[3].AssetUid, "Wrong asset1 Uid (2)");
            Assert.AreEqual(assetId1Good, result.AssetOnDesignLayerPeriods[3].AssetId, "Wrong legacyAssetId1 (2)");
            Assert.AreEqual(assetUid2Expected, result.AssetOnDesignLayerPeriods[4].AssetUid, "Wrong asset2 Uid (3)");
            Assert.AreEqual(assetId2Invalid, result.AssetOnDesignLayerPeriods[4].AssetId, "Wrong legacyAssetId2 (3)");
            Assert.AreEqual(assetUid3Expected, result.AssetOnDesignLayerPeriods[5].AssetUid, "Wrong asset3 Uid (5)");
            Assert.AreEqual(assetId3NotFound, result.AssetOnDesignLayerPeriods[5].AssetId, "Wrong legacyAssetId3 (5)");
        }
示例#27
0
        public async Task GetAssetOnDesignLayerPeriodsExecutor_Raptor_Success()
        {
            var projectIds  = new ProjectIDs(999, Guid.NewGuid());
            var customerUid = Guid.NewGuid();
            var assetId     = 777;
            var assetUid    = Guid.NewGuid();
            var designId    = 888;
            var layerId     = 999;
            var machineName = "MachineName2";
            var isJohnDoe   = false;

            // for GetAssetOnDesignLayerPeriodsExecutor
            var expectedAssetOnDesignLayerPeriodsExecutionResult = new AssetOnDesignLayerPeriodsExecutionResult
                                                                   (
                new List <AssetOnDesignLayerPeriod>(1)
            {
                new AssetOnDesignLayerPeriod(assetId, designId, layerId, DateTime.UtcNow.AddDays(-50), DateTime.UtcNow.AddDays(-40))
            }
                                                                   );

            var tLayers = new[]
            {
                new TDesignLayer
                {
                    FAssetID   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].AssetId,
                    FDesignID  = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].OnMachineDesignId,
                    FLayerID   = (int)expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].LayerId,
                    FStartTime = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].StartDate,
                    FEndTime   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].EndDate
                }
            };

            raptorClient
            .Setup(x => x.GetOnMachineLayers(projectIds.ProjectId, out tLayers))
            .Returns(0);
            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_LAYERS")).Returns(false);

            // for GetMachineIdsExecutor
            GetRaptorMachineIdsMock(new[] { new TMachineDetail {
                                                Name = machineName, ID = assetId, IsJohnDoeMachine = isJohnDoe
                                            } },
                                    projectIds.ProjectId, raptorClient);

            // for GetMachineIdsExecutor
            var assetMatches = new List <KeyValuePair <Guid, long> > {
                new KeyValuePair <Guid, long>(assetUid, assetId)
            };

            assetProxy.Setup(x => x.GetMatchingAssets(It.IsAny <List <long> >(), It.IsAny <IHeaderDictionary>()))
            .ReturnsAsync(assetMatches);
            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_MACHINES")).Returns(false);

            // GetAssetOnDesignLayerPeriodsExecutor will call GetMachineIdsExecutor
            var executor = RequestExecutorContainerFactory
                           .Build <GetAssetOnDesignLayerPeriodsExecutor>(logger, raptorClient.Object, configStore: configStore.Object,
                                                                         assetResolverProxy: assetProxy.Object,
                                                                         customHeaders: _customHeaders, customerUid: customerUid.ToString());
            var result = await executor.ProcessAsync(projectIds) as AssetOnDesignLayerPeriodsExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(1, result.AssetOnDesignLayerPeriods.Count, "Wrong layer count");
            Assert.AreEqual(expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].AssetId, result.AssetOnDesignLayerPeriods[0].AssetId, "Wrong machine OnMachineDesignId");
            Assert.AreEqual(assetMatches[0].Key, result.AssetOnDesignLayerPeriods[0].AssetUid, "Wrong assetUid");

            Assert.AreEqual(expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].OnMachineDesignId, result.AssetOnDesignLayerPeriods[0].OnMachineDesignId, "Wrong design OnMachineDesignId");
            Assert.IsNull(result.AssetOnDesignLayerPeriods[0].OnMachineDesignName, "Wrong design OnMachineDesignName");
            Assert.AreEqual(expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].LayerId, result.AssetOnDesignLayerPeriods[0].LayerId, "Wrong layer OnMachineDesignId");
            Assert.AreEqual(expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].StartDate, result.AssetOnDesignLayerPeriods[0].StartDate, "Wrong startDate");
            Assert.AreEqual(expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].EndDate, result.AssetOnDesignLayerPeriods[0].EndDate, "Wrong endDate");
        }
示例#28
0
        /// <summary>
        /// Matches asset UIDs returned from TRex to legacy asset IDs.
        /// </summary>
        protected async Task <Dictionary <Guid, long> > GetAssetIds(ProjectIDs projectIds, List <Guid> assetUids)
        {
            var machineExecutionResult = await GetMachines(projectIds) as MachineExecutionResult;

            return(machineExecutionResult?.MachineStatuses?.Where(a => a.AssetUid.HasValue && assetUids.Contains(a.AssetUid.Value)).ToDictionary(m => m.AssetUid.Value, m => m.AssetId));
        }
示例#29
0
        public async Task GetAssetOnDesignLayerPeriodsExecutor_RaptorJohnDoe_Success()
        {
            var projectIds  = new ProjectIDs(999, Guid.NewGuid());
            var customerUid = Guid.NewGuid();
            var assetId     = 777;
            var assetUid    = Guid.NewGuid();
            var designId    = 888;
            var layerId     = 999;
            var machineName = "MachineName2";
            var isJohnDoe   = true;

            // for GetAssetOnDesignLayerPeriodsExecutor
            var expectedAssetOnDesignLayerPeriodsExecutionResult = new AssetOnDesignLayerPeriodsExecutionResult
                                                                   (
                new List <AssetOnDesignLayerPeriod>(1)
            {
                new AssetOnDesignLayerPeriod(assetId, designId, layerId, DateTime.UtcNow.AddDays(-50), DateTime.UtcNow.AddDays(-40))
            }
                                                                   );

            var tLayers = new[]
            {
                new TDesignLayer
                {
                    FAssetID   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].AssetId,
                    FDesignID  = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].OnMachineDesignId,
                    FLayerID   = (int)expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].LayerId,
                    FStartTime = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].StartDate,
                    FEndTime   = expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].EndDate
                }
            };

            raptorClient
            .Setup(x => x.GetOnMachineLayers(projectIds.ProjectId, out tLayers))
            .Returns(0);
            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_LAYERS")).Returns(false);

            // for GetMachineIdsExecutor
            GetRaptorMachineIdsMock(new[] { new TMachineDetail {
                                                Name = machineName, ID = assetId, IsJohnDoeMachine = isJohnDoe
                                            } },
                                    projectIds.ProjectId, raptorClient);

            // GetMachineIdsExecutor trex call to assetMatch on JohnDoe assets
            GetTRexMachineIdsMock(new List <MachineStatus>(1)
            {
                new MachineStatus(NULL_ASSETID, machineName, isJohnDoe, assetUid: assetUid)
            },
                                  projectIds.ProjectUid, configStore, false, true, tRexProxy);


            // GetAssetOnDesignLayerPeriodsExecutor will call GetMachineIdsExecutor
            var executor = RequestExecutorContainerFactory
                           .Build <GetAssetOnDesignLayerPeriodsExecutor>(logger, raptorClient.Object, configStore: configStore.Object,
                                                                         trexCompactionDataProxy: tRexProxy.Object,
                                                                         customHeaders: _customHeaders, customerUid: customerUid.ToString());
            var result = await executor.ProcessAsync(projectIds) as AssetOnDesignLayerPeriodsExecutionResult;

            Assert.IsNotNull(result, "Result should not be null");
            Assert.AreEqual(1, result.AssetOnDesignLayerPeriods.Count, "Wrong layer count");
            Assert.AreEqual(expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].AssetId, result.AssetOnDesignLayerPeriods[0].AssetId, "Wrong machine OnMachineDesignId");
            Assert.AreEqual(assetUid, result.AssetOnDesignLayerPeriods[0].AssetUid, "Wrong assetUid");

            Assert.AreEqual(expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].OnMachineDesignId, result.AssetOnDesignLayerPeriods[0].OnMachineDesignId, "Wrong design OnMachineDesignId");
            Assert.IsNull(result.AssetOnDesignLayerPeriods[0].OnMachineDesignName, "Wrong design OnMachineDesignName");
            Assert.AreEqual(layerId, result.AssetOnDesignLayerPeriods[0].LayerId, "Wrong layer OnMachineDesignId");
            Assert.AreEqual(expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].StartDate, result.AssetOnDesignLayerPeriods[0].StartDate, "Wrong startDate");
            Assert.AreEqual(expectedAssetOnDesignLayerPeriodsExecutionResult.AssetOnDesignLayerPeriods[0].EndDate, result.AssetOnDesignLayerPeriods[0].EndDate, "Wrong endDate");
        }
示例#30
0
        public void ProjectIDsRequest_Success(int projectId, string projectUid)
        {
            var request = new ProjectIDs(projectId, Guid.Parse(projectUid));

            request.Validate();
        }