Пример #1
0
        public static void CreateNewTabInFolder(int IDList, TabID FolderIDs, string FileName, Encoding encoding, StorageListTypes type, string content)
        {
            var newtab = new InfosTab
            {
                TabName               = FileName,
                TabStorageMode        = type,
                TabEncoding           = encoding.CodePage,
                TabContentType        = ContentType.File,
                CanBeDeleted          = true,
                CanBeModified         = true,
                TabType               = LanguagesHelper.GetLanguageType(FileName),
                TabInvisibleByDefault = true
            };

            Task.Run(() =>
            {
                int id_tab = Task.Run(async() => { return(await TabsWriteManager.CreateTabAsync(newtab, IDList, false)); }).Result;
                if (Task.Run(async() => { return(await TabsWriteManager.PushTabContentViaIDAsync(new TabID {
                        ID_Tab = id_tab, ID_TabsList = IDList
                    }, content, false)); }).Result)
                {
                    Messenger.Default.Send(new STSNotification {
                        Type = TypeUpdateTab.NewTab, ID = new TabID {
                            ID_Tab = id_tab, ID_TabsList = IDList
                        }
                    });

                    InfosTab Folder = TabsAccessManager.GetTabViaID(FolderIDs);
                    Folder.FolderContent.Add(id_tab);
                    Task.Run(async() => { await TabsWriteManager.PushUpdateTabAsync(Folder, FolderIDs.ID_TabsList, false); });
                }
            });
        }
Пример #2
0
        public static int CreateNewTabReturn(int IDList, string FileName, Encoding encoding, bool encodingbom, StorageListTypes type, string content)
        {
            var newtab = new InfosTab
            {
                TabName                     = FileName,
                TabStorageMode              = type,
                TabEncoding                 = encoding.CodePage,
                TabEncodingWithBOM          = encodingbom,
                TabEncodingReplacingRequest = EncodingReplacingRequest.NotRequested,
                TabContentType              = ContentType.File,
                CanBeDeleted                = true,
                CanBeModified               = true,
                TabType                     = LanguagesHelper.GetLanguageType(FileName),
                TabInvisibleByDefault       = false
            };

            int id_tab = Task.Run(async() => { return(await TabsWriteManager.CreateTabAsync(newtab, IDList, false)); }).Result;

            if (Task.Run(async() => { return(await TabsWriteManager.PushTabContentViaIDAsync(new TabID {
                    ID_Tab = id_tab, ID_TabsList = IDList
                }, content, false)); }).Result)
            {
                Messenger.Default.Send(new STSNotification {
                    Type = TypeUpdateTab.NewTab, ID = new TabID {
                        ID_Tab = id_tab, ID_TabsList = IDList
                    }
                });
                return(id_tab);
            }
            else
            {
                return(0);
            }
        }
Пример #3
0
        public async Task <bool> CreateFile()
        {
            bool result = false;

            await DispatcherHelper.ExecuteOnUIThreadAsync(async() =>
            {
                var folderPicker = new FolderPicker();
                StorageFolder folder;
                folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
                folderPicker.FileTypeFilter.Add("*");

                folder = await folderPicker.PickSingleFolderAsync();
                if (folder != null)
                {
                    StorageFile file = await folder.CreateFileAsync(Tab.TabName, CreationCollisionOption.OpenIfExists);
                    Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
                    Windows.Storage.FileProperties.BasicProperties date = await file.GetBasicPropertiesAsync();

                    Tab.TabDateModified        = date.DateModified.ToString();
                    Tab.TabType                = LanguagesHelper.GetLanguageType(file.FileType);
                    Tab.TabOriginalPathContent = file.Path;

                    await TabsWriteManager.PushUpdateTabAsync(Tab, ListTabsID, true);

                    result = true;
                }
            });

            return(result);
        }
Пример #4
0
        private List <OnedriveExplorerItem> ConvertItemToListTab(Item ListItem)
        {
            List <OnedriveExplorerItem> ListTabs = new List <OnedriveExplorerItem>();

            foreach (var OnedriveItem in ListItem.Children)
            {
                if (OnedriveItem.Folder == null)
                {
                    //FILE
                    if (OnedriveItem.File != null)
                    {
                        if (OnedriveItem.File.MimeType.Contains("text") || OnedriveItem.File.MimeType.Contains("application"))
                        {
                            ListTabs.Add(new OnedriveExplorerItem {
                                IconContent = "",
                                LastModificationDatetime = OnedriveItem.LastModifiedDateTime.Value.ToString(@"MM\/dd\/yyyy HH:mm"),
                                Tab = new InfosTab
                                {
                                    TabName                = OnedriveItem.Name,
                                    TabContentType         = ContentType.File,
                                    TabOriginalPathContent = OnedriveItem.Id,
                                    TabType                = LanguagesHelper.GetLanguageType(OnedriveItem.Name),
                                    TabDateModified        = OnedriveItem.LastModifiedDateTime.ToString(),
                                    DateTabContentUpdated  = OnedriveItem.LastModifiedDateTime.Value
                                }
                            });
                        }
                    }
                }
                else
                {
                    //FOLDER
                    ListTabs.Add(new OnedriveExplorerItem
                    {
                        IconContent = "",
                        LastModificationDatetime = "",
                        Tab = new InfosTab
                        {
                            TabName                = OnedriveItem.Name,
                            TabContentType         = ContentType.Folder,
                            TabOriginalPathContent = OnedriveItem.Id,
                            TabType                = LanguagesHelper.GetLanguageType(OnedriveItem.Name),
                            TabDateModified        = OnedriveItem.LastModifiedDateTime.ToString(),
                            DateTabContentUpdated  = OnedriveItem.LastModifiedDateTime.Value
                        }
                    });
                }
            }

            return(ListTabs);
        }
Пример #5
0
        public async Task <bool> CreateFile()
        {
            bool result = false;

            await DispatcherHelper.ExecuteOnUIThreadAsync(async() =>
            {
                FileSavePicker filePicker         = new FileSavePicker();
                filePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                filePicker.SuggestedFileName      = Path.GetFileNameWithoutExtension(Tab.TabName);

                string Extension = Path.GetExtension(Tab.TabName);
                if (Extension != "")
                {
                    filePicker.FileTypeChoices.Add("File", new List <string> {
                        Extension
                    });
                }

                foreach (string name in LanguagesHelper.GetLanguagesNames())
                {
                    List <string> Types = LanguagesHelper.GetLanguageExtensions(LanguagesHelper.GetLanguageTypeViaName(name));

                    if (Types.Count == 0)
                    {
                        Types.Add(".txt");
                    }

                    filePicker.FileTypeChoices.Add(name, Types);
                }

                StorageFile file = await filePicker.PickSaveFileAsync();
                if (file != null)
                {
                    Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
                    Windows.Storage.FileProperties.BasicProperties date = await file.GetBasicPropertiesAsync();

                    Tab.TabDateModified        = date.DateModified.ToString();
                    Tab.TabType                = LanguagesHelper.GetLanguageType(file.FileType);
                    Tab.TabOriginalPathContent = file.Path;
                    Tab.TabName                = file.Name;

                    await TabsWriteManager.PushUpdateTabAsync(Tab, ListTabsID, true);

                    result = true;
                }
            });

            return(result);
        }
Пример #6
0
        public static async Task <List <int> > OpenFilesAlreadyOpenedAndCreateNewTabsFiles(int IDList, IReadOnlyList <IStorageItem> files)
        {
            var list_ids = new List <int>();

            Messenger.Default.Send(new STSNotification {
                Type = TypeUpdateTab.RefreshCurrentList, ID = new TabID {
                    ID_TabsList = IDList
                }
            });

            foreach (StorageFile file in files)
            {
                await Task.Run(() =>
                {
                    bool FileAlreadyAvailable = false; int IDSelectedFile = 0;

                    if (file != null)
                    {
                        foreach (InfosTab Tab in TabsAccessManager.GetTabsListViaID(IDList).tabs)
                        {
                            if (Tab.TabOriginalPathContent == file.Path)
                            {
                                IDSelectedFile       = Tab.ID;
                                FileAlreadyAvailable = true;
                                break;
                            }
                        }

                        if (!FileAlreadyAvailable)
                        {
                            StorageApplicationPermissions.FutureAccessList.Add(file);

                            var tab = new InfosTab {
                                TabName = file.Name, TabStorageMode = StorageListTypes.LocalStorage, TabContentType = ContentType.File, CanBeDeleted = true, CanBeModified = true, TabOriginalPathContent = file.Path, TabInvisibleByDefault = false, TabType = LanguagesHelper.GetLanguageType(file.Name)
                            };

                            int id_tab = Task.Run(async() => { return(await TabsWriteManager.CreateTabAsync(tab, IDList, false)); }).Result;
                            if (Task.Run(async() => { return(await new StorageRouter(TabsAccessManager.GetTabViaID(new TabID {
                                    ID_Tab = id_tab, ID_TabsList = IDList
                                }), IDList).ReadFile(true)); }).Result)
                            {
                                Messenger.Default.Send(new STSNotification {
                                    Type = TypeUpdateTab.NewTab, ID = new TabID {
                                        ID_Tab = id_tab, ID_TabsList = IDList
                                    }
                                });
                            }

                            list_ids.Add(id_tab);
                        }
                        else
                        {
                            Messenger.Default.Send(new STSNotification {
                                Type = TypeUpdateTab.SelectTab, ID = new TabID {
                                    ID_Tab = IDSelectedFile, ID_TabsList = IDList
                                }
                            });
                        }
                    }
                });
            }

            return(list_ids);
        }
Пример #7
0
        public static async Task <List <int> > OpenFilesAndCreateNewTabsFiles(int IDList, StorageListTypes type)
        {
            var list_ids = new List <int>();

            switch (type)
            {
            case StorageListTypes.LocalStorage:
                var opener = new FileOpenPicker();
                opener.ViewMode = PickerViewMode.Thumbnail;
                opener.SuggestedStartLocation = PickerLocationId.ComputerFolder;
                opener.FileTypeFilter.Add("*");

                IReadOnlyList <StorageFile> files = await opener.PickMultipleFilesAsync();

                foreach (StorageFile file in files)
                {
                    await Task.Run(() =>
                    {
                        if (file != null)
                        {
                            StorageApplicationPermissions.FutureAccessList.Add(file);
                            var tab = new InfosTab {
                                TabName = file.Name, TabStorageMode = type, TabContentType = ContentType.File, CanBeDeleted = true, CanBeModified = true, TabOriginalPathContent = file.Path, TabInvisibleByDefault = false, TabType = LanguagesHelper.GetLanguageType(file.Name)
                            };

                            int id_tab = Task.Run(async() => { return(await TabsWriteManager.CreateTabAsync(tab, IDList, false)); }).Result;
                            if (Task.Run(async() => { return(await new StorageRouter(TabsAccessManager.GetTabViaID(new TabID {
                                    ID_Tab = id_tab, ID_TabsList = IDList
                                }), IDList).ReadFile(true)); }).Result)
                            {
                                Messenger.Default.Send(new STSNotification {
                                    Type = TypeUpdateTab.NewTab, ID = new TabID {
                                        ID_Tab = id_tab, ID_TabsList = IDList
                                    }
                                });
                            }

                            list_ids.Add(id_tab);
                        }
                    });
                }
                break;

            case StorageListTypes.OneDrive:
                var currentAV = ApplicationView.GetForCurrentView(); var newAV = CoreApplication.CreateNewView();

                await newAV.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal,
                    async() =>
                {
                    var newWindow    = Window.Current;
                    var newAppView   = ApplicationView.GetForCurrentView();
                    newAppView.Title = "OneDrive explorer";

                    var frame = new Frame();
                    frame.Navigate(typeof(OnedriveExplorer), new Tuple <OnedriveExplorerMode, TabID>(OnedriveExplorerMode.SelectFile, new TabID {
                        ID_TabsList = IDList
                    }));
                    newWindow.Content = frame;
                    newWindow.Activate();

                    await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
                        newAppView.Id,
                        ViewSizePreference.UseHalf,
                        currentAV.Id,
                        ViewSizePreference.UseHalf);
                });

                break;
            }

            return(list_ids);
        }
Пример #8
0
        private async static Task <int> OpenSubFolder(StorageFolder Folder, int IDList, StorageListTypes type)
        {
            return(await Task.Run(async() =>
            {
                var FolderItemIDs = new List <int>();

                foreach (IStorageItem Item in await Folder.GetItemsAsync())
                {
                    StorageApplicationPermissions.FutureAccessList.Add(Item);

                    if (Item.IsOfType(StorageItemTypes.File))
                    {
                        StorageFile file = (StorageFile)Item;

                        if (file.ContentType.Contains("text") || LanguagesHelper.IsFileLanguageIsCompatible(file.Name))
                        {
                            var tab = new InfosTab {
                                TabName = file.Name, TabStorageMode = type, TabContentType = ContentType.File, CanBeDeleted = true, CanBeModified = true, TabOriginalPathContent = file.Path, TabInvisibleByDefault = true, TabType = LanguagesHelper.GetLanguageType(file.Name)
                            };

                            int id_tab = await TabsWriteManager.CreateTabAsync(tab, IDList, false);

                            await new StorageRouter(TabsAccessManager.GetTabViaID(new TabID {
                                ID_Tab = id_tab, ID_TabsList = IDList
                            }), IDList).ReadFile(true);

                            FolderItemIDs.Add(id_tab);
                        }
                    }
                    else
                    {
                        FolderItemIDs.Add(await OpenSubFolder((StorageFolder)Item, IDList, type));
                    }
                }

                return await TabsWriteManager.CreateTabAsync(new InfosTab {
                    TabName = Folder.Name, TabOriginalPathContent = Folder.Path, TabContentType = ContentType.Folder, FolderContent = FolderItemIDs, FolderOpened = false, TabInvisibleByDefault = true
                }, IDList, false);
            }));
        }
Пример #9
0
        public static async Task <List <int> > OpenFolder(int IDList, StorageListTypes type)
        {
            var list_ids = new List <int>();

            var opener = new FolderPicker();

            opener.ViewMode = PickerViewMode.Thumbnail;
            opener.SuggestedStartLocation = PickerLocationId.ComputerFolder;
            opener.FileTypeFilter.Add("*");

            var Folder = await opener.PickSingleFolderAsync();

            if (Folder != null)
            {
                StorageApplicationPermissions.FutureAccessList.Add(Folder);

                foreach (IStorageItem Item in await Folder.GetItemsAsync())
                {
                    await Task.Run(async() =>
                    {
                        if (Item.IsOfType(StorageItemTypes.File))
                        {
                            StorageFile file = (StorageFile)Item;

                            if (file != null)
                            {
                                StorageApplicationPermissions.FutureAccessList.Add(file);

                                if (file.ContentType.Contains("text") || LanguagesHelper.IsFileLanguageIsCompatible(file.Name))
                                {
                                    var tab = new InfosTab {
                                        TabName = file.Name, TabStorageMode = type, TabContentType = ContentType.File, CanBeDeleted = true, CanBeModified = true, TabOriginalPathContent = file.Path, TabInvisibleByDefault = true, TabType = LanguagesHelper.GetLanguageType(file.Name)
                                    };

                                    int id_tab = Task.Run(async() => { return(await TabsWriteManager.CreateTabAsync(tab, IDList, false)); }).Result;


                                    if (Task.Run(async() => { return(await new StorageRouter(TabsAccessManager.GetTabViaID(new TabID {
                                            ID_Tab = id_tab, ID_TabsList = IDList
                                        }), IDList).ReadFile(true)); }).Result)
                                    {
                                        Messenger.Default.Send(new STSNotification {
                                            Type = TypeUpdateTab.NewTab, ID = new TabID {
                                                ID_Tab = id_tab, ID_TabsList = IDList
                                            }
                                        });
                                    }

                                    list_ids.Add(id_tab);
                                }
                            }
                        }
                        else
                        {
                            StorageFolder FolderItem = (StorageFolder)Item;
                            list_ids.Add(await OpenSubFolder(FolderItem, IDList, type));
                        }
                    });
                }
                await TabsWriteManager.CreateTabAsync(new InfosTab { TabName = Folder.Name, TabOriginalPathContent = Folder.Path, TabContentType = ContentType.Folder, FolderContent = list_ids, FolderOpened = true }, IDList, true);
            }

            return(list_ids);
        }
        public static async Task <List <int> > OpenFilesAndCreateNewTabsFiles(int IDList, StorageListTypes type)
        {
            var list_ids = new List <int>();

            var opener = new FileOpenPicker();

            opener.ViewMode = PickerViewMode.Thumbnail;
            opener.SuggestedStartLocation = PickerLocationId.ComputerFolder;
            opener.FileTypeFilter.Add("*");

            IReadOnlyList <StorageFile> files = await opener.PickMultipleFilesAsync();

            foreach (StorageFile file in files)
            {
                await Task.Run(() =>
                {
                    if (file != null)
                    {
                        StorageApplicationPermissions.FutureAccessList.Add(file);
                        var tab = new InfosTab {
                            TabName = file.Name, TabStorageMode = type, TabContentType = ContentType.File, CanBeDeleted = true, CanBeModified = true, PathContent = file.Path, TabInvisibleByDefault = false, TabType = LanguagesHelper.GetLanguageType(file.Name)
                        };

                        int id_tab = Task.Run(async() => { return(await TabsWriteManager.CreateTabAsync(tab, IDList, false)); }).Result;
                        if (Task.Run(async() => { return(await new StorageRouter(TabsAccessManager.GetTabViaID(new TabID {
                                ID_Tab = id_tab, ID_TabsList = IDList
                            }), IDList).ReadFile(true)); }).Result)
                        {
                            Messenger.Default.Send(new STSNotification {
                                Type = TypeUpdateTab.NewTab, ID = new TabID {
                                    ID_Tab = id_tab, ID_TabsList = IDList
                                }
                            });
                        }

                        list_ids.Add(id_tab);
                    }
                });
            }

            return(list_ids);
        }
Пример #11
0
        private async void Accept_Click(object sender, RoutedEventArgs e)
        {
            OneDriveLoadStart();
            InfosTab RequestedTab = TabsAccessManager.GetTabViaID(TabIDRequest);

            switch (CurrentExplorerMode)
            {
            case OnedriveExplorerMode.CreateFile:
                MemoryStream stream = new MemoryStream();
                var          file   = await TabsDataCache.OneDriveClient.Drive.Items[CurrentTab.TabOriginalPathContent].ItemWithPath(RequestedTab.TabName).Content.Request().PutAsync <Item>(stream);

                RequestedTab.TabOriginalPathContent = file.Id;
                RequestedTab.TabDateModified        = file.LastModifiedDateTime.ToString();
                await TabsWriteManager.PushUpdateTabAsync(RequestedTab, TabIDRequest.ID_TabsList, false);

                break;

            case OnedriveExplorerMode.SelectFile:
                var tab = new InfosTab {
                    TabName = CurrentTab.TabName, TabStorageMode = Storage.StorageListTypes.OneDrive, TabContentType = ContentType.File, CanBeDeleted = true, CanBeModified = true, TabOriginalPathContent = CurrentTab.TabOriginalPathContent, TabInvisibleByDefault = false, TabType = LanguagesHelper.GetLanguageType(CurrentTab.TabName)
                };

                int id_tab = await TabsWriteManager.CreateTabAsync(tab, TabIDRequest.ID_TabsList, false);

                if (await new StorageRouter(TabsAccessManager.GetTabViaID(new TabID {
                    ID_Tab = id_tab, ID_TabsList = TabIDRequest.ID_TabsList
                }), TabIDRequest.ID_TabsList).ReadFile(true))
                {
                    Messenger.Default.Send(new STSNotification {
                        Type = TypeUpdateTab.NewTab, ID = new TabID {
                            ID_Tab = id_tab, ID_TabsList = TabIDRequest.ID_TabsList
                        }
                    });
                }
                break;
            }

            OnedriveLoadFinished();
            try { Window.Current.Close(); } catch { }
        }