Beispiel #1
0
 public PlugIn LoadByName(string plugName)
 {
     using (PlugInFactory factory = PlugInFactory.GetInstance())
     {
         factory.Context = this.FactoryContext;
         return(factory.InternalLoadByName(plugName));
     }
 }
Beispiel #2
0
 public PlugIn LoadByPrimaryKey(int plugInId)
 {
     using (PlugInFactory factory = PlugInFactory.GetInstance())
     {
         factory.Context = this.FactoryContext;
         return(factory.InternalLoadByPrimaryKey(plugInId));
     }
 }
Beispiel #3
0
 public List <PlugIn> LoadAll()
 {
     using (PlugInFactory factory = PlugInFactory.GetInstance())
     {
         factory.Context = this.FactoryContext;
         return(factory.InternalLoadAll());
     }
 }
Beispiel #4
0
 public void Delete(PlugIn plug)
 {
     using (PlugInFactory factory = PlugInFactory.GetInstance())
     {
         factory.Context = this.FactoryContext;
         ValidateInstance(plug);
         factory.InternalDelete(plug);
     }
 }
Beispiel #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;
            }
        }
Beispiel #6
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;
            }
        }
Beispiel #7
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!");
        }