public static List <int> GetTabsID(int id_list)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                var list_ids = new List <int>();

                if (TabsDataCache.TabsListDeserialized != null)
                {
                    if (TabsDataCache.TabsListDeserialized.Where(m => m.ID == id_list).FirstOrDefault().tabs != null)
                    {
                        foreach (InfosTab tab in TabsDataCache.TabsListDeserialized.Where(m => m.ID == id_list).FirstOrDefault().tabs)
                        {
                            if (!tab.TabInvisibleByDefault)
                            {
                                list_ids.Add(tab.ID);
                            }
                        }
                    }

                    return(list_ids);
                }
                else
                {
                    return(list_ids);
                }
            }
            catch
            {
                return(null);
            }
        }
        /// <summary>
        /// Create a new tabs list
        /// </summary>
        /// <param name="new_name">Name of your tabs list</param>
        /// <returns>ID of the new tabs list created</returns>
        public static async Task <int> CreateTabsListAsync(string new_name, int TabsListTypeID = 48)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                int id = new Random().Next(999999);

                TabsDataCache.TabsListDeserialized.Add(new TabsList {
                    ID = id, name = new_name, tabs = new List <InfosTab>(), TabsListProjectTypeID = TabsListTypeID
                });
                TabsDataCache.WriteTabsListContentFile();

                foreach (CoreApplicationView view in CoreApplication.Views)
                {
                    await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Messenger.Default.Send(new STSNotification {
                            Type = TypeUpdateTab.NewList, ID = new TabID {
                                ID_TabsList = id
                            }
                        });
                    });
                }

                return(id);
            }
            catch
            {
                return(0);
            }
        }
        public static List <int> GetTabsListID()
        {
            TabsDataCache.LoadTabsData();

            try
            {
                var list_ids = new List <int>();

                if (TabsDataCache.TabsListDeserialized != null)
                {
                    foreach (TabsList list_tabs in TabsDataCache.TabsListDeserialized)
                    {
                        list_ids.Add(list_tabs.ID);
                    }
                    return(list_ids);
                }
                else
                {
                    return(list_ids);
                }
            }
            catch
            {
                return(null);
            }
        }
        /// <summary>
        /// Delete a tab who was selected by his ID and tabs list ID
        /// </summary>
        /// <param name="ids">ID of the tab and tabs list where is the tab</param>
        /// <returns></returns>
        public static async Task <bool> DeleteTabAsync(TabID ids)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                TabsList list_tabs = TabsDataCache.TabsListDeserialized.First(m => m.ID == ids.ID_TabsList);
                InfosTab tab       = list_tabs.tabs.First(m => m.ID == ids.ID_Tab);
                list_tabs.tabs.Remove(tab);
                StorageFile delete_file = await TabsDataCache.TabsListFolder.CreateFileAsync(ids.ID_TabsList + "_" + ids.ID_Tab + ".json", CreationCollisionOption.ReplaceExisting); await delete_file.DeleteAsync();

                TabsDataCache.WriteTabsListContentFile();

                foreach (CoreApplicationView view in CoreApplication.Views)
                {
                    await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Messenger.Default.Send(new STSNotification {
                            Type = TypeUpdateTab.TabDeleted, ID = new TabID {
                                ID_Tab = ids.ID_Tab, ID_TabsList = ids.ID_TabsList
                            }
                        });
                    });
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #5
0
        /// <summary>
        /// Update tab informations (please use PushTabContentViaIDAsync() for set tab content)
        /// </summary>
        /// <param name="tab">Tab infos you want to update</param>
        /// <param name="id_list">ID of the tabs list where is the tab</param>
        /// <returns></returns>
        public static async Task <bool> PushUpdateTabAsync(InfosTab tab, int id_list, bool UpdateMonacoID)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                TabsList list_tabs = TabsDataCache.TabsListDeserialized.First(m => m.ID == id_list);
                InfosTab _tab = list_tabs.tabs.First(m => m.ID == tab.ID);
                int      index_list = TabsDataCache.TabsListDeserialized.IndexOf(list_tabs), index_tab = list_tabs.tabs.IndexOf(_tab);

                if (UpdateMonacoID)
                {
                    tab.TabMonacoModelID = Guid.NewGuid().ToString();
                }

                TabsDataCache.TabsListDeserialized[index_list].tabs[index_tab] = tab;

                StorageFile data_tab = await TabsDataCache.TabsListFolder.CreateFileAsync(id_list + "_" + tab.ID + ".json", CreationCollisionOption.OpenIfExists);

                if (tab.TabContentTemporary != null)
                {
                    await FileIO.WriteTextAsync(data_tab, JsonConvert.SerializeObject(new ContentTab {
                        ID = tab.ID, Content = tab.TabContentTemporary
                    }, Formatting.Indented));
                }

                TabsDataCache.WriteTabsListContentFile();

                foreach (CoreApplicationView view in CoreApplication.Views)
                {
                    await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Messenger.Default.Send(new STSNotification {
                            Type = TypeUpdateTab.TabUpdated, ID = new TabID {
                                ID_Tab = tab.ID, ID_TabsList = id_list
                            }
                        });
                    });
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #6
0
        /// <summary>
        /// Create a tab in a tabs list who was selected by his ID
        /// </summary>
        /// <param name="tab">Tab you want to create</param>
        /// <param name="id_list">ID of the tabs list</param>
        /// <returns>ID of the new tab</returns>
        public static async Task <int> CreateTabAsync(InfosTab tab, int id_list, bool SendNotification)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                tab.ID = new Random().Next(999999);
                tab.TabMonacoModelID = Guid.NewGuid().ToString();
                TabsList list_tabs = TabsDataCache.TabsListDeserialized.First(m => m.ID == id_list);

                if (list_tabs.tabs == null)
                {
                    list_tabs.tabs = new List <InfosTab>();
                }

                list_tabs.tabs.Add(tab);
                StorageFile data_tab = await TabsDataCache.TabsListFolder.CreateFileAsync(id_list + "_" + tab.ID + ".json", CreationCollisionOption.ReplaceExisting);

                await FileIO.WriteTextAsync(data_tab, JsonConvert.SerializeObject(new ContentTab {
                    ID = tab.ID, Content = ""
                }, Formatting.Indented));

                TabsDataCache.WriteTabsListContentFile();

                foreach (CoreApplicationView view in CoreApplication.Views)
                {
                    await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        if (SendNotification)
                        {
                            Messenger.Default.Send(new STSNotification {
                                Type = TypeUpdateTab.NewTab, ID = new TabID {
                                    ID_Tab = tab.ID, ID_TabsList = id_list
                                }
                            });
                        }
                    });
                }
                return(tab.ID);
            }
            catch
            {
                return(0);
            }
        }
        public static void UpdateTabRef(ref InfosTab tab, int id_list)
        {
            TabsDataCache.LoadTabsData();

            using (var reader = new StreamReader(Task.Run(async() => { return(await TabsDataCache.TabsListFile.OpenStreamForReadAsync()); }).Result))
            {
                try
                {
                    int     id         = tab.ID;
                    JObject tabs       = JObject.Parse(reader.ReadToEnd()).Values <JObject>().Where(m => m["ID"].Value <int>() == id_list).FirstOrDefault(),
                            tab_search = tabs.Values <JObject>().Where(m => m["ID"].Value <int>() == id).FirstOrDefault();

                    if (tab != null)
                    {
                        tab = tab_search.Value <InfosTab>();
                    }
                }
                catch { }
            }
        }
        public static List <InfosTab> GetTabs(int id)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                if (TabsDataCache.TabsListDeserialized != null)
                {
                    return(TabsDataCache.TabsListDeserialized.Where(m => m.ID == id).FirstOrDefault().tabs.Where(n => n.TabInvisibleByDefault == false).ToList());
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
        /// <summary>
        /// Push code content in a tab
        /// </summary>
        /// <param name="id">ID of the tab and tabs list where is the tab</param>
        /// <param name="content">Content you want to push in the tab</param>
        /// <param name="sendnotification">Send (or not) a notification about the updated content with MVVMLight</param>
        /// <returns></returns>
        public static async Task <bool> PushTabContentViaIDAsync(TabID id, string content, bool sendnotification)
        {
            try
            {
                TabsDataCache.LoadTabsData();
                StorageFile file_content = await TabsDataCache.TabsListFolder.CreateFileAsync(id.ID_TabsList + "_" + id.ID_Tab + ".json", CreationCollisionOption.OpenIfExists);

                using (var reader = new StreamReader(await file_content.OpenStreamForReadAsync()))
                    using (JsonReader JsonReader = new JsonTextReader(reader))
                    {
                        try
                        {
                            ContentTab _content = new JsonSerializer().Deserialize <ContentTab>(JsonReader);

                            if (content != null)
                            {
                                _content.Content = content;
                                await FileIO.WriteTextAsync(file_content, JsonConvert.SerializeObject(_content, Formatting.Indented));

                                if (sendnotification)
                                {
                                    foreach (CoreApplicationView view in CoreApplication.Views)
                                    {
                                        await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                        {
                                            Messenger.Default.Send(new STSNotification {
                                                Type = TypeUpdateTab.TabUpdated, ID = id
                                            });
                                        });
                                    }
                                }

                                return(true);
                            }
                        }
                        catch { }
                    }
            }
            catch { }
            return(false);
        }
예제 #10
0
        /// <summary>
        /// Push code content in a tab
        /// </summary>
        /// <param name="id">ID of the tab and tabs list where is the tab</param>
        /// <param name="content">Content you want to push in the tab</param>
        /// <param name="sendnotification">Send (or not) a notification about the updated content with MVVMLight</param>
        /// <returns></returns>
        public static async Task <bool> PushTabContentViaIDAsync(TabID id, string content, bool sendnotification)
        {
            try
            {
                TabsDataCache.LoadTabsData();
                StorageFile file_content = await TabsDataCache.TabsListFolder.CreateFileAsync(id.ID_TabsList + "_" + id.ID_Tab + ".json", CreationCollisionOption.OpenIfExists);

                try
                {
                    if (content != null)
                    {
                        string ContentToBeWritenn = JsonConvert.SerializeObject(new ContentTab {
                            ID = id.ID_Tab, Content = content
                        }, Formatting.Indented);
                        using (var writer = new StreamWriter(await file_content.OpenStreamForWriteAsync()))
                        {
                            writer.Write(ContentToBeWritenn);
                        }

                        if (sendnotification)
                        {
                            foreach (CoreApplicationView view in CoreApplication.Views)
                            {
                                await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                {
                                    Messenger.Default.Send(new STSNotification {
                                        Type = TypeUpdateTab.TabUpdated, ID = id
                                    });
                                });
                            }
                        }

                        return(true);
                    }
                }
                catch { }
            }
            catch { }
            return(false);
        }
예제 #11
0
        /// <summary>
        /// Delete tabs list and the tabs content of the list
        /// </summary>
        /// <param name="id">ID of the tabs list</param>
        /// <returns></returns>
        public static async Task <bool> DeleteTabsListAsync(int id)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                TabsList list_tabs = TabsDataCache.TabsListDeserialized.First(m => m.ID == id);

                foreach (InfosTab tab in list_tabs.tabs)
                {
                    try
                    {
                        await TabsDataCache.TabsListFolder.GetFileAsync(id + "_" + tab.ID + ".json").GetResults().DeleteAsync();
                    }
                    catch { }
                }

                TabsDataCache.TabsListDeserialized.Remove(list_tabs);
                TabsDataCache.WriteTabsListContentFile();

                foreach (CoreApplicationView view in CoreApplication.Views)
                {
                    await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Messenger.Default.Send(new STSNotification {
                            Type = TypeUpdateTab.ListDeleted, ID = new TabID {
                                ID_TabsList = id
                            }
                        });
                    });
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public static InfosTab GetTabViaID(TabID id)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                if (TabsDataCache.TabsListDeserialized != null)
                {
                    List <InfosTab> InfosTabList = TabsDataCache.TabsListDeserialized.Where(m => m.ID == id.ID_TabsList).FirstOrDefault().tabs;

                    if (InfosTabList != null)
                    {
                        return(InfosTabList.Where(m => m.ID == id.ID_Tab).FirstOrDefault());
                    }
                }
            }
            catch
            {
                return(null);
            }

            return(null);
        }
        public static TabsList GetTabsListViaID(int id)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                if (TabsDataCache.TabsListDeserialized != null)
                {
                    TabsList List = TabsDataCache.TabsListDeserialized.Where(m => m.ID == id).FirstOrDefault();

                    if (List.tabs != null)
                    {
                        return(List);
                    }
                }
            }
            catch
            {
                return(null);
            }

            return(null);
        }