Esempio n. 1
0
        public async void AddProductToUser(int productId, User user)
        {
            try
            {
                var client = new RestClient("http://" + _serverAdress);
                var request = new RestRequest("AddProductToUser.php", Method.POST);
                request.AddParameter("user_Email", user.user_Email);
                request.AddParameter("product_ID", productId);

                request.Timeout = 5000;
                IRestResponse response = await client.ExecutePostTaskAsync(request);
                if (response.ErrorException != null)
                {
                    throw response.ErrorException;
                }
            }
            catch (Exception e)
            {
                new Exception("Fehler aufgetreten: " + e);
            }

        }
Esempio n. 2
0
        public async Task<User> ValidateUser(User user)
        {
            try
            {
                var client = new RestClient("http://" + _serverAdress);
                var request = new RestRequest("getUser.php", Method.GET);
                request.AddParameter("user_Email", user.user_Email);

                request.Timeout = 5000;
                IRestResponse response = await client.ExecuteGetTaskAsync(request);
                if (response.ErrorException != null)
                {
                    throw response.ErrorException;
                }

                if (response.Content == "0 results")
                    return null;
                var model = Newtonsoft.Json.JsonConvert.DeserializeObject<User>(response.Content);
                //Checks if the JSON String has a user and if so, then checks for valid password 
                return user.user_Password.Equals(model.user_Password) ? model : null;
            }
            catch (Exception e)
            {
                throw new Exception("Fehler aufgetreten: " + e);
            }
        }
Esempio n. 3
0
        public async Task<List<Product>> GetUserProducts(User user)
        {
            try
            {
                var client = new RestClient("http://" + _serverAdress);
                var request = new RestRequest("getUserProducts.php", Method.GET);
                request.AddParameter("user_Email", user.user_Email);

                request.Timeout = 5000;
                IRestResponse response = await client.ExecuteGetTaskAsync(request);
                if (response.ErrorException != null)
                {
                    throw response.ErrorException;
                }
                if (response.Content.Equals("0 results"))
                {
                    return new List<Product>();
                }
                var model = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Product>>(response.Content);

                //creates a new List<Product> and adds a List<int> of Content_Kind
                var model2 = new List<Product>();
                foreach (var product in model)
                {
                    //inserts for each Product of List<Product>
                    var request2 = new RestRequest("getProductContentID.php", Method.GET);
                    request2.AddParameter("product_ID", product.product_ID);

                    request.Timeout = 1000;
                    IRestResponse response2 = await client.ExecuteGetTaskAsync(request2);
                    if (response.ErrorException != null)
                    {
                        throw response.ErrorException;
                    }
                    //Adds a List<int> of content_Kind to each Product
                    List<int> productList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<int>>(response2.Content).Distinct().ToList(); //Distinct entfernt duplicate
                    Product product2 = product;
                    product2.PContents = productList;
                    model2.Add(product2);
                }
                return model2;
            }
            catch (Exception e)
            {
                throw new Exception("Fehler aufgetreten: " + e);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Checks if loginData.xml exists and delete it if so. Definitaly creates a new loginData.xml file
 /// </summary>
 /// <param name="user"></param>
 public async void RememberLogin(User user)
 {
     await Task.Run(() =>
     {
         localFileSystem file = new localFileSystem();
         file.SaveUser(user);
         //string userLoginDataFilePath = UserLoginDataFilePath();
         //ISaveAndLoad saveAndLoad = DependencyService.Get<ISaveAndLoad>();
         //if(saveAndLoad.fileExist(userLoginDataFilePath))
         //    saveAndLoad.deleteFile(userLoginDataFilePath);
         //saveAndLoad.saveUserXml(userLoginDataFilePath, user);
     });
 }
Esempio n. 5
0
 /// <summary>
 /// Set current user with user parameter and saves the login in loginData.xml
 /// </summary>
 /// <param name="user"></param>
 public void Login(User user)
 {
     localFileSystem file = new localFileSystem();
     file.SaveUser(user);
     RememberLogin(user);
 }
Esempio n. 6
0
 /// <summary>
 /// saves the User as User-File-XML
 /// </summary>
 /// <param name="inputUser"></param>
 /// <returns></returns>
 public void SaveUser(User inputUser)
 {
     DependencyService.Get<ISaveAndLoad>().SaveUserXml(userLocation, inputUser);
 }
Esempio n. 7
0
        /// <summary>
        /// Checks: if Account is already in the database, if inserted String is a valid Email format, if entry password1 is equal entry password2. Adds then the User to the Database with hashed Password and continous to the MainPage().
        /// </summary>
        public CreateAccountPage()
        {
            var button = new Button { Text = "Account erstellen", BackgroundColor = Color.FromHex("E2001A") };
            button.Clicked += async (sender, e) =>
            {
                //Checks if the User is already in the database 
                if (await IsDuplicatedUserAsync(username.Text))
                {
                    if (_exception)
                        await DisplayAlert("Verbindungsfehler", "Server ist nicht erreichtbar. Internetzugang aktiv?", "OK");
                    else
                        await DisplayAlert("Account bereits vorhanden!", "Anderen account angeben", "OK");
                }
                //Checks if the User is in a Valid Email Format
                else if (!LoginPage.IsValidEmail(username.Text))
                {
                    await DisplayAlert("Ungültige E-Mail", "E-Mail ist in einem ungültigen Format angegeben worden", "Neue Eingabe");
                }
                // Checks if password1 equals password2
                else if (!(password1.Text.Equals(password2.Text)))
                {
                    await DisplayAlert("Passwort wiederholen!", "Passwörter sind nicht identisch", "OK");
                }
                // Adds the user to the database with hashed password
                else
                {
                    AddUser(username.Text, password1.Text);
                    if (_exception)
                        await DisplayAlert("Verbindungsfehler", "Server ist nicht erreichtbar. Internetzugang aktiv?", "OK");
                    else
                    {
                        User user = new User(username.Text, password1.Text);
                        await DisplayAlert("Account erstellt!", "Neuer Account wurde erstellt", "OK");
                        await DownloadInitialContent(user);
                        await Navigation.PushModalAsync(new NavigationPage(new MainMenuPage(user)));
                    }
                }
            };
            var cancel = new Button { Text = "Zurück", BackgroundColor = Color.FromHex("006AB3") };
            cancel.Clicked += (sender, e) =>
            {
                MessagingCenter.Send<ContentPage>(this, "Login");
            };

            username = new Entry { Text = "" };
            password1 = new Entry { Text = "", IsPassword = true };
            password2 = new Entry { Text = "", IsPassword = true };

            Content = new StackLayout
            {
                Padding = new Thickness(10, 40, 10, 10),
                Children = {
                    new Label { Text = "Account erstellen", Font = Font.SystemFontOfSize(NamedSize.Large) },
                    new Label { Text = "Gib deine E-Mail Addresse an" },
                    username,
                    new Label { Text = "Passwort" },
                    password1,
                    new Label { Text = "Passwort wiederholen" },
                    password2,
                    button, cancel
                }
            };
        }
Esempio n. 8
0
        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");
            }
        }
Esempio n. 9
0
        /// <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
        }
Esempio n. 10
0
 /// <summary>
 /// Checks if the user is already in the Database with the ValidateUser REST API
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public async Task<User> IsValidLogin(User user)
 {
     //decommend to avoid login input for testing purposes
     //return user;
     try
     {
         return await DataAccessHandler.DataAccess.ValidateUser(user);
     }
     catch (Exception e)
     {
         Debug.WriteLine("Exception e: " + e);
         _exception = true;
         return null;
     }
 }