Example #1
0
        public void RemoveRepair(RepairData repairData)
        {
            Events.Remove((repairData.customControllerData as CustomPRCData).PAWSelectionToggleButton);
            part.Events.Remove((repairData.customControllerData as CustomPRCData).PAWSelectionToggleButton);
            part.PartActionWindow.displayDirty = true;

            repairDatas.Remove(repairData);
        }
Example #2
0
        public void AddRepair_ReturnsBadRequest()
        {
            RepairData repair = new RepairData();

            _repairController.ModelState.AddModelError("Customer", "Required");

            var badResponse = _repairController.CreateRepair(repair);

            Assert.IsType <BadRequestObjectResult>(badResponse);
        }
Example #3
0
        public void AddRepair_CustomerNotExistReturnsBadRequest()
        {
            RepairData repair = new RepairData
            {
                Customer = 100
            };

            var badResponse = _repairController.CreateRepair(repair);

            Assert.IsType <BadRequestObjectResult>(badResponse);
        }
Example #4
0
        public void AddRepair_ReturnsCreatedResponse()
        {
            RepairData repair = new RepairData
            {
                Customer = 1
            };

            var createdResponse = _repairController.CreateRepair(repair);

            Assert.IsType <CreatedResult>(createdResponse);
        }
Example #5
0
        public void AddRepair_ReturnedResponseHasCreatedMessage()
        {
            RepairData repair = new RepairData
            {
                Customer = 1
            };

            ActionResult <Repair> actionResult  = _repairController.CreateRepair(repair);
            CreatedResult         createdResult = actionResult.Result as CreatedResult;
            var result = createdResult.Value;

            Assert.Equal("Repair Created", result);
        }
Example #6
0
 static KSPEvent GenerateCutAssignmentsAttribs(RepairData repairData)
 {
     return(new KSPEvent
     {
         guiActive = true,
         guiActiveUncommand = true,
         guiActiveUnfocused = true,
         requireFullControl = false,
         guiName = $"Cut Assignments For {repairData.RepairOptionDescription}",
         groupName = "KRTRepeirsAssignment",
         groupDisplayName = "KRT Repairs Assignment"
     });
 }
Example #7
0
 static KSPEvent GenerateRepairAssignmentCatchingToggleAtribs(RepairData repairData)
 {
     return(new KSPEvent
     {
         guiActive = true,
         guiActiveUncommand = true,
         guiActiveUnfocused = true,
         requireFullControl = false,
         guiName = $"Start Assigning: {repairData.RepairOptionDescription}",
         groupName = "KRTRepeirsAssignment",
         groupDisplayName = "KRT Repairs Assignment"
     });
 }
Example #8
0
        void StartRepairAssignment(RepairData repairData, CustomPRCData customPRCData)
        {
            customPRCData.PAWCatchingAssignmentButton.guiName = $"Stop Assigning: {repairData.RepairOptionDescription}";
            repairsCatchingAssignments.Add(repairData);

            customPRCData.PAWCutAssignmentsButton = new BaseEvent(Events, $"CutAssignmentsFor {repairData.RepairOptionDescription}",
                                                                  () => CutRepairAssignments(repairData), GenerateCutAssignmentsAttribs(repairData));

            participantsCatchingAssignments.RemoveAll((IRepairParticipant a) => a == null);
            foreach (IRepairParticipant assigningRepairParticipant in participantsCatchingAssignments)
            {
                PerformAssignment(assigningRepairParticipant, repairData);
            }
        }
Example #9
0
        void DeselectRepair(RepairData repairData)      // Does not call repairData.Deselect, supposed to be used after/before calling it or Toggle somewhere else
        {
            CustomPRCData cPRCD = (repairData.customControllerData as CustomPRCData);

            cPRCD.PAWSelectionToggleButton.guiName = $"Select: {repairData.RepairOptionDescription}";

            Events.Remove(cPRCD.PAWCatchingAssignmentButton);
            part.Events.Remove(cPRCD.PAWCatchingAssignmentButton);
            part.PartActionWindow.displayDirty = true;
            cPRCD.PAWCatchingAssignmentButton  = null;

            StopRepairAssignment(repairData, cPRCD);
            CutRepairAssignments(repairData);
        }
Example #10
0
        public void AddRepair(RepairData repairData)
        {
            repairDatas.Add(repairData);

            KSPEvent attribHolder = GenerateRepairOptionSelectionAttribs(repairData);

            repairData.customControllerData = new CustomPRCData(repairData.RequestedResources.Keys.AsEnumerable());
            BaseEvent PAWButton = new BaseEvent(Events, $"SelectionToggle {repairData.RepairOptionDescription}", () =>
            {
                ToggleRepairSelection(repairData);
            }, attribHolder);

            Events.Add(PAWButton);
            (repairData.customControllerData as CustomPRCData).PAWSelectionToggleButton = PAWButton;
        }
Example #11
0
        static KSPEvent GenerateRepairOptionSelectionAttribs(RepairData repairData)
        {
            KSPEvent attribHolder = new KSPEvent
            {
                guiActive          = true,
                guiActiveUncommand = true,
                guiActiveUnfocused = true,
                requireFullControl = false,
                guiName            = $"Select: {repairData.RepairOptionDescription}",
                groupName          = "KRTRepeirsSelection",
                groupDisplayName   = "KRT Repairs Selection",
            };

            return(attribHolder);
        }
Example #12
0
        void ToggleRepairAssigning(RepairData repairData)
        {
            CustomPRCData customPRCData = repairData.customControllerData as CustomPRCData;

            customPRCData.isBeingAssigned = !customPRCData.isBeingAssigned;

            if (customPRCData.isBeingAssigned)
            {
                StartRepairAssignment(repairData, customPRCData);
            }
            else
            {
                StopRepairAssignment(repairData, customPRCData);
            }
        }
Example #13
0
        void ToggleRepairSelection(RepairData repairData)
        {
            if (repairData == null)
            {
                Debug.LogError($"[KRT] Repair toggle button pressed but relevant repairData is null");
                return;
            }
            repairData.ToggleSelection();

            if (repairData.IsSelected)
            {
                SelectRepair(repairData);
            }
            else
            {
                DeselectRepair(repairData);
            }
        }
Example #14
0
        void CutRepairAssignments(RepairData repairData)
        {
            CustomPRCData cPRCD = (repairData.customControllerData as CustomPRCData);

            if (cPRCD.PAWCutAssignmentsButton != null)
            {
                Events.Remove(cPRCD.PAWCutAssignmentsButton);
                part.Events.Remove(cPRCD.PAWCutAssignmentsButton);
                cPRCD.PAWCutAssignmentsButton = null;
            }

            cPRCD.assignedParticipants.RemoveAll((IRepairParticipant a) => a == null);
            foreach (IRepairParticipant repairParticipant in cPRCD.assignedParticipants)
            {
                repairParticipant.DeassignRepair(repairData);
            }
            cPRCD.assignedParticipants.Clear();
        }
Example #15
0
        public void UpdateRepair_DateCompletedIsBeforeDateOpenedReturnsBadRequest()
        {
            RepairData repair = new RepairData
            {
                Customer = 1
            };

            var createdRepair = _fixItTrackerRepository.AddRepair(repair.Repair);

            var jsonPatchDocument  = new JsonPatchDocument <RepairPatchData>();
            var jsonPatchOperation = new Operation <RepairPatchData>("replace", "DateCompleted", null, createdRepair.DateOpened.AddYears(-1).ToShortDateString());

            jsonPatchDocument.Operations.Add(jsonPatchOperation);

            var badResponse = _repairController.UpdateRepair(createdRepair.RepairID, jsonPatchDocument);

            Assert.IsType <BadRequestObjectResult>(badResponse);
        }
Example #16
0
        void SelectRepair(RepairData repairData)        // Does not call repairData.Select, supposed to be used after/before calling it or Toggle somewhere else
        {
            string displayedResList = $"Chosen repair option is {repairData.RepairOptionDescription}.\nIt needs this set of rsources to be completed\n(Assuming repair efficiency is not lower than 1):";

            foreach (KeyValuePair <string, double> i in repairData.RequestedResources)
            {
                displayedResList += $"\n{PartResourceLibrary.Instance.GetDefinition(i.Key).displayName}: {i.Value}";
            }
            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "KRTRepairRequests", "Repair Option Chosen", displayedResList, "Prepare Duct Tape!", false, HighLogic.UISkin);
            (repairData.customControllerData as CustomPRCData).PAWSelectionToggleButton.guiName = $"Deselect: {repairData.RepairOptionDescription}";

            KSPEvent  attribHolder = GenerateRepairAssignmentCatchingToggleAtribs(repairData);
            BaseEvent PAWButton    = new BaseEvent(Events, $"AssigningToggle: {repairData.RepairOptionDescription}", () =>
            {
                ToggleRepairAssigning(repairData);
            }, attribHolder);

            Events.Add(PAWButton);
            (repairData.customControllerData as CustomPRCData).PAWCatchingAssignmentButton = PAWButton;
        }
Example #17
0
        public double GetAssignedQuality(RepairData repair)         // Making it repair-dependent for further possible features
        {
            if (part.protoModuleCrew.Count == 1)
            {
                ProtoCrewMember kerbal = part.protoModuleCrew[0];

                if (kerbal != null)
                {
                    return(KerbalReconstructionTapeAddon.GetRepairQuality(kerbal.trait, kerbal.experienceLevel));
                }
                else
                {
                    Debug.LogError($"[KRT] Bungler module at part {part.name} has found a null ProtoCrewMember");
                    return(0);
                }
            }
            else
            {
                Debug.LogError($"[KRT] Bungler module has found out that his part {part.name} has not 1 crew member. It seems it is not an EVA Kerbal.");
                return(0);
            }
        }
Example #18
0
        public double GetAssginedWorkPower(RepairData repair)
        {
            if (part.protoModuleCrew.Count == 1)
            {
                ProtoCrewMember kerbal = part.protoModuleCrew[0];

                if (kerbal != null)
                {
                    return(KerbalReconstructionTapeAddon.GetRepairSpeed(kerbal.trait, kerbal.experienceLevel) * KerbalReconstructionTapeAddon.GetRepairQuality(kerbal.trait, kerbal.experienceLevel));
                }
                else
                {
                    Debug.LogError($"[KRT] Bungler module at part {part.name} has found a null ProtoCrewMember");
                    return(0);
                }
            }
            else
            {
                Debug.LogError($"[KRT] Bungler module has found out that his part {part.name} has not 1 crew member. It seems it is not an EVA Kerbal.");
                return(0);
            }
        }
Example #19
0
        static void PerformAssignment(IRepairParticipant repairParticipant, RepairData repairData)
        {
            CustomPRCData cPRCD = repairData.customControllerData as CustomPRCData;

            cPRCD.assignedParticipants.Add(repairParticipant);
            repairParticipant.AssignRepair(repairData);

            double newlyAssignedQuality = repairParticipant.GetAssignedQuality(repairData);

            if (newlyAssignedQuality > cPRCD.maxAssignedQuality)
            {
                cPRCD.maxAssignedQuality = newlyAssignedQuality;
            }

            if (repairParticipant.IsHandlingThisRepairNow(repairData) && newlyAssignedQuality > cPRCD.currentlyAvailableQuality)
            {
                cPRCD.currentlyAvailableQuality = newlyAssignedQuality;
            }

            if (newlyAssignedQuality > cPRCD.workingAtQuality && (repairData.progressRatio != 0 || cPRCD.isRunning))
            {
                // TODO: notify about ability to restart repair for better quality
            }
        }
Example #20
0
        public ActionResult CreateRepair([FromBody] RepairData repairData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Customer customer = _dataContext.GetCustomer(repairData.Customer);

            if (customer == null)
            {
                return(BadRequest("Customer doesn't exist"));
            }

            Repair repair = repairData.Repair;

            repair.Customer = customer;

            var createdRepair = _dataContext.AddRepair(repair);

            var uri = Request != null?Request.GetDisplayUrl().ToString() + createdRepair.RepairID : "";

            return(Created(uri, "Repair Created"));
        }
Example #21
0
 public void DeassignRepair(RepairData repair)
 {
     tasks.Remove(repair);
 }
Example #22
0
 public void AssignRepair(RepairData repair)
 {
     tasks.Add(repair);
 }
Example #23
0
 void StopRepairAssignment(RepairData repairData, CustomPRCData customPRCData)
 {
     customPRCData.PAWCatchingAssignmentButton.guiName = $"Start Assigning: {repairData.RepairOptionDescription}";
     repairsCatchingAssignments.RemoveAll((RepairData a) => a == repairData);
 }
Example #24
0
 public bool IsHandlingThisRepairNow(RepairData repair)
 {
     return(tasks[0] == repair);
 }
Example #25
0
        public async Task Save(string id, RepairData data)
        {
            await Repair.DeleteOneAsync(Builders <RepairInfo> .Filter.Where(info => info.Key == id));

            await Repair.InsertOneAsync(new RepairInfo { Key = id, RepairData = data });
        }