Exemple #1
0
        private static void CheckContracts()
        {
            EveApi api;
            List <EveAI.Live.Utility.Contract> Contracts;
            Dictionary <long, EveCharacter>    Names = new Dictionary <long, EveCharacter>();
            List <long> IDs = new List <long>();
            var         now = DateTime.Now;

            DateTime lastFullRunTime = GetLastRunTime();

            Console.WriteLine(string.Format("Start Time : {0}", lastFullRunTime.ToString("yyyy-MM-dd HH:mm:ss")));

            try
            {
                api       = new EveAI.Live.EveApi("Clyde en Marland's Contract Notifier", (long)Properties.Settings.Default.CorpAPI, Properties.Settings.Default.VCode);
                Contracts = api.GetCorporationContracts().ToList().Where(contract => contract.DateIssued > lastFullRunTime).ToList();

                foreach (EveAI.Live.Utility.Contract Contract in Contracts)
                {
                    IDs.Add(Contract.IssuerID);
                }

                foreach (long Id in IDs)
                {
                    if (!Names.ContainsKey(Id))
                    {
                        Names.Add(Id, JKON.EveWho.Api.GetCharacter(Id));
                    }
                }

                foreach (EveAI.Live.Utility.Contract Contract in Contracts)
                {
                    if ((Contract.Type == EveAI.Live.Utility.Contract.ContractType.Courier) &&
                        ((Contract.Status == EveAI.Live.Utility.Contract.ContractStatus.Outstanding) || (Contract.Status == EveAI.Live.Utility.Contract.ContractStatus.Completed)))
                    {
                        //Console.WriteLine(string.Format("Contract notification: {0}", FormatMessage(Contract, Names[Contract.IssuerID].result.characterName)));
                        SendMessage(HyperFormatMessage(Contract, Names[Contract.IssuerID].result.characterName));
                        if (Contract.DateIssued > lastFullRunTime)
                        {
                            lastFullRunTime = Contract.DateIssued;
                        }
                    }
                }
                UpdateRunTime(lastFullRunTime);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            if (Environment.UserInteractive)
            {
                System.Threading.Thread.Sleep(10000);
            }
        }
        public ActionResult ContractStatus()
        {
            EveApi api;
            List <EveAI.Live.Utility.Contract> Contracts = new List <EveAI.Live.Utility.Contract>();
            Dictionary <long, EveCharacter>    Names     = new Dictionary <long, EveCharacter>();
            List <long> IDs = new List <long>();

            DateTime backDate = DateTime.Now.AddDays(-7).Date;

            try
            {
                api = new EveAI.Live.EveApi("Clyde en Marland's Contract Notifier", (long)Properties.Settings.Default.LogisticsCorpAPI, Properties.Settings.Default.LogisticsVCode);

                Contracts = api.GetCorporationContracts().ToList().Where(contract =>
                                                                         (contract.Type == EveAI.Live.Utility.Contract.ContractType.Courier)
                                                                         &&
                                                                         (contract.Status != EveAI.Live.Utility.Contract.ContractStatus.Deleted)
                                                                         &&
                                                                         ((contract.DateIssued >= backDate)
                                                                          ||
                                                                          (contract.Status == EveAI.Live.Utility.Contract.ContractStatus.Outstanding)
                                                                          ||
                                                                          (contract.Status == EveAI.Live.Utility.Contract.ContractStatus.InProgress))).ToList();

                if (!User.IsInRole("Logistics"))
                {
                    try
                    {
                        var user = UserManager.FindById(User.Identity.GetUserId());
                        user.LoadApiKeys();

                        var apiKeys = user.ApiKeys.GroupBy(apiKey => apiKey.ApiKey).Select(apiKey => apiKey.First()).ToList();
                        var toons   = new List <AccountCharacter>();

                        apiKeys.ForEach(apiKey => toons.AddRange(JKON.EveWho.EveWho.GetCharacters(apiKey.ApiKey, apiKey.VerificationCode)));

                        Contracts = Contracts.Where(contract => toons.Any(toon => toon.CharacterID.Equals(contract.IssuerID))).ToList();
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message(ex.Message);
                        return(RedirectToAction("Index", "LoggedInHome"));
                    }
                }

                IDs = Contracts.Select(contract => contract.IssuerID).ToList();

                Contracts.ForEach(contract =>
                {
                    if (contract.StartStation == null)
                    {
                        var startStation      = Api.GetStation(contract.StartStationID);
                        contract.StartStation = new EveAI.SpaceStation.Station()
                        {
                            Name = startStation.stationName
                        };
                    }
                    if (contract.EndStation == null)
                    {
                        var endStation      = Api.GetStation(contract.EndStationID);
                        contract.EndStation = new EveAI.SpaceStation.Station()
                        {
                            Name = endStation.stationName
                        };
                    }
                });

                Contracts.Select(contract => contract.IssuerID).ToList().ForEach(id =>
                {
                    if (!Names.ContainsKey(id))
                    {
                        Names.Add(id, JKON.EveWho.Api.GetCharacter(id));
                    }
                });
                Contracts.Select(contract => contract.AcceptorID).ToList().ForEach(id =>
                {
                    if (!Names.ContainsKey(id))
                    {
                        Names.Add(id, JKON.EveWho.Api.GetCharacter(id));
                    }
                });

                if ((DateTime.Now.Month == 12) && (DateTime.Now.Day > 17) && (DateTime.Now.Day < 25))
                {
                    var id      = JKON.EveWho.Api.GetCharacterID(User.Identity.Name);
                    var toon1   = JKON.EveWho.Api.GetCharacter(id);
                    var toon2   = JKON.EveWho.Api.GetCorpMembers(Convert.ToInt64(Properties.Settings.Default.CorpAPI), Properties.Settings.Default.VCode).Where(member => member.Name == User.Identity.Name).FirstOrDefault();
                    var station = new Station()
                    {
                        Name = toon2.Location
                    };

                    Names.Add(id, toon1);
                    Names.Add(-1, new EveCharacter()
                    {
                        result = new JKON.EveWho.EveCharacter.Models.result()
                        {
                            characterID = -1, characterName = "Hauled By Reindeer (corp)"
                        }
                    });
                    Names.Add(-2, new EveCharacter()
                    {
                        result = new JKON.EveWho.EveCharacter.Models.result()
                        {
                            characterID = -2, characterName = "Santa Claus"
                        }
                    });

                    var contract = new EveAI.Live.Utility.Contract()
                    {
                        StartStation = new EveAI.SpaceStation.Station()
                        {
                            Name        = "Lapland VI - Santas Workshop",
                            SolarSystem = new EveAI.Map.SolarSystem()
                            {
                                Name = "North Pole"
                            }
                        },
                        EndStation   = station,
                        DateIssued   = new DateTime(2015, 12, 15),
                        DateAccepted = new DateTime(2015, 12, 17),
                        AcceptorID   = -1,
                        IssuerID     = -2,
                        Status       = GetStatus(),
                        Volume       = 10000,
                        Title        = string.Format("Christmas Presents for {0}", toon2.Name)
                    };

                    if (contract.Status == EveAI.Live.Utility.Contract.ContractStatus.Outstanding)
                    {
                        Contracts.Insert(0, contract);
                    }
                    else if (contract.Status == EveAI.Live.Utility.Contract.ContractStatus.InProgress)
                    {
                        var index = Contracts.Where(c => c.Status == EveAI.Live.Utility.Contract.ContractStatus.Outstanding).Count();
                        Contracts.Insert(index, contract);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(View(new LogisticsContractsViewModel()
            {
                DisplayContracts = Contracts, CharacterInfos = Names
            }));
        }
        public ActionResult ContractStatus()
        {
            EveApi api;
            List<EveAI.Live.Utility.Contract> Contracts = new List<EveAI.Live.Utility.Contract>();
            Dictionary<long, EveCharacter> Names = new Dictionary<long, EveCharacter>();
            List<long> IDs = new List<long>();

            DateTime backDate = DateTime.Now.AddDays(-7).Date;

            try
            {
                api = new EveAI.Live.EveApi("Clyde en Marland's Contract Notifier", (long)Properties.Settings.Default.LogisticsCorpAPI, Properties.Settings.Default.LogisticsVCode);

                Contracts = api.GetCorporationContracts().ToList().Where(contract =>
                    (contract.Type == EveAI.Live.Utility.Contract.ContractType.Courier)
                    &&
                    (contract.Status != EveAI.Live.Utility.Contract.ContractStatus.Deleted)
                    &&
                    ((contract.DateIssued >= backDate)
                    ||
                    (contract.Status == EveAI.Live.Utility.Contract.ContractStatus.Outstanding)
                    ||
                    (contract.Status == EveAI.Live.Utility.Contract.ContractStatus.InProgress))).ToList();

                if(!User.IsInRole("Logistics"))
                {
                    try
                    {
                        var user = UserManager.FindById(User.Identity.GetUserId());
                        user.LoadApiKeys();

                        var apiKeys = user.ApiKeys.GroupBy(apiKey => apiKey.ApiKey).Select(apiKey => apiKey.First()).ToList();
                        var toons = new List<AccountCharacter>();

                        apiKeys.ForEach(apiKey => toons.AddRange(JKON.EveWho.EveWho.GetCharacters(apiKey.ApiKey, apiKey.VerificationCode)));

                        Contracts = Contracts.Where(contract => toons.Any(toon => toon.CharacterID.Equals(contract.IssuerID))).ToList();
                    }
                    catch(Exception ex)
                    {
                        ViewBag.Message(ex.Message);
                        return RedirectToAction("Index", "LoggedInHome");
                    }
                }

                IDs = Contracts.Select(contract => contract.IssuerID).ToList();

                Contracts.ForEach(contract =>
                {
                    if(contract.StartStation == null) {
                        var startStation = Api.GetStation(contract.StartStationID);
                        contract.StartStation = new EveAI.SpaceStation.Station() { Name = startStation.stationName };
                    }
                    if (contract.EndStation == null)
                    {
                        var endStation = Api.GetStation(contract.EndStationID);
                        contract.EndStation = new EveAI.SpaceStation.Station() { Name = endStation.stationName };
                    }
                });

                Contracts.Select(contract => contract.IssuerID).ToList().ForEach(id =>
                        {
                            if (!Names.ContainsKey(id))
                            {
                                Names.Add(id, JKON.EveWho.Api.GetCharacter(id));
                            }
                        });
                Contracts.Select(contract => contract.AcceptorID).ToList().ForEach(id =>
                {
                    if (!Names.ContainsKey(id))
                    {
                        Names.Add(id, JKON.EveWho.Api.GetCharacter(id));
                    }
                });

                if((DateTime.Now.Month == 12) && (DateTime.Now.Day > 17) && (DateTime.Now.Day < 25))
                {

                    var id = JKON.EveWho.Api.GetCharacterID(User.Identity.Name);
                    var toon1 = JKON.EveWho.Api.GetCharacter(id);
                    var toon2 = JKON.EveWho.Api.GetCorpMembers(Convert.ToInt64(Properties.Settings.Default.CorpAPI), Properties.Settings.Default.VCode).Where(member => member.Name == User.Identity.Name).FirstOrDefault();
                    var station = new Station()
                    {
                        Name = toon2.Location
                    };

                    Names.Add(id, toon1);
                    Names.Add(-1, new EveCharacter() { result = new JKON.EveWho.EveCharacter.Models.result() { characterID = -1, characterName = "Hauled By Reindeer (corp)" } });
                    Names.Add(-2, new EveCharacter() { result = new JKON.EveWho.EveCharacter.Models.result() { characterID = -2, characterName = "Santa Claus" } });

                    var contract = new EveAI.Live.Utility.Contract()
                    {
                        StartStation = new EveAI.SpaceStation.Station()
                        {
                            Name = "Lapland VI - Santas Workshop",
                            SolarSystem = new EveAI.Map.SolarSystem() { Name = "North Pole" }
                        },
                        EndStation = station,
                        DateIssued = new DateTime(2015, 12, 15),
                        DateAccepted = new DateTime(2015, 12, 17),
                        AcceptorID = -1,
                        IssuerID = -2,
                        Status = GetStatus(),
                        Volume = 10000,
                        Title = string.Format("Christmas Presents for {0}", toon2.Name)
                    };

                    if (contract.Status == EveAI.Live.Utility.Contract.ContractStatus.Outstanding)
                    {
                        Contracts.Insert(0, contract);
                    }
                    else if(contract.Status == EveAI.Live.Utility.Contract.ContractStatus.InProgress)
                    {
                        var index = Contracts.Where(c => c.Status == EveAI.Live.Utility.Contract.ContractStatus.Outstanding).Count();
                        Contracts.Insert(index, contract);
                    }
                }
            }
            catch(Exception ex)
            {
            }

            return View(new LogisticsContractsViewModel() { DisplayContracts = Contracts, CharacterInfos = Names });
        }