Beispiel #1
0
        /// <summary>
        /// Refresh the packaged volume for a ship fit.
        /// </summary>
        /// <param name="shipFit">A doctrine ships ship fit.</param>
        internal void RefreshShipFitPackagedVolume(ShipFit shipFit)
        {
            shipFit.FitPackagedVolume = 0;

            // Ensure that there are ship fit components to be refreshed.
            if (shipFit.ShipFitComponents != null && shipFit.ShipFitComponents.Any() != false)
            {
                foreach (var item in shipFit.ShipFitComponents)
                {
                    // Add the value to the shipfit's total volume.
                    shipFit.FitPackagedVolume += item.Component.Volume * item.Quantity;
                }

                // Update the ship fit in the database.
                this.doctrineShipsRepository.UpdateShipFit(shipFit);

                // Commit changes to the database.
                this.doctrineShipsRepository.Save();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Generate and refresh the EVE IGB fitting string for a ship fit.
        /// </summary>
        /// <param name="shipFit">A doctrine ships ship fit.</param>
        internal void RefreshFittingString(ShipFit shipFit)
        {
            string fittingString = string.Empty;

            // Generate the fitting string.
            fittingString += shipFit.HullId + ":";

            foreach (var item in shipFit.ShipFitComponents)
            {
                fittingString += item.ComponentId + ";" + item.Quantity + ":";
            }

            fittingString += ":";

            // Update the fitting string and ship fit in the database.
            shipFit.FittingString = fittingString;
            this.doctrineShipsRepository.UpdateShipFit(shipFit);

            // Commit changes to the database.
            this.doctrineShipsRepository.Save();
        }
Beispiel #3
0
        /// <summary>
        /// Generate and returns an EFT fitting string for a ship fit.
        /// </summary>
        /// <param name="shipFitId">The id of a doctrine ships ship fit.</param>
        /// <param name="accountId">The currently logged-in account id for security checking.</param>
        /// <returns>Returns a string containing an EFT fitting or an empty string if an error occurs.</returns>
        internal string GetEftFittingString(int shipFitId, int accountId)
        {
            string eftFitting = string.Empty;

            ShipFit shipFit = this.doctrineShipsRepository.GetShipFit(shipFitId);

            if (shipFit != null)
            {
                if (accountId == shipFit.AccountId)
                {
                    // Generate the fitting string.
                    eftFitting += "[" + shipFit.Hull + ", " + shipFit.Name + "]" + Environment.NewLine;

                    List <SlotType> expectedSlotTypes = new List <SlotType>();
                    expectedSlotTypes.Add(SlotType.Low);
                    expectedSlotTypes.Add(SlotType.Medium);
                    expectedSlotTypes.Add(SlotType.High);
                    expectedSlotTypes.Add(SlotType.Rig);
                    expectedSlotTypes.Add(SlotType.Subsystem);
                    expectedSlotTypes.Add(SlotType.Drone);
                    expectedSlotTypes.Add(SlotType.Cargo);

                    foreach (SlotType slot in expectedSlotTypes)
                    {
                        var itemsInSlot = shipFit.ShipFitComponents.Where(component => component.SlotType == slot);
                        foreach (var item in itemsInSlot)
                        {
                            eftFitting += GenerateModuleEFTLine(item);
                        }
                        if (itemsInSlot.Count() > 0)
                        {
                            eftFitting += Environment.NewLine;
                        }
                    }
                }
            }

            return(eftFitting);
        }
Beispiel #4
0
        /// <summary>
        /// Updates the state of a ship fit's contract availability monitoring.
        /// </summary>
        /// <param name="accountId">The account Id of the requestor. The account Id should own the sales agent being changed.</param>
        /// <param name="shipFitId">The id of the ship fit to be changed.</param>
        /// <param name="isActive">The required boolean state.</param>
        /// <returns>Returns true if the change was successful or false if not.</returns>
        internal bool UpdateShipFitMonitoringState(int accountId, int shipFitId, bool isActive)
        {
            ShipFit shipFit = this.doctrineShipsRepository.GetShipFit(shipFitId);

            if (shipFit != null)
            {
                // If the account Id matches the account Id of the ship fit being changed, continue.
                if (accountId == shipFit.AccountId)
                {
                    // Change the state of the ship fit and log the event.
                    if (isActive == true)
                    {
                        shipFit.IsMonitored = true;
                    }
                    else
                    {
                        shipFit.IsMonitored = false;
                    }

                    this.doctrineShipsRepository.UpdateShipFit(shipFit);
                    this.doctrineShipsRepository.Save();

                    if (isActive == true)
                    {
                        logger.LogMessage("Contract Availability Monitoring For Ship Fit '" + shipFit.Name + "' Successfully Enabled. Account Id: " + shipFit.AccountId, 2, "Message", MethodBase.GetCurrentMethod().Name);
                    }
                    else
                    {
                        logger.LogMessage("Contract Availability Monitoring For Ship Fit '" + shipFit.Name + "' Successfully Disabled. Account Id: " + shipFit.AccountId, 2, "Message", MethodBase.GetCurrentMethod().Name);
                    }

                    return(true);
                }
            }

            return(false);
        }
Beispiel #5
0
        /// <summary>
        /// Generate and refresh the fitting hash, unique to an account.
        /// </summary>
        /// <param name="shipFit">A doctrine ships ship fit.</param>
        /// <param name="accountId">The account Id for which a fitting hash should be generated.</param>
        internal void RefreshFittingHash(ShipFit shipFit, int accountId)
        {
            string concatComponents = string.Empty;
            IEnumerable <ShipFitComponent> compressedShipFitComponents = new List <ShipFitComponent>();

            if (shipFit.ShipFitComponents != null && shipFit.ShipFitComponents.Any() == true)
            {
                // Compress the ship fit components list, removing duplicates but adding the quantities.
                compressedShipFitComponents = shipFit.ShipFitComponents
                                              .OrderBy(o => o.ComponentId)
                                              .GroupBy(u => u.ComponentId)
                                              .Select(x => new ShipFitComponent()
                {
                    ComponentId = x.Key,
                    Quantity    = x.Sum(p => p.Quantity)
                });

                // Concatenate all components and their quantities into a single string.
                foreach (var item in compressedShipFitComponents)
                {
                    concatComponents += item.ComponentId + item.Quantity;
                }

                // Generate a hash for the fitting and salt it with the account id. This permits identical fits across accounts.
                shipFit.FittingHash = Security.GenerateHash(concatComponents, accountId.ToString());
            }
            else
            {
                // There are no components so generate a random hash.
                shipFit.FittingHash = Security.GenerateHash(Security.GenerateRandomString(32), Security.GenerateSalt(6));
            }

            // Commit changes to the database.
            this.doctrineShipsRepository.UpdateShipFit(shipFit);
            this.doctrineShipsRepository.Save();
        }
Beispiel #6
0
        public IEnumerable <IBotTask> GetTasks(Bot bot)
        {
            //yield return new BotTask { Component = EnumerateConfigDiagnostics() };

            yield return(new EnableInfoPanelCurrentSystem {
                MemoryMeasurement = bot.MemoryMeasurementAtTime?.Value
            });

            var saveShipTask = new SaveShipTask {
                Bot = bot
            };

            yield return(saveShipTask);

            var shipFit = new ShipFit(bot.MemoryMeasurementAccu?.ShipUiModule,
                                      new[]
            {
                new[]
                {
                    new ShipFit.ModuleInfo(ShipFit.ModuleType.Etc),
                },
                new[]
                {
                    new ShipFit.ModuleInfo(ShipFit.ModuleType.Hardener),
                    new ShipFit.ModuleInfo(ShipFit.ModuleType.Hardener),
                    new ShipFit.ModuleInfo(ShipFit.ModuleType.Hardener),
                },
                new[]
                {
                    new ShipFit.ModuleInfo(ShipFit.ModuleType.Etc),
                    new ShipFit.ModuleInfo(ShipFit.ModuleType.Etc)
                }
            });

            yield return(bot.EnsureIsActive(shipFit.GetAlwaysActiveModules().Select(m => m.UiModule)));

            //var moduleUnknown = MemoryMeasurementAccu?.ShipUiModule?.FirstOrDefault(module => null == module?.TooltipLast?.Value);

            //yield return new BotTask { ClientActions = new[] { moduleUnknown?.MouseMove() } };

            if (!saveShipTask.AllowRoam)
            {
                yield break;
            }


            var combatTask = new CombatTask {
                bot = bot
            };

            yield return(combatTask);

            if (!saveShipTask.AllowAnomalyEnter)
            {
                yield break;
            }

            yield return(new UndockTask(bot.MemoryMeasurementAtTime?.Value));

            if (combatTask.Completed)
            {
                if (!currentAnomalyLooted)
                {
                    var lootTask = new LootTask(bot);
                    yield return(lootTask);

                    if (!lootTask.HasWreckToLoot)
                    {
                        currentAnomalyLooted = true;
                    }
                }
                yield return(new AnomalyEnter {
                    bot = bot
                });
            }
        }
 /// <summary>
 /// Updates a ship fit for a particular account.
 /// </summary>
 /// <param name="shipFit">A partially populated ship fit object to be updated.</param>
 /// <returns>Returns a validation result object.</returns>
 public IValidationResult UpdateShipFit(ShipFit shipFit)
 {
     return(ShipFitManager.UpdateShipFit(shipFit));
 }
 public IValidationResult ShipFit(ShipFit shipFit)
 {
     return(ShipFitCheck.ShipFit(shipFit));
 }
Beispiel #9
0
 public ShipFit CreateShipFit(ShipFit shipFit)
 {
     return(ShipFitOperations.CreateShipFit(shipFit));
 }
Beispiel #10
0
        /// <summary>
        /// Imports a Doctrine Ships ship fit from a string formatted in the standard CCP Xml format.
        /// </summary>
        /// <param name="toParse">A ship fitting string formatted in the standard CCP Xml format.</param>
        /// <param name="accountId">The account for which the ship fit should be imported.</param>
        /// <returns>Returns a list of populated ship fit objects or an empty list if the process fails.</returns>
        internal IEnumerable <ShipFit> ImportShipFitEveXml(string toParse, int accountId)
        {
            ICollection <ShipFit> shipFits = new List <ShipFit>();
            XDocument             xmlDoc;

            // Does the account exist?
            if (this.doctrineShipsRepository.GetAccount(accountId) != null)
            {
                try
                {
                    using (StringReader stringReader = new StringReader(toParse))
                    {
                        xmlDoc = XDocument.Load(stringReader);
                    }

                    foreach (XElement fitting in xmlDoc.Root.Elements("fitting"))
                    {
                        // Read and cleanse the initial xml elements containing the fitting name, description and ship type.
                        string shipFitName = String.Empty;
                        string shipFitHull = String.Empty;
                        string shipFitRole = String.Empty;

                        shipFitName = Conversion.StringToSafeString((string)fitting.Attribute("name") ?? String.Empty);

                        if (fitting.Element("shipType") != null)
                        {
                            shipFitHull = Conversion.StringToSafeString((string)fitting.Element("shipType").Attribute("value") ?? String.Empty);
                        }

                        if (fitting.Element("description") != null)
                        {
                            shipFitRole = Conversion.StringToSafeString((string)fitting.Element("description").Attribute("value") ?? String.Empty);
                        }

                        // Attempt to populate, validate and add a new ship fit to the database.
                        ShipFit newShipFit = this.AddShipFit(shipFitName, shipFitRole, shipFitHull, accountId);

                        // If the ship fit addition was successful, continue with the parse.
                        if (newShipFit != null)
                        {
                            // Add the ship fit to the list of successfully imported ship fits.
                            shipFits.Add(newShipFit);

                            // Instantiate a new list of ShipFitComponents.
                            ICollection <ShipFitComponent> shipFitComponents = new List <ShipFitComponent>();

                            // Add the ship hull itself to the list of ShipFitComponents.
                            this.AddComponent(newShipFit.Hull);
                            shipFitComponents.Add(new ShipFitComponent
                            {
                                ComponentId = newShipFit.HullId,
                                ShipFitId   = newShipFit.ShipFitId,
                                SlotType    = SlotType.Hull,
                                Quantity    = 1
                            });

                            // Iterate through the 'hardware' xml elements containing the ship fitting components.
                            foreach (XElement component in fitting.Elements("hardware"))
                            {
                                // Attempt to add this parsed component to the database.
                                Component newComponent = this.AddComponent((string)component.Attribute("type") ?? String.Empty);

                                // Unless the component was not recognised, continue with the parse.
                                if (newComponent != null)
                                {
                                    ShipFitComponent newShipFitComponent = new ShipFitComponent();

                                    newShipFitComponent.ComponentId = newComponent.ComponentId;
                                    newShipFitComponent.ShipFitId   = newShipFit.ShipFitId;

                                    switch (component.Attribute("slot").Value.Split(' ').FirstOrDefault())
                                    {
                                    case "hi":
                                        newShipFitComponent.SlotType = SlotType.High;
                                        break;

                                    case "med":
                                        newShipFitComponent.SlotType = SlotType.Medium;
                                        break;

                                    case "low":
                                        newShipFitComponent.SlotType = SlotType.Low;
                                        break;

                                    case "rig":
                                        newShipFitComponent.SlotType = SlotType.Rig;
                                        break;

                                    case "subsystem":
                                        newShipFitComponent.SlotType = SlotType.Subsystem;
                                        break;

                                    case "drone":
                                        newShipFitComponent.SlotType = SlotType.Drone;
                                        break;

                                    case "cargo":
                                        newShipFitComponent.SlotType = SlotType.Cargo;
                                        break;

                                    default:
                                        newShipFitComponent.SlotType = SlotType.Other;
                                        break;
                                    }

                                    if (component.Attribute("qty") != null)
                                    {
                                        newShipFitComponent.Quantity = Conversion.StringToLong(component.Attribute("qty").Value);
                                    }
                                    else
                                    {
                                        newShipFitComponent.Quantity = 1;
                                    }

                                    // Add this component to the list.
                                    shipFitComponents.Add(newShipFitComponent);
                                }
                            }

                            // Add the full list of components to the ship fit.
                            this.AddShipFitComponents(shipFitComponents);

                            // Now that all of the ship fit components have been added, refresh the total volume of the fit.
                            this.RefreshShipFitPackagedVolume(newShipFit);

                            // Generate and refresh the fitting string for the ship fit.
                            this.RefreshFittingString(newShipFit);

                            // Generate a fitting hash unique to this account.
                            this.RefreshFittingHash(newShipFit, accountId);
                        }
                    }
                }
                catch (System.FormatException e)
                {
                    this.logger.LogMessage("An error occured while parsing the fitting Xml. Is the Xml format correct?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                    this.logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
                }
                catch (System.ArgumentException e)
                {
                    this.logger.LogMessage("An error occured while parsing the fitting Xml. Is the Xml format correct?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                    this.logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
                }
                catch (System.Xml.XmlException e)
                {
                    this.logger.LogMessage("An error occured while parsing the fitting Xml. Is the Xml format correct?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                    this.logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return(shipFits);
        }
Beispiel #11
0
 public ShipFit AddShipFit(ShipFit shipFit)
 {
     return(ShipFitOperations.AddShipFit(shipFit));
 }
Beispiel #12
0
 public void UpdateShipFit(ShipFit shipFit)
 {
     ShipFitOperations.UpdateShipFit(shipFit);
 }
Beispiel #13
0
 internal ShipFit CreateShipFit(ShipFit shipFit)
 {
     shipFit.ObjectState = ObjectState.Added;
     this.unitOfWork.Repository <ShipFit>().Insert(shipFit);
     return(shipFit);
 }
Beispiel #14
0
 internal ShipFit AddShipFit(ShipFit shipFit)
 {
     this.unitOfWork.Repository <ShipFit>().Insert(shipFit);
     return(shipFit);
 }
Beispiel #15
0
 internal void UpdateShipFit(ShipFit shipFit)
 {
     shipFit.ObjectState = ObjectState.Modified;
     this.unitOfWork.Repository <ShipFit>().Update(shipFit);
 }