示例#1
0
        /// <summary>
        /// Drop collection on active database.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public int DropCollection <T>() where T : class, new()
        {
            VerifyActiveDatabase();
            var table = typeof(T).TableNameAttributeValidate();

            ActiveDatabase.DropCollection(table);
            return(0);
        }
示例#2
0
        /// <summary>
        /// Delete document using predicate in asynchronous manner.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public async Task <DeleteResult> DeleteAsync <T>(Expression <Func <T, bool> > predicate) where T : class, new()
        {
            VerifyActiveDatabase();
            var table      = typeof(T).TableNameAttributeValidate();
            var collection = ActiveDatabase.GetCollection <T>(table);

            return(await collection.DeleteOneAsync(predicate));
        }
示例#3
0
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            ///Update Icon Field in Page
            var pageEntityBuilder = new PageEntityBuilder(migrationBuilder, ActiveDatabase);
            var updateSql         = ActiveDatabase.ConcatenateSql("'oi oi-'", $"{ActiveDatabase.RewriteName("Icon")}");

            pageEntityBuilder.UpdateColumn("Icon", updateSql, $"{ActiveDatabase.RewriteName("Icon")} <> ''");
        }
示例#4
0
        /// <summary>
        /// Create collection on active database.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="database"></param>
        /// <returns></returns>
        public int CreateCollection <T>() where T : class, new()
        {
            var tableName = Utilities.Shared.AttributeExtension.TableNameAttributeValidate(typeof(T));

            ActiveDatabase.CreateCollection(tableName);
            Databases.Add(tableName);
            return(1);
        }
示例#5
0
        /// <summary>
        /// Insert specified document in an asynchronous manner.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public async Task <int> InsertAsync <T>(T obj) where T : class, new()
        {
            VerifyActiveDatabase();
            var table      = typeof(T).TableNameAttributeValidate();
            var collection = ActiveDatabase.GetCollection <T>(table);
            await collection.InsertOneAsync(obj);

            return(0);
        }
示例#6
0
        /// <summary>
        /// Insert documents.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int Insert <T>(IEnumerable <T> obj) where T : class, new()
        {
            VerifyActiveDatabase();
            var table      = typeof(T).TableNameAttributeValidate();
            var collection = ActiveDatabase.GetCollection <T>(table);

            collection.InsertMany(obj);
            return(0);
        }
示例#7
0
        /// <summary>
        /// Read documents which match predicate.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="predicate"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        public IEnumerable <T> Query <T>(Expression <Func <T, bool> > predicate, int?top = null) where T : class, new()
        {
            VerifyActiveDatabase();
            var table      = typeof(T).TableNameAttributeValidate();
            var collection = ActiveDatabase.GetCollection <T>(table);
            var buffer     = collection.Find <T>(predicate);
            var result     = top == null?buffer.ToList() : buffer.Limit(top.Value).ToList();

            return(result);
        }
示例#8
0
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            //Add Column to Notification table
            var notificationEntityBuilder = new NotificationEntityBuilder(migrationBuilder, ActiveDatabase);

            notificationEntityBuilder.AddDateTimeColumn("SendOn", true);

            //Update new Column
            notificationEntityBuilder.UpdateColumn("SendOn", $"{ActiveDatabase.RewriteName("CreatedOn")}", $"{ActiveDatabase.RewriteName("SendOn")} IS NULL");
        }
示例#9
0
 /// <summary>
 /// This function handles the user-click on the menu item that
 /// deactivates the plugin for the active database
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnDeactivatePlugin(object sender, EventArgs e)
 {
     if (!ActiveDatabase.IsOpen || !IsPluginActive() || IsActiveDbDeltaDb())
     {
         return;
     }
     //we deactivate the plugin by untagging the database
     ActiveDatabase.SetCustomAttribute(KeeShare.AttributeFlags.IsKeeShareEnabled, false);
     m_keeShare.Unregister(ActiveDatabase.IOConnectionInfo);
     UpdateUI(ActiveDatabase.RootGroup, Changes.None, true);
 }
示例#10
0
        /// <summary>
        /// Delete document using key.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="primaryKey"></param>
        /// <returns></returns>
        public DeleteResult Delete <T>(object primaryKey) where T : class, new()
        {
            VerifyActiveDatabase();
            var pk         = typeof(T).PrimaryKeyAttributeValidate();
            var field      = pk.Name;
            var value      = primaryKey;
            var table      = typeof(T).TableNameAttributeValidate();
            var collection = ActiveDatabase.GetCollection <T>(table);
            var filter     = Builders <T> .Filter.Eq(field, value);

            return(collection.DeleteOne(filter));
        }
示例#11
0
        /// <summary>
        /// Delete specified document in an asynchronous manner.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public async Task <DeleteResult> DeleteAsync <T>(T obj) where T : class, new()
        {
            VerifyActiveDatabase();
            var primaryKey = typeof(T).PrimaryKeyAttributeValidate();
            var field      = primaryKey.Name;
            var value      = primaryKey.GetValue(obj);
            var table      = typeof(T).TableNameAttributeValidate();
            var collection = ActiveDatabase.GetCollection <T>(table);
            var filter     = Builders <T> .Filter.Eq(field, value);

            return(await collection.DeleteOneAsync(filter));
        }
示例#12
0
        /// <summary>
        /// Read document using key.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="primaryKey"></param>
        /// <returns></returns>
        public T Query <T>(object primaryKey) where T : class, new()
        {
            VerifyActiveDatabase();
            var type       = typeof(T);
            var table      = type.TableNameAttributeValidate();
            var collection = ActiveDatabase.GetCollection <T>(table);
            var filter     = Builders <T> .Filter.Eq(type.PrimaryKeyAttributeValidate().Name, primaryKey);

            var buffer = collection.Find <T>(filter);

            return(buffer.FirstOrDefault());
        }
示例#13
0
        /// <summary>
        /// This function deactivates the plugin on the actual database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnActivatePlugin(object sender, EventArgs e)
        {
            if (!ActiveDatabase.IsOpen || IsPluginActive() || IsActiveDbDeltaDb())
            {
                return;
            }
            //we activate the plugin by tagging the active db and initializing the managers
            ActiveDatabase.SetCustomAttribute(KeeShare.AttributeFlags.IsKeeShareEnabled, true);
            Changes changes = m_keeShare.Initialize(ActiveDatabase)
                              | m_keeShare.Register(ActiveDatabase, ActiveDatabase.IOConnectionInfo);

            UpdateUI(ActiveDatabase.RootGroup, changes, true);
        }
示例#14
0
        /// <summary>
        /// Update specified document in an asynchrounous manner.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public async Task <ReplaceOneResult> UpdateAsync <T>(T obj) where T : class, new()
        {
            VerifyActiveDatabase();
            var type       = typeof(T);
            var table      = type.TableNameAttributeValidate();
            var collection = ActiveDatabase.GetCollection <T>(table);
            var primaryKey = type.PrimaryKeyAttributeValidate();
            var filter     = Builders <T> .Filter.Eq(primaryKey.Name, primaryKey.GetValue(obj));

            var result = await collection.ReplaceOneAsync(filter, obj);

            return(result);
        }
示例#15
0
        private void OnGroupMenuAddImportFolder(object sender, EventArgs e)
        {
            if (!IsPluginActive())
            {
                return;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();
            DialogResult   result         = openFileDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                Changes changes = m_keeShare.AddImportPath(openFileDialog.FileName);
                UpdateUI(ActiveDatabase.GetImportGroup(), changes, true);
            }
        }
示例#16
0
        private void OnGroupMenuAddExportFolder(object sender, EventArgs e)
        {
            if (!IsPluginActive())
            {
                return;
            }

            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
            DialogResult        result = folderBrowserDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                Changes changes = m_keeShare.AddExportPath(folderBrowserDialog.SelectedPath);
                UpdateUI(ActiveDatabase.GetExportGroup(), changes, true);
            }
        }
示例#17
0
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            //Add Column to Site table
            var siteEntityBuilder = new SiteEntityBuilder(migrationBuilder, ActiveDatabase);

            siteEntityBuilder.AddStringColumn("AdminContainerType", 200, true);

            //Update new column
            siteEntityBuilder.UpdateColumn("AdminContainerType", "''");


            //Delete records from Page
            var pageEntityBuilder = new PageEntityBuilder(migrationBuilder, ActiveDatabase);

            pageEntityBuilder.DeleteFromTable($"{ActiveDatabase.RewriteName("Path")} = 'admin/tenants'");
        }
示例#18
0
            public DocumentManagerExInfo(object documentManagerEx)
            {
                if (documentManagerEx == null)
                {
                    throw new ArgumentNullException("documentManagerEx");
                }
                this.documentManagerEx = documentManagerEx;

                Type documentType = documentManagerEx.GetType();

                var property = documentType.GetProperty(ActiveDatabaseName);

                ActiveDatabase = property.GetValue(documentManagerEx, null);

                property       = documentType.GetProperty(ActiveDocumentName);
                ActiveDocument = property.GetValue(documentManagerEx, null);

                Type databaseType = ActiveDatabase.GetType();

                property  = databaseType.GetProperty(RootGroupName);
                RootGroup = property.GetValue(ActiveDatabase, null);

                Debug.WriteLine(string.Format("[KeeFarceDLL] Created DocumentManagerExInfo Got Database={0}; Got RootGroup={1}", ActiveDatabase != null, RootGroup != null));
            }
示例#19
0
 /// <summary>
 /// This function validates if the active database is a deltaContainer
 /// </summary>
 /// <returns>True if the active db is a deltaContainer</returns>
 private bool IsActiveDbDeltaDb()
 {
     return(ActiveDatabase.IsOpen &&
            ActiveDatabase.IsCustomAttributeSet(KeeShare.AttributeFlags.IsDeltaDatabase));
 }
示例#20
0
 /// <summary>
 /// This function validates if the plugin is allowed to handel the active database.
 /// </summary>
 /// <returns>True if a special tag was set to the database, so we could identify it as a
 /// KeeShare-database</returns>
 private bool IsPluginActive()
 {
     return(!IsActiveDbDeltaDb() &&
            ActiveDatabase.IsOpen &&
            ActiveDatabase.IsCustomAttributeSet(KeeShare.AttributeFlags.IsKeeShareEnabled));
 }
示例#21
0
        static void Main(string[] args)
        {
            bool      ProgramRunning = true;
            string    StartupMode    = "console";
            string    UserInput      = "";
            MARIAFile ActiveFile     = new MARIAFile(args.ElementAtOrDefault(0));
            MARIASqlServerDatabase ActiveDatabase    = null;
            HttpClient             ApplicationClient = new HttpClient();

            if (ActiveFile.IsValid && ActiveFile.IsMARIAFile)
            {
                StartupMode = "file";
            }
            /*Set UserInput based on File Type*/
            if (StartupMode == "file")
            {
                try
                {
                    ActiveFile.ParseNativeFile();
                    Console.ReadKey();
                }
                catch (Exception e)
                {
                }
            }
            else if (StartupMode == "console")
            {
                while (ProgramRunning)
                {
                    try
                    {
                        Console.Write("Command: ");
                        UserInput = Console.ReadLine();
                        string PrimaryCommand = UserInput.Split(' ').ElementAtOrDefault(0).Trim();
                        string InstructionSet = UserInput.Remove(0, PrimaryCommand.Length).Trim();
                        if (UserInput != "exit")
                        {
                            if (PrimaryCommand == "file")
                            {
                                if (ActiveFile != null && ActiveFile.IsValid)
                                {
                                    string SecondaryCommand = InstructionSet.Split(' ')[0];
                                    if (SecondaryCommand == "open")
                                    {
                                        string FilePath;
                                        Console.Write("Set Active File: ");
                                        FilePath   = Console.ReadLine();
                                        ActiveFile = new MARIAFile(FilePath);
                                    }
                                    else if (SecondaryCommand == "imageread")
                                    {
                                        ActiveFile.ReadImage();
                                    }
                                    else if (SecondaryCommand == "clear")
                                    {
                                        ActiveFile = null;
                                    }
                                    else
                                    {
                                        Console.WriteLine("{0} {1} is not a recognized command", PrimaryCommand, SecondaryCommand);
                                    }
                                }
                                else
                                {
                                    string FilePath;
                                    Console.Write("Set Active File: ");
                                    FilePath   = Console.ReadLine();
                                    ActiveFile = new MARIAFile(FilePath);
                                }
                            }
                            else if (PrimaryCommand == "database")
                            {
                                if (ActiveDatabase != null)
                                {
                                    string SecondaryCommand = InstructionSet.Split(' ')[0];
                                    string DatabaseCommand  = InstructionSet.Remove(0, SecondaryCommand.Length).Trim();
                                    if (SecondaryCommand == "open")
                                    {
                                        string DatabaseCredentials;
                                        Console.Write("Set Active Database: ");
                                        DatabaseCredentials = Console.ReadLine();
                                        ActiveDatabase      = new MARIASqlServerDatabase(DatabaseCredentials);
                                    }
                                    else if (SecondaryCommand == "readerquery")
                                    {
                                        StatusObject SO_ReaderQuery = ActiveDatabase.ExecuteReaderQuery(DatabaseCommand);
                                        if (SO_ReaderQuery.Status != StatusCode.FAILURE)
                                        {
                                            ActiveDatabase.DisplayResultSet(SO_ReaderQuery.UDDynamic);
                                        }
                                    }
                                    else if (SecondaryCommand == "executedqueryhistory")
                                    {
                                        StatusObject SO_ExecutedQueryHistory = ActiveDatabase.GetAllExecutedQueries();
                                        if (SO_ExecutedQueryHistory.Status != StatusCode.FAILURE)
                                        {
                                            ActiveDatabase.DisplayResultSet(SO_ExecutedQueryHistory.UDDynamic);
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("{0} {1} is not a recognized command", PrimaryCommand, SecondaryCommand);
                                    }
                                }
                                else
                                {
                                    string DatabaseCredentials;
                                    Console.Write("Set Active Database: ");
                                    DatabaseCredentials = Console.ReadLine();
                                    ActiveDatabase      = new MARIASqlServerDatabase(DatabaseCredentials);
                                }
                            }
                            else if (PrimaryCommand == "webrequest")
                            {
                                string SecondaryCommand = InstructionSet.Split(' ').ElementAtOrDefault(0);
                                if (SecondaryCommand == "fromfile")
                                {
                                    if (ActiveFile != null)
                                    {
                                        if (ActiveFile.IsValid && ActiveFile.IsMARIAFile)
                                        {
                                            Console.WriteLine("hello");
                                        }
                                    }
                                    else
                                    {
                                    }
                                }
                                else if (SecondaryCommand == "sequential")
                                {
                                }
                                else if (SecondaryCommand == "get")
                                {
                                    MARIAWebRequest NewRequest = new MARIAWebRequest("http://uat.merimen.com/uat_id/claims/", WebRequestMethod.GET, ref ApplicationClient);
                                    NewRequest.ConventionalGet(NewRequest.ReadResponse);
                                }
                                else if (SecondaryCommand == "post")
                                {
                                }
                                else
                                {
                                    Console.WriteLine("{0} {1} is not a recognized command", PrimaryCommand, SecondaryCommand);
                                }
                            }
                            else if (PrimaryCommand == "cryptography")
                            {
                                MARIACryptography CryptoTools = new MARIACryptography("abcdefghijklmnopqrstuvwxyz");
                                CryptoTools.GetPermutations();
                            }
                            else if (PrimaryCommand == "crypto2")
                            {
                                Console.BufferHeight = 30000;
                                MARIACryptography CryptoTools = new MARIACryptography("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
                                CryptoTools.GetPermutations("A", "AAAA");
                            }
                            else if (PrimaryCommand == "crypto3")
                            {
                                Console.BufferHeight = 30000;
                                string            StartSequence = InstructionSet.Split(' ').ElementAtOrDefault(0);
                                int               Iterations    = Convert.ToInt32(InstructionSet.Split(' ').ElementAtOrDefault(1));
                                MARIACryptography CryptoTools   = new MARIACryptography("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
                                CryptoTools.GetEndSequence(StartSequence, Iterations);
                            }
                            else if (PrimaryCommand == "tasktest")
                            {
                                MARIATaskManager TaskManager = new MARIATaskManager();
                                MARIATask        NewTask     = new MARIATask(TaskManager.UserDefinedTask1, "hello");
                                MARIATask        NewTask2    = new MARIATask(TaskManager.UserDefinedTask1, "world");
                                MARIATask        NewTask3    = new MARIATask(TaskManager.UserDefinedTask2);
                                TaskManager.AddTask("hello", NewTask);
                                TaskManager.AddTask("world", NewTask2);
                                TaskManager.AddTask("hiii", NewTask3);
                                TaskManager.StartTask();
                            }
                            else if (PrimaryCommand == "extdll")
                            {
                            }
                            else if (PrimaryCommand == "thread")
                            {
                            }
                            else if (PrimaryCommand == "process")
                            {
                                MARIAProcess newprocess = new MARIAProcess("chrome");
                                newprocess.Start();
                                newprocess.GetMemoryAddresses();
                            }
                            else if (PrimaryCommand == "process2")
                            {
                                MARIAProcessManager ProcessManager = new MARIAProcessManager();
                                ProcessManager.GetAllProcesses("chrome");
                            }
                            else
                            {
                                Console.WriteLine("{0} is not a recognized command", PrimaryCommand);
                            }
                        }
                        else
                        {
                            ProgramRunning = false;
                            UserInput      = null;
                        }
                    }
                    catch (Exception e)
                    {
                        ProgramRunning = false;
                        UserInput      = null;
                        Console.WriteLine(e.ToString());
                    }
                }
            }
        }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            var folderEntityBuilder = new FolderEntityBuilder(migrationBuilder, ActiveDatabase);

            folderEntityBuilder.AddIntegerColumn("Capacity", true);
            folderEntityBuilder.UpdateColumn("Capacity", "0");
            folderEntityBuilder.UpdateColumn("Capacity", Constants.UserFolderCapacity.ToString(), $"{ActiveDatabase.RewriteName("Name")} = 'My Folder'");
            folderEntityBuilder.AddStringColumn("ImageSizes", 512, true, true);

            var fileEntityBuilder = new FileEntityBuilder(migrationBuilder, ActiveDatabase);

            fileEntityBuilder.AddStringColumn("Description", 512, true, true);
        }