public async Task DownloadInitialContent(User user) { try { localFileSystem files = new localFileSystem(); String userPath = files.AdjustPath(user.user_Email); //A newly created User cant have a folder with the same name in the folder so no check must be implemented files.CreateInitalFolders(userPath); DataAccessHandler accessHandler = new DataAccessHandler(); string serverAdress = accessHandler.ServerAdress; IFtpClient client = DependencyService.Get<IFtpClient>(); //Download all Products from the database List<Product> listAllProducts = await DataAccessHandler.DataAccess.GetAllProducts(); List<PContent> newEmptyContent = new List<PContent>(); foreach (var productAll in listAllProducts) { if (productAll.product_ID == 0) break; //Download Thumbnail in Produkte Folder client.DownloadFile(@"Produkte/" + productAll.product_Thumbnail, DependencyService.Get<ISaveAndLoad>().Getpath(@"Produkte/") + productAll.product_Thumbnail, serverAdress, accessHandler.FtpName, accessHandler.FtpPassword); } files.SaveUser(user); files.SaveModelsLocal(userPath, listAllProducts, newEmptyContent); //Hier GetALLProducts ansttt nur user products List<Product> listUserProducts = await DataAccessHandler.DataAccess.GetUserProducts(user); List<PContent> newlistPContents = new List<PContent>(); foreach (var product in listUserProducts) { //loads the PContent from the server List<PContent> listUserPContents = await DataAccessHandler.DataAccess.GetPContent(product.product_ID); if (product.product_ID == 0) break; foreach (var pcontent in listUserPContents) { if (pcontent.content_ID == 0) break; //creates a new p folder if not exists for content_Kind DependencyService.Get<ISaveAndLoad>().CreateFolder(DependencyService.Get<ISaveAndLoad>().PathCombine( DependencyService.Get<ISaveAndLoad>().Getpath(userPath), "p" + pcontent.content_ID)); List<string> contentPath = await DataAccessHandler.DataAccess.GetFileServerPath(pcontent.content_ID); foreach (var path in contentPath) { //loads every content from PContent client.DownloadFile(path, DependencyService.Get<ISaveAndLoad>().Getpath(files.GetUser().user_Email) + @"/p" + pcontent.content_ID + @"/" + Path.GetFileName(path), serverAdress, accessHandler.FtpName, accessHandler.FtpPassword); } while (newlistPContents.Count <= pcontent.content_ID) { newlistPContents.Add(null); } //updates Pcontent newlistPContents[pcontent.content_ID] = pcontent; if (pcontent.content_Kind != 0) { client.DownloadFile(@"Thumbnail/" + pcontent.content_ID + ".png", DependencyService.Get<ISaveAndLoad>().Getpath(files.GetUser().user_Email + @"/Thumbnail/") + pcontent.content_ID + ".png", serverAdress, accessHandler.FtpName, accessHandler.FtpPassword); } } } //Saves User, Products and PContent XML files.SaveUser(user); files.SaveModelsLocal(userPath, listAllProducts, newlistPContents); } catch (Exception e) { Debug.WriteLine("catched DL Exception: " + e); await DisplayAlert("Fehler beim Downloaden", "Es gab einen Fehler beim Downloaden, bitte erneut versuchen", "OK"); } }
/// <summary> /// Konstruktor der MainMenuPage, welcher eine Instanz der Seite erstellt. /// </summary> /// <param name="user"></param> public MainMenuPage(User user) { DataAccessHandler accessHandler = new DataAccessHandler(); string serverAdress = accessHandler.ServerAdress; files = new localFileSystem(); String userPath = files.AdjustPath(user.user_Email); files.CreateInitalFolders(userPath); //Toolbar ToolbarItem toolButton = new ToolbarItem { Name = "Hinzufügen", Order = ToolbarItemOrder.Primary, Icon = null, Command = new Command(() => Navigation.PushAsync(new AddProduktPage())) }; this.ToolbarItems.Add(toolButton); //? //InitLogout(); //Ende Toolbar //View ProductCollection = new Collection<Product>(); ProductCollection = files.LoadProductList(); List<PContent> PcontentCollection = files.loadContentList(userPath); ScrollView scrollView = new ScrollView(); StackLayout stackLayout = new StackLayout(); foreach (Product product in ProductCollection) { TapGestureRecognizer gesture = new TapGestureRecognizer(); bool owned = files.HasContent(product, PcontentCollection); Color color = Color.FromHex("E2001A"); DetailPage detailPage = new DetailPage(product, userPath); var test = (DependencyService.Get<ISaveAndLoad>().PathCombine(DependencyService.Get<ISaveAndLoad>().Getpath(localFileSystem.productFolderLocation), product.product_ID + product.product_Thumbnail)); if (owned == true) color = Color.FromHex("006AB3"); Frame frame = new Frame { BackgroundColor = color, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Content = new StackLayout { Orientation = StackOrientation.Horizontal, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.StartAndExpand, Children = { new Image { Source = ImageSource.FromFile(DependencyService.Get<ISaveAndLoad>().PathCombine(DependencyService.Get<ISaveAndLoad>().Getpath(localFileSystem.productFolderLocation), product.product_Thumbnail)), VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, HeightRequest = 110 }, new Label { FormattedText = product.product_Name, TextColor = Color.Black, VerticalOptions = LayoutOptions.Center, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), HorizontalOptions = LayoutOptions.Center }, }//ende stacklayout (innen) }//ende stacklayout };//frame ende stackLayout.Children.Add(frame); gesture.Tapped += async (sender, e) => { await Navigation.PushAsync(detailPage); }; frame.GestureRecognizers.Add(gesture); } scrollView.Content = stackLayout; Content = scrollView; BackgroundColor = Color.White; Padding = new Thickness(5, Device.OnPlatform(0, 15, 0), 5, 5); //View Ende }