示例#1
0
        private static TreeNode GetCharacterRosterTreeNodeRecursive(SINnerList list, ref ConcurrentDictionary <string, CharacterCache> CharCache)
        {
            var            sinner   = list.SiNner;
            CharacterCache objCache = null;

            if (!String.IsNullOrEmpty(sinner?.MyExtendedAttributes?.JsonSummary))
            {
                objCache =
                    Newtonsoft.Json.JsonConvert.DeserializeObject <CharacterCache>(sinner.MyExtendedAttributes
                                                                                   .JsonSummary);
                SetEventHandlers(sinner, objCache);
            }
            else
            {
                objCache = new CharacterCache();
                objCache.CharacterName  = "pending";
                objCache.CharacterAlias = sinner.Alias;
                objCache.BuildMethod    = "online";
                SetEventHandlers(sinner, objCache);
            }

            TreeNode objListNode = new TreeNode
            {
                Text             = objCache.CalculatedName(),
                Tag              = sinner.Id.Value.ToString(),
                ToolTipText      = "Last Change: " + sinner.LastChange,
                ContextMenuStrip = PluginHandler.MainForm.CharacterRoster.ContextMenuStrip
            };

            if (!string.IsNullOrEmpty(objCache.ErrorText))
            {
                objListNode.ForeColor    = Color.Red;
                objListNode.ToolTipText += Environment.NewLine + Environment.NewLine + LanguageManager.GetString("String_Error", GlobalOptions.Language)
                                           + LanguageManager.GetString("String_Colon", GlobalOptions.Language) + Environment.NewLine + objCache.ErrorText;
            }
            CharacterCache delObj;

            CharCache.TryRemove(sinner.Id.Value.ToString(), out delObj);
            CharCache.TryAdd(sinner.Id.Value.ToString(), objCache);
            foreach (var childlist in list.SinList)
            {
                var childnode = GetCharacterRosterTreeNodeRecursive(childlist, ref CharCache);
                if (childnode != null)
                {
                    objListNode.Nodes.Add(childnode);
                }
            }
            return(objListNode);
        }
        public async Task <ActionResult <SINSearchResult> > GetSINnersByAuthorization()
        {
            SINSearchResult ret = new SINSearchResult();

            try
            {
                var user = await _signInManager.UserManager.GetUserAsync(User);

                if (user == null)
                {
                    ret.ErrorText = "Unauthorized";
                    throw new AuthenticationException("User is not authenticated.");
                }
                //get all from visibility
                SINnersList   list      = new SINnersList();
                List <SINner> mySinners = await SINner.GetSINnersFromUser(user, _context, true);

                foreach (var sin in mySinners)
                {
                    SINnerList owndSINner = new SINnerList
                    {
                        SINner = sin
                    };
                    if (sin.MyGroup != null)
                    {
                        //add all members of his group
                        var members = await sin.MyGroup.GetGroupMembers(_context);

                        foreach (var member in members)
                        {
                            if (member.Id == sin.Id)
                            {
                                continue;
                            }
                            if ((member.SINnerMetaData.Visibility.IsGroupVisible == true) ||
                                (member.SINnerMetaData.Visibility.IsPublic)
                                )
                            {
                                member.MyGroup          = sin.MyGroup;
                                member.MyGroup.MyGroups = new List <SINnerGroup>();
                                SINnerList memberlist = new SINnerList();
                                memberlist.SINner = member;
                                owndSINner.SINList.Add(memberlist);
                            }
                        }
                        sin.MyGroup.MyGroups = new List <SINnerGroup>();
                        ;
                    }
                    list.MySINnersList.Add(owndSINner);
                }

                ret.SINLists.Add(list);
                return(Ok(ret));
            }
            catch (Exception e)
            {
                if (e is HubException)
                {
                    return(BadRequest(e));
                }
                HubException hue = new HubException(e.Message, e);
                return(BadRequest(hue));
            }
        }