예제 #1
0
        public static APIDataType fromDataType(DataType sourceDataType)
        {
            APIDataType result = new APIDataType();

            result.ID    = sourceDataType.ID;
            result.Title = sourceDataType.Title;
            return(result);
        }
예제 #2
0
 public void SetLastAPIUpdateError(CharOrCorp corc, APIDataType type, string error)
 {
     _apiSettings.SetLastUpdateError(corc, type, error);
 }
예제 #3
0
 public void SetAPIAutoUpdate(CharOrCorp corc, APIDataType type, bool auto)
 {
     _apiSettings.SetAutoUpdateFlag(corc, type, auto);
     StoreGroupLevelSettings(corc == CharOrCorp.Char ? SettingsStoreType.Char : SettingsStoreType.Corp);
 }
예제 #4
0
 public string GetLastAPIUpdateError(CharOrCorp corc, APIDataType type)
 {
     return _apiSettings.GetLastUpdateError(corc, type);
 }
예제 #5
0
 public bool GetAPIAutoUpdate(CharOrCorp corc, APIDataType type)
 {
     GetGroupLevelCharSettings();
     return _apiSettings.GetAutoUpdateFlag(corc, type);
 }
예제 #6
0
        public bool CharHasCorporateAccess(APIDataType type)
        {
            bool retVal = true;
            switch (type)
            {
                case APIDataType.Transactions:
                    retVal = Settings.CorpTransactionsAPIAccess;
                    break;
                case APIDataType.Journal:
                    retVal = Settings.CorpJournalAPIAccess;
                    break;
                case APIDataType.Assets:
                    retVal = Settings.CorpAssetsAPIAccess;
                    break;
                case APIDataType.Orders:
                    retVal = Settings.CorpOrdersAPIAccess;
                    break;
                case APIDataType.IndustryJobs:
                    retVal = Settings.CorpIndustryJobsAPIAccess;
                    break;
                case APIDataType.Unknown:
                    break;
                case APIDataType.Full:
                    retVal = Settings.CorpTransactionsAPIAccess && Settings.CorpJournalAPIAccess &&
                        Settings.CorpAssetsAPIAccess && Settings.CorpOrdersAPIAccess &&
                        Settings.CorpIndustryJobsAPIAccess;
                    break;
                default:
                    break;
            }

            return retVal;
        }
예제 #7
0
        /// <summary>
        /// Download XML from the Eve API
        /// </summary>
        /// <param name="corc"></param>
        /// <param name="type"></param>
        private void RetrieveAPIXML(CharOrCorp corc, APIDataType type)
        {
            TimeSpan timeBetweenUpdates = UserAccount.Settings.GetAPIUpdatePeriod(type);
            DateTime earliestUpdate = GetLastAPIUpdateTime(corc, type).Add(timeBetweenUpdates);
            DateTime dataDate = DateTime.MinValue;

            short walletID = corc == CharOrCorp.Corp ? (short)1000 : (short)0;
            decimal beforeID = 0;
            bool finishedDownloading = false;
            bool walletExhausted = false;
            bool noData = true;
            bool abort = false;
            string xmlFile = "";
            int rowCount = 200;
            XmlDocument xml = null;

            long currentMaxID = 0;
            if (type == APIDataType.Transactions) { currentMaxID = _apiSettings.GetHighestID(corc, APIDataType.Transactions); }
            if (type == APIDataType.Journal) { currentMaxID = _apiSettings.GetHighestID(corc, APIDataType.Journal); }

            try
            {
                // Make sure we don't download if we've already done so recently.
                if (earliestUpdate.CompareTo(DateTime.UtcNow) > 0)
                {
                    throw new EMMAEveAPIException(ExceptionSeverity.Warning, 1000, "Cannot get " +
                        type.ToString() + " data so soon after the last update. Wait until at least " +
                        earliestUpdate.ToLongTimeString() + " before updating.");
                }

                while (!finishedDownloading)
                {
                    try
                    {
                        // Set parameters that will be passed to the API
                        #region Set parameters
                        StringBuilder parameters = new StringBuilder();
                        parameters.Append("keyID=");
                        parameters.Append(_userID);
                        parameters.Append("&vCode=");
                        parameters.Append(_apiKey);
                        parameters.Append("&characterID=");
                        parameters.Append(_charID);
                        if (type == APIDataType.Journal || type == APIDataType.Transactions)
                        {
                            parameters.Append("&rowCount=");
                            parameters.Append(rowCount);
                            if (walletID != 0)
                            {
                                parameters.Append("&accountKey=");
                                parameters.Append(walletID);
                            }
                            if (beforeID != 0)
                            {
                                parameters.Append("&fromID=");
                                parameters.Append(beforeID);
                            }
                        }
                        if (type == APIDataType.Assets || type == APIDataType.Orders)
                        {
                            parameters.Append("&version=2");
                        }
                        #endregion

                        xml = EveAPI.GetXml(EveAPI.URL_EveApiHTTPS + EveAPI.GetURL(corc, type),
                            parameters.ToString(), ref xmlFile);
                        XmlNodeList tmp = EveAPI.GetResults(xml);
                        if (xmlFile.Length > 0)
                        {
                            lock (_unprocessedXMLFiles) { _unprocessedXMLFiles.Enqueue(xmlFile); }
                            noData = false;
                        }
                        if (type == APIDataType.Journal || type == APIDataType.Transactions)
                        {
                            if (tmp.Count < rowCount) { walletExhausted = true; }
                        }

                        // Set the last update time based upon the 'cached until'
                        // time rather than the actual time the update occured
                        // Note we could modify the API update period timer instead but
                        // that would cause other issues. It's better for the user if
                        // we just do things this way.
                        if (type == APIDataType.Transactions)
                        {
                            // Transactions XML often gives a cache expiry date time that is too soon.
                            // If we try and update again when it says then it will fail so just wait
                            // for the usual 1 hour. (Or whatever the user has it set to)
                            SetLastAPIUpdateTime(corc, type, DateTime.UtcNow);
                        }
                        else
                        {
                            DateTime nextAllowed = EveAPI.GetCachedUntilTime(xml);
                            SetLastAPIUpdateTime(corc, type, nextAllowed.Subtract(
                                UserAccount.Settings.GetAPIUpdatePeriod(type)));
                        }

                        // If we've been successfull in getting data and this is a corporate data request
                        // then make sure we've got access set to true;
                        if (corc == CharOrCorp.Corp)
                        {
                            Settings.SetCorpAPIAccess(type, true);
                        }

                    }
                    catch (EMMAEveAPIException emmaApiEx)
                    {
                        #region API Error Handling
                        if (emmaApiEx.EveCode == 100)
                        {
                            // Error code 100 indicates that a 'beforeRefID' has been passed in when the
                            // api was not expecting it. If we know for sure that we've already called
                            // the api once then have to abandon the data we have got so far.
                            // (No idea why the API does this, it just happens from time to time)
                            if (!noData)
                            {
                                walletExhausted = true;
                                //SetLastAPIUpdateError(corc, type, "Eve API Error 100");
                            }
                            else
                            {
                                throw emmaApiEx;
                            }
                        }
                        else if (emmaApiEx.EveCode == 101 || emmaApiEx.EveCode == 102 ||
                            emmaApiEx.EveCode == 103 || emmaApiEx.EveCode == 116 || emmaApiEx.EveCode == 117)
                        {
                            // Data already retrieved
                            string err = emmaApiEx.EveDescription;

                            // If there is a cachedUntil tag, dont try and get data again until
                            // after it has expired.
                            DateTime nextAllowed = EveAPI.GetCachedUntilTime(xml);
                            SetLastAPIUpdateTime(corc, type, nextAllowed.Subtract(
                                UserAccount.Settings.GetAPIUpdatePeriod(type)));
                            if (noData)
                            {
                                SetLastAPIUpdateError(corc, type,
                                    "The Eve API reports that this data has already been retrieved, no update has occured.");
                            }
                            walletExhausted = true;
                        }
                        else if (emmaApiEx.EveCode == 200)
                        {
                            // Security level not high enough
                            SetLastAPIUpdateError(corc, type,
                                "You must enter your FULL api key to retrieve financial and asset data.\r\n" +
                                "Use the 'manage group' button to correct this.");
                            abort = true;
                        }
                        else if (emmaApiEx.EveCode == 206 || emmaApiEx.EveCode == 208 ||
                            emmaApiEx.EveCode == 209 || emmaApiEx.EveCode == 213)
                        {
                            // Character does not have required corporate role.
                            Settings.SetCorpAPIAccess(type, false);
                            SetAPIAutoUpdate(corc, type, false);
                            SetLastAPIUpdateError(corc, type, emmaApiEx.Message);
                            abort = true;
                        }
                        else
                        {
                            throw emmaApiEx;
                        }
                        #endregion
                    }

                    /// By default, we're now done..
                    finishedDownloading = true;

                    // However, for some update types, we'll want to go round a few more times
                    #region Determine if we should access API again with different variables
                    if (!abort)
                    {
                        if (type == APIDataType.Journal || type == APIDataType.Transactions)
                        {
                            //XmlNode lastRowNode = xml.SelectSingleNode(@"/eveapi/result/rowset/row[last()]");
                            XmlNodeList results = xml.SelectNodes(@"/eveapi/result/rowset/row");
                            long minID = long.MaxValue;
                            if (results != null)
                            {
                                foreach (XmlNode node in results)
                                {
                                    string idAttribName = "";
                                    if (type == APIDataType.Journal) { idAttribName = "@refID"; }
                                    if (type == APIDataType.Transactions) { idAttribName = "@transactionID"; }
                                    long val = long.Parse(node.SelectSingleNode(idAttribName).Value);
                                    if (val < minID) { minID = val; }
                                }
                            }

                            if (minID != long.MaxValue && minID > currentMaxID)
                            {
                                beforeID = minID;
                            }
                            else { walletExhausted = true; }
                            if (!walletExhausted) { finishedDownloading = false; }
                            if (walletExhausted && corc == CharOrCorp.Corp && walletID < 1006)
                            {
                                walletID++;
                                beforeID = 0;
                                finishedDownloading = false;
                            }
                        }
                    }
                    #endregion
                }

            }
            catch (Exception ex)
            {
                EMMAException emmaEx = ex as EMMAException;
                if (emmaEx == null)
                {
                    // If we've caught a standard exception rather than an EMMA one then log it be creating a
                    // new exception.
                    // Note that we don't need to actually throw it..
                    emmaEx = new EMMAException(ExceptionSeverity.Error,
                        "Error when downloading " + type.ToString() + " from Eve API", ex);
                }

                SetLastAPIUpdateError(corc, type, ex.Message);
                noData = true;
            }

            // If we have not retrieved any data at all then mark the update as completed.
            if (noData)
            {
                if (UpdateEvent != null)
                {
                    UpdateEvent(this, new APIUpdateEventArgs(type,
                        corc == CharOrCorp.Char ? _charID : _corpID,
                        APIUpdateEventType.UpdateCompleted));
                }
            }
        }
 public bool GetCorpAPIAccess(APIDataType type)
 {
     bool retVal =false;
     switch (type)
     {
         case APIDataType.Transactions:
             retVal = CorpTransactionsAPIAccess;
             break;
         case APIDataType.Journal:
             retVal = CorpJournalAPIAccess;
             break;
         case APIDataType.Assets:
             retVal = CorpAssetsAPIAccess;
             break;
         case APIDataType.Orders:
             retVal = CorpOrdersAPIAccess;
             break;
         case APIDataType.IndustryJobs:
             retVal = CorpIndustryJobsAPIAccess;
             break;
         case APIDataType.Unknown:
             break;
         case APIDataType.Full:
             break;
         default:
             break;
     }
     return retVal;
 }
 public void SetLastUpdateTime(CharOrCorp corc, APIDataType type, DateTime time)
 {
     switch (corc)
     {
         case CharOrCorp.Char:
             switch (type)
             {
                 case APIDataType.Transactions:
                     _lastCharTransUpdate = time;
                     break;
                 case APIDataType.Journal:
                     _lastCharJournalUpdate = time;
                     break;
                 case APIDataType.Assets:
                     _lastCharAssetsUpdate = time;
                     break;
                 case APIDataType.Orders:
                     _lastCharOrdersUpdate = time;
                     break;
                 case APIDataType.IndustryJobs:
                     _settings.LastCharIndustryJobsUpdate = time;
                     break;
                 default:
                     break;
             }
             break;
         case CharOrCorp.Corp:
             switch (type)
             {
                 case APIDataType.Transactions:
                     _lastCorpTransUpdate = time;
                     break;
                 case APIDataType.Journal:
                     _lastCorpJournalUpdate = time;
                     break;
                 case APIDataType.Assets:
                     _lastCorpAssetsUpdate = time;
                     break;
                 case APIDataType.Orders:
                     _lastCorpOrdersUpdate = time;
                     break;
                 case APIDataType.IndustryJobs:
                     _settings.LastCorpIndustryJobsUpdate = time;
                     break;
                 default:
                     break;
             }
             break;
         default:
             break;
     }
 }
 public void SetLastUpdateError(CharOrCorp corc, APIDataType type, string error)
 {
     switch (corc)
     {
         case CharOrCorp.Char:
             switch (type)
             {
                 case APIDataType.Transactions:
                     _lastCharTransUpdateError = error;
                     break;
                 case APIDataType.Journal:
                     _lastCharJournalUpdateError = error;
                     break;
                 case APIDataType.Assets:
                     _lastCharAssetsUpdateError = error;
                     break;
                 case APIDataType.Orders:
                     _lastCharOrdersUpdateError = error;
                     break;
                 case APIDataType.IndustryJobs:
                     _lastCharIndustryJobsUpdateError = error;
                     break;
                 default:
                     break;
             }
             break;
         case CharOrCorp.Corp:
             switch (type)
             {
                 case APIDataType.Transactions:
                     _lastCorpTransUpdateError = error;
                     break;
                 case APIDataType.Journal:
                     _lastCorpJournalUpdateError = error;
                     break;
                 case APIDataType.Assets:
                     _lastCorpAssetsUpdateError = error;
                     break;
                 case APIDataType.Orders:
                     _lastCorpOrdersUpdateError = error;
                     break;
                 case APIDataType.IndustryJobs:
                     _lastCorpIndustryJobsUpdateError = error;
                     break;
                 default:
                     break;
             }
             break;
         default:
             break;
     }
 }
 public void SetHighestID(CharOrCorp corc, APIDataType type, long id)
 {
     switch (corc)
     {
         case CharOrCorp.Char:
             switch (type)
             {
                 case APIDataType.Transactions:
                     _highestCharTransID = id;
                     break;
                 case APIDataType.Journal:
                     _highestCharJournalID = id;
                     break;
                 default:
                     break;
             }
             break;
         case CharOrCorp.Corp:
             switch (type)
             {
                 case APIDataType.Transactions:
                     _highestCorpTransID = id;
                     break;
                 case APIDataType.Journal:
                     _highestCorpJournalID = id;
                     break;
                 default:
                     break;
             }
             break;
         default:
             break;
     }
 }
 public void SetAutoUpdateFlag(CharOrCorp corc, APIDataType type, bool auto)
 {
     switch (corc)
     {
         case CharOrCorp.Char:
             switch (type)
             {
                 case APIDataType.Transactions:
                     _autoUpdateCharTrans = auto;
                     break;
                 case APIDataType.Journal:
                     _autoUpdateCharJournal = auto;
                     break;
                 case APIDataType.Assets:
                     _autoUpdateCharAssets = auto;
                     break;
                 case APIDataType.Orders:
                     _autoUpdateCharOrders = auto;
                     break;
                 case APIDataType.IndustryJobs:
                     _autoUpdateCharIndustryJobs = auto;
                     break;
                 default:
                     break;
             }
             break;
         case CharOrCorp.Corp:
             switch (type)
             {
                 case APIDataType.Transactions:
                     _autoUpdateCorpTrans = auto;
                     break;
                 case APIDataType.Journal:
                     _autoUpdateCorpJournal = auto;
                     break;
                 case APIDataType.Assets:
                     _autoUpdateCorpAssets = auto;
                     break;
                 case APIDataType.Orders:
                     _autoUpdateCorpOrders = auto;
                     break;
                 case APIDataType.IndustryJobs:
                     _autoUpdateCorpIndustryJobs = auto;
                     break;
                 default:
                     break;
             }
             break;
         default:
             break;
     }
 }
        public DateTime GetLastUpdateTime(CharOrCorp corc, APIDataType type)
        {
            DateTime retVal = SqlDateTime.MinValue.Value;
            switch (corc)
            {
                case CharOrCorp.Char:
                    switch (type)
                    {
                        case APIDataType.Transactions:
                            retVal = _lastCharTransUpdate;
                            break;
                        case APIDataType.Journal:
                            retVal = _lastCharJournalUpdate;
                            break;
                        case APIDataType.Assets:
                            retVal = _lastCharAssetsUpdate;
                            break;
                        case APIDataType.Orders:
                            retVal = _lastCharOrdersUpdate;
                            break;
                        case APIDataType.IndustryJobs:
                            retVal = _settings.LastCharIndustryJobsUpdate;
                            break;
                        default:
                            break;
                    }
                    break;
                case CharOrCorp.Corp:
                    switch (type)
                    {
                        case APIDataType.Transactions:
                            retVal = _lastCorpTransUpdate;
                            break;
                        case APIDataType.Journal:
                            retVal = _lastCorpJournalUpdate;
                            break;
                        case APIDataType.Assets:
                            retVal = _lastCorpAssetsUpdate;
                            break;
                        case APIDataType.Orders:
                            retVal = _lastCorpOrdersUpdate;
                            break;
                        case APIDataType.IndustryJobs:
                            retVal = _settings.LastCorpIndustryJobsUpdate;
                            break;
                        default:
                            break;
                    }
                    break;
                default:
                    break;
            }

            return retVal;
        }
        public string GetLastUpdateError(CharOrCorp corc, APIDataType type)
        {
            string retVal = "";
            switch (corc)
            {
                case CharOrCorp.Char:
                    switch (type)
                    {
                        case APIDataType.Transactions:
                            retVal = _lastCharTransUpdateError;
                            break;
                        case APIDataType.Journal:
                            retVal = _lastCharJournalUpdateError;
                            break;
                        case APIDataType.Assets:
                            retVal = _lastCharAssetsUpdateError;
                            break;
                        case APIDataType.Orders:
                            retVal = _lastCharOrdersUpdateError;
                            break;
                        case APIDataType.IndustryJobs:
                            retVal = _lastCharIndustryJobsUpdateError;
                            break;
                        default:
                            break;
                    }
                    break;
                case CharOrCorp.Corp:
                    switch (type)
                    {
                        case APIDataType.Transactions:
                            retVal = _lastCorpTransUpdateError;
                            break;
                        case APIDataType.Journal:
                            retVal = _lastCorpJournalUpdateError;
                            break;
                        case APIDataType.Assets:
                            retVal = _lastCorpAssetsUpdateError;
                            break;
                        case APIDataType.Orders:
                            retVal = _lastCorpOrdersUpdateError;
                            break;
                        case APIDataType.IndustryJobs:
                            retVal = _lastCorpIndustryJobsUpdateError;
                            break;
                        default:
                            break;
                    }
                    break;
                default:
                    break;
            }

            return retVal;
        }
        public long GetHighestID(CharOrCorp corc, APIDataType type)
        {
            long retVal = 0;
            switch (corc)
            {
                case CharOrCorp.Char:
                    switch (type)
                    {
                        case APIDataType.Transactions:
                            retVal = _highestCharTransID;
                            break;
                        case APIDataType.Journal:
                            retVal = _highestCharJournalID;
                            break;
                        default:
                            break;
                    }
                    break;
                case CharOrCorp.Corp:
                    switch (type)
                    {
                        case APIDataType.Transactions:
                            retVal = _highestCorpTransID;
                            break;
                        case APIDataType.Journal:
                            retVal = _highestCorpJournalID;
                            break;
                        default:
                            break;
                    }
                    break;
                default:
                    break;
            }

            return retVal;
        }
예제 #16
0
 public static string GetURL(CharOrCorp corc, APIDataType type)
 {
     string retVal = "";
     switch (type)
     {
         case APIDataType.Transactions:
             retVal = corc == CharOrCorp.Char ? URL_TransApi : URL_TransCorpApi;
             break;
         case APIDataType.Journal:
             retVal = corc == CharOrCorp.Char ? URL_JournApi : URL_JournCorpApi;
             break;
         case APIDataType.Assets:
             retVal = corc == CharOrCorp.Char ? URL_AssetApi : URL_AssetCorpApi;
             break;
         case APIDataType.Orders:
             retVal = corc == CharOrCorp.Char ? URL_CharOrdersApi : URL_CorpOrdersApi;
             break;
         case APIDataType.IndustryJobs:
             retVal = corc == CharOrCorp.Char ? URL_IndustryApi : URL_IndustryCorpApi;
             break;
         case APIDataType.Unknown:
             break;
         case APIDataType.Full:
             break;
         default:
             break;
     }
     return retVal;
 }
        public bool GetAutoUpdateFlag(CharOrCorp corc, APIDataType type)
        {
            bool retVal = false;
            switch (corc)
            {
                case CharOrCorp.Char:
                    switch (type)
                    {
                        case APIDataType.Transactions:
                            retVal = _autoUpdateCharTrans;
                            break;
                        case APIDataType.Journal:
                            retVal = _autoUpdateCharJournal;
                            break;
                        case APIDataType.Assets:
                            retVal = _autoUpdateCharAssets;
                            break;
                        case APIDataType.Orders:
                            retVal = _autoUpdateCharOrders;
                            break;
                        case APIDataType.IndustryJobs:
                            retVal = _autoUpdateCharIndustryJobs;
                            break;
                        default:
                            break;
                    }
                    break;
                case CharOrCorp.Corp:
                    switch (type)
                    {
                        case APIDataType.Transactions:
                            retVal = _autoUpdateCorpTrans;
                            break;
                        case APIDataType.Journal:
                            retVal = _autoUpdateCorpJournal;
                            break;
                        case APIDataType.Assets:
                            retVal = _autoUpdateCorpAssets;
                            break;
                        case APIDataType.Orders:
                            retVal = _autoUpdateCorpOrders;
                            break;
                        case APIDataType.IndustryJobs:
                            retVal = _autoUpdateCorpIndustryJobs;
                            break;
                        default:
                            break;
                    }
                    break;
                default:
                    break;
            }

            return retVal;
        }
 public void SetCorpAPIAccess(APIDataType type, bool value)
 {
     switch (type)
     {
         case APIDataType.Transactions:
             CorpTransactionsAPIAccess = value;
             break;
         case APIDataType.Journal:
             CorpJournalAPIAccess = value;
             break;
         case APIDataType.Assets:
             CorpAssetsAPIAccess = value;
             break;
         case APIDataType.Orders:
             CorpOrdersAPIAccess = value;
             break;
         case APIDataType.IndustryJobs:
             CorpIndustryJobsAPIAccess = value;
             break;
         case APIDataType.Unknown:
             break;
         case APIDataType.Full:
             break;
         default:
             break;
     }
 }
예제 #19
0
 public List<CharCorpOption> GetCharCorpOptions(APIDataType type)
 {
     return GetCharCorpOptions(type, false);
 }
예제 #20
0
 public APIUpdateInfo(CharOrCorp corc, APIDataType type)
 {
     Corc = corc;
     Type = type;
 }
예제 #21
0
        public List<CharCorpOption> GetCharCorpOptions(APIDataType type, bool charsOnly)
        {
            List<CharCorpOption> options = new List<CharCorpOption>();

            foreach (EVEAccount account in _accounts)
            {
                foreach (APICharacter apichar in account.Chars)
                {
                    if (account.Type == CharOrCorp.Char && apichar.CharIncWithRptGroup)
                    {
                        CharCorpOption opt = new CharCorpOption(apichar, false);
                        options.Add(opt);
                    }
                    if (account.Type == CharOrCorp.Corp && !charsOnly && apichar.CorpIncWithRptGroup && apichar.CharHasCorporateAccess(type))
                    {
                        CharCorpOption opt = new CharCorpOption(apichar, true);
                        options.Add(opt);
                    }
                }
            }

            return options;
        }
예제 #22
0
 public void DownloadXMLFromAPI(CharOrCorp corc, APIDataType type)
 {
     switch (type)
     {
         case APIDataType.Transactions:
             SetLastAPIUpdateError(corc, type, "QUEUED");
             ThreadPool.QueueUserWorkItem(RetrieveAPIXML, new APIUpdateInfo(corc, type));
             break;
         case APIDataType.Journal:
             SetLastAPIUpdateError(corc, type, "QUEUED");
             ThreadPool.QueueUserWorkItem(RetrieveAPIXML, new APIUpdateInfo(corc, type));
             break;
         case APIDataType.Assets:
             SetLastAPIUpdateError(corc, type, "QUEUED");
             ThreadPool.QueueUserWorkItem(RetrieveAPIXML, new APIUpdateInfo(corc, type));
             break;
         case APIDataType.Orders:
             SetLastAPIUpdateError(corc, type, "QUEUED");
             ThreadPool.QueueUserWorkItem(RetrieveAPIXML, new APIUpdateInfo(corc, type));
             break;
         case APIDataType.IndustryJobs:
             SetLastAPIUpdateError(corc, type, "QUEUED");
             ThreadPool.QueueUserWorkItem(RetrieveAPIXML, new APIUpdateInfo(corc, type));
             break;
         case APIDataType.Unknown:
             break;
         case APIDataType.Full:
             SetLastAPIUpdateError(corc, APIDataType.Transactions, "QUEUED");
             SetLastAPIUpdateError(corc, APIDataType.Orders, "QUEUED");
             SetLastAPIUpdateError(corc, APIDataType.IndustryJobs, "QUEUED");
             SetLastAPIUpdateError(corc, APIDataType.Journal, "QUEUED");
             SetLastAPIUpdateError(corc, APIDataType.Assets, "QUEUED");
             ThreadPool.QueueUserWorkItem(RetrieveAPIXML, new APIUpdateInfo(corc, APIDataType.Transactions));
             ThreadPool.QueueUserWorkItem(RetrieveAPIXML, new APIUpdateInfo(corc, APIDataType.Orders));
             ThreadPool.QueueUserWorkItem(RetrieveAPIXML, new APIUpdateInfo(corc, APIDataType.IndustryJobs));
             ThreadPool.QueueUserWorkItem(RetrieveAPIXML, new APIUpdateInfo(corc, APIDataType.Journal));
             ThreadPool.QueueUserWorkItem(RetrieveAPIXML, new APIUpdateInfo(corc, APIDataType.Assets));
             break;
         default:
             break;
     }
 }
예제 #23
0
 public List<FinanceAccessParams> GetFinanceAccessParams(APIDataType type)
 {
     List<FinanceAccessParams> accessList = new List<FinanceAccessParams>();
     foreach (EVEAccount account in _accounts)
     {
         foreach (APICharacter character in account.Chars)
         {
             if (character.CharIncWithRptGroup)
             {
                 accessList.Add(new FinanceAccessParams(character.CharID));
             }
             if (character.CorpIncWithRptGroup && character.CharHasCorporateAccess(type))
             {
                 accessList.Add(new FinanceAccessParams(character.CorpID));
             }
         }
     }
     return accessList;
 }
예제 #24
0
 public long GetHighestID(CharOrCorp corc, APIDataType type)
 {
     return _apiSettings.GetHighestID(corc, type);
 }
예제 #25
0
 public APIUpdateEventArgs(APIDataType updateType, long ownerID, APIUpdateEventType eventType)
 {
     _updateType = updateType;
     _id = ownerID;
     _eventType = eventType;
 }
예제 #26
0
 public DateTime GetLastAPIUpdateTime(CharOrCorp corc, APIDataType type)
 {
     return _apiSettings.GetLastUpdateTime(corc, type);
 }
예제 #27
0
        private void UpdateLabel(Label label, Label otherLabel, CharOrCorp corc, APIDataType dataType, TimeSpan minTimeBetweenUpdates)
        {
            DateTime lastDataUpdate = _character.GetLastAPIUpdateTime(corc, dataType);
            TimeSpan time = DateTime.UtcNow.Subtract(lastDataUpdate);
            string errorText = _character.GetLastAPIUpdateError(corc, dataType);
            bool doUpdate = false;
            bool checkForAccess = false;

            // No need for this.
            // The 'update completed' event is fired by the APICharacter object and handled by the
            // UpdateStatus window anyway.
            //if (label.Text.ToUpper().Equals("UPDATING") && !errorText.ToUpper().Equals("UPDATING")
            //    && !errorText.ToUpper().Equals("BLOCKED") && !errorText.ToUpper().Equals("AWAITING ACKNOWLEDGEMENT"))
            //{
            //    // If the label currently says 'updating' but the error text no longer says 'updating' (or blocked)
            //    // then fire the update completed event.
            //    if (UpdateEvent != null)
            //    {
            //        UpdateEvent(this, new APIUpdateEventArgs(dataType, corc ==
            //            CharOrCorp.Char ? _character.CharID : _character.CorpID,
            //            APIUpdateEventType.UpdateCompleted));
            //    }
            //}

            if (errorText.Equals("") || (_type == CharOrCorp.Corp && (
                errorText.ToUpper().Contains("CHARACTER MUST BE A") ||
                errorText.ToUpper().Contains("CHARACTER MUST HAVE"))))
            {
                if (_type == CharOrCorp.Corp && !_character.CharHasCorporateAccess(dataType))
                {
                    label.Text = "No Access";
                    label.BackColor = _errorColour;
                    otherLabel.BackColor = _errorColour;
                    if (chkUpdate.Checked) { checkForAccess = true; }
                    //switch (dataType)
                    //{
                    //    case APIDataType.Transactions:
                    //        if (chkAutoTrans.Checked) { checkForAccess = true; chkAutoTrans.Checked = false; }
                    //        break;
                    //    case APIDataType.Journal:
                    //        if (chkAutoJournal.Checked) { checkForAccess = true; chkAutoJournal.Checked = false; }
                    //        break;
                    //    case APIDataType.Assets:
                    //        if (chkAutoAssets.Checked) { checkForAccess = true; chkAutoAssets.Checked = false; }
                    //        break;
                    //    case APIDataType.Orders:
                    //        if (chkAutoOrders.Checked) { checkForAccess = true; chkAutoOrders.Checked = false; }
                    //        break;
                    //    default:
                    //        break;
                    //}
                }
                else if (minTimeBetweenUpdates.CompareTo(time) > 0)
                {
                    time = minTimeBetweenUpdates.Subtract(time);
                    // Waiting for next update window
                    label.Text = time.Hours.ToString().PadLeft(2, '0') + ":" +
                        time.Minutes.ToString().PadLeft(2, '0') + ":" +
                        time.Seconds.ToString().PadLeft(2, '0');
                    label.BackColor = _upToDateColour;
                    otherLabel.BackColor = _upToDateColour;
                }
                else
                {
                    // Update overdue
                    label.Text = "Overdue";
                    label.BackColor = _overdueUpdateColour;
                    otherLabel.BackColor = _overdueUpdateColour;
                    doUpdate = true;
                }
            }
            else if (errorText.ToUpper().Equals("UPDATING"))
            {
                if (label.Text.Equals(BLOCKEDTEXT))
                {
                    // If the update was previously blocked then need to let the rest of EMMA
                    // know that the update is now restarted.
                    if (UpdateEvent != null)
                    {
                        UpdateEvent(this, new APIUpdateEventArgs(dataType, corc ==
                            CharOrCorp.Char ? _character.CharID : _character.CorpID,
                            APIUpdateEventType.UpdateStarted));
                    }
                }
                // The update is in progress.
                label.Text = "Updating";
                label.BackColor = _updatingColour;
                otherLabel.BackColor = _updatingColour;
            }
            else if (errorText.ToUpper().Equals("DOWNLOADING"))
            {
                // The update is in progress.
                label.Text = "Downloading";
                label.BackColor = _updatingColour;
                otherLabel.BackColor = _updatingColour;
            }
            else if (errorText.ToUpper().Equals("QUEUED"))
            {
                // The thread performing the update has been started but is currently waiting
                // for some other update to complete before it can proceed.
                // No transaction, orders or assets update can be running at the same time for a particular
                // character or corp.
                // No journal update can be running at the same time for ANY character or corp.
                label.Text = "Queued";
                label.BackColor = _updatingColour;
                otherLabel.BackColor = _updatingColour;
            }
            else if (errorText.ToUpper().Equals("BLOCKED"))
            {
                // An assets update has been blocked because the most recent transaction and orders
                // updates are not within the timeframe specified.
                // Ask the user if they want to reconfigure this to always allow asset updates.
                if (!label.Text.Equals(BLOCKEDTEXT))
                {
                    label.Text = BLOCKEDTEXT;
                    label.BackColor = _updatingColour;

                    otherLabel.BackColor = _updatingColour;
                    // Make sure we let the rest of EMMA know that the update has stopped.
                    // Otherwise, the user will be unable to use reports, exit, etc while
                    // waiting for it to unblock.
                    if (UpdateEvent != null)
                    {
                        UpdateEvent(this, new APIUpdateEventArgs(dataType, corc ==
                            CharOrCorp.Char ? _character.CharID : _character.CorpID,
                            APIUpdateEventType.UpdateCompleted));
                    }
                    DialogResult result = MessageBox.Show("An assets update for " + (corc == CharOrCorp.Char ?
                        _character.CharName : _character.CorpName) + " has been blocked because transaction " +
                        " & orders updates have not occured within the last " +
                        UserAccount.Settings.AssetsUpdateMaxMinutes + " minutes.\r\n" +
                        "The assets update is only allowed to run when the number of minutes since transactions & " +
                        "orders updates is less than a configured number. This setting can be changed in " +
                        "Settings -> API Update Settings.\r\n" +
                        "Do you wish to set this to zero now? (i.e. always allow assets updates regardless of " +
                        "the last time a transaction/orders update occured)", "Question",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        UserAccount.Settings.AssetsUpdateMaxMinutes = 0;
                    }
                }
            }
            else if (errorText.ToUpper().Equals("AWAITING ACKNOWLEDGEMENT"))
            {
                if (!label.Text.Equals(WAITINGTEXT))
                {
                    label.Text = WAITINGTEXT;
                    label.BackColor = _updatingColour;
                    otherLabel.BackColor = _updatingColour;
                }
            }
            else
            {
                // The last update caused an error of some sort.

                if (minTimeBetweenUpdates.CompareTo(time) > 0)
                {
                    time = minTimeBetweenUpdates.Subtract(time);
                    // Waiting for next update window
                    label.Text = "Error " + time.Hours.ToString().PadLeft(2, '0') + ":" +
                        time.Minutes.ToString().PadLeft(2, '0') + ":" +
                        time.Seconds.ToString().PadLeft(2, '0');
                    label.BackColor = _errorColour;
                    LabelMetaData metaData = (LabelMetaData)otherLabel.Tag;
                    metaData.TimerType = APIUpdateTimerType.Normal;
                    otherLabel.BackColor = _errorColour;
                }
                else
                {
                    LabelMetaData metaData = (LabelMetaData)otherLabel.Tag;
                    if (metaData.TimerType == APIUpdateTimerType.Normal)
                    {
                        // Update overdue
                        label.Text = "Overdue";
                        label.BackColor = _overdueUpdateColour;
                        otherLabel.BackColor = _overdueUpdateColour;
                        doUpdate = true;
                    }
                    else
                    {
                        // If we didn't even get as far as setting the update time when
                        // requesting data from the API last time then just use a one hour
                        // timer to make sure we don't request updates every few seconds
                        // after an error occurs.
                        metaData.TimerType = APIUpdateTimerType.Error;
                        DateTime lastAttempt = _lastUpdateAttempt[dataType];
                        TimeSpan timeSinceLastAttempt = DateTime.UtcNow.Subtract(lastAttempt);
                        if (timeSinceLastAttempt.TotalMinutes > 60)
                        {
                            // Update overdue
                            label.Text = "Overdue";
                            label.BackColor = _overdueUpdateColour;
                            otherLabel.BackColor = _overdueUpdateColour;
                            doUpdate = true;
                        }
                        else
                        {
                            // Error on the last update
                            time = new TimeSpan(0, 61, 0);
                            time = time.Subtract(timeSinceLastAttempt);
                            label.Text = "Error " + time.Hours.ToString().PadLeft(2, '0') + ":" +
                                    time.Minutes.ToString().PadLeft(2, '0') + ":" +
                                    time.Seconds.ToString().PadLeft(2, '0'); ;
                            label.BackColor = _errorColour;
                            otherLabel.BackColor = _errorColour;
                        }
                    }
                }
            }

            if (checkForAccess || (doUpdate && _character.GetAPIAutoUpdate(corc, dataType)))
            {
                // If we're updating assets and order or transaction updates are pending then do those first.
                if (dataType == APIDataType.Assets &&
                    ((_character.GetAPIAutoUpdate(corc, APIDataType.Orders) &&
                    (lblOrdersStatus.Text.Equals("Overdue") || lblOrdersStatus.Text.Equals("Queued"))) ||
                    (_character.GetAPIAutoUpdate(corc, APIDataType.Transactions) &&
                    (lblTransStatus.Text.Equals("Overdue") || lblTransStatus.Text.Equals("Queued")))))
                {
                }
                else
                {
                    // If we're auto updating then kick it off.
                    LabelMetaData metaData = (LabelMetaData)otherLabel.Tag;
                    metaData.TimerType = APIUpdateTimerType.Normal;
                    if (UpdateEvent != null)
                    {
                        UpdateEvent(this, new APIUpdateEventArgs(dataType, corc ==
                            CharOrCorp.Char ? _character.CharID : _character.CorpID,
                            APIUpdateEventType.UpdateStarted));
                    }
                    if (_lastUpdateAttempt.ContainsKey(dataType))
                    {
                        _lastUpdateAttempt.Remove(dataType);
                    }
                    _lastUpdateAttempt.Add(dataType, DateTime.UtcNow);
                    _character.DownloadXMLFromAPI(corc, dataType);
                    //if (corc == CharOrCorp.Corp && dataType == APIDataType.Orders)
                    //{
                    //    // If we're dealing with corporate orders then we need to grab corporate orders for
                    //    // all characters in this report group that are part of the corp.
                    //    // This is because orders will only be returned that were actually created by
                    //    // the character we are retrieving data for.
                    //    foreach (EVEAccount account in UserAccount.CurrentGroup.Accounts)
                    //    {
                    //        foreach (APICharacter character in account.Chars)
                    //        {
                    //            if (character.CorpID == _character.CorpID && character.CharID != _character.CharID)
                    //            {
                    //                if (character.CharHasCorporateAccess(APIDataType.Orders))
                    //                {
                    //                    character.UpdateDataFromAPI(corc, dataType);
                    //                }
                    //            }
                    //        }
                    //    }
                    //}
                }
            }

            // Make sure the state of the auto update checkboxes reflects the true values.
            // This only needs to be done for corps because the only way the auto-update
            // setting can change without user intervention is if a char does not have corp
            // data access.
            if (corc == CharOrCorp.Corp)
            {
                switch (dataType)
                {
                    case APIDataType.Transactions:
                        chkAutoTrans.Checked = _character.GetAPIAutoUpdate(corc, dataType);
                        break;
                    case APIDataType.Journal:
                        chkAutoJournal.Checked = _character.GetAPIAutoUpdate(corc, dataType);
                        break;
                    case APIDataType.Assets:
                        chkAutoAssets.Checked = _character.GetAPIAutoUpdate(corc, dataType);
                        break;
                    case APIDataType.Orders:
                        chkAutoOrders.Checked = _character.GetAPIAutoUpdate(corc, dataType);
                        break;
                    case APIDataType.IndustryJobs:
                        chkAutoIndustryJobs.Checked = _character.GetAPIAutoUpdate(corc, dataType);
                        break;
                    default:
                        break;
                }
                SetOverallUpdateState();
            }
        }
예제 #28
0
 public void SetHighestID(CharOrCorp corc, APIDataType type, long id)
 {
     _apiSettings.SetHighestID(corc, type, id);
 }
예제 #29
0
 public LabelMetaData(APIDataType type)
 {
     _type = type;
     _timerType = APIUpdateTimerType.Normal;
 }
예제 #30
0
 public void SetLastAPIUpdateTime(CharOrCorp corc, APIDataType type, DateTime time)
 {
     _apiSettings.SetLastUpdateTime(corc, type, time);
 }
예제 #31
0
 public ReportType(IReport report, string description, RptParamsBase parameterForm,
     bool needFinanceAccessParams, bool needAssetAccessParams, APIDataType accessType)
 {
     _report = report;
     _name = report.GetTitle();
     _description = description;
     _parameterForm = parameterForm;
     _needFinanceAccessParams = needFinanceAccessParams;
     _needAssetAccessParams = needAssetAccessParams;
     _accessType = accessType;
 }