Exemple #1
0
        internal List <PlugIn> InternalLoadAll()
        {
            RawSqlExecuteReaderAction readerAction = new RawSqlExecuteReaderAction();

            readerAction.CommandText = _loadAllCommandText;
            this.ExecuteCommand(readerAction);

            List <PlugIn> plugList   = new List <PlugIn>();
            IDataReader   dataReader = readerAction.DataReader;

            try
            {
                int[] ordinals = GetPlugFieldOrdinals(dataReader);
                while (dataReader.Read())
                {
                    PlugIn p = new PlugIn();
                    TranslateToPlug(dataReader, p, ordinals[0], ordinals[1], ordinals[2], ordinals[3], ordinals[4], ordinals[5]);
                    plugList.Add(p);
                }
            }
            finally
            {
                dataReader.Close();
            }

            return(plugList);
        }
Exemple #2
0
 public virtual void ValidateInstance(PlugIn plug)
 {
     if (string.IsNullOrEmpty(plug.PlugFriendlyName))
     {
         throw new ValidationException("Plug FriendlyName should be not empty");
     }
     //TODO: continue validation;
 }
Exemple #3
0
 public void Delete(PlugIn plug)
 {
     using (PlugInFactory factory = PlugInFactory.GetInstance())
     {
         factory.Context = this.FactoryContext;
         ValidateInstance(plug);
         factory.InternalDelete(plug);
     }
 }
Exemple #4
0
        protected void Delete(PlugIn plug)
        {
            RawSqlExecuteNonQueryAction deleteAction = new RawSqlExecuteNonQueryAction();

            deleteAction.CommandText = _deleteCommandText;

            deleteAction.AddParameter("@PlugId", plug.PlugId, DbType.Int32);

            this.ExecuteCommand(deleteAction);
        }
Exemple #5
0
        public void UpdateAll(PlugIn plug)
        {
            try
            {
                this.FactoryContext.BeginTransaction();
                ValidateInstance(plug);
                using (PlugInFactory factory = PlugInFactory.GetInstance())
                {
                    factory.Context = this.FactoryContext;
                    factory.InternalUpdate(plug);
                }
                using (PlugLocationFactory locationFactory = PlugLocationFactory.GetInstance())
                {
                    locationFactory.Context = this.FactoryContext;
                    foreach (PlugLocation location in plug.Locations)
                    {
                        locationFactory.InternalUpdate(location);
                    }
                }
                using (PlugFileFactory fileFactory = PlugFileFactory.GetInstance())
                {
                    fileFactory.Context = this.FactoryContext;
                    foreach (PlugFile file in plug.Files)
                    {
                        fileFactory.InternalUpdate(file);
                    }
                }

                using (BindablePointDefinitionFactory bindablePointDefinitionFactory = BindablePointDefinitionFactory.GetInstance())
                {
                    bindablePointDefinitionFactory.Context = this.FactoryContext;
                    foreach (BindablePointDefinition bindablePointDefinition in plug.BindablePointDefinitions)
                    {
                        bindablePointDefinitionFactory.InternalUpdate(bindablePointDefinition);
                    }
                }
                using (ClassDefinitionFactory classDefinitionFactory = ClassDefinitionFactory.GetInstance())
                {
                    classDefinitionFactory.Context = this.FactoryContext;
                    foreach (ClassDefinition classDefinition in plug.ClassDefinitions)
                    {
                        classDefinitionFactory.InternalUpdate(classDefinition);
                    }
                }
                // TODO: something else?..
                this.FactoryContext.Commit();
            }
            catch
            {
                this.FactoryContext.RollBack();
                throw;
            }
        }
Exemple #6
0
 protected void TranslateToPlug(IDataReader dataReader, PlugIn plug, int idIndex, int nameIndex, int friendlyNameIndex, int descriptionIndex, int versionIndex, int activeIndex)
 {
     plug.PlugId           = dataReader.GetInt32(idIndex);
     plug.PlugName         = dataReader.GetString(nameIndex);
     plug.PlugFriendlyName = dataReader.GetString(friendlyNameIndex);
     if (!dataReader.IsDBNull(descriptionIndex))
     {
         plug.PlugDescription = dataReader.GetString(descriptionIndex);
     }
     plug.PlugVersion = dataReader.GetString(versionIndex);
     plug.Active      = dataReader.GetBoolean(activeIndex);
 }
Exemple #7
0
        protected void Insert(PlugIn plug)
        {
            RawSqlInsertAction insertAction = new RawSqlInsertAction();

            insertAction.CommandText = _insertCommandText;

            insertAction.AddParameter("@PlugName", plug.PlugName, DbType.String);
            insertAction.AddParameter("@PlugFriendlyName", plug.PlugFriendlyName, DbType.String);
            insertAction.AddParameter("@PlugDescription", plug.PlugDescription, DbType.String);
            insertAction.AddParameter("@PlugVersion", plug.PlugVersion, DbType.String);
            insertAction.AddParameter("@Active", plug.Active, DbType.Boolean);
            this.ExecuteCommand(insertAction);
            plug.PlugId = insertAction.InsertedIdentity;
        }
Exemple #8
0
        protected void Update(PlugIn plug)
        {
            RawSqlExecuteNonQueryAction updateAction = new RawSqlExecuteNonQueryAction();

            updateAction.CommandText = _updateCommandText;

            updateAction.AddParameter("@PlugName", plug.PlugName, DbType.String);
            updateAction.AddParameter("@PlugFriendlyName", plug.PlugFriendlyName, DbType.String);
            updateAction.AddParameter("@PlugDescription", plug.PlugDescription, DbType.String);
            updateAction.AddParameter("@PlugVersion", plug.PlugVersion, DbType.String);
            updateAction.AddParameter("@Active", plug.Active, DbType.Boolean);
            updateAction.AddParameter("@PlugId", plug.PlugId, DbType.Int32);

            this.ExecuteCommand(updateAction);
        }
Exemple #9
0
        internal PlugIn InternalLoadByPrimaryKey(int plugId)
        {
            RawSqlExecuteReaderAction readerAction = new RawSqlExecuteReaderAction();

            readerAction.CommandText = _loadByIdCommandText;

            readerAction.AddParameter("@PlugId", plugId, DbType.Int32);

            PlugIn plug = null;

            this.ExecuteCommand(readerAction);
            try
            {
                readerAction.DataReader.Read();
                plug = TranslateToPlug(readerAction.DataReader);
            }
            finally
            {
                readerAction.DataReader.Close();
            }
            return(plug);
        }
Exemple #10
0
        internal PlugIn InternalLoadByName(string plugName)
        {
            RawSqlExecuteReaderAction readerAction = new RawSqlExecuteReaderAction();

            readerAction.CommandText = _loadByNameCommandText;

            readerAction.AddParameter("@PlugName", plugName, DbType.String);

            PlugIn plug = null;

            this.ExecuteCommand(readerAction);
            try
            {
                readerAction.DataReader.Read();
                plug = TranslateToPlug(readerAction.DataReader);
            }
            finally
            {
                readerAction.DataReader.Close();
            }

            return(plug);
        }
Exemple #11
0
        public void InsertAll(PlugIn plug)
        {
            try
            {
                this.FactoryContext.BeginTransaction();
                ValidateInstance(plug);
                using (PlugInFactory factory = PlugInFactory.GetInstance())
                {
                    factory.Context = this.FactoryContext;
                    factory.InternalInsert(plug);
                }
                using (PlugLocationFactory locationFactory = PlugLocationFactory.GetInstance())
                {
                    locationFactory.Context = this.FactoryContext;
                    foreach (PlugLocation location in plug.Locations)
                    {
                        location.PlugId = plug.PlugId;
                        locationFactory.InternalInsert(location);
                    }
                    using (PlugFileFactory fileFactory = PlugFileFactory.GetInstance())
                    {
                        fileFactory.Context = this.FactoryContext;
                        foreach (PlugFile file in plug.Files)
                        {
                            file.DestinationLocationId = locationFactory.InternalLoadByName(file.DestinationPath).PlugLocationId;
                            file.PlugId = plug.PlugId;
                            fileFactory.InternalInsert(file);
                        }

                        using (ClassDefinitionFactory classDefinitionFactory = ClassDefinitionFactory.GetInstance())
                        {
                            classDefinitionFactory.Context = this.FactoryContext;
                            foreach (ClassDefinition classDefinition in plug.ClassDefinitions)
                            {
                                classDefinition.PlugId = plug.PlugId;
                                int fileId = -1;
                                foreach (PlugFile file in plug.Files)
                                {
                                    if (file.PlugFileName == classDefinition.FileName)
                                    {
                                        fileId = file.PlugFileId;
                                        break;
                                    }
                                }
                                if (fileId == -1)
                                {
                                    throw new Exception("Not found corresponding file for class definition!");
                                }
                                classDefinition.FileId = fileId;
                                classDefinitionFactory.InternalInsert(classDefinition);
                            }

                            using (BindablePointDefinitionFactory bindablePointDefinitionFactory = BindablePointDefinitionFactory.GetInstance())
                            {
                                bindablePointDefinitionFactory.Context = this.FactoryContext;
                                foreach (BindablePointDefinition bindPointDef in plug.BindablePointDefinitions)
                                {
                                    bindPointDef.ClassDefinitionId = classDefinitionFactory.InternalLoadByClassName(bindPointDef.ClassDefinitionName).ClassDefinitionId;
                                    bindablePointDefinitionFactory.InternalInsert(bindPointDef);
                                }
                            }
                        }
                    }
                }

                // TODO: something else?..
                this.FactoryContext.Commit();
            }
            catch (Exception ex)
            {
                this.FactoryContext.RollBack();
                throw;
            }
        }
Exemple #12
0
        public override void RegisterPlug(ITransactionContext context)
        {
            #region Installing Required Environments
            Console.WriteLine("Installing Kernel required environment");
            PlugInFactory factoryPlug = PlugInFactory.GetInstance();
            factoryPlug.Context = context as SqlTransactionContext;
            factoryPlug.InstallRequiredEnvironment();
            Console.WriteLine("Installed PlugInFactory");

            PlugLocationFactory factoryPlugLocation = PlugLocationFactory.GetInstance();
            factoryPlugLocation.Context = context as SqlTransactionContext;
            factoryPlugLocation.InstallRequiredEnvironment();
            Console.WriteLine("Installed PlugLocationFactory");

            PlugFileFactory factoryPlugFile = PlugFileFactory.GetInstance();
            factoryPlugFile.Context = context as SqlTransactionContext;
            factoryPlugFile.InstallRequiredEnvironment();
            Console.WriteLine("Installed PlugFileFactory");

            ClassDefinitionFactory factoryClassDefinition = ClassDefinitionFactory.GetInstance();
            factoryClassDefinition.Context = context as SqlTransactionContext;
            factoryClassDefinition.InstallRequiredEnvironment();
            Console.WriteLine("Installed ClassDefinitionFactory");

            BindablePointDefinitionFactory factoryBindablePointDefinition = BindablePointDefinitionFactory.GetInstance();
            factoryBindablePointDefinition.Context = context as SqlTransactionContext;
            factoryBindablePointDefinition.InstallRequiredEnvironment();
            Console.WriteLine("Installed BindablePointDefinitionFactory");

            BindablePointFactory factoryBindablePoint = BindablePointFactory.GetInstance();
            factoryBindablePoint.Context = context as SqlTransactionContext;
            factoryBindablePoint.InstallRequiredEnvironment();
            Console.WriteLine("Installed BindablePointFactory");

            BindingFactory factoryBinding = BindingFactory.GetInstance();
            factoryBinding.Context = context as SqlTransactionContext;
            factoryBinding.InstallRequiredEnvironment();

            InstanceFactory factoryInstance = InstanceFactory.GetInstance();
            factoryInstance.Context = context as SqlTransactionContext;
            factoryInstance.InstallRequiredEnvironment();
            #endregion

            FileTransaction trans = new FileTransaction();
            trans.BeginTransaction();

            PlugIn plug = new PlugIn();
            plug.PlugName         = "Interlogic.Trainings.Plugs.Kernel";
            plug.PlugVersion      = "0.0.0.1";
            plug.PlugFriendlyName = "RemoteAdmin Kernel";
            plug.PlugDescription  = "RemoteAdmin Kernel";
            plug.Active           = true;

            PlugLocation loc = new PlugLocation();
            loc.PlugLocationName        = "EXECUTABLE_DIR";
            loc.PlugLocationPath        = Path.Combine(InitialDir, @"bin");
            loc.PlugLocationDescription = "Main executable directory";
            plug.Locations.Add(loc);

            string EXEC_DIR = loc.PlugLocationPath;

            PlugFile file = new PlugFile();
            file.PlugFileName         = "Interlogic.Trainings.Plugs.Kernel.dll";
            file.RelativeIncomingPath = @"..\..\..\Interlogic.Trainings.Plugs.Kernel\bin\Debug";
            file.DestinationPath      = "EXECUTABLE_DIR";
            plug.Files.Add(file);
            trans.AddAction(new CopyFileAction(Path.Combine(file.RelativeIncomingPath, file.PlugFileName), Path.Combine(EXEC_DIR, file.PlugFileName), true));

            file = new PlugFile();
            file.PlugFileName         = "Interlogic.Trainings.Plugs.Kernel.pdb";
            file.RelativeIncomingPath = @"..\..\..\Interlogic.Trainings.Plugs.Kernel\bin\Debug";
            file.DestinationPath      = "EXECUTABLE_DIR";
            plug.Files.Add(file);
            trans.AddAction(new CopyFileAction(Path.Combine(file.RelativeIncomingPath, file.PlugFileName), Path.Combine(EXEC_DIR, file.PlugFileName), true));

            ClassDefinition classDef = new ClassDefinition();
            classDef.Active = true;
            classDef.ClassDefinitionDescription = "IInstantiatable public interface";
            classDef.ClassName = "Interlogic.Trainings.Plugs.Kernel.IInstantiatable";
            classDef.FileName  = "Interlogic.Trainings.Plugs.Kernel.dll";
            plug.ClassDefinitions.Add(classDef);

            try
            {
                Console.WriteLine("Trying to execute file transactions");
                trans.Execute();
                trans.Commit();
                Console.WriteLine("File transactions completed");
                Console.WriteLine("KernelPlug database insertion");
                PlugInController plugController = new PlugInController(context);
                plugController.InsertAll(plug);
            }
            catch (Exception e)
            {
                Console.WriteLine("Kernel installation failed! Rolling back");
                trans.RollBack();
                throw new Exception("Kernel Installation Process Failed!", e);
            }
            Console.WriteLine("KernelPlug succesfully installed!");
        }
Exemple #13
0
 internal void InternalUpdate(PlugIn plug)
 {
     this.Update(plug);
 }
Exemple #14
0
 internal void InternalInsert(PlugIn plug)
 {
     Insert(plug);
 }
Exemple #15
0
 protected void TranslateToPlug(IDataReader dataReader, PlugIn plug)
 {
     int[] indexes = GetPlugFieldOrdinals(dataReader);
     TranslateToPlug(dataReader, plug, indexes[0], indexes[1], indexes[2], indexes[3], indexes[4], indexes[5]);
 }
Exemple #16
0
 internal void InternalDelete(PlugIn plug)
 {
     this.Delete(plug);
 }