Beispiel #1
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 #2
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 #3
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!");
        }
Beispiel #4
0
        public DomainObject GetObjectByInstanceName(string instanceName)
        {
            if (this.NeedCaching(instanceName) && this.IsInCache(instanceName))
            {
                return(this.GetFromCache(instanceName));
            }
            Instance instance  = GetBySystemName(instanceName);
            string   className = null;
            int      fileId    = 0;

            using (ClassDefinitionFactory classFactory = ClassDefinitionFactory.GetInstance())
            {
                classFactory.Context = this.FactoryContext;
                ClassDefinition definition = classFactory.InternalLoadByPrimaryKey(instance.ClassDefinitionId);
                fileId    = definition.FileId;
                className = definition.ClassName;
            }
            string fileName       = null;
            int    fileLocationId = 0;

            using (PlugFileFactory fileFactory = PlugFileFactory.GetInstance())
            {
                fileFactory.Context = this.FactoryContext;
                PlugFile file = fileFactory.InternalLoadByPrimaryKey(fileId);
                fileName       = file.PlugFileName;
                fileLocationId = file.DestinationLocationId;
            }
            string path = null;

            using (PlugLocationFactory locationFactory = PlugLocationFactory.GetInstance())
            {
                locationFactory.Context = this.FactoryContext;
                PlugLocation location = locationFactory.InternalLoadByPrimaryKey(fileLocationId);
                path = location.PlugLocationPath;
            }
            string filePath     = Path.Combine(path, fileName);
            string assemblyName = Path.GetFileNameWithoutExtension(filePath);
            Type   requiredType = null;

            Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
            foreach (Assembly assembly in loadedAssemblies)
            {
                if (assembly.GetName().Name == assemblyName)
                {
                    requiredType = assembly.GetType(className, false, false);
                    if (requiredType != null)
                    {
                        break;
                    }
                }
            }
            if (requiredType == null)
            {
                Assembly newDll = Assembly.LoadFrom(filePath);
                requiredType = newDll.GetType(className, false, false);
            }

            if (requiredType == null)
            {
                throw new ArgumentException(string.Format("Type '{0}' was not found.", className));
            }
            DomainObject    instanceObject = (DomainObject)Activator.CreateInstance(requiredType);
            IInstantiatable instantinable  = instanceObject as IInstantiatable;

            if (instantinable != null)
            {
                instantinable.Setup(instance, this.FactoryContext);
            }
            if (NeedCaching(instanceName))
            {
                SetToCache(instanceName, instanceObject);
            }
            return(instanceObject);
        }