コード例 #1
0
ファイル: Database.cs プロジェクト: hiboudev/R3E-HUD-Manager
        public List <BackgroundModel> GetAllBackgrounds()
        {
            List <BackgroundModel> backgrounds = new List <BackgroundModel>();

            using (SQLiteConnection db = new SQLiteConnection(dbArgs))
            {
                db.Open();

                using (SQLiteDataReader reader = new SQLiteCommand("SELECT * from backgrounds", db).ExecuteReader())
                {
                    while (reader.Read())
                    {
                        backgrounds.Add(BackgroundFactory.NewBackgroundModel(
                                            reader.GetInt32(0),
                                            reader.GetString(1),
                                            reader.GetString(2),
                                            (BaseDirectoryType)reader.GetInt32(3),
                                            Convert.ToBoolean(reader.GetInt32(4)),
                                            (ScreenLayoutType)reader.GetInt32(5)));
                    }
                    reader.Close();
                }

                db.Close();
            }

            return(backgrounds);
        }
コード例 #2
0
        public void Execute()
        {
            string fileName = Path.GetFileName(args.FilePath);

            if (File.Exists(Path.Combine(locationModel.LocalDirectoryBackgrounds, fileName)))
            {
                fileName = GetUnusedName(locationModel.LocalDirectoryBackgrounds, fileName);
            }

            string destinationFileName = $"{Path.GetFileNameWithoutExtension(fileName)}.jpg";
            string destinationPath     = Path.Combine(locationModel.LocalDirectoryBackgrounds, destinationFileName);

            BitmapImage originalBitmap = new BitmapImage(new Uri(args.FilePath));

            if (!args.CropArea.IsEmpty)
            {
                SaveJpeg(CropBitmap(originalBitmap, args.CropArea), destinationPath);
            }
            else
            {
                SaveJpeg(originalBitmap, destinationPath);
            }

            BackgroundModel background = BackgroundFactory.NewBackgroundModel(args.Name, destinationFileName, BaseDirectoryType.BACKGROUNDS_DIRECTORY, false, args.Layout);

            database.AddBackground(background);
            collection.Add(background);
            screenModel.SetBackground(background);

            Injector.ExecuteCommand <ValidatePlaceholderCollectionCommand>(new CollectionEventArgs <PlaceholderModel>(0, placeholderCollection, placeholderCollection.Items.ToArray()));
        }
コード例 #3
0
        public void Execute()
        {
            List <BackgroundModel> backgrounds = database.GetAllBackgrounds();

            if (backgrounds.Count == 0)
            {
                BackgroundModel defaultBackground = BackgroundFactory.NewBackgroundModel("Default", "background.png", BaseDirectoryType.GRAPHICAL_ASSETS, true, ScreenLayoutType.SINGLE);
                backgroundCollection.AddRange(new List <BackgroundModel>(new BackgroundModel[] { defaultBackground }));
                database.AddBackground(defaultBackground);
                screenModel.SetBackground(defaultBackground);
            }
            else
            {
                backgroundCollection.AddRange(backgrounds);
                screenModel.SetBackground(backgrounds[0]);
            }
        }