From aa47939c96190f0ae704175354e26a212dc0ec62 Mon Sep 17 00:00:00 2001 From: s_falahati Date: Mon, 9 Oct 2017 20:57:09 +0330 Subject: [PATCH] Updated to LiteDB v4.0 Beta2 --- LiteDB | 1 - LiteDBViewer.Setup/LiteDBViewer.Setup.isl | 29 ++++---- LiteDBViewer/LiteDB.Shell/Shell/Display.cs | 12 --- LiteDBViewer/LiteDB.Shell/Shell/Env.cs | 7 -- .../LiteDB.Shell/Shell/InputCommand.cs | 7 -- LiteDBViewer/LiteDBViewer.csproj | 73 +------------------ LiteDBViewer/MainForm.cs | 60 ++++----------- LiteDBViewer/Properties/AssemblyInfo.cs | 10 +-- LiteDBViewer/packages.config | 2 +- LiteDBViewerVersionSelector/LiteDBVersion.cs | 3 +- .../LiteDBViewerExecutionException.cs | 3 + .../Properties/AssemblyInfo.cs | 6 +- .../VersionSelector.cs | 21 ++++++ 13 files changed, 68 insertions(+), 166 deletions(-) delete mode 160000 LiteDB delete mode 100644 LiteDBViewer/LiteDB.Shell/Shell/Display.cs delete mode 100644 LiteDBViewer/LiteDB.Shell/Shell/Env.cs delete mode 100644 LiteDBViewer/LiteDB.Shell/Shell/InputCommand.cs diff --git a/LiteDB b/LiteDB deleted file mode 160000 index d9c24b1..0000000 --- a/LiteDB +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d9c24b108cfae7f58d6859fd64985f42a106b0aa diff --git a/LiteDBViewer.Setup/LiteDBViewer.Setup.isl b/LiteDBViewer.Setup/LiteDBViewer.Setup.isl index 7598917..aa4dcf1 100644 --- a/LiteDBViewer.Setup/LiteDBViewer.Setup.isl +++ b/LiteDBViewer.Setup/LiteDBViewer.Setup.isl @@ -1148,7 +1148,7 @@ FavoritesFolderTARGETDIR.:FAVORI~1|Favorites0 FontsFolderTARGETDIR.:Fonts0 GlobalAssemblyCacheTARGETDIR.:Global~1|GlobalAssemblyCache0 - INSTALLDIRLITEDB_VIEWER_3.0 + INSTALLDIRLITEDB_VIEWER_4.0 ISCommonFilesFolderCommonFilesFolderInstal~1|InstallShield0 ISMyCompanyDirProgramFilesFolderMYCOMP~1|My Company Name0 ISMyProductDirISMyCompanyDirMYPROD~1|My Product Name0 @@ -1156,6 +1156,7 @@ LITEDB_VIEWERProgramFilesFolderLITEDB~1|LiteDB Viewer0 LITEDB_VIEWER_2ProgramFilesFolderLITEDB~1|LiteDB Viewer 20 LITEDB_VIEWER_3ProgramFilesFolderLITEDB~1|LiteDB Viewer 30 + LITEDB_VIEWER_4ProgramFilesFolderLITEDB~1|LiteDB Viewer 40 LocalAppDataFolderTARGETDIR.:LocalA~1|LocalAppData0 MY_PRODUCT_NAMEFALAHATI.NETMYPROD~1|My Product Name0 MyPicturesFolderTARGETDIR.:MyPict~1|MyPictures0 @@ -1853,7 +1854,7 @@ NewExtension2LiteDBViewer.Primary_outputAlwaysInstall NewExtension3LiteDBViewer.Primary_outputAlwaysInstall dbLiteDBViewerVersionSelector.Primary_outputlitedbviewerversionselector.databasefileAlwaysInstall - db3LiteDBViewer.Primary_outputlitedbviewer3.databasefileAlwaysInstall + db4LiteDBViewer.Primary_outputlitedbviewer4.databasefileAlwaysInstall @@ -3730,18 +3731,19 @@ - - - + + + - + +
IDS__TargetReq_DESC_RESOLUTION1033The screen resolution is not adequate for running [ProductName].0-2086347445 ID_STRING11033http://www.falahati.net0-2086371957 ID_STRING21033Falahati.net0-2086386293ID_STRING31033LiteDB Viewer 30-920300433ID_STRING41033LiteDB Viewer 30-920300433ID_STRING51033LiteDB Viewer 3 Installer0-920296337ID_STRING31033LiteDB Viewer 401294272180ID_STRING41033LiteDB Viewer 401294276276ID_STRING51033LiteDB Viewer 4 Installer01294280372 ID_STRING61033Project's Github Page0-2086363765 ID_STRING71033https://github.com/falahati/LiteDBViewer/issues0-2086343285ID_STRING81033LITEDB~1|LiteDB Viewer 30-920285647ID_STRING81033LITEDB~1|LiteDB Viewer 401294306996 IIDS_UITEXT_FeatureUninstalled1033This feature will remain uninstalled.0-2086347445 NEW_STRING11033db0-2086381524 NEW_STRING21033db30-920264079 NEW_STRING31033db20-920309103 NEW_STRING41033db30-920305007 NEW_STRING51033db0-920300911NEW_STRING61033db401294321332
@@ -3859,6 +3861,7 @@ + @@ -4295,7 +4298,7 @@ UwBpAG4AZwBsAGUASQBtAGEAZwBlAAEARQB4AHAAcgBlAHMAcwA= Icon_IconIndexISAttributes -
_219C5000_4998_4C15_B805_57028684DB4C<VSSolutionFolder>\LiteDBViewer\logo.ico0 _447D0E92_67F0_4A84_B481_9D23D148B67A<VSSolutionFolder>\LiteDBViewer\logo.ico0 _5D5C1D88239E4E93AD3A586210514E6B.exeE:\Personal\Open-Source Projects\LiteDBViewer\LiteDBViewer\bin\Release\LiteDBViewer.exe0_AB6DA949_CB70_4AD7_ABE9_A180C48741D7<VSSolutionFolder>\LiteDBViewer\logo.ico0 _B998458B9BAB4CCCB4E32310C9CE2506.exeE:\Personal\Open-Source Projects\LiteDBViewer\LiteDBViewer\bin\Release\LiteDBViewer.exe0 _F094E218_E425_4B70_AC66_093EC1A36A9E<VSSolutionFolder>\LiteDBViewer\logo.ico0 _FD7293EB_5A56_41B8_A546_E4F5D75E382D[INSTALLDIR]LiteDBViewer.exe0
litedbviewer3.databasefileLiteDB 3 Database_219C5000_4998_4C15_B805_57028684DB4C0 + litedbviewer4.databasefileLiteDB 4 Database_AB6DA949_CB70_4AD7_ABE9_A180C48741D70 litedbviewerversionselector.databasefileLiteDB Database_447D0E92_67F0_4A84_B481_9D23D148B67A0
@@ -4376,9 +4379,9 @@ UwBpAG4AZwBsAGUASQBtAGEAZwBlAAEARQB4AHAAcgBlAHMAcwA= PROGMSG_IIS_ROLLBACKVROOTS##IDS_PROGMSG_IIS_ROLLBACKVROOTS## PROGMSG_IIS_ROLLBACKWEBSERVICEEXTENSIONS##IDS_PROGMSG_IIS_ROLLBACKWEBSERVICEEXTENSIONS## PROGRAMFILETOLAUNCHATEND[INSTALLDIR]LiteDBViewer.Primary output - ProductCode{6EFB147B-92A8-4F04-BE51-6D2A8EFB40F7} - ProductNameLiteDB Viewer 3 - ProductVersion3.0.1.0 + ProductCode{6EFB147B-92A8-4F04-BE51-6D2A8EFB40F8} + ProductNameLiteDB Viewer 4 + ProductVersion4.0.0.0 ProgressType0install ProgressType1Installing ProgressType2installed @@ -4394,7 +4397,7 @@ UwBpAG4AZwBsAGUASQBtAGEAZwBlAAEARQB4AHAAcgBlAHMAcwA= SecureCustomPropertiesISFOUNDNEWERPRODUCTVERSION;USERNAME;COMPANYNAME;ISX_SERIALNUM;SUPPORTDIR;DOTNETVERSION45FULL;ISACTIONPROP1 SelectedSetupType##IDS__DisplayName_Typical## SetupTypeTypical - UpgradeCode{F00B78B2-02D6-4298-8D9B-D75F4CDFCAE0} + UpgradeCode{F00B78B2-02D6-4298-8D9B-D75F4CDFCAE1} _IsMaintenanceChange _IsSetupTypeMinTypical @@ -4663,7 +4666,7 @@ UwBpAG4AZwBsAGUASQBtAGEAZwBlAAEARQB4AHAAcgBlAHMAcwA= ActionProperty ISDisplayName {00000000-0000-0000-0000-000000000000}***ALL_VERSIONS***2ISFOUNDNEWERPRODUCTVERSIONISPreventDowngrade - {F00B78B2-02D6-4298-8D9B-D75F4CDFCAE0}3.0.1.03.0.1.01033256ISACTIONPROP1UpgradeEntry + {F00B78B2-02D6-4298-8D9B-D75F4CDFCAE1}4.0.0.04.0.0.01033256ISACTIONPROP1UpgradeEntry @@ -4673,7 +4676,7 @@ UwBpAG4AZwBsAGUASQBtAGEAZwBlAAEARQB4AHAAcgBlAHMAcwA= CommandArgument - +
dbopenView with LiteDB Viewer"%1"db3openView with LiteDB Viewer 3"%1"db4openView with LiteDB Viewer 4"%1"
diff --git a/LiteDBViewer/LiteDB.Shell/Shell/Display.cs b/LiteDBViewer/LiteDB.Shell/Shell/Display.cs deleted file mode 100644 index 3aa77c5..0000000 --- a/LiteDBViewer/LiteDB.Shell/Shell/Display.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace LiteDB.Shell -{ - public class Display - { - public BsonValue LastResult { get; private set; } - - public void WriteResult(BsonValue result) - { - LastResult = result; - } - } -} \ No newline at end of file diff --git a/LiteDBViewer/LiteDB.Shell/Shell/Env.cs b/LiteDBViewer/LiteDB.Shell/Shell/Env.cs deleted file mode 100644 index e926bda..0000000 --- a/LiteDBViewer/LiteDB.Shell/Shell/Env.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace LiteDB.Shell -{ - public class Env - { - - } -} \ No newline at end of file diff --git a/LiteDBViewer/LiteDB.Shell/Shell/InputCommand.cs b/LiteDBViewer/LiteDB.Shell/Shell/InputCommand.cs deleted file mode 100644 index 5425e8d..0000000 --- a/LiteDBViewer/LiteDB.Shell/Shell/InputCommand.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace LiteDB.Shell -{ - public class InputCommand - { - - } -} \ No newline at end of file diff --git a/LiteDBViewer/LiteDBViewer.csproj b/LiteDBViewer/LiteDBViewer.csproj index 2448ade..a3e5165 100644 --- a/LiteDBViewer/LiteDBViewer.csproj +++ b/LiteDBViewer/LiteDBViewer.csproj @@ -42,8 +42,8 @@ ..\packages\JsonPrettyPrinter.1.0.1.1\lib\net35\JsonPrettyPrinterPlus.dllTrue - - ..\packages\LiteDB.3.0.1\lib\net35\LiteDB.dll + + ..\packages\LiteDB.4.0.0-beta2\lib\net40\LiteDB.dll True @@ -56,72 +56,6 @@ - - LiteDB.Shell\Commands\Collections\BaseCollection.cs - - - LiteDB.Shell\Commands\Collections\Bulk.cs - - - LiteDB.Shell\Commands\Collections\Count.cs - - - LiteDB.Shell\Commands\Collections\Delete.cs - - - LiteDB.Shell\Commands\Collections\Drop.cs - - - LiteDB.Shell\Commands\Collections\DropIndex.cs - - - LiteDB.Shell\Commands\Collections\EnsureIndex.cs - - - LiteDB.Shell\Commands\Collections\Find.cs - - - LiteDB.Shell\Commands\Collections\Indexes.cs - - - LiteDB.Shell\Commands\Collections\Insert.cs - - - LiteDB.Shell\Commands\Collections\Max.cs - - - LiteDB.Shell\Commands\Collections\Min.cs - - - LiteDB.Shell\Commands\Collections\Rename.cs - - - LiteDB.Shell\Commands\Collections\Update.cs - - - LiteDB.Shell\Commands\ICommand.cs - - - LiteDB.Shell\Commands\Storage\BaseStorage.cs - - - LiteDB.Shell\Commands\Storage\Delete.cs - - - LiteDB.Shell\Commands\Storage\Download.cs - - - LiteDB.Shell\Commands\Storage\Find.cs - - - LiteDB.Shell\Commands\Storage\Update.cs - - - LiteDB.Shell\Commands\Storage\Upload.cs - - - LiteDB.Shell\Utils\StringExtensions.cs - Form @@ -140,9 +74,6 @@ DocumentViewForm.cs - - - Form diff --git a/LiteDBViewer/MainForm.cs b/LiteDBViewer/MainForm.cs index 5db7acd..ffabd3b 100644 --- a/LiteDBViewer/MainForm.cs +++ b/LiteDBViewer/MainForm.cs @@ -7,7 +7,6 @@ using System.Reflection; using System.Windows.Forms; using LiteDB; -using LiteDB.Shell; namespace LiteDBViewer { @@ -21,22 +20,7 @@ internal partial class MainForm : Form new Dictionary(); private LiteDatabase _db; - - private static readonly List Commands = new List(); - - static MainForm() - { - var type = typeof(ICommand); - var types = typeof(ICommand).Assembly - .GetTypes() - .Where(p => type.IsAssignableFrom(p) && p.IsClass); - - foreach (var cmd in types) - { - Commands.Add(Activator.CreateInstance(cmd) as ICommand); - } - } - + public MainForm(string fileName, string password = null, bool upgrade = false) { _encrypted = !string.IsNullOrWhiteSpace(password); @@ -61,6 +45,12 @@ public MainForm(string fileName, string password = null, bool upgrade = false) InitializeComponent(); txt_filename.Text = _fileName + (_encrypted ? " [ENCRYPTED]" : string.Empty); + RefreshCollections(); + } + + private void RefreshCollections() + { + lb_Collections.Items.Clear(); foreach (var collection in _db.GetCollectionNames()) { if (!collection.Equals("_chunks") && !collection.Equals("_files")) @@ -272,35 +262,15 @@ private void RunQuery(string query) try { txt_query.Text = query; - var resultHolder = new Display(); - var scanner = new StringScanner(query); - var found = false; - - foreach (var command in Commands) - { - if (!command.IsCommand(scanner)) continue; - command.Execute(_db.Engine, scanner, resultHolder, null, null); - found = true; - break; - } - if (!found) throw new Exception("Command not found."); - FillDataGridView(null); - var rows = new List(); - if (resultHolder.LastResult.IsArray) - { - rows.AddRange( - resultHolder.LastResult.AsArray.Select( - item => - item.IsDocument - ? item.AsDocument - : new BsonDocument {{"RESULT", resultHolder.LastResult}})); - } - else - { - rows.Add(new BsonDocument { { "RESULT", resultHolder.LastResult } }); - } - FillDataGridView(rows); + var results = _db.Engine.Run(query); + RefreshCollections(); + FillDataGridView( + results.Select( + item => + item.IsDocument + ? item.AsDocument + : new BsonDocument(new Dictionary {{"[Result]", item}}))); } catch (Exception ex) { diff --git a/LiteDBViewer/Properties/AssemblyInfo.cs b/LiteDBViewer/Properties/AssemblyInfo.cs index 23dc3cf..95f2994 100644 --- a/LiteDBViewer/Properties/AssemblyInfo.cs +++ b/LiteDBViewer/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("LiteDB Viewer 3")] -[assembly: AssemblyDescription("LiteDB Viewer 3")] +[assembly: AssemblyTitle("LiteDB Viewer 4")] +[assembly: AssemblyDescription("LiteDB Viewer 4")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Soroush Falahati")] -[assembly: AssemblyProduct("LiteDB Viewer 3")] +[assembly: AssemblyProduct("LiteDB Viewer 4")] [assembly: AssemblyCopyright("Copyright © Soroush Falahati 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -35,5 +35,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.0.1.0")] -[assembly: AssemblyFileVersion("3.0.1.0")] \ No newline at end of file +[assembly: AssemblyVersion("4.0.0.0")] +[assembly: AssemblyFileVersion("4.0.0.0")] \ No newline at end of file diff --git a/LiteDBViewer/packages.config b/LiteDBViewer/packages.config index 85b4e6d..9079b3a 100644 --- a/LiteDBViewer/packages.config +++ b/LiteDBViewer/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/LiteDBViewerVersionSelector/LiteDBVersion.cs b/LiteDBViewerVersionSelector/LiteDBVersion.cs index 149f592..353ceff 100644 --- a/LiteDBViewerVersionSelector/LiteDBVersion.cs +++ b/LiteDBViewerVersionSelector/LiteDBVersion.cs @@ -7,6 +7,7 @@ public enum LiteDBVersion LiteDB_1_0, LiteDB_2_0RC, LiteDB_2_0, - LiteDB_3_0 + LiteDB_3_0, + LiteDB_4_0 } } \ No newline at end of file diff --git a/LiteDBViewerVersionSelector/LiteDBViewerExecutionException.cs b/LiteDBViewerVersionSelector/LiteDBViewerExecutionException.cs index 81d5709..3855102 100644 --- a/LiteDBViewerVersionSelector/LiteDBViewerExecutionException.cs +++ b/LiteDBViewerVersionSelector/LiteDBViewerExecutionException.cs @@ -31,6 +31,9 @@ private static string VersionToString(LiteDBVersion version) case LiteDBVersion.LiteDB_3_0: versionString = "LiteDBViewer v3.0"; break; + case LiteDBVersion.LiteDB_4_0: + versionString = "LiteDBViewer v4.0"; + break; } return $"Can not find or execute the {versionString}. Please make sure that you have it installed."; } diff --git a/LiteDBViewerVersionSelector/Properties/AssemblyInfo.cs b/LiteDBViewerVersionSelector/Properties/AssemblyInfo.cs index e98f256..a36c4f6 100644 --- a/LiteDBViewerVersionSelector/Properties/AssemblyInfo.cs +++ b/LiteDBViewerVersionSelector/Properties/AssemblyInfo.cs @@ -9,7 +9,7 @@ [assembly: AssemblyDescription("LiteDB Viewer Version Selector")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Soroush Falahati")] -[assembly: AssemblyProduct("LiteDB Viewer 3")] +[assembly: AssemblyProduct("LiteDB Viewer 4")] [assembly: AssemblyCopyright("Copyright © Soroush Falahati 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] diff --git a/LiteDBViewerVersionSelector/VersionSelector.cs b/LiteDBViewerVersionSelector/VersionSelector.cs index b0eb995..2b57cdc 100644 --- a/LiteDBViewerVersionSelector/VersionSelector.cs +++ b/LiteDBViewerVersionSelector/VersionSelector.cs @@ -30,6 +30,10 @@ public static LiteDBVersion GetFileVersion(string fileName) { return LiteDBVersion.LiteDB_3_0; } + if (DetectIs40(fileName)) + { + return LiteDBVersion.LiteDB_4_0; + } return LiteDBVersion.Unknown; } @@ -49,6 +53,9 @@ public static void OpenLiteDBViewer(string[] fileNames, LiteDBVersion version) case LiteDBVersion.LiteDB_3_0: classId = "litedbviewer3.databasefile"; break; + case LiteDBVersion.LiteDB_4_0: + classId = "litedbviewer4.databasefile"; + break; default: throw new LiteDBViewerExecutionException(version); } @@ -137,5 +144,19 @@ private static bool DetectIs30(string fileName) } return false; } + + private static bool DetectIs40(string fileName) + { + using (var s = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + var header = new byte[4096]; + if (s.Length >= header.Length) + { + s.Read(header, 0, header.Length); + return header[52] == 7; // FILE_VERSION + } + } + return false; + } } } \ No newline at end of file