Ejemplo n.º 1
0
        public async Task WriteFile()
        {
            await DispatcherHelper.ExecuteOnUIThreadAsync(async() =>
            {
                if (string.IsNullOrWhiteSpace(Tab.TabOriginalPathContent))
                {
                    await CreateFile().ContinueWith((e) =>
                    {
                        //await WriteFile();
                    });
                }
                else
                {
                    try
                    {
                        await OneDriveAuthHelper.OneDriveAuthentification();

                        MemoryStream stream = new MemoryStream();
                        StreamWriter writer = new StreamWriter(stream, Encoding.GetEncoding(Tab.TabEncoding));
                        writer.Write(await TabsAccessManager.GetTabContentViaIDAsync(new TabID {
                            ID_Tab = Tab.ID, ID_TabsList = ListTabsID
                        }));
                        writer.Flush();
                        stream.Position = 0;

                        var item = await TabsDataCache.OneDriveClient.Drive.Items[Tab.TabOriginalPathContent].Content.Request().PutAsync <Item>(stream);
                    }
                    catch
                    {
                        await new MessageDialog("Please verify your internet connection or verify if the file still exist in your OneDrive or if you have enough stockage for saving the file.", "OneDrive error").ShowAsync();
                    }
                }
            });
        }
Ejemplo n.º 2
0
        public async void DeleteFile()
        {
            try
            {
                await OneDriveAuthHelper.OneDriveAuthentification();

                await TabsDataCache.OneDriveClient.Drive.Items[Tab.TabOriginalPathContent].Request().DeleteAsync();
                Tab.TabStorageMode         = StorageListTypes.Nothing;
                Tab.TabOriginalPathContent = "";
                await TabsWriteManager.PushUpdateTabAsync(Tab, ListTabsID, false);
            }
            catch { }
        }
Ejemplo n.º 3
0
        public async Task <string> ReadFileAndGetContent()
        {
            await OneDriveAuthHelper.OneDriveAuthentification();

            var    Item = await TabsDataCache.OneDriveClient.Drive.Items[Tab.TabOriginalPathContent].Content.Request().GetAsync();
            string Code = "";

            using (StreamReader st = new StreamReader(Item))
            {
                await TabsWriteManager.PushTabContentViaIDAsync(new TabID { ID_Tab = Tab.ID, ID_TabsList = ListTabsID }, st.ReadToEnd(), true);

                Code = st.ReadToEnd();
                st.Dispose();
            }

            return(Code);
        }
Ejemplo n.º 4
0
        private async void Tabs_Loaded(object sender, RoutedEventArgs e)
        {
            if (await OneDriveAuthHelper.OneDriveAuthentification())
            {
                if (OneDriveNavigationHistory.Count == 0)
                {
                    OneDriveLoadStart();
                    Tabs.Items.Clear(); var root = await OneDriveGetRootFolder();

                    OneDriveNavigationHistory.Add(new Tuple <string, string>(root.Item1, root.Item2));
                    foreach (var item in root.Item3)
                    {
                        Tabs.Items.Add(item);
                    }
                    OnedriveLoadFinished();
                }
            }
        }
Ejemplo n.º 5
0
        public async Task <bool> ReadFile(bool ReplaceEncoding)
        {
            await OneDriveAuthHelper.OneDriveAuthentification();

            var Item = await TabsDataCache.OneDriveClient.Drive.Items[Tab.TabOriginalPathContent].Content.Request().GetAsync();

            using (StreamReader st = new StreamReader(Item))
            {
                await TabsWriteManager.PushTabContentViaIDAsync(new TabID { ID_Tab = Tab.ID, ID_TabsList = ListTabsID }, st.ReadToEnd(), true);

                if (ReplaceEncoding)
                {
                    Tab.TabEncoding = st.CurrentEncoding.CodePage;
                    await TabsWriteManager.PushUpdateTabAsync(Tab, ListTabsID, true);
                }

                st.Dispose();
            }

            return(true);
        }
Ejemplo n.º 6
0
        private async void More_Tab_Click(object sender, RoutedEventArgs e)
        {
            if (infos_opened)
            {
                RemoveInfos.Begin(); infos_opened = false;

                if (current_tab.TabContentType == ContentType.Folder)
                {
                    current_tab.FolderOpened = false;
                    await TabsWriteManager.PushUpdateTabAsync(current_tab, current_list, false);
                }
            }
            else
            {
                enable_selection = false;

                switch (current_tab.TabContentType)
                {
                case ContentType.File:
                    try
                    {
                        list_types.SelectedItem = LanguagesHelper.GetLanguageNameViaType(current_tab.TabType);

                        bool ItemFound = false; int EncodingCodepage = Encoding.GetEncoding(current_tab.TabEncoding).CodePage;
                        for (int i = 0; i < (list_encodings.Items.Count - 1); i++)
                        {
                            if (((EncodingType)list_encodings.Items[i]).EncodingCodepage == EncodingCodepage && ((EncodingType)list_encodings.Items[i]).EncodingBOM == current_tab.TabEncodingWithBOM)
                            {
                                list_encodings.SelectedIndex = i;
                                ItemFound = true;
                                break;
                            }
                        }

                        if (!ItemFound)
                        {
                            list_encodings.Items.Insert(0, new EncodingType {
                                EncodingName = Encoding.GetEncoding(current_tab.TabEncoding).EncodingName, EncodingCodepage = Encoding.GetEncoding(current_tab.TabEncoding).CodePage
                            });
                            list_encodings.SelectedIndex = 0;
                        }

                        switch (current_tab.TabStorageMode)
                        {
                        case StorageListTypes.LocalStorage:
                            StorageFile file = await StorageFile.GetFileFromPathAsync(current_tab.TabOriginalPathContent);

                            BasicProperties properties = await file.GetBasicPropertiesAsync();

                            if (properties.Size != 0)
                            {
                                if (properties.Size > 1024f)         //Ko
                                {
                                    size_file.Text = string.Format("{0:0.00}", (properties.Size / 1024f)) + " Ko";

                                    if ((properties.Size / 1024f) > 1024f)         //Mo
                                    {
                                        size_file.Text = string.Format("{0:0.00}", ((properties.Size / 1024f) / 1024f)) + " Mo";
                                    }
                                }
                                else         //Octect
                                {
                                    size_file.Text = properties.Size + " Octect(s)";
                                }
                            }

                            modified_file.Text = properties.DateModified.ToString();
                            created_file.Text  = file.DateCreated.ToString();
                            break;

                        case StorageListTypes.OneDrive:
                            if (await OneDriveAuthHelper.OneDriveAuthentification())
                            {
                                var Item = await TabsDataCache.OneDriveClient.Drive.Items[current_tab.TabOriginalPathContent].Request().GetAsync();

                                if (Item.Size != 0)
                                {
                                    if (Item.Size > 1024f)         //Ko
                                    {
                                        size_file.Text = string.Format("{0:0.00}", (Item.Size / 1024f)) + " Ko";

                                        if ((Item.Size / 1024f) > 1024f)         //Mo
                                        {
                                            size_file.Text = string.Format("{0:0.00}", ((Item.Size / 1024f) / 1024f)) + " Mo";
                                        }
                                    }
                                    else         //Octect
                                    {
                                        size_file.Text = Item.Size + " Octect(s)";
                                    }
                                }

                                modified_file.Text = Item.LastModifiedDateTime.ToString();
                                created_file.Text  = Item.CreatedDateTime.ToString();

                                //path_tab.Text = System.Net.WebUtility.HtmlDecode(Item.ParentReference.Path);
                            }
                            break;
                        }
                    }
                    catch { }

                    break;

                case ContentType.Folder:
                    current_tab.FolderOpened = true;
                    await TabsWriteManager.PushUpdateTabAsync(current_tab, current_list, false);

                    break;
                }

                ShowInfos.Begin(); infos_opened = true; enable_selection = true;
            }
        }