public async Task <string> GetNewItemID(List <IContentItem> parents, string name)
        {
            if ((parents == null) || !parents.Any() || string.IsNullOrEmpty(name))
            {
                return(null);
            }

            if ((Root == null) || (Root.Children == null))
            {
                return(null);
            }

            var channel = Root.Children.FirstOrDefault(c => c.Name == parents[0].Name);

            if (channel == null)
            {
                return(null);
            }

            string currentID = channel.ID;

            while (parents.Count > 0)
            {
                var currentParent = parents[0];
                parents.RemoveAt(0);
                string title = name;
                if (parents.Count > 0)
                {
                    title = parents[0].Name;
                }

                IEnumerable <ContentItemEx> items = null;
                try
                {
                    if ((currentID == channel.ID) && (channel is ChannelEx) && ((channel as ChannelEx).LoginInfo != null) && (channel as ChannelEx).LoginInfo.HasCredentials)
                    {
                        items = await ContentClient.LoginAndGetChildren(currentID, (channel as ChannelEx).LoginInfo);
                    }
                    else
                    {
                        if (currentParent.IsFromSearch)
                        {
                            items = await ContentClient.Search(channel.ID, currentID);
                        }
                        else if (currentParent.IsDeepLink)
                        {
                            items = await ContentClient.DeepLink(channel.ID, currentID);
                        }
                        else
                        {
                            items = await ContentClient.GetChildren(currentID);
                        }
                    }
                }
                catch
                {
                }

                if ((items == null) || !items.Any())
                {
                    return(null);
                }

                if (parents.Count == 0)
                {
                    var item = items.FirstOrDefault(i => i.Name == name);
                    if (item != null)
                    {
                        return(item.ID);
                    }
                }
                else
                {
                    var item = items.FirstOrDefault(i => i.Name == title);
                    if (item != null)
                    {
                        currentID = item.ID;
                    }
                    else if (parents[0].IsFromSearch || parents[0].IsDeepLink)
                    {
                        currentID = parents[0].ID;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(null);
        }
        private async Task <IEnumerable <IContentItem> > getItemChildren(IContentItem item, bool silent)
        {
            if (item.IsRoot)
            {
                lastChannelsLoaded = DateTime.Now;
                var result = await ContentClient.GetChannels();

                canRefresh = true;
                if ((result != null) && result.Any())
                {
                    return(result);
                }
                else
                {
                    var isConnected = await RestService.Instance.GetIsConnected();

                    if (!silent && isConnected)
                    {
                        Device.BeginInvokeOnMainThread(() => Application.Current.MainPage.DisplayAlert("Error", "Unable to get channel list. Please make sure you are online, and try again.", "OK"));
                    }

                    return(null);
                }
            }
            else
            {
                if (item.IsChannel)
                {
                    var channel = item as ChannelEx;
                    if (!channel.IsAvailable)
                    {
                        return(null);
                    }

                    if ((channel.LoginInfo != null) && channel.LoginInfo.HasCredentials)
                    {
                        channel.LoginInfo.LoginPerformed = true;
                        var result = await ContentClient.LoginAndGetChildren(item.ID, channel.LoginInfo);

                        if (result == null)
                        {
                            var validation = await SettingsClient.ValidateCredentials(channel.ID, channel.LoginInfo);

                            if ((validation != null) && !validation.Success)
                            {
                                channel.LoginInfo.ValidationSuccessful = false;
                                Device.BeginInvokeOnMainThread(() => AlertViewService.Instance.ShowAlert(validation.Message));
                            }
                        }
                        else
                        {
                            channel.LoginInfo.ValidationSuccessful = true;
                            UserStoreService.Instance.StoreRecordInKeychain(getAccountEmail() + "channel-" + item.ID, JsonConvert.SerializeObject((item as ChannelEx).LoginInfo));
                        }

                        channel.RefreshIsSearchVisible();

                        return(result);
                    }
                    else if (channel.CredentialsType != ChannelCredentialsType.Anonymous)
                    {
                        return(await ContentClient.LoginAndGetChildren(item.ID, new ChannelLoginInfo()));
                    }
                }

                return(await ContentClient.GetChildren(item.ID));
            }
        }