コード例 #1
0
        /// <summary>
        /// Update the explorer listview met items that resides in the parent folder.
        /// </summary>
        private void ToParentFolder()
        {
            if (SelectedDriveFolder is null)
            {
                return;
            }

            if (ParentItem is null)
            {
                return;
            }

            string id = ParentItem.ParentItemId;
            List <CachedDriveItem> ParentItemList = App.Current.CacheHelper.GetDriveOrItemsWithParentId(SelectedDriveFolder, id);

            // Update both the UI and the cached items with the new list.
            ExplorerItemsList         = ParentItemList;
            App.Current.MediaItemList = ParentItemList;

            if (App.Current.CacheHelper.IsParentChildOfDrive(SelectedDriveFolder, id))
            {
                ParentItem = null;
            }
            else
            {
                // Every time we go up a folder, we need to set the ParentItem to one higher
                ParentItem = App.Current.CacheHelper.GetParentItemByParentItemId(SelectedDriveFolder, ParentItem.ParentItemId);
            }
        }
コード例 #2
0
        /// <summary>
        /// Retrieves the children that are inside an item and fills the the Childrenlist property with those items.
        /// </summary>
        /// <param name="obj"></param>
        public async void GetChildrenFomItem()
        {
            //Prevents exception when user clicks an empty space in the ListBox.
            if (SelectedExplorerItem is null)
            {
                return;
            }

            if (SelectedDriveFolder is null)
            {
                return;
            }

            //Checks if the SelectedExplorerItem is an folder.
            if (SelectedExplorerItem.IsFolder)
            {
                //Sets the current selected item as a parent item.
                ParentItem = SelectedExplorerItem;

                string ItemId = SelectedExplorerItem.ItemId;

                List <CachedDriveItem> driveItems = await App.Current.CacheHelper.GetCachedChildrenFromItem(SelectedDriveFolder, ItemId);

                Debug.WriteLine(" + Loaded folder.");

                // Update both the UI and the cached items with the new list.
                ExplorerItemsList         = driveItems;
                App.Current.MediaItemList = driveItems;
            }
            else
            {
                OpenItemWithVideoPlayer(SelectedExplorerItem);
            }
            Debug.WriteLine(" + Loaded children from folder item.");
        }
コード例 #3
0
        /// <summary>
        /// Opens the selected item with the videoplayer.
        /// </summary>
        private void OpenItemWithVideoPlayer(CachedDriveItem SelectedExplorerItem)
        {
            MediaWrapper MediaWrapper = new MediaWrapper(SelectedExplorerItem, SelectedDriveId);

            // Navigate to the VideoPlayerPage
            NavigationService.Navigate <VideoPlayerPage>(MediaWrapper);
        }
コード例 #4
0
        /// <summary>
        /// Retrieves the children that are inside the drive and fills the the Childrenlist property with those items.
        /// </summary>
        /// <param name="obj"></param>
        public async void GetChildrenFomDrive()
        {
            ParentItem = null;

            //Prevents exception when user clicks an empty space in the ListBox.
            if (SelectedDriveFolder is null)
            {
                return;
            }
            ;

            //Sets the SelectedDriveId field with the driveid of the selected drive.
            SelectedDriveId = SelectedDriveFolder.DriveId;

            //Sets the item id of the selectedItem variable.
            string itemId = SelectedDriveFolder.Id;

            List <CachedDriveItem> driveItems = await App.Current.CacheHelper.GetCachedChildrenFromDrive(SelectedDriveId, itemId);

            if (driveItems is null)
            {
                // Show dialog and return
                //MessageBox.Show("An error has occured while entering this shared folder. Please try again later.");
                return;
            }
            Debug.WriteLine(" + Loaded children from selected Drive.");

            // Update both the UI and the cached items with the new list.
            ExplorerItemsList         = driveItems;
            App.Current.MediaItemList = driveItems;
        }
コード例 #5
0
        /// <summary>
        /// Convert a GraphItem retreived from the MS Graph API to a CachedDriveItem. This means filtering out
        /// items which are not folder or file with the correct mimetype.
        /// </summary>
        /// <param name="GraphItem">The MS Graph item to convert</param>
        /// <returns>A CachedDriveItem in case the item is a correct file or a folder, null otherwise.</returns>
        public CachedDriveItem ConvertGraphItem(DriveItem GraphItem)
        {
            // Check if the item to convert is either a folder or file.
            if (GraphItem.Folder is null && GraphItem.File is null)
            {
                return(null);
            }

            //TODO: Remove the mkv extension workaround when Graph is fixed or a better solution is implemented.
            // Check that files have the correct mimetype (either contains audio or video).
            if (GraphItem.File != null && !(GraphItem.File.MimeType.Contains("video") || GraphItem.File.MimeType.Contains("audio") || Path.GetExtension(GraphItem.Name).Equals(".mkv")))
            {
                return(null);
            }

            CachedDriveItem ConvertedItem = new CachedDriveItem
            {
                ItemId   = GraphItem.Id,
                IsFolder = GraphItem.Folder != null,
                Name     = GraphItem.Name,
                Size     = GraphItem.Size ?? 0
            };

            if (ConvertedItem.IsFolder)
            {
                ConvertedItem.ChildCount = GraphItem.Folder.ChildCount;
            }
            else
            {
                // GraphItem.File won't be null since we checked that beforehand
                ConvertedItem.MimeType = GraphItem.File.MimeType;
            }
            return(ConvertedItem);
        }
コード例 #6
0
        /// <summary>
        /// Converts objects on runtime.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            //Changes the ItemContentType icon of the items in the explorer.
            if (parameter.Equals("ContentTypeExplorerItem"))
            {
                if ((bool)value)
                {
                    return("/Assets/Icons/folder.png");
                }
                else
                {
                    return("/Assets/Icons/MultiMediaIcon.png");
                }
            }

            //Returns the item child when it's a folder. Otherwise return a line.
            if (parameter.Equals("ContentChildCountExplorer"))
            {
                CachedDriveItem item = (CachedDriveItem)value;
                if (item.IsFolder)
                {
                    return(item.ChildCount);
                }
                return("-");
            }

            //Returns the correct size format.
            if (parameter.Equals("ContentItemSizeExplorer"))
            {
                Console.WriteLine(value);
                long size = (long)value;
                if (size > 1000 && size < 1000000000)
                {
                    return(Math.Round((size / (double)Math.Pow(1024, 2))) + " MB");
                }
                else if (size > 1000000000)
                {
                    return(Decimal.Round((Decimal)(size / (double)Math.Pow(1024, 3)), 2) + " GB");
                }
                else
                {
                    return(size + " Bytes");
                }
            }
            return(null);
        }
コード例 #7
0
 public CachedDriveItem GetParentItemByParentItemId(CachedDrive SelectedDriveFolder, string ParentId)
 {
     lock (CacheLock)
     {
         try
         {
             // Get the current drive from the cache
             CachedDrive     CurrentDrive = CurrentUserCache.Drives.First((currentDrive) => currentDrive.DriveId.Equals(SelectedDriveFolder.DriveId) && currentDrive.Id.Equals(SelectedDriveFolder.Id));
             CachedDriveItem Parent       = CurrentDrive.ItemList.First((currentItem) => currentItem.ItemId.Equals(ParentId));
             return(Parent);
         }
         catch (InvalidOperationException)
         {
             // This should not happen.
             return(null);
         }
     }
 }
コード例 #8
0
        public async Task <List <CachedDriveItem> > GetItemChildrenFromGraph(string DriveId, string ItemId)
        {
            List <DriveItem> ItemsFromGraph = (await Graph.GetChildrenOfItemAsync(DriveId, ItemId)).ToList();

            List <CachedDriveItem> ChildrenFromItem = new List <CachedDriveItem>();

            ItemsFromGraph.ForEach((graphItem) =>
            {
                CachedDriveItem ConvertedItem = this.ConvertGraphItem(graphItem);
                if (ConvertedItem != null)
                {
                    ConvertedItem.ParentItemId = graphItem.ParentReference.Id;
                    ChildrenFromItem.Add(ConvertedItem);
                }
            });

            return(ChildrenFromItem);
        }
コード例 #9
0
        public async Task <List <CachedDriveItem> > GetDriveChildrenFromGraph(string SelectedDriveId, string ItemId)
        {
            List <DriveItem> ItemsFromGraph = (await Graph.GetChildrenOfItemAsync(SelectedDriveId, ItemId)).ToList();
            // Convert Graph DriveItems to CachedDriveItems
            List <CachedDriveItem> DriveChildren = new List <CachedDriveItem>();

            ItemsFromGraph.ForEach((graphDriveItem) =>
            {
                CachedDriveItem ConvertedItem = this.ConvertGraphItem(graphDriveItem);
                if (ConvertedItem != null)
                {
                    ConvertedItem.ParentItemId = ItemId;
                    DriveChildren.Add(ConvertedItem);
                }
            });

            return(DriveChildren);
        }
コード例 #10
0
 public MediaWrapper(CachedDriveItem cachedDriveItem, string driveId)
 {
     DriveId         = driveId;
     CachedDriveItem = cachedDriveItem;
 }