示例#1
0
        public ApiLoadResponse <AccountBalance> Load(ApiKeyType keyType, int keyID, string vCode, int eveApiID)
        {
            var url    = string.Format("http://api.eve-online.com/{0}/AccountBalance.xml.aspx?keyID={1}&vCode={2}&characterID={3}", keyType.ServiceBase(), keyID, vCode, eveApiID);
            var result = EveApiLoader.Load(url);

            if (!result.Success)
            {
                throw new Exception(result.ErrorMessage);
            }
            var xElement = result.Result.Element("rowset");
            var response = new ApiLoadResponse <AccountBalance>
            {
                Data        = new List <AccountBalance>(),
                CachedUntil = result.CachedUntil
            };

            if (xElement != null)
            {
                response.Data = xElement.Elements("row").Select(f => new AccountBalance
                {
                    AccountID  = (int)f.Attribute("accountID"),
                    AccountKey = (int)f.Attribute("accountKey"),
                    Balance    = (decimal)f.Attribute("balance")
                }).ToList();
            }
            return(response);
        }
示例#2
0
 internal ApiKey(int id, string verificationCode, ApiKeyType type, int accessMask, DateTime expiresOn)
 {
     this.Id = id;
     this.VerificationCode = verificationCode;
     this.Type = type;
     this.AccessMask = accessMask;
     this.ExpiresOn = expiresOn;
 }
 public API_Key_Store(int ID, string VCode, ApiKeyType Type, DateTime Expires, string Desc)
 {
     this.KeyID = ID;
     this.VerificationCode = VCode;
     this.KeyType = Type;
     this.Expiration = Expires;
     this.Description = Desc;
     this.Active = true;
 }
        /// <summary>
        /// Creates a new API client (for backend or user-aware usage) in current instance. Only Admin permission role can create new API clients.
        /// </summary>
        /// <param name="description">Description of new API client.</param>
        /// <param name="type">Type of new API client.</param>
        /// <param name="roleId">New API client's permission role id (see role.get()). Not used when creating User API key (type = user)</param>
        /// <returns>New User object.</returns>
        public Task<ApiKey> New(string description, ApiKeyType type = ApiKeyType.Backend, string roleId = null)
        {
            if(description == null)
                throw new ArgumentNullException();

            if(type == ApiKeyType.User && roleId != null)
                throw new ArgumentException();

            return _syncanoClient.PostAsync<ApiKey>("apikey.new", new {description, type = type.ToString(), role_id = roleId}, "apikey");
        }
示例#5
0
        public ApiLoadResponse <IndustryJob> Load(ApiKeyType keyType, int apiKeyId, string vCode, int eveApiID)
        {
            var kt       = keyType == ApiKeyType.Character ? "char" : "corp";
            var url      = string.Format("http://api.eve-online.com/{0}/IndustryJobsHistory.xml.aspx?keyID={1}&vCode={2}&characterID={3}", kt, apiKeyId, vCode, eveApiID);
            var response = EveApiLoader.Load(url);

            if (!response.Success)
            {
                throw new Exception(response.ErrorMessage);
            }
            if (!response.Success)
            {
                throw new Exception(response.ErrorMessage);
            }
            var xElement = response.Result.Element("rowset");
            var result   = new ApiLoadResponse <IndustryJob>
            {
                CachedUntil = response.CachedUntil
            };

            if (xElement == null)
            {
                return(result);
            }
            foreach (var job in xElement.Elements("row").Select(f => new IndustryJob
            {
                ID = int.Parse(f.Attribute("jobID").Value),
                InstalledItemID = long.Parse(f.Attribute("blueprintID").Value),
                InstallerID = int.Parse(f.Attribute("installerID").Value),
                Runs = int.Parse(f.Attribute("runs").Value),
                InstalledItemTypeID = int.Parse(f.Attribute("productTypeID").Value),
                LicensedRuns = int.Parse(f.Attribute("licensedRuns").Value),
                OutputTypeID = int.Parse(f.Attribute("productTypeID").Value),
                Completed = GetCompleted(f),
                ActivityID = int.Parse(f.Attribute("activityID").Value),
                BeginProductionTime = GetTime(f.Attribute("startDate")),
                EndProductionTime = GetTime(f.Attribute("endDate")),
                PauseProductionTime = GetTime(f.Attribute("pauseDate")),
                TeamID = int.Parse(f.Attribute("teamID").Value)
            }))
            {
                result.Data.Add(job);
            }
            return(result);
        }
示例#6
0
        public ApiLoadResponse <MarketOrder> Load(ApiKeyType keyType, int apiKeyId, string vCode, int eveApiID)
        {
            var kt       = keyType == ApiKeyType.Character ? "char" : "corp";
            var url      = string.Format("http://api.eve-online.com/{0}/MarketOrders.xml.aspx?keyID={1}&vCode={2}&characterID={3}", kt, apiKeyId, vCode, eveApiID);
            var response = EveApiLoader.Load(url);

            if (!response.Success)
            {
                throw new Exception(response.ErrorMessage);
            }
            var result = new ApiLoadResponse <MarketOrder>
            {
                CachedUntil = response.CachedUntil
            };
            var element = response.Result.Element("rowset");

            if (element != null)
            {
                result.Data.AddRange(element.Elements("row").Select(f => new MarketOrder
                {
                    ID              = (long)f.Attribute("orderID"),
                    CharacterID     = (int)f.Attribute("charID"),
                    StationID       = (int)f.Attribute("stationID"),
                    VolumeEntered   = (int)f.Attribute("volEntered"),
                    VolumeRemaining = (int)f.Attribute("volRemaining"),
                    MinimumVolume   = (int)f.Attribute("minVolume"),
                    OrderState      = (OrderState)(int)f.Attribute("orderState"),
                    ItemID          = (int)f.Attribute("typeID"),
                    Range           = (short)f.Attribute("range"),
                    AccountKey      = (int)f.Attribute("accountKey"),
                    Duration        = (int)f.Attribute("duration"),
                    Escrow          = (decimal)f.Attribute("escrow"),
                    Price           = (decimal)f.Attribute("price"),
                    OrderType       = (bool)f.Attribute("bid") ? OrderType.Buy : OrderType.Sell,
                    WhenIssued      = (DateTime)f.Attribute("issued")
                }));
            }
            return(result);
        }
        /*public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            // Use the AddValue method to specify serialized values.
            info.AddValue("Active", Active, typeof(bool));
            info.AddValue("KeyID", KeyID, typeof(int));
            info.AddValue("KeyType", KeyType, typeof(ApiKeyType));
            info.AddValue("Description", Description, typeof(string));
            info.AddValue("Expiration", Expiration, typeof(DateTime));
            info.AddValue("VerificationCode", VerificationCode, typeof(string));

        }

        public API_Key_Store(SerializationInfo info, StreamingContext context)
        {
            // Reset the property value using the GetValue method.
            Active = (bool)info.GetValue("Active", typeof(bool));
            KeyID = (int)info.GetValue("KeyID", typeof(int));
            KeyType = (ApiKeyType)info.GetValue("KeyType", typeof(ApiKeyType));
            Description = (string)info.GetValue("Description", typeof(string));
            Expiration = (DateTime)info.GetValue("Expiration", typeof(DateTime));
            VerificationCode = (string)info.GetValue("VerificationCode", typeof(string));
        }*/
        public static string APIKeyTypeToString(ApiKeyType type)
        {
            switch (type)
            {
                case ApiKeyType.Account:
                    return "Account";

                case ApiKeyType.Character:
                    return "Character";

                case ApiKeyType.Corporation:
                    return "Corporation";
            }

            return "";
        }
        public ApiLoadResponse <WalletTransaction> Load(ApiKeyType keyType, int apiKeyId, string vCode, int eveApiID, int maxAge, long lastTransactionId)
        {
            var  done   = false;
            long?before = null;
            var  result = new ApiLoadResponse <WalletTransaction>
            {
                Data = new List <WalletTransaction>(),
            };
            var enough = false;

            while (!done)
            {
                var kt      = keyType == ApiKeyType.Character ? "char" : "corp";
                var service = string.Format("http://api.eve-online.com/{0}/WalletTransactions.xml.aspx?keyID={1}&vCode={2}&characterID={3}", kt, apiKeyId, vCode, eveApiID);
                if (before != null)
                {
                    service += string.Format("&beforeTransID={0}", before);
                }

                var response = EveApiLoader.Load(service);
                if (!response.Success)
                {
                    throw new Exception(response.ErrorMessage);
                }
                var xElement = response.Result.Element("rowset");
                if (xElement != null)
                {
                    result.CachedUntil = response.CachedUntil;
                    if (keyType == ApiKeyType.Character)
                    {
                        result.Data.AddRange(
                            xElement
                            .Elements("row")
                            .Where(f => f.Attribute("transactionFor").Value == "personal")
                            .Select(f => new WalletTransaction
                        {
                            ID       = long.Parse(f.Attribute("transactionID").Value),
                            DateTime = DateTime.Parse(f.Attribute("transactionDateTime").Value),
                            Quantity = int.Parse(f.Attribute("quantity").Value),
                            TypeID   = int.Parse(f.Attribute("typeID").Value),
                            Type     = f.Attribute("transactionType").Value,
                            Price    = Decimal.Parse(f.Attribute("price").Value)
                        }));
                    }
                    else
                    {
                        result.Data.AddRange(
                            xElement
                            .Elements("row")
                            .Select(f => new WalletTransaction
                        {
                            ID       = long.Parse(f.Attribute("transactionID").Value),
                            DateTime = DateTime.Parse(f.Attribute("transactionDateTime").Value),
                            Quantity = int.Parse(f.Attribute("quantity").Value),
                            TypeID   = int.Parse(f.Attribute("typeID").Value),
                            Type     = f.Attribute("transactionType").Value,
                            Price    = Decimal.Parse(f.Attribute("price").Value)
                        }));
                    }
                    if (xElement.Elements("row").Any())
                    {
                        var first = xElement.Elements("row").Min(f => long.Parse(f.Attribute("transactionID").Value));
                        enough = xElement.Elements("row").Min(f => DateTime.Parse(f.Attribute("transactionDateTime").Value)) < DateTime.Now.AddDays(-maxAge);
                        before = first;
                    }
                    else
                    {
                        enough = true;
                    }
                }
                done = enough || result.Data.Count == 0 || result.Data[0].ID <= lastTransactionId;
            }
            return(result);
        }
示例#9
0
 public static string ServiceBase(this ApiKeyType keyType)
 {
     return(keyType == ApiKeyType.Character ? "char" : "corp");
 }