Ejemplo n.º 1
0
        internal IValidationResult ShipFitComponent(ShipFitComponent shipFitComponent)
        {
            IValidationResult validationResult = new ValidationResult();

            // Check that the ship fit component has a valid quantity.
            if (shipFitComponent.Quantity <= 0 || shipFitComponent.Quantity > long.MaxValue)
            {
                validationResult.AddError("Quantity.Range_" + shipFitComponent.ShipFitComponentId.ToString(), "Quantity can not be less than or equal to 0. Also, the upper limit cannot exceed the max value of the long data type.");
            }

            return(validationResult);
        }
Ejemplo n.º 2
0
        private string GenerateModuleEFTLine(ShipFitComponent item)
        {
            string moduleLine = string.Empty;

            if (item.SlotType == SlotType.Cargo || item.SlotType == SlotType.Drone)
            {
                // This is a cargo or drone slot, so append the quantity.
                moduleLine += item.Component.Name + " x" + item.Quantity + Environment.NewLine;
            }
            else if (item.SlotType != SlotType.Hull)
            {
                for (int i = 1; i <= item.Quantity; i++)
                {
                    // This is a module, so add each of the items as a separate line.
                    moduleLine += item.Component.Name + Environment.NewLine;
                }
            }
            return(moduleLine);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// <para>Adds a ship fit component from a list of partially populated ship fit components.</para>
        /// <para>The minimum properties that should be populated:</para>
        /// <para>-ShipFitId</para>
        /// <para>-ComponentId</para>
        /// <para>-Quantity</para>
        /// <para>-Slot</para>
        /// </summary>
        /// <param name="componentList">A list of partially populated ship fit components.</param>
        /// <returns>Returns a list of populated component objects or an empty list if the process fails.</returns>
        internal IEnumerable <ShipFitComponent> AddShipFitComponents(IEnumerable <ShipFitComponent> componentList)
        {
            ICollection <ShipFitComponent> shipFitComponents = new List <ShipFitComponent>();

            if (componentList != null && componentList.Count() != 0)
            {
                var compressedComponentList = CompressShipFitComponents(componentList);

                if (compressedComponentList != null && compressedComponentList.Count() != 0)
                {
                    foreach (var component in compressedComponentList)
                    {
                        ShipFitComponent shipFitComponent = new ShipFitComponent();

                        shipFitComponent.ShipFitId   = component.ShipFitId;
                        shipFitComponent.ComponentId = component.ComponentId;
                        shipFitComponent.Quantity    = component.Quantity;
                        shipFitComponent.SlotType    = component.SlotType;
                        shipFitComponent.BuyPrice    = 0;
                        shipFitComponent.SellPrice   = 0;

                        // Validate the new ship fit component.
                        if (this.doctrineShipsValidation.ShipFitComponent(shipFitComponent).IsValid == true)
                        {
                            // Add the populated ship fit component object to the database and read it back to get the auto generated primary key id.
                            shipFitComponent = this.doctrineShipsRepository.CreateShipFitComponent(shipFitComponent);

                            // Add the ship fit component to the return list.
                            shipFitComponents.Add(shipFitComponent);
                        }
                    }

                    // Commit changes to the database.
                    this.doctrineShipsRepository.Save();
                }
            }

            return(shipFitComponents);
        }
 public IValidationResult ShipFitComponent(ShipFitComponent shipFitComponent)
 {
     return(ShipFitCheck.ShipFitComponent(shipFitComponent));
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
 public ShipFitComponent CreateShipFitComponent(ShipFitComponent shipFitComponent)
 {
     return(ShipFitComponentOperations.CreateShipFitComponent(shipFitComponent));
 }
Ejemplo n.º 7
0
 public ShipFitComponent AddShipFitComponent(ShipFitComponent shipFitComponent)
 {
     return(ShipFitComponentOperations.AddShipFitComponent(shipFitComponent));
 }
Ejemplo n.º 8
0
 public void UpdateShipFitComponent(ShipFitComponent shipFitComponent)
 {
     ShipFitComponentOperations.UpdateShipFitComponent(shipFitComponent);
 }
Ejemplo n.º 9
0
 internal ShipFitComponent CreateShipFitComponent(ShipFitComponent shipFitComponent)
 {
     shipFitComponent.ObjectState = ObjectState.Added;
     this.unitOfWork.Repository <ShipFitComponent>().Insert(shipFitComponent);
     return(shipFitComponent);
 }
Ejemplo n.º 10
0
 internal ShipFitComponent AddShipFitComponent(ShipFitComponent shipFitComponent)
 {
     this.unitOfWork.Repository <ShipFitComponent>().Insert(shipFitComponent);
     return(shipFitComponent);
 }
Ejemplo n.º 11
0
 internal void UpdateShipFitComponent(ShipFitComponent shipFitComponent)
 {
     shipFitComponent.ObjectState = ObjectState.Modified;
     this.unitOfWork.Repository <ShipFitComponent>().Update(shipFitComponent);
 }