示例#1
0
        public static async Task UpdateOneCharacter(StructureContext context, Character character, bool force = false)
        {
            if (string.IsNullOrEmpty(character.AccessToken))
            {
                throw new Exception("User had no existing token.");
            }
            if (character.ExpiresAt < DateTime.UtcNow)
            {
                var token = await EVESwagger.GetToken(Token.REFRESH, character.RefreshToken);

                character.ConsumeToken(token);

                context.Update(character);

                await context.SaveChangesAsync();
            }

            //get notifications
            // if (force || character.ExpiresAt < DateTime.UtcNow){
            var notifications =
                await EVESwagger.GetNotificationsByCharacterId(character.CharacterID, character.AccessToken);

            //deduplciated
            //TODO this SHould work except it doesnt so we need to figure out why.
            // var Current = context.Notifications.Select(x => x.NotificationId).ToArray();
            notifications = notifications.Where(n => context.Notifications.Select(x => x.NotificationId).Contains(n.NotificationId) == false).ToList();
            context.Notifications.AddRange(notifications);
            context.SaveChanges();
            // }
        }
示例#2
0
 public static void UpdatePublicStructureList(StructureContext context)
 {
     //get items htat are not in the database already. add them witha first seen date.
     // List<long> publicStructures = await ESIClient.Universe.Structures();
     // List<long> known= context.Structures.Select(s=>s.Id).ToList();
     // List<long> newStructures = publicStructures.RemoveAll(known);
 }
示例#3
0
        public async Task GetCodeAsync(string code, string state)
        {
            var token = await EVESwagger.GetToken("authorization_code", code);

            var auth_char = await EVESwagger.Verify(token);


            using (var context = new StructureContext())
            {
                //if we have on update it to use the token we just got or bail.
                var fromdb = context.Characters.Where(c => c.CharacterID == auth_char.CharacterID).FirstOrDefault();
                if (fromdb == null)
                {
                    context.Characters.Attach(auth_char);
                    //If we have just signed in for the first time, force update the notifications for that character
                    var ignoreWarning = StructureWatch.Services.Polling.UpdateOneCharacter(context, auth_char, true);
                }
                else
                {
                    fromdb.ConsumeToken(token);
                    context.Characters.Update(fromdb);
                }

                context.SaveChanges();


                //sign in the user:
                var principal = new EveSSOClaim().BuildClaimsPrincipal(context, auth_char.CharacterName);
                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

                HttpContext.User = principal;
            }

            Response.Redirect("/LoggedIn");
        }
示例#4
0
        /// <summary>
        ///     Main entry point for establishing a principal.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="username"></param>
        /// <returns></returns>
        public ClaimsPrincipal BuildClaimsPrincipal(StructureContext context, string username)
        {
            BuildUserClaim(username);
            SetPermissionClaims(context, username);
            var userIdentity = new ClaimsIdentity(_userClaims, "Passport");

            return(new ClaimsPrincipal(userIdentity));
        }
示例#5
0
        public void RegisterPendingStructure(StructureInfo info, StructureContext context)
        {
            if (info == null || context == null)
            {
                return;
            }

            lock (pendingStructureMutex)
            {
                {
                    bool alreadyThere = false;

                    // Do not register the same thing twice
                    for (int i = 0; i < pendingStructureInfo.Count; i++)
                    {
                        if (pendingStructureInfo[i].Equals(info))
                        {
                            alreadyThere = true;
                            break;
                        }
                    }

                    if (!alreadyThere)
                    {
                        pendingStructureInfo.Add(info);
                    }
                }

                List <StructureContext> list;
                if (pendingStructures.TryGetValue(context.chunkPos, out list))
                {
                    list.Add(context);
                }
                else
                {
                    pendingStructures.Add(context.chunkPos, new List <StructureContext> {
                        context
                    });
                }
            }

            {
                Chunk chunk;
                lock (chunks)
                {
                    // Let the chunk know it needs an update if it exists
                    chunk = GetChunk(ref context.chunkPos);
                }
                if (chunk != null)
                {
                    chunk.NeedApplyStructure = true;
                }
            }
        }
        public async Task FullyUpdateData()
        {
            if (!string.IsNullOrEmpty(User.Identity.Name))
            {
                using (var context = new StructureContext())
                {
                    await Polling.FullyUpdateData(context);
                }
            }

            Response.Redirect("/Me/Notifications");
        }
        public async Task Hide(long id)
        {
            using (var context = new StructureContext())
            {
                var notif = context.Notifications.Find(id);
                if (notif != null)
                {
                    notif.Hidden = true;
                    context.Update(notif);
                    await context.SaveChangesAsync();
                }
            }


            Response.Redirect("/Me/Notifications");
        }
        public async Task GetNotifications(int Id)
        {
            if (!string.IsNullOrEmpty(User.Identity.Name))
            {
                using (var context = new StructureContext())
                {
                    var character = context.Characters.Where(c => c.Id == Id)
                                    .FirstOrDefault();
                    if (character != null)
                    {
                        await Polling.UpdateOneCharacter(context, character);
                    }
                }
            }

            Response.Redirect("/Me/Notifications");
        }
示例#9
0
        public static async Task FullyUpdateData(StructureContext context)
        {
            //get all public structres
            //UpdatePublicStructureList(context);
            //GET ALL CHARs
            var           all_chars = context.Characters.ToList();
            List <String> Failed    = new List <string>();

            foreach (var c in all_chars)
            {
                try{
                    await UpdateOneCharacter(context, c);
                }
                catch (Exception ex) {
                    Failed.Add(c.CharacterName + ":" + ex.Message);
                }
            }

            //at this point pull
            if (Failed.Count > 0)
            {
                throw new Exception("Failed to poll all characters:" + String.Join("\n", Failed));
            }
        }
示例#10
0
 public CharacterModel(StructureContext _context)
 {
     context = _context;
 }
示例#11
0
 /// <summary>
 ///     Set permission claims.  You can assign a user
 ///     different policy claims based upon their username.
 /// </summary>
 private void SetPermissionClaims(StructureContext context, string username)
 {
     // if we get where we have a db  record.
     _userClaims.Add(new Claim(ClaimTypes.Role, "User", ClaimValueTypes.String)); //, issuer));
 }
示例#12
0
 public StructureContext Init()
 {
     return(_dbContext ?? (_dbContext = new StructureContext()));
 }
示例#13
0
 public indexModel(StructureContext _context)
 {
     context = _context;
 }
示例#14
0
 public structureModel(StructureContext _context)
 {
     context = _context;
 }
示例#15
0
 public static void UpdateStructures(StructureContext context, List <int> structuresIdList)
 {
 }
示例#16
0
 public NotificiationsModel(StructureContext _context)
 {
     context = _context;
 }