コード例 #1
0
        /// <summary>
        /// Handle a message
        /// </summary>
        /// <param name="message"></param>
        /// <param name="origin">Item that initiated request</param>
        /// <param name="mm">Module manager</param>
        /// <param name="response"></param>
        private IResponse HandleCoreReadItemGraphRequest(
            IMessage message,
            Item origin,
            IModuleManager mm,
            IResponse response)
        {
            var request = message.GetMessageAsType <CoreReadItemGraphRequest>();

            response = HandleRequestWrapper <CoreReadItemGraphResponse>(request, res =>
            {
                var itemId = request.ItemId ??
                             mm.GetModule <IWorldModule>().GetDefaultGame().Id;
                var item      = mm.GetManager <IItemManager>().Read(itemId);
                var itemGraph = new ItemGraph()
                {
                    Id   = item.Id,
                    Name = item.GetProperty <VisibleItemProperty>()?.Name ?? "N/A"
                };
                BuildItemGraph(mm.GetManager <IItemManager>(), itemGraph);
                ((CoreReadItemGraphResponse)res).CoreReadItemGraphEvent = new CoreReadItemGraphEvent()
                {
                    ItemGraph = itemGraph
                };
                res.SetSuccess(true);
            });
            return(response);
        }
コード例 #2
0
        /// <summary>
        /// Build an item graph
        /// </summary>
        /// <param name="itemManager"></param>
        /// <param name="itemGraph"></param>
        private void BuildItemGraph(IItemManager itemManager, ItemGraph itemGraph)
        {
            var parentItem = itemManager.Read(itemGraph.Id);

            parentItem.ChildrenIds?.ForEach((itemId) =>
            {
                var item       = itemManager.Read(itemId);
                var name       = item.GetProperty <VisibleItemProperty>()?.Name ?? "N/A";
                var childGraph = new ItemGraph()
                {
                    Id   = itemId,
                    Name = name
                };
                BuildItemGraph(itemManager, childGraph);
                itemGraph.Children.Add(childGraph);
            });
        }
コード例 #3
0
 /// <summary>
 /// Read item graph
 /// </summary>
 /// <returns></returns>
 public async Task LoadItemGraphAsync()
 {
     Working = true;
     try
     {
         if (ItemGraph.Count() == 0)
         {
             ItemGraph = new List <ItemGraph>()
             {
                 await ItemService.ReadGraphAsync()
             };
         }
     }
     finally
     {
         Working = false;
     }
 }