public void ApplyToMechlab() { if (Applied) { return; } var mechLab = MechLabHelper.CurrentMechLab; var lhelper = mechLab.GetLocationHelper(Location); if (lhelper == null) { return; } if (slot != null) { if (mechLab.InSimGame) { WorkOrderEntry_InstallComponent subEntry = mechLab.MechLab.Sim.CreateComponentInstallWorkOrder( mechLab.MechLab.baseWorkOrder.MechID, slot.ComponentRef, Location, slot.MountedLocation); mechLab.MechLab.baseWorkOrder.AddSubEntry(subEntry); } } else { slot = DefaultHelper.CreateSlot(ItemID, Type); } lhelper.widget.OnAddItem(slot, true); slot.MountedLocation = Location; }
internal static void AddDefaultToInventory(MechDef mechdef, SimGameState simgame, ChassisLocations location, ArmActuatorSlot slot, ref ArmActuatorSlot totalSlots) { bool add_item(string id, ref ArmActuatorSlot total_slot) { if (string.IsNullOrEmpty(id)) { return(false); } var r = DefaultHelper.CreateRef(id, ComponentType.Upgrade, UnityGameInstance.BattleTechGame.DataManager, simgame); if (r.Is <ArmActuator>(out var actuator) && (actuator.Type & total_slot) == 0) { DefaultHelper.AddInventory(id, mechdef, location, ComponentType.Upgrade, simgame); total_slot = total_slot | actuator.Type; return(true); } return(false); } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- adding {slot} to {totalSlots}"); if (totalSlots.HasFlag(slot)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- already present"); return; } if (add_item(GetDefaultActuator(mechdef, location, slot), ref totalSlots)) { return; } add_item(GetDefaultActuator(null, location, slot), ref totalSlots); }
public ControlPoint this[int index] { get { if (_client is ExpandoObject) { return((_client as ExpandoObject).HasProperty("this[int index]") ? _client[index] : default(ControlPoint)); } var local = this; return(X.Instance.CurrentContext.GetValue(sc => { if (DefaultHelper.IsDefault(local._client[index])) { return default(ControlPoint); } return new ControlPoint(local._client[index]); })); } set { if (_client is ExpandoObject) { _client[index] = value; } } }
public void ExpectValidSenderTest() { var line = "31/03/2019 03:23 - Giovani: To aqui cara"; var sender = DefaultHelper.ValidSender(line); Assert.Equal(sender, "Giovani"); }
public async Task <List <ChatMessage> > SearchEntityChatText(string text, int id) { var messages = await _context.Chats.Where(c => c.FolderId == id).OrderByDescending(c => c.MessageTime).ToListAsync(); var findText = DefaultHelper.SearchChatText(text, messages); return(findText); }
public void ExpectCleanMessageTest() { //Given var line = "31/03/2019 03:23 - Giovani: To aqui cara"; var message = DefaultHelper.CleanMessage(line); Assert.Equal(message, "To aqui cara"); }
public void ExpectValidDateTest() { var dateFormat = "dd/MM/yyyy HH:mm"; var line = "31/03/2019 03:23 - Giovani: To aqui cara"; var parsedDate = DefaultHelper.ValidDate(line, dateFormat); Assert.NotNull(parsedDate); }
private void SetDefaultPayment(PaymentType paymentType) { SelectedPayment = new Payment { Type = (int)paymentType, Date = DateTime.Now, // Assign empty category to reset the GUI Category = new Category(), ChargedAccount = DefaultHelper.GetDefaultAccount(ChargedAccounts.ToList()) }; }
public void SearchChatTextTest() { var msgList = new List <ChatMessage>(); msgList.Add(new ChatMessage("tester", DateTime.Now, DateTime.Now, "ShOuLD IgNoRe Case", 0)); var search = "should"; var helper = DefaultHelper.SearchChatText(search, msgList); Assert.Equal(helper.Count, 1); }
public void ApplyToInventory(MechDef mech, List <MechComponentRef> inventory) { if (Applied) { return; } var r = DefaultHelper.CreateRef(ItemID, Type, Location); if (r.IsDefault()) { inventory.Add(r); } }
public void PreviewApply(InventoryOperationState state) { InvItem i = null; if (!Applied) { i = new InvItem(DefaultHelper.CreateRef(ItemID, Type, Location), Location); item = i.Item; } if (i != null) { state.Inventory.Add(i); } }
/// <summary> /// Used to fill in the extra details into the insights data before storage. /// </summary> /// <param name="data"></param> private async Task FillData(IInsightData data) { data.Created = DateTime.UtcNow; data.AppVersion = CleanVersion(DefaultHelper.GetOrDefault(_deviceInfo.GetAppVersion, new Version("0.0.0.0"))); data.Battery = await DefaultHelper.GetOrDefaultAsync(_deviceInfo.GetBattery, null); data.ConnectionStrength = await DefaultHelper.GetOrDefaultAsync(_deviceInfo.GetConnectionStrength, null); data.ConnectionType = DefaultHelper.GetOrDefault(_deviceInfo.GetConnectionType, ConnectionType.Unknown); data.DeviceIdentifier = DefaultHelper.GetOrDefault(_deviceInfo.GetUniqueId, ""); data.FullName = _fullName; data.Id = Guid.NewGuid(); data.IPAddress = await DefaultHelper.GetOrDefaultAsync(_deviceInfo.GetIPAddress, ""); data.Model = await DefaultHelper.GetOrDefaultAsync(_deviceInfo.GetModel, ""); data.OSVersion = CleanVersion(await DefaultHelper.GetOrDefaultAsync(_deviceInfo.GetOSVersion, new Version("0.0.0.0"))); data.SessionId = _sessionId; data.UserId = _userId; }
private static void MakeMech(SimGameState sim) { Control.LogDebug($"Mech Assembly started for {mech.Description.UIName}"); MechDef new_mech = new MechDef(mech, mechBay.Sim.GenerateSimGameUID(), true); try { if (Control.Settings.UnEquipedMech) { Control.LogDebug($"-- Clear Inventory"); #if USE_CC new_mech.SetInventory(DefaultHelper.ClearInventory(new_mech, mechBay.Sim)); #else new_mech.SetInventory(new MechComponentRef[0]); #endif } } catch (Exception e) { Control.LogError($"ERROR in ClearInventory", e); } if (Control.Settings.BrokenMech) { BrokeMech(new_mech, sim); } try { Control.LogDebug("-- Adding mech"); mechBay.Sim.AddMech(0, new_mech, true, false, true, null); Control.LogDebug("-- Posting Message"); mechBay.Sim.MessageCenter.PublishMessage(new SimGameMechAddedMessage(new_mech, chassis.MechPartMax, true)); } catch (Exception e) { Control.LogError($"ERROR in MakeMach", e); } }
internal static void ClearInventory(MechDef mech, List <MechComponentRef> result, SimGameState state) { if (SkipArmActuatorValidationAndFixingForMechDef(mech)) { return; } var total_slot = ArmActuatorSlot.None; void add_default(ChassisLocations location, ArmActuatorSlot slot) { bool add_item(string id) { CustomComponents.Control.LogDebug(DType.ClearInventory, $"--- adding {id} to {location}"); if (string.IsNullOrEmpty(id)) { CustomComponents.Control.LogDebug(DType.ClearInventory, $"---- is null - skipping"); return(false); } var r = DefaultHelper.CreateRef(id, ComponentType.Upgrade, state.DataManager, state); if (r.Is <ArmActuator>(out var actuator) && (actuator.Type & total_slot) == 0) { r.SetData(location, -1, ComponentDamageLevel.Functional, true); result.Add(r); total_slot = total_slot | actuator.Type; return(true); } return(false); } if (total_slot.HasFlag(slot)) { CustomComponents.Control.LogDebug(DType.ClearInventory, $"--- already have {slot} skip"); return; } if (!add_item(GetDefaultActuator(mech, location, slot))) { add_item(GetDefaultActuator(null, location, slot)); } } void clear_side(ChassisLocations location) { result.RemoveAll(i => i.MountedLocation == location & i.Is <ArmActuator>() && !i.IsModuleFixed(mech)); total_slot = ArmActuatorSlot.None; foreach (var item in result.Where(i => i.MountedLocation == location)) { if (item.Is <ArmActuator>(out var a)) { total_slot = total_slot | a.Type; } } CustomComponents.Control.LogDebug(DType.ClearInventory, $"-- {location} current {total_slot}"); add_default(location, ArmActuatorSlot.PartShoulder); add_default(location, ArmActuatorSlot.PartUpper); if (ArmActuatorFeature.settings.ForceFullDefaultActuators && !IsIgnoreFullActuators(mech)) { var limit = mech.Chassis.Is <ArmActuatorSupport>(out var s) ? s.GetLimit(location) : ArmActuatorSlot.Hand; if (limit.HasFlag(ArmActuatorSlot.Lower)) { add_default(location, ArmActuatorSlot.PartLower); } if (limit.HasFlag(ArmActuatorSlot.Hand)) { add_default(location, ArmActuatorSlot.PartHand); } } } clear_side(ChassisLocations.LeftArm); clear_side(ChassisLocations.RightArm); }
public string ReplaceValidateDrop(MechLabItemSlotElement drop_item, LocationHelper location, List <IChange> changes) { if (location.widget.loadout.Location != ChassisLocations.LeftArm && location.widget.loadout.Location != ChassisLocations.RightArm) { return(string.Empty); } var total_slot = Type; var mount_loc = location.widget.loadout.Location; var mechlab = location.mechLab; var mech = mechlab.activeMechDef; CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- ArmActuator: {Def.Description.Id} {Type}"); void add_default(ArmActuatorSlot slot) { bool add_item(string id) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- id:[{id}]"); if (string.IsNullOrEmpty(id)) { return(false); } var r = DefaultHelper.CreateRef(id, ComponentType.Upgrade, mechlab.dataManager, mechlab.Sim); if (r.Is <ArmActuator>(out var actuator) && (actuator.Type & total_slot) == 0) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"----- actuator fit: install"); changes.Add(new AddDefaultChange(mount_loc, DefaultHelper.CreateSlot(r, mechlab))); total_slot = total_slot | actuator.Type; return(true); } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"----- actuator not fit, ski[["); return(false); } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- adding {slot} to {total_slot}"); if (total_slot.HasFlag(slot)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- already exist, return"); return; } if (add_item(ArmActuatorCC.GetDefaultActuator(mech, mount_loc, slot))) { return; } add_item(ArmActuatorCC.GetDefaultActuator(null, mount_loc, slot)); } foreach (var item in location.LocalInventory.Where(i => i.ComponentRef.Is <ArmActuator>())) { var actuator = item.ComponentRef.GetComponent <ArmActuator>(); if ((actuator.Type & Type) != 0) { if (item.ComponentRef.IsModuleFixed(location.mechLab.activeMechDef)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- cannot remove {item.ComponentRef.ComponentDefID}"); return ($"Cannot install {drop_item.ComponentRef.Def.Description.Name} - {Type} occuped by {item.ComponentRef.Def.Description.Name}"); } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- removing {item.ComponentRef.ComponentDefID}"); changes.Add(new RemoveChange(location.widget.loadout.Location, item)); } else { total_slot = total_slot | actuator.Type; } } add_default(ArmActuatorSlot.PartShoulder); add_default(ArmActuatorSlot.PartUpper); if (ArmActuatorCC.IsIgnoreFullActuators(mech)) { if (!total_slot.HasFlag(ArmActuatorSlot.PartLower) && total_slot.HasFlag(ArmActuatorSlot.PartHand)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- adding Lower to {total_slot}"); var change = AddFromInventoryChange.FoundInInventory(mount_loc, new MechLabHelper(mechlab), item => item.Is <ArmActuator>(out var actuator) && actuator.Type == ArmActuatorSlot.PartLower, item => item.Description.Id == ArmActuatorFeature.settings.DefaultCBTLower ); if (change != null) { changes.Add(change); } else if (ArmActuatorFeature.settings.InterruptHandDropIfNoLower) { return($"Cannot found LowerArm"); } } else { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- Lower exist in {total_slot}, done"); } } else { var limit = mech.Chassis.Is <ArmActuatorSupport>(out var s) ? s.GetLimit(mount_loc) : ArmActuatorSlot.Hand; if (limit.HasFlag(ArmActuatorSlot.PartLower)) { add_default(ArmActuatorSlot.PartLower); } if (limit.HasFlag(ArmActuatorSlot.PartHand)) { add_default(ArmActuatorSlot.PartHand); } } return(string.Empty); }
public void OnItemGrabbed(IMechLabDraggableItem item, MechLabPanel mechLab, MechLabLocationWidget widget) { if (widget.loadout.Location != ChassisLocations.LeftArm && widget.loadout.Location != ChassisLocations.RightArm) { return; } var loc_helper = new LocationHelper(widget); var total_slot = ArmActuatorSlot.None; var mount_loc = widget.loadout.Location; var ml_helper = new MechLabHelper(mechLab); CustomComponents.Control.LogDebug(DType.ComponentInstall, $"- ArmActuator: {Def.Description.Id} {Type}"); void add_default(ArmActuatorSlot slot) { bool add_item(string id) { if (string.IsNullOrEmpty(id)) { return(false); } var r = DefaultHelper.CreateRef(id, ComponentType.Upgrade, mechLab.dataManager, mechLab.Sim); if (r.Is <ArmActuator>(out var actuator) && (actuator.Type & total_slot) == 0) { DefaultHelper.AddMechLab(id, ComponentType.Upgrade, ml_helper, mount_loc); total_slot = total_slot | actuator.Type; return(true); } return(false); } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- adding {slot} to {total_slot}"); if (total_slot.HasFlag(slot)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- already present"); return; } if (add_item(ArmActuatorCC.GetDefaultActuator(mechLab.activeMechDef, mount_loc, slot))) { return; } add_item(ArmActuatorCC.GetDefaultActuator(null, mount_loc, slot)); } for (int i = loc_helper.LocalInventory.Count - 1; i >= 0; i--) { var slotitem = loc_helper.LocalInventory[i]; if (!slotitem.ComponentRef.Is <ArmActuator>()) { continue; } var actuator = slotitem.ComponentRef.GetComponent <ArmActuator>(); if (slotitem.ComponentRef.IsDefault() && !slotitem.ComponentRef.IsModuleFixed(ml_helper.MechLab.activeMechDef)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- removing {slotitem.ComponentRef.ComponentDefID} {actuator.Type}"); DefaultHelper.RemoveMechLab(slotitem.ComponentRef.ComponentDefID, slotitem.ComponentRef.ComponentDefType, ml_helper, mount_loc); } else { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- checking {slotitem.ComponentRef.ComponentDefID} {actuator.Type}"); total_slot = total_slot | actuator.Type; } } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- actuators {total_slot}"); add_default(ArmActuatorSlot.PartShoulder); add_default(ArmActuatorSlot.PartUpper); if (ArmActuatorCC.IsIgnoreFullActuators(mechLab.activeMechDef)) { if (total_slot.HasFlag(ArmActuatorSlot.PartHand) && !total_slot.HasFlag(ArmActuatorSlot.PartLower)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- Removing hand from {total_slot}"); var hand = loc_helper.LocalInventory.FirstOrDefault(i => i.ComponentRef.Is <ArmActuator>(out var actuator) && actuator.Type.HasFlag(ArmActuatorSlot.PartHand)); if (hand == null || hand.ComponentRef.IsFixed) { return; } var dragitem = mechLab.DragItem; widget.OnRemoveItem(hand, false); mechLab.ForceItemDrop(hand); ml_helper.SetDragItem(dragitem as MechLabItemSlotElement); } else { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- hand already removed from {total_slot}"); } } else { var limit = mechLab.activeMechDef.Chassis.Is <ArmActuatorSupport>(out var s) ? s.GetLimit(mount_loc) : ArmActuatorSlot.Hand; if (limit.HasFlag(ArmActuatorSlot.PartLower)) { add_default(ArmActuatorSlot.PartLower); } if (limit.HasFlag(ArmActuatorSlot.PartHand)) { add_default(ArmActuatorSlot.PartHand); } } }
private async Task ProcessTxt(Upload file) { string WhatsappDate = _conf["WhatsappDate"]; var systemTime = DateTime.Now; var chatList = new List <ChatMessage>(); var toString = Encoding.UTF8.GetString(file.FileContent); var entityChat = await _context.Chats.Where(c => c.FolderId == file.FolderId).Select(c => new Tuple <string, string, DateTime>(c.Message, c.PersonName, c.MessageTime)).ToListAsync(); var hashSet = new HashSet <Tuple <string, string, DateTime> >(entityChat); string[] lines = toString.Split( new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None ); //not a fan of this approach var linesCounter = lines.Count() - 1; var messageDate = DefaultHelper.ValidDate(lines[0], WhatsappDate); var messageSender = DefaultHelper.ValidSender(lines[0]); var messageText = DefaultHelper.CleanMessage(lines[0]); for (int i = 0; i < linesCounter; i++) { var date = DefaultHelper.ValidDate(lines[i], WhatsappDate); var sender = DefaultHelper.ValidSender(lines[i]); var message = DefaultHelper.CleanMessage(lines[i]); if (date != null) { if (String.IsNullOrWhiteSpace(message) == false) { if (String.IsNullOrWhiteSpace(messageText) == false && String.IsNullOrWhiteSpace(messageSender) == false) { if (!(hashSet.Contains(new Tuple <string, string, DateTime>(messageText, messageSender, messageDate.Value)))) { var newChat = new ChatMessage(messageSender, messageDate.Value, systemTime, messageText, file.FolderId); chatList.Add(newChat); if (chatList.Count > 9999) { _context.Chats.AddRange(chatList); await _context.SaveChangesAsync(); chatList.Clear(); } } } messageDate = date; messageSender = sender; messageText = message; } } else { //Keep adding the message text until a new line is avaliable. messageText = String.Concat(messageText, " \n ", message); } } _context.Chats.AddRange(chatList); await _context.SaveChangesAsync(); _context.Uploads.Remove(file); await _context.SaveChangesAsync(); }