/// <summary>
        /// <para>Adds a customer.</para>
        /// </summary>
        /// <param name="name">The name of the new customer. This must be identical to the in-game name.</param>
        /// <param name="type">Is this customer a corporation, an alliance or an individual character?</param>
        /// <returns>Returns a validation result object.</returns>
        internal IValidationResult AddCustomer(string name, int type)
        {
            int customerId = 0;
            IValidationResult validationResult = new ValidationResult();

            // Does the customer name successfully resolve to an id?
            customerId = eveDataSource.GetCharacterId(name);

            if (customerId != 0)
            {
                // Populate a new customer object.
                Customer newCustomer = new Customer();

                // Populate the remaining properties.
                newCustomer.CustomerId  = customerId;
                newCustomer.Name        = name;
                newCustomer.LastRefresh = DateTime.UtcNow;

                switch (type)
                {
                case 1:
                    newCustomer.ImageUrl = eveDataSource.GetCorporationLogoUrl(newCustomer.CustomerId);
                    newCustomer.IsCorp   = true;
                    break;

                case 2:
                    newCustomer.ImageUrl = eveDataSource.GetAllianceLogoUrl(newCustomer.CustomerId);
                    newCustomer.IsCorp   = true;
                    break;

                case 3:
                    newCustomer.ImageUrl = eveDataSource.GetCharacterPortraitUrl(newCustomer.CustomerId);
                    newCustomer.IsCorp   = false;
                    break;
                }

                // Validate the new customer.
                validationResult = this.doctrineShipsValidation.Customer(newCustomer);
                if (validationResult.IsValid == true)
                {
                    // Add the new customer and log the event.
                    this.doctrineShipsRepository.CreateCustomer(newCustomer);
                    this.doctrineShipsRepository.Save();
                    logger.LogMessage("Customer '" + newCustomer.Name + "' Successfully Added.", 2, "Message", MethodBase.GetCurrentMethod().Name);
                }
            }
            else
            {
                validationResult.AddError("CustomerName.Valid", "An invalid customer name was entered.");
            }

            return(validationResult);
        }
Beispiel #2
0
        public ActionResult RefreshContracts(string key, string force, string batchSize)
        {
            Stopwatch stopWatch = new Stopwatch();

            // Cleanse the passed string parameters to prevent XSS.
            string cleanKey       = Server.HtmlEncode(key);
            bool   cleanForce     = Conversion.StringToBool(Server.HtmlEncode(force), false);
            int    cleanBatchSize = Conversion.StringToInt32(Server.HtmlEncode(batchSize), 10);

            if (cleanKey == doctrineShipsServices.Settings.TaskKey)
            {
                // Time the execution of the contract refresh.
                stopWatch.Reset();
                stopWatch.Start();

                // Check sales agents and refresh their contracts if required. Also update various contract counts.
                this.doctrineShipsServices.RefreshContracts(cleanForce, cleanBatchSize);

                // Stop the clock.
                stopWatch.Stop();

                logger.LogMessage("Contract Refresh Successful, Time Taken: " + stopWatch.Elapsed, 2, "Message", MethodBase.GetCurrentMethod().Name);
                return(Content("Contract Refresh Successful, Time Taken: " + stopWatch.Elapsed));
            }
            else
            {
                logger.LogMessage("Contract Refresh Failed, Invalid Key: " + cleanKey, 1, "Message", MethodBase.GetCurrentMethod().Name);
                return(Content("Contract Refresh Failed, Invalid Key"));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Deletes a ship fit, its components and all related contracts.
        /// </summary>
        /// <param name="accountId">The account Id of the requestor. The account Id should own the ship fit being deleted.</param>
        /// <param name="shipFitId">The ship fit Id to be deleted.</param>
        /// <returns>Returns true if the deletion was successful or false if not.</returns>
        internal bool DeleteShipFit(int accountId, int shipFitId)
        {
            ShipFit shipFit = this.doctrineShipsRepository.GetShipFit(shipFitId);

            if (shipFit != null)
            {
                // If the account Id matches the account Id of the ship fit being deleted, continue.
                if (accountId == shipFit.AccountId)
                {
                    // Delete any contracts matching this ship fit id.
                    this.doctrineShipsRepository.DeleteContractsByShipFitId(shipFit.ShipFitId);

                    // Delete the ship fit from any doctrines.
                    this.doctrineShipsRepository.DeleteDoctrineShipFitsByShipFitId(shipFit.ShipFitId);

                    // Delete all of the ship fit's components.
                    this.doctrineShipsRepository.DeleteShipFitComponentsByShipFitId(shipFit.ShipFitId);

                    // Delete the ship fit.
                    this.doctrineShipsRepository.DeleteShipFit(shipFit.ShipFitId);

                    // Save and log the event.
                    this.doctrineShipsRepository.Save();
                    logger.LogMessage("Ship Fit '" + shipFit.Name + "' Successfully Deleted For Account Id: " + shipFit.AccountId, 1, "Message", MethodBase.GetCurrentMethod().Name);

                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Resolve a solar system id to its name.
        /// </summary>
        /// <param name="solarSystemId">The solar system id.</param>
        /// <param name="apiUrl">An optional apiUrl parameter that overrides the method's internal value. Primarily used in unit tests to force errors.</param>
        /// <returns>Returns a string containing the solar system name or 'Unknown' if not found.</returns>
        internal string SolarSystemName(int solarSystemId, string apiUrl = "")
        {
            XDocument xmlDoc;
            string    solarSystemName = "Unknown";

            // Assign the Api Url to a string if it has not already been passed as a parameter.
            if (apiUrl == string.Empty)
            {
                apiUrl = "http://api.eve-marketdata.com/api/solarsystem_name.xml?char_name=DS&v=" + solarSystemId;
            }

            // Create a new XMLDoc object loaded from the Api Url.
            try
            {
                xmlDoc = XDocument.Load(apiUrl);

                // Populate a list of the station ids within the xml results where the name attribute matches stationId.
                var xmlValue = xmlDoc.Descendants("val")
                               .Where(x => (int)x.Attribute("id") == solarSystemId)
                               .Select(x => x.Value);

                // If the first value found is not null or empty then assign it.
                if (xmlValue.FirstOrDefault() != null && xmlValue.FirstOrDefault() != string.Empty)
                {
                    solarSystemName = xmlValue.FirstOrDefault();
                }
            }
            catch (System.Net.WebException e)
            {
                logger.LogMessage("An error occured while parsing the eve-marketdata.com solarsystem_name Xml.", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (System.Xml.XmlException e)
            {
                logger.LogMessage("An error occured while loading the eve-marketdata.com solarsystem_name Xml. Is the API available?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (Exception)
            {
                throw;
            }

            return(solarSystemName);
        }
Beispiel #5
0
        /// <summary>
        /// Resolve a character name to a character id.
        /// </summary>
        /// <param name="characterName">The character name.</param>
        /// <param name="apiUrl">An optional apiUrl parameter that overrides the method's internal value. Primarily used in unit tests to force errors.</param>
        /// <returns>Returns an integer containing the character id  or 0 if not found.</returns>
        internal int EveCharacterId(string characterName, string apiUrl = "")
        {
            XDocument xmlDoc;
            int       characterId = 0;

            // Assign the Api Url to a string if it has not already been passed as a parameter.
            if (apiUrl == string.Empty)
            {
                apiUrl = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names=" + characterName;
            }

            // Create a new XMLDoc object loaded from the Api Url.
            try
            {
                xmlDoc = XDocument.Load(apiUrl);

                // Populate a list of the character Ids within the xml results where the name attribute matches characterName.
                var xmlValue = xmlDoc.Descendants("row")
                               .Where(x => (string)x.Attribute("name") == characterName)
                               .Select(x => (string)x.Attribute("characterID"));

                // Convert the first value found to an integer.
                characterId = Conversion.StringToInt32(xmlValue.FirstOrDefault());
            }
            catch (System.Net.WebException e)
            {
                logger.LogMessage("An error occured while parsing the CCP CharacterID Xml.", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (System.Xml.XmlException e)
            {
                logger.LogMessage("An error occured while loading the CCP CharacterID Xml. Is the API available?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (Exception)
            {
                throw;
            }

            return(characterId);
        }
Beispiel #6
0
        public ActionResult Error(int statusCode, Exception e)
        {
            // Ignore '404 Not Found' Errors.
            if (statusCode != 404)
            {
                // Log any other status codes & exception.
                logger.LogMessage("Status Code: " + statusCode + " Exception: " + e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }

            Response.StatusCode = statusCode;
            return(View());
        }
Beispiel #7
0
        /// <summary>
        /// Send a twitter direct message.
        /// <param name="twitterContext">A twitter context for the sending of messages.</param>
        /// </summary>
        internal async Task <bool> SendDirectMessage(LinqToTwitter::TwitterContext twitterContext, string screenName, string message)
        {
            try
            {
                var result = await twitterContext.NewDirectMessageAsync(screenName, message);

                if (result != null)
                {
                    this.logger.LogMessage("Sent A Direct Message To '" + result.RecipientScreenName + "' With Message '" + result.Text + "'.", 2, "Message", MethodBase.GetCurrentMethod().Name);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                logger.LogMessage("An error occured while sending a twitter message. Are the twitter api credentials correct?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
                return(false);
            }
        }
Beispiel #8
0
        /// <summary>
        /// This method returns information about an Api Key and the characters exposed by it.
        /// </summary>
        /// <param name="apiId">A valid eve api id (keyID).</param>
        /// <param name="apiKey">A valid eve api key (vCode).</param>
        /// <param name="apiUrl">An optional apiUrl parameter that overrides the method's internal value. Primarily used in unit tests to force errors.</param>
        /// <returns>Returns a populated IEveDataApiKey object relating to the passed Api Key, or a null object if a problem occured.</returns>
        internal IEveDataApiKey ApiKeyInfo(int apiId, string apiKey, string apiUrl = "")
        {
            XDocument      xmlDoc;
            IEveDataApiKey apiKeyInfo = null;

            // Assign the Api Url to a string if it has not already been passed as a parameter.
            if (apiUrl == string.Empty)
            {
                apiUrl = "https://api.eveonline.com/account/APIKeyInfo.xml.aspx?keyID=" + apiId + "&vCode=" + apiKey;
            }

            try
            {
                xmlDoc = XDocument.Load(apiUrl);

                // Populate key values.
                apiKeyInfo = xmlDoc.Descendants("key")
                             .Select(x => new EveDataApiKey()
                {
                    AccessMask = Conversion.StringToInt32(x.Attribute("accessMask").Value),
                    Expires    = Conversion.StringToDateTime(x.Attribute("expires").Value),
                    Type       = Conversion.StringToEnum <EveDataApiKeyType>(x.Attribute("type").Value, EveDataApiKeyType.Character)
                })
                             .FirstOrDefault();

                // Populate key characters.
                apiKeyInfo.Characters = xmlDoc.Descendants("row")
                                        .Select(x => new EveDataApiKeyCharacter()
                {
                    CharacterId     = Conversion.StringToInt32(x.Attribute("characterID").Value),
                    CharacterName   = x.Attribute("characterName").Value,
                    CorporationId   = Conversion.StringToInt32(x.Attribute("corporationID").Value),
                    CorporationName = x.Attribute("corporationName").Value
                })
                                        .ToList();
            }
            catch (System.FormatException e)
            {
                logger.LogMessage("An error occured while parsing the CCP ApiKeyInfo Xml for ApiID: " + apiId + ". Is the data source present and correct?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (System.Net.WebException e)
            {
                logger.LogMessage("An error occured while parsing the CCP ApiKeyInfo Xml for ApiID: " + apiId + ". Is the data source present and correct?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (System.Xml.XmlException e)
            {
                logger.LogMessage("An error occured while loading the CCP ApiKeyInfo Xml for ApiID: " + apiId + ". Is the API available?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (System.NullReferenceException e)
            {
                logger.LogMessage("An error occured while loading the CCP ApiKeyInfo Xml for ApiID: " + apiId + ". Is the API key correct?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (Exception)
            {
                throw;
            }

            return(apiKeyInfo);
        }
        /// <summary>
        /// Populate a list of contracts for the corporation api key passed.
        /// </summary>
        /// <param name="apiId">A valid eve corporation api id (keyID).</param>
        /// <param name="apiKey">A valid eve corporation api key (vCode).</param>
        /// <param name="apiUrl">An optional apiUrl parameter that overrides the method's internal value. Primarily used in unit tests to force errors.</param>
        /// <returns>Returns a populated list of IEveDataContract objects relating to the corporation.</returns>
        internal IEnumerable <IEveDataContract> CorporationContracts(int apiId, string apiKey, string apiUrl = "")
        {
            XDocument xmlDoc;
            IEnumerable <IEveDataContract> xmlValues = null;

            // Assign the Api Url to a string if it has not already been passed as a parameter.
            if (apiUrl == string.Empty)
            {
                apiUrl = "https://api.eveonline.com/corp/Contracts.xml.aspx?keyID=" + apiId + "&vCode=" + apiKey;
            }

            try
            {
                xmlDoc = XDocument.Load(apiUrl);

                xmlValues = xmlDoc.Descendants("row")
                            .Select(x => new EveDataContract()
                {
                    ContractId     = Conversion.StringToLong(x.Attribute("contractID").Value),
                    IssuerId       = Conversion.StringToLong(x.Attribute("issuerID").Value),
                    IssuerCorpId   = Conversion.StringToLong(x.Attribute("issuerCorpID").Value),
                    AssigneeId     = Conversion.StringToLong(x.Attribute("assigneeID").Value),
                    AcceptorId     = Conversion.StringToLong(x.Attribute("acceptorID").Value),
                    StartStationId = Conversion.StringToInt32(x.Attribute("startStationID").Value),
                    EndStationId   = Conversion.StringToInt32(x.Attribute("endStationID").Value),
                    Type           = Conversion.StringToEnum <EveDataContractType>(x.Attribute("type").Value, EveDataContractType.ItemExchange),
                    Status         = Conversion.StringToEnum <EveDataContractStatus>(x.Attribute("status").Value, EveDataContractStatus.Deleted),
                    Title          = x.Attribute("title").Value,
                    ForCorp        = Conversion.StringToBool(x.Attribute("forCorp").Value, true),
                    Availability   = Conversion.StringToEnum <EveDataContractAvailability>(x.Attribute("availability").Value, EveDataContractAvailability.Private),
                    DateIssued     = Conversion.StringToDateTime(x.Attribute("dateIssued").Value),
                    DateExpired    = Conversion.StringToDateTime(x.Attribute("dateExpired").Value),
                    DateAccepted   = Conversion.StringToDateTime(x.Attribute("dateAccepted").Value),
                    NumDays        = Conversion.StringToInt32(x.Attribute("numDays").Value),
                    DateCompleted  = Conversion.StringToDateTime(x.Attribute("dateCompleted").Value),
                    Price          = Conversion.StringToDouble(x.Attribute("price").Value),
                    Reward         = Conversion.StringToDouble(x.Attribute("reward").Value),
                    Collateral     = Conversion.StringToDouble(x.Attribute("collateral").Value),
                    Buyout         = Conversion.StringToDouble(x.Attribute("buyout").Value),
                    Volume         = Conversion.StringToDouble(x.Attribute("volume").Value)
                })
                            .ToList();
            }
            catch (System.FormatException e)
            {
                logger.LogMessage("An error occured while parsing the CCP CorporationContracts Xml for ApiID: " + apiId + ". Is the data source present and correct?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (System.Net.WebException e)
            {
                logger.LogMessage("An error occured while parsing the CCP CorporationContracts Xml for ApiID: " + apiId + ". Is the data source present and correct?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (System.Xml.XmlException e)
            {
                logger.LogMessage("An error occured while loading the CCP CorporationContracts Xml for ApiID: " + apiId + ". Is the API available?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (Exception)
            {
                throw;
            }

            return(xmlValues);
        }
Beispiel #10
0
        /// <summary>
        /// Resolve a type id and station id to a station buy price.
        /// </summary>
        /// <param name="typeId">The type id. E.g. '16229' for a Brutix.</param>
        /// <param name="stationId">The station id. E.g. '60003760' for 'Jita IV - Moon 4 - Caldari Navy Assembly Plant'.</param>
        /// <returns>Returns a double containing the station buy price of the passed type or 0 if not found.</returns>
        internal double PriceTypeStationBuy5Pc(int typeId, int stationId, string apiUrl = "")
        {
            XDocument xmlDoc;
            double    price = 0;

            // Assign the Api Url to a string if it has not already been passed as a parameter.
            if (apiUrl == string.Empty)
            {
                apiUrl = "http://api.eve-marketdata.com/api/price_type_station_buy_5pct.xml?char_name=DS&type_id=" + typeId + "&v=" + stationId;
            }

            // Create a new XMLDoc object loaded from the Api Url.
            try
            {
                xmlDoc = XDocument.Load(apiUrl);

                // Populate a list of the type ids within the xml results where the id attribute matches typeId.
                var xmlValue = xmlDoc.Descendants("val")
                               .Where(x => (double)x.Attribute("type_id") == typeId)
                               .Select(x => x.Value);

                // Convert the first value found to a double.
                price = Conversion.StringToDouble(xmlValue.FirstOrDefault());
            }
            catch (System.Net.WebException e)
            {
                logger.LogMessage("An error occured while parsing the eve-marketdata.com price_type_station_buy_5Pct Xml.", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (System.Xml.XmlException e)
            {
                logger.LogMessage("An error occured while loading the eve-marketdata.com price_type_station_buy_5Pct Xml. Is the API available?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (Exception)
            {
                throw;
            }

            return(price);
        }
Beispiel #11
0
        /// <summary>
        /// <para>Adds a sales agent from an api key and account id.</para>
        /// </summary>
        /// <param name="apiId">A valid eve api id (keyID).</param>
        /// <param name="apiKey">A valid eve api key (vCode).</param>
        /// <param name="accountId">The id of the account for which a sales agent should be added.</param>
        /// <returns>Returns a validation result object.</returns>
        internal IValidationResult AddSalesAgent(int apiId, string apiKey, int accountId)
        {
            IValidationResult validationResult = new ValidationResult();

            // Check the remaining sales agent licences for the account.
            if (this.GetRemainingSalesAgentLicences(accountId) <= 0)
            {
                validationResult.AddError("SalesAgent.Licences", "You have exceeded the number of sales agent licences available with your account subscription plan.");
            }
            else
            {
                // Fetch details about the Api Key from Eve Data.
                IEveDataApiKey apiKeyInfo = this.eveDataSource.GetApiKeyInfo(apiId, apiKey);

                if (apiKeyInfo != null)
                {
                    // Validate the api key.
                    validationResult = this.doctrineShipsValidation.ApiKey(apiKeyInfo);
                    if (validationResult.IsValid == true)
                    {
                        // Use the api key info to populate a new sales agent object.
                        SalesAgent newSalesAgent = new SalesAgent();

                        // If this is a character or account key use the character details, if a corp key use the corp details.
                        if (apiKeyInfo.Type == EveDataApiKeyType.Character || apiKeyInfo.Type == EveDataApiKeyType.Account)
                        {
                            // If this is an account key, the first character in the list will be used.
                            newSalesAgent.SalesAgentId = apiKeyInfo.Characters.FirstOrDefault().CharacterId;
                            newSalesAgent.Name         = apiKeyInfo.Characters.FirstOrDefault().CharacterName;
                            newSalesAgent.ImageUrl     = eveDataSource.GetCharacterPortraitUrl(newSalesAgent.SalesAgentId);
                            newSalesAgent.IsCorp       = false;
                        }
                        else if (apiKeyInfo.Type == EveDataApiKeyType.Corporation)
                        {
                            newSalesAgent.SalesAgentId = apiKeyInfo.Characters.FirstOrDefault().CorporationId;
                            newSalesAgent.Name         = apiKeyInfo.Characters.FirstOrDefault().CorporationName;
                            newSalesAgent.ImageUrl     = eveDataSource.GetCorporationLogoUrl(newSalesAgent.SalesAgentId);
                            newSalesAgent.IsCorp       = true;
                        }

                        // Populate the remaining properties.
                        newSalesAgent.AccountId           = accountId;
                        newSalesAgent.ApiId               = apiId;
                        newSalesAgent.ApiKey              = apiKey;
                        newSalesAgent.IsActive            = true;
                        newSalesAgent.LastForce           = DateTime.UtcNow;
                        newSalesAgent.LastContractRefresh = DateTime.UtcNow;

                        // Validate the new sales agent.
                        validationResult = this.doctrineShipsValidation.SalesAgent(newSalesAgent);
                        if (validationResult.IsValid == true)
                        {
                            // Add the new sales agent and log the event.
                            this.doctrineShipsRepository.CreateSalesAgent(newSalesAgent);
                            this.doctrineShipsRepository.Save();
                            logger.LogMessage("Sales Agent '" + newSalesAgent.Name + "' Successfully Added For Account Id: " + newSalesAgent.AccountId, 2, "Message", MethodBase.GetCurrentMethod().Name);
                        }
                    }
                }
                else
                {
                    validationResult.AddError("ApiKey.Valid", "An invalid api key was entered or the eve api is currently unavailable.");
                }
            }

            return(validationResult);
        }
        /// <summary>
        /// <para>Adds an account with a default setting profile and an account admin access code.</para>
        /// </summary>
        /// <param name="description">A short description for the new account.</param>
        /// <param name="subscriptionPlanId">The subscription plan for the new account.</param>
        /// <param name="generatedKey">An out string parameter containing the account admin key or an emptry string on failure.</param>
        /// <param name="newAccountId">An out int parameter containing the new account id or 0 on failure.</param>
        /// <returns>Returns a validation result object.</returns>
        internal IValidationResult AddAccount(string description, int subscriptionPlanId, out string generatedKey, out int newAccountId)
        {
            generatedKey = string.Empty;
            newAccountId = 0;
            IValidationResult validationResult = new ValidationResult();

            // Populate a new account object.
            Account newAccount = new Account();

            // Populate the remaining properties.
            newAccount.Description        = description;
            newAccount.DateCreated        = DateTime.UtcNow;
            newAccount.LastCredit         = DateTime.UtcNow;
            newAccount.LastDebit          = DateTime.UtcNow;
            newAccount.Balance            = 0;
            newAccount.IsActive           = true;
            newAccount.SettingProfileId   = 0;
            newAccount.SubscriptionPlanId = subscriptionPlanId;

            // Validate the new account.
            validationResult = this.doctrineShipsValidation.Account(newAccount);
            if (validationResult.IsValid == true)
            {
                // Add the new account and read it back to get the account id.
                newAccount = this.doctrineShipsRepository.CreateAccount(newAccount);
                this.doctrineShipsRepository.Save();

                // Assign the new account id to the passed out parameter.
                newAccountId = newAccount.AccountId;

                // Add a default account admin access code for the account and capture the generated key.
                generatedKey = this.AddAccessCode(newAccount.AccountId, "Default Account Admin", Role.Admin);

                // Create a default setting profile with the new account Id and assign it to the account.
                newAccount.SettingProfileId = this.AddDefaultSettingProfile(newAccount.AccountId);
                this.doctrineShipsRepository.UpdateAccount(newAccount);
                this.doctrineShipsRepository.Save();

                // Log the addition.
                logger.LogMessage("Account '" + newAccount.Description + "' Successfully Added.", 2, "Message", MethodBase.GetCurrentMethod().Name);
            }

            return(validationResult);
        }
        /// <summary>
        /// Resolve a type name to its typeid.
        /// </summary>
        /// <param name="typeName">The type name. E.g. 'Veldspar'.</param>
        /// <param name="apiUrl">An optional apiUrl parameter that overrides the method's internal value. Primarily used in unit tests to force errors.</param>
        /// <returns>Returns an integer containing a type id or 0 if not found.</returns>
        internal int TypeId(string typeName, string apiUrl = "")
        {
            XDocument xmlDoc;
            int       typeId = 0;

            // Assign the Api Url to a string if it has not already been passed as a parameter.
            if (apiUrl == string.Empty)
            {
                apiUrl = "http://api.eve-marketdata.com/api/type_id.xml?char_name=DS&v=" + typeName;
            }

            // Create a new XMLDoc object loaded from the Api Url.
            try
            {
                xmlDoc = XDocument.Load(apiUrl);

                // Populate a list of the type ids within the xml results where the id attribute matches typeName.
                var xmlValue = xmlDoc.Descendants("val")
                               .Where(x => (string)x.Attribute("id") == typeName)
                               .Select(x => x.Value);

                // Convert the first value found to an integer.
                typeId = Conversion.StringToInt32(xmlValue.FirstOrDefault());
            }
            catch (System.Net.WebException e)
            {
                logger.LogMessage("An error occured while parsing the eve-marketdata.com type_id Xml.", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (System.Xml.XmlException e)
            {
                logger.LogMessage("An error occured while loading the eve-marketdata.com type_id Xml. Is the API available?", 0, "Message", MethodBase.GetCurrentMethod().Name);
                logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name);
            }
            catch (Exception)
            {
                throw;
            }

            return(typeId);
        }