public void DeleteModels(List <LocalModel> models)
        {
            ModelSaberOnlineUserControl onlineUserControl = PropertyHelper.GetPropValue <ModelSaberOnlineUserControl>(MainWindow.ViewModel, $"{ModelType}OnlineUserControl");
            List <OnlineModel>          onlineModels      = new List <OnlineModel>();

            foreach (LocalModel model in models)
            {
                LocalModels.Models.Remove(model);
                App.ModelSaberApi.DeleteModel(model);

                OnlineModel onlineModel = onlineUserControl.ViewModel.OnlineModels?.Models.FirstOrDefault(x => x.Id == model.Id || x.Name == model.Name && model.Id == -1);

                if (onlineModel != null)
                {
                    onlineModels.Add(onlineModel);
                }
            }

            if (onlineModels.Count == models.Count)
            {
                onlineModels.ForEach(x => x.IsDownloaded = false);
            }
            else
            {
                ModelChanged = true;
            }

            LocalModels = App.ModelSaberApi.RefreshLocalPages(LocalModels);
        }
        private void ModelSaberApi_DownloadCompleted(object sender, DownloadCompletedEventArgs e)
        {
            if (OnlineModels is null || e.Model.ModelType != ModelType)
            {
                return;
            }

            if (!OnlineModels.Models.Contains(e.Model))
            {
                OnlineModel onlineModel = OnlineModels.Models.FirstOrDefault(x => x.Id == e.Model.Id);
                if (onlineModel != null)
                {
                    onlineModel.IsDownloading = e.Model.IsDownloading;
                    onlineModel.IsDownloaded  = e.Model.IsDownloaded;
                }
            }

            if (!OnlineModels.Models.Any(x => x.IsDownloading) && !App.ModelSaberApi.Downloading.Any())
            {
                MainWindow.radioButtonSettings.IsEnabled = true;
            }

            ModelChanged = true;
            UpdatePageButtons();
        }
        public void ModelDetails(OnlineModel model, bool changePage = true)
        {
            MainWindow.ViewModel.ModelSaberOnlineDetailsUserControl.ViewModel.Model = model;
            if (changePage)
            {
                MainWindow.userControlMain.Content = MainWindow.ViewModel.ModelSaberOnlineDetailsUserControl;
            }

            userControl.dataGridModels.UnselectAll();
        }
Example #4
0
 /// <summary>
 /// The constructor for the event
 /// </summary>
 /// <param name="model">The model to download</param>
 /// <param name="bytesReceived">The total amount of bytes received</param>
 /// <param name="totalBytesToReceive">The total amount of bytes to receive</param>
 /// <param name="progressPercent">The download progress percent</param>
 /// <param name="timeLeft">The estimated time left until completed</param>
 /// <param name="timeSpent">The time spent downloading</param>
 /// <param name="downloaded">The current amount downloaded</param>
 /// <param name="toDownload">The current amount to download</param>
 public DownloadProgressedEventArgs(OnlineModel model, long bytesReceived, long totalBytesToReceive, int progressPercent, string timeLeft, string timeSpent, string downloaded, string toDownload)
 {
     Model               = model;
     BytesReceived       = bytesReceived;
     TotalBytesToReceive = totalBytesToReceive;
     ProgressPercent     = progressPercent;
     TimeLeft            = timeLeft;
     TimeSpent           = timeSpent;
     Downloaded          = downloaded;
     ToDownload          = toDownload;
 }
        public ModelSaberFailedUserControl(OnlineModel model, Exception exception)
        {
            InitializeComponent();
            string message = exception.Message;

            if (exception.InnerException != null && !exception.Message.Contains(exception.InnerException.Message))
            {
                message += $" ({exception.InnerException.Message})";
            }

            ViewModel   = new ModelSaberFailedUserControlViewModel(model, message);
            DataContext = ViewModel;
        }
        public void DeleteModel(OnlineModel model)
        {
            ModelSaberLocalUserControl localUserControl = PropertyHelper.GetPropValue <ModelSaberLocalUserControl>(MainWindow.ViewModel, $"{ModelType}LocalUserControl");
            LocalModel localModel = localUserControl.ViewModel.LocalModels?.Models.FirstOrDefault(x => x.Id == model.Id || x.Name == model.Name && x.Id == -1);

            if (localModel != null)
            {
                localUserControl.ViewModel.DeleteModel(localModel);
            }

            App.ModelSaberApi.DeleteModel(model);
            ModelChanged = true;
        }
Example #7
0
 public OnlineModel GetCourseByOnline(int pageIndex, int pageSize)
 {
     try
     {
         List <StudentClient.Models.Cours> videos = base.Search(d => !d.Course_IsDel && !d.Course_IsOffline, d => d.Course_Time, pageIndex, pageSize);
         OnlineModel online = new OnlineModel();
         online.Courses = videos;
         return(online);
     }
     catch (Exception e)
     {
         mLog.Error("An error has occurred in the get course by online,error:{0}", e.ToString());
         throw;
     }
 }
Example #8
0
        public IHttpActionResult DeleteOnline(OnlineModel online)
        {
            using (IDbConnection con = new ApplicationDbContext().Database.Connection)
            {
                string sql = $"DELETE FROM dbo.Online WHERE IdPlayer = '{online.IdPlayer}'";

                try
                {
                    con.Execute(sql);
                }
                catch (Exception e)
                {
                    return(BadRequest("Error delete online in database, " + e.Message));
                }
            }
            return(Ok());
        }
        private ModelSaberCompletedUserControl GetCompletedModelSaber(OnlineModel model)
        {
            ModelSaberCompletedUserControl completedUserControl = null;

            foreach (object obj in userControl.stackPanelCompleted.Children)
            {
                if (obj is ModelSaberCompletedUserControl control)
                {
                    if (control.ViewModel.Model == model)
                    {
                        completedUserControl = control;
                        break;
                    }
                }
            }

            return(completedUserControl);
        }
        private ModelSaberDownloadingUserControl GetDownloadingModelSaber(OnlineModel model)
        {
            ModelSaberDownloadingUserControl downloadingUserControl = null;

            foreach (object obj in userControl.stackPanelDownloading.Children)
            {
                if (obj is ModelSaberDownloadingUserControl control)
                {
                    if (control.ViewModel.Model == model)
                    {
                        downloadingUserControl = control;
                        break;
                    }
                }
            }

            return(downloadingUserControl);
        }
Example #11
0
        public IHttpActionResult InsertOnline(OnlineModel online)
        {
            using (IDbConnection con = new ApplicationDbContext().Database.Connection)
            {
                string sql = "INSERT INTO dbo.Online (IdPlayer, DateOnline) " +
                             $"VALUES ('{online.IdPlayer}','{DateTime.Now}')";

                try
                {
                    con.Execute(sql);
                }
                catch (Exception e)
                {
                    return(BadRequest("Error insert online in database, " + e.Message));
                }
            }
            return(Ok());
        }
        public void DeleteModel(LocalModel model)
        {
            ModelSaberOnlineUserControl onlineUserControl = PropertyHelper.GetPropValue <ModelSaberOnlineUserControl>(MainWindow.ViewModel, $"{ModelType}OnlineUserControl");
            OnlineModel onlineModel = onlineUserControl.ViewModel.OnlineModels?.Models.FirstOrDefault(x => x.Id == model.Id || x.Name == model.Name && model.Id == -1);

            App.ModelSaberApi.DeleteModel(model);
            LocalModels.Models.Remove(model);
            if (onlineModel is null)
            {
                ModelChanged = true;
            }
            else
            {
                onlineModel.IsDownloaded = false;
            }

            LocalModels = App.ModelSaberApi.RefreshLocalPages(LocalModels);
        }
        public async Task DownloadModel(OnlineModel model)
        {
            try
            {
                MainWindow.radioButtonSettings.IsEnabled = false;
                await App.ModelSaberApi.DownloadModel(model);
            }
            catch (InvalidOperationException e)
            {
                MainWindow.ToggleLoading(false);
                string errorMessage = e.Message;
                if (e.InnerException != null && !e.Message.Contains(e.InnerException.Message))
                {
                    errorMessage += $" ({e.InnerException.Message})";
                }

                await MainWindow.ShowMessageAsync("Downloading failed", "Downloading the model failed with the following error\n\n" +
                                                  "Error:\n" +
                                                  $"{errorMessage}");
            }
            catch (Exception e)
            {
                MainWindow.ToggleLoading(false);
                string errorMessage = e.Message;
                if (e.InnerException != null && !e.Message.Contains(e.InnerException.Message))
                {
                    errorMessage += $" ({e.InnerException.Message})";
                }

                MessageDialogResult result = await MainWindow.ShowMessageAsync("Downloading failed", "Downloading the model failed, would you like to try again?\n\n" +
                                                                               "Error:\n" +
                                                                               $"{errorMessage}", MessageDialogStyle.AffirmativeAndNegative);

                if (result == MessageDialogResult.Affirmative)
                {
                    await DownloadModel(model);
                }
            }
        }
Example #14
0
 public DownloadCompletedEventArgs(OnlineModel model)
 {
     Model = model;
 }
Example #15
0
 public OnlineModelDeletedEventArgs(OnlineModel model)
 {
     Model = model;
 }
Example #16
0
 public ModelSaberCompletedUserControl(OnlineModel model, string downloaded)
 {
     InitializeComponent();
     ViewModel   = new ModelSaberCompletedUserControlViewModel(model, downloaded);
     DataContext = ViewModel;
 }
Example #17
0
        public async Task <OnlineModels> GetOnlineModels(ModelType modelType, Sort sort, bool descending, List <Filter> filters, OnlineModels cachedOnlineModels = null)
        {
            try
            {
                using (WebClient webClient = new WebClient())
                {
                    string projectName = Assembly.GetEntryAssembly().GetName().Name;
                    webClient.Headers.Add(HttpRequestHeader.UserAgent, projectName);
                    int    startIndex    = cachedOnlineModels is null ? 0 : cachedOnlineModels.CurrentPage * 10;
                    int    endIndex      = startIndex + 10;
                    string sortDirection = descending ? "desc" : "asc";
                    string filtersText   = string.Join(",", filters.Select(x => $"{x.Type.ToString().ToLower()}:{x.Text}"));
                    string json          = null;
                    string apiString     = $"{modelSaberApi}?type={modelType.ToString().ToLower()}&sort={sort.ToString().ToLower()}&sortDirection={sortDirection}";

                    if (cachedOnlineModels != null)
                    {
                        apiString += $"&start={startIndex}&end={endIndex}";
                    }
                    if (filters != null && filters.Count > 0)
                    {
                        apiString += $"&filter={filtersText}";
                    }

                    json = await webClient.DownloadStringTaskAsync(apiString);

                    Dictionary <string, JToken> jsonDictionary = JsonConvert.DeserializeObject <Dictionary <string, JToken> >(json);
                    OnlineModels onlineModels;
                    if (cachedOnlineModels is null || jsonDictionary.Count > cachedOnlineModels.TotalModels)
                    {
                        cachedOnlineModels = null;
                        onlineModels       = new OnlineModels
                        {
                            TotalModels = jsonDictionary.Count
                        };
                    }
                    else
                    {
                        onlineModels = new OnlineModels(cachedOnlineModels, false);
                    }

                    List <JToken> jTokens   = jsonDictionary.Take(10).Select(x => x.Value).ToList();
                    string        extension = null;
                    string        filesPath = null;
                    switch (modelType)
                    {
                    case ModelType.None:
                        break;

                    case ModelType.Saber:
                        extension = ".saber";
                        filesPath = SabersPath;
                        break;

                    case ModelType.Avatar:
                        extension = ".avatar";
                        filesPath = AvatarsPath;
                        break;

                    case ModelType.Platform:
                        extension = ".plat";
                        filesPath = PlatformsPath;
                        break;

                    case ModelType.Bloq:
                        extension = ".bloq";
                        filesPath = BloqsPath;
                        break;

                    default:
                        break;
                    }

                    string[] modelsDownloaded = Directory.GetFiles(filesPath, $"*{extension}");

                    foreach (JToken jToken in jTokens)
                    {
                        OnlineModel onlineModel = JsonConvert.DeserializeObject <OnlineModel>(jToken.ToString());
                        string      filePath    = null;
                        foreach (string downloadedModel in modelsDownloaded)
                        {
                            string[] modelNames = Path.GetFileNameWithoutExtension(downloadedModel).Split(" ", 2);
                            if (modelNames.Length == 1)
                            {
                                if (modelNames[0] == onlineModel.Name)
                                {
                                    filePath = downloadedModel;
                                }
                            }
                            else if (int.TryParse(modelNames[0], out int id))
                            {
                                if (onlineModel.Id == id)
                                {
                                    filePath = downloadedModel;
                                }
                            }
                        }

                        if (string.IsNullOrEmpty(filePath))
                        {
                            if (Downloading.Any(x => x.Id == onlineModel.Id))
                            {
                                onlineModel.IsDownloading = true;
                            }
                        }
                        else
                        {
                            onlineModel.IsDownloaded = true;
                            onlineModel.ModelPath    = filePath;
                        }

                        onlineModels.Models.Add(onlineModel);
                    }

                    return(RefreshOnlinePages(onlineModels));
                }
Example #18
0
 public ModelSaberFailedUserControlViewModel(OnlineModel model, string message)
 {
     Model   = model;
     Message = message;
 }
 public ModelSaberDownloadingUserControlViewModel(OnlineModel model)
 {
     Model = model;
 }
Example #20
0
 public DownloadStartedEventArgs(OnlineModel model)
 {
     Model = model;
 }
 private async void Saber_Download(object sender, RoutedEventArgs e)
 {
     OnlineModel model = ((Button)sender).Tag as OnlineModel;
     await ViewModel.DownloadModel(model);
 }
 public ModelSaberDownloadingUserControl(OnlineModel model)
 {
     InitializeComponent();
     ViewModel   = new ModelSaberDownloadingUserControlViewModel(model);
     DataContext = ViewModel;
 }
        private void Saber_Details(object sender, RoutedEventArgs e)
        {
            OnlineModel model = ((Button)sender).Tag as OnlineModel;

            ViewModel.ModelDetails(model);
        }
 public ModelSaberCompletedUserControlViewModel(OnlineModel model, string downloaded)
 {
     Model      = model;
     Downloaded = downloaded;
 }
 public DownloadFailedEventArgs(OnlineModel model, Exception exception)
 {
     Model     = model;
     Exception = exception;
 }