示例#1
0
        private void UpdateAddinDueDateByNamespace(string licenseNamespace)
        {
            List <string> addinsCode = licenseDAO.getAddinsByNamespace(licenseNamespace);

            licenseDAO.UpdateNamespaceDueDate(licenseNamespace, DateTime.MinValue);

            var setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.ConfigureDomain";
            setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
            AppDomain configureDomain = AppDomain.CreateDomain("ConfigureDomain", null, setup);

            try
            {
                configureDomain.SetData("assemblyName", "tempDomain");
                IApplication app = (IApplication)configureDomain.CreateInstanceAndUnwrap("Framework",
                                                                                         "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(configureDomain);
                LicenseManager licenseManager = app.Resolve <LicenseManager>();
                foreach (var addinCode in addinsCode)
                {
                    DateTime dueDate;
                    if (licenseManager.AddinIsValid(addinCode, out dueDate))
                    {
                        licenseDAO.UpdateAddinDueDate(addinCode, dueDate);
                    }
                }
            }
            finally
            {
                AppDomain.Unload(configureDomain);
            }
        }
示例#2
0
 protected override void Append(log4net.Core.LoggingEvent loggingEvent)
 {
     try
     {
         string asm, version;
         var    app = SAPServiceFactory.ApplicationFactory();
         GetAsmName(loggingEvent.LocationInformation.ClassName, out asm, out version);
         if (app != null)
         {
             UIAPILog(loggingEvent, app, asm);
         }
         if (B1DAO != null && loggingEvent.Level >= Level.Error)
         {
             DIAPILog(loggingEvent, asm, version);
         }
     }
     catch (COMException c)
     {
         // do nothing, SAP is closed, ignore.
     }
     catch (Exception e)
     {
         System.Windows.Forms.MessageBox.Show(String.Format("{0}\n\n{1}", e.Message, e.StackTrace));
         // Cannot log, can't do anything. Just prevent app crash.
     }
 }
示例#3
0
        public static string GetSQL(this Object o, string resource)
        {
            if (dbType == null)
            {
                dbType = (SAPServiceFactory.CompanyFactory().DbServerType == SAPbobsCOM.BoDataServerTypes.dst_HANADB) ? "hana" : "sql";
            }
            Type baseType = (typeof(Type).IsAssignableFrom(o.GetType())) ? (Type)o : o.GetType();

            if (baseType.Assembly.IsDynamic)
            {
                baseType = baseType.BaseType;
            }

            string ns = baseType.Namespace;

            using (var stream = baseType.Assembly.GetManifestResourceStream(ns + "." + dbType + "." + resource))
            {
                if (stream != null)
                {
                    using (var streamReader = new StreamReader(stream))
                    {
                        return(streamReader.ReadToEnd());
                    }
                }
            }
            return(string.Empty);
        }
示例#4
0
        internal bool AddinIsValid(string asmCode, out DateTime dueDate)
        {
            dueDate = DateTime.MinValue;
            if (asmCode == null)
            {
                return(false);
            }

            var setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.ConfigureDomain";
            string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            Directory.CreateDirectory(tempDirectory);
            setup.ApplicationBase = tempDirectory;
            AppDomain configureDomain = AppDomain.CreateDomain("ConfigureDomain", null, setup);

            try
            {
                AssemblyInformation asm = asmDAO.GetAssemblyInformation(asmCode);
                fileUpdate.UpdateAppDataFolder(asm, tempDirectory);

                configureDomain.SetData("assemblyName", "tempDomain");
                IApplication app = (IApplication)configureDomain.CreateInstanceAndUnwrap("Framework",
                                                                                         "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(configureDomain);
                LicenseVerifyAddin licenseManager = app.Resolve <LicenseVerifyAddin>();

                if (asm != null)
                {
                    return(licenseManager.AddinIsValid(asm.Name, out dueDate));
                }
            }
            catch (Exception e)
            {
                Logger.Error("Unhandled error", e);
            }
            finally
            {
                AppDomain.Unload(configureDomain);
                try
                {
                    Directory.Delete(tempDirectory, true);
                }
                catch (Exception e)
                {
                    Logger.Debug(string.Format("Directory {0} not cleaned", tempDirectory), e);
                }
            }
            return(false);
        }
示例#5
0
        /// <summary>
        /// Return true if the addin is valid.
        /// </summary>
        /// <param name="path">Path name for the intended addin</param>
        /// <param name="comments">DataTable serialized, to be displayed to the user with db change information.</param>
        /// <returns>true if addin is valid</returns>
        internal bool AddInIsValid(string path, out string datatable)
        {
            string    extension  = Path.GetExtension(path);
            AppDomain testDomain = null;
            string    mainDll    = string.Empty;
            bool      ret;
            string    tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            Directory.CreateDirectory(tempDirectory);

            // check if it's a DLL or ZIP.
            if (extension != null && extension == ".zip")
            {
                mainDll = UnzipFile(path, tempDirectory);
            }
            else if (extension != null && (extension == ".dll" || extension == ".exe"))
            {
                string destination = Path.Combine(tempDirectory, Path.GetFileName(path));
                File.Copy(path, destination);
                mainDll = Path.GetFileName(path);
            }
            else
            {
                throw new ArgumentException(Messages.InvalidAddInExtension);
            }
            if (mainDll == null)
            {
                datatable = string.Empty;
                return(false);
            }

            mainDll = mainDll.Substring(0, mainDll.Length - 4);

            testDomain = CreateTestDomain(mainDll, tempDirectory);
            try
            {
                testDomain.SetData("assemblyName", mainDll); // Used to get current AssemblyName for logging and reflection
                Application testApp = (Application)testDomain.CreateInstanceAndUnwrap("Framework", "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(testDomain);
                var addinManager = testApp.Resolve <AddinManager>();
                ret = addinManager.CheckAddinConfiguration(mainDll, out datatable);
                testApp.ShutDownApp();
            }
            finally
            {
                AppDomain.Unload(testDomain);
                Directory.Delete(tempDirectory, true);
            }
            return(ret);
        }
示例#6
0
        /// <summary>
        /// Return true if the addin is valid.
        /// </summary>
        /// <param name="path">Path name for the intended addin</param>
        /// <param name="datatable">DataTable serialized, to be displayed to the user with db change information.</param>
        /// <param name="addinName">Name of the addin, defined using an AddinAttribute</param>
        /// <param name="addinName">Namespace of the addin, defined using an AddinAttribute</param>
        /// <returns>true if addin is valid</returns>
        internal bool AddInIsValid(string path, out string datatable, out string addinName, out string addinNamespace)
        {
            string    extension  = Path.GetExtension(path);
            AppDomain testDomain = null;
            string    mainDll    = string.Empty;
            bool      ret;
            string    tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            Directory.CreateDirectory(tempDirectory);

            // check if it's a DLL or ZIP.
            if (extension != null && extension == ".dover")
            {
                mainDll = UnzipFile(path, tempDirectory);
            }
            else
            {
                throw new ArgumentException(Messages.InvalidAddInExtension);
            }
            if (mainDll == null)
            {
                datatable      = string.Empty;
                addinName      = string.Empty;
                addinNamespace = string.Empty;
                return(false);
            }

            mainDll    = Path.GetFileNameWithoutExtension(mainDll);
            testDomain = CreateTestDomain(mainDll, tempDirectory);
            try
            {
                testDomain.SetData("assemblyName", mainDll); // Used to get current AssemblyName for logging and reflection
                IApplication testApp = (IApplication)testDomain.CreateInstanceAndUnwrap("Framework", "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(testDomain);
                var addinManager = testApp.Resolve <IAddinManager>();
                ret = addinManager.CheckAddinConfiguration(mainDll, out datatable, out addinName, out addinNamespace);
            }
            finally
            {
                AppDomain.Unload(testDomain);
                try
                {
                    Directory.Delete(tempDirectory, true);
                } catch (Exception e)
                {
                    Logger.Debug(string.Format("Directory {0} not cleaned", tempDirectory), e);
                }
            }
            return(ret);
        }
示例#7
0
        private void GetAssemblyInfoFromBin(string directory, byte[] asmBytes, AssemblyInformation asmInfo)
        {
            AppDomain tempDomain;
            var       setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.GetAssemblyInformation";
            setup.ApplicationBase = directory;
            tempDomain            = AppDomain.CreateDomain("Dover.GetAssemblyInformation", null, setup);
            List <AssemblyInformation> dependencyInformation;

            try
            {
                IApplication app = (IApplication)tempDomain.CreateInstanceAndUnwrap("Framework",
                                                                                    "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(tempDomain);
                ITempAssemblyLoader asmLoader = app.Resolve <ITempAssemblyLoader>();
                dependencyInformation = asmLoader.GetAssemblyInfoFromBin(asmBytes, asmInfo);
                asmInfo.Dependencies  = new List <AssemblyInformation>();

                // The appDomain will die, clone return.
                foreach (var dep in dependencyInformation)
                {
                    AssemblyInformation newInfo = new AssemblyInformation();
                    newInfo.Build       = dep.Build;
                    newInfo.Code        = dep.Code;
                    newInfo.Date        = dep.Date;
                    newInfo.FileName    = string.Copy(dep.FileName);
                    newInfo.Major       = dep.Major;
                    newInfo.MD5         = string.Copy(dep.MD5);
                    newInfo.Minor       = dep.Minor;
                    newInfo.Name        = string.Copy(dep.Name);
                    newInfo.Namespace   = string.Empty;
                    newInfo.Description = string.Copy(dep.Description);
                    newInfo.Revision    = dep.Revision;
                    newInfo.Size        = dep.Size;
                    newInfo.Type        = dep.Type;
                    asmInfo.Dependencies.Add(newInfo);
                }
            }
            finally
            {
                AppDomain.Unload(tempDomain);
            }
        }
示例#8
0
 private void PrivateBoot()
 {
     try
     {
         Application app = (Application)Inception.CreateInstanceAndUnwrap("Framework", "Dover.Framework.Application");
         SAPServiceFactory.PrepareForInception(Inception); // need to be after Application creation because of assembly resolving from embedded resources.
         Inception.SetData("assemblyName", "Framework");   // Used to get current AssemblyName for logging and reflection
         InceptionAddinManager = app.Resolve <AddinManager>();
         Sponsor <Application>  appSponsor          = new Sponsor <Application>(app);
         Sponsor <AddinManager> addInManagerSponsor = new Sponsor <AddinManager>(InceptionAddinManager);
         app.RunInception();
         AppDomain.Unload(Inception); // release AppDomain on shutdown.
     }
     catch (Exception e)
     {
         System.Windows.Forms.MessageBox.Show(string.Format("{0}\n{1}", e.Message, e.StackTrace));
         throw e;
     }
 }
示例#9
0
        internal void PrepareFramework()
        {
            try
            {
                while (reboot)
                {
                    microBoot.coreShutdownEvent.Reset();
                    reboot = false;
                    Logger.Debug(Messages.PreparingFramework);
                    dbConf.PrepareDatabase();

                    if (InsideInception())
                    {
                        return;
                    }

                    string appFolder = CheckAppFolder();
                    Logger.Debug(DebugString.Format(Messages.CreatedAppFolder, appFolder));

                    assemblyLoader.UpdateFrameworkAssemblies(appFolder);
                    assemblyLoader.UpdateAddinsDBAssembly();

                    if (rebootCount == 0)
                    {
                        dispatcher.RegisterEvents();
                    }

                    microBoot.AppFolder = appFolder;
                    microBoot.StartInception();
                    microBoot.Boot();
                    microBoot.coreShutdownEvent.WaitOne();
                    rebootCount++;
                }
                reboot = true; // in case we need to start it again (i.e. unit test).
                ContainerManager.Container.Dispose();
                SAPServiceFactory.LogOff();
            }
            catch (Exception e)
            {
                Logger.Fatal(String.Format(Messages.GeneralError, e.Message), e);
                Environment.Exit(10);
            }
        }
示例#10
0
        internal void PrepareFramework()
        {
            try
            {
                while (reboot)
                {
                    reboot = false;
                    Logger.Debug(Messages.PreparingFramework);
                    dbConf.PrepareDatabase();

                    if (InsideInception())
                    {
                        return;
                    }

                    string appFolder = CheckAppFolder();
                    Logger.Debug(DebugString.Format(Messages.CreatedAppFolder, appFolder));

                    assemblyLoader.UpdateAssemblies(AssemblySource.Core, appFolder);
                    assemblyLoader.UpdateAssemblies(AssemblySource.AddIn, appFolder);
                    CopyInstallResources(appFolder, Environment.CurrentDirectory);

                    if (rebootCount == 0)
                    {
                        dispatcher.RegisterEvents();
                    }

                    microBoot.AppFolder = appFolder;
                    microBoot.StartInception();
                    microBoot.Boot();
                    System.Windows.Forms.Application.Run();
                    rebootCount++;
                }
                ContainerManager.Container.Dispose();
                SAPServiceFactory.LogOff();
            }
            catch (Exception e)
            {
                Logger.Fatal(String.Format(Messages.GeneralError, e.Message), e);
                Environment.Exit(10);
            }
        }
示例#11
0
        private void GetAssemblyInfoFromBin(byte[] asmBytes, AssemblyInformation asmInfo)
        {
            AppDomain tempDomain;
            var       setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.GetAssemblyInformation";
            setup.ApplicationBase = Environment.CurrentDirectory;
            tempDomain            = AppDomain.CreateDomain("Dover.GetAssemblyInformation", null, setup);

            try
            {
                Application app = (Application)tempDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName,
                                                                                  "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(tempDomain);
                TempAssemblyLoader asmLoader = app.Resolve <TempAssemblyLoader>();
                asmLoader.GetAssemblyInfoFromBin(asmBytes, asmInfo);
            }
            finally
            {
                AppDomain.Unload(tempDomain);
            }
        }
示例#12
0
        private void ConfigureAddin(AssemblyInformation addin)
        {
            Logger.Info(String.Format(Messages.ConfiguringAddin, addin));
            var setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.ConfigureDomain";
            setup.ApplicationBase = Environment.CurrentDirectory;
            AppDomain configureDomain = AppDomain.CreateDomain("ConfigureDomain", null, setup);

            try
            {
                Application app = (Application)configureDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName,
                                                                                       "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(configureDomain);
                ConfigAddin addinConfig = app.Resolve <ConfigAddin>();
                addinConfig.ConfigureAddin(addin);
            }
            finally
            {
                AppDomain.Unload(configureDomain);
            }
        }
示例#13
0
        internal void Run()
        {
            var setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.Inception";
            setup.ApplicationBase = Environment.CurrentDirectory;
            var domain = AppDomain.CreateDomain("Dover.AddIn", null, setup);

            domain.SetData("shutdownEvent", shutdownEvent); // Thread synchronization
            domain.SetData("assemblyName", asm.Name);       // Used to get current AssemblyName for logging and reflection
            domain.SetData("frameworkManager", frameworkAddinManager);
            Application app = (Application)domain.CreateInstanceAndUnwrap("Framework", "Dover.Framework.Application");

            SAPServiceFactory.PrepareForInception(domain);
            addinB1SResourceManager = app.Resolve <B1SResourceManager>();
            addinFormEventHandler   = app.Resolve <FormEventHandler>();
            addinLoader             = app.Resolve <AddinLoader>();
            eventDispatcher         = app.Resolve <EventDispatcher>();
            Sponsor <Application>        appSponsor       = new Sponsor <Application>(app);
            Sponsor <B1SResourceManager> b1sSponsor       = new Sponsor <B1SResourceManager>(addinB1SResourceManager);
            Sponsor <FormEventHandler>   formEventSponsor = new Sponsor <FormEventHandler>(addinFormEventHandler);
            Sponsor <AddinLoader>        loaderSponsor    = new Sponsor <AddinLoader>(addinLoader);
            Sponsor <EventDispatcher>    eventSponsor     = new Sponsor <EventDispatcher>(eventDispatcher);

            try
            {
                app.RunAddin();
                AppDomain.Unload(domain);
            }
            catch (AppDomainUnloadedException e)
            {
                // ignore and continue shutdown.
            }
            finally
            {
                runningAddins.Remove(this);
                runningAddinsHash.Remove(asm.Name);
            }
        }
示例#14
0
        private void ConfigureAddin(AssemblyInformation addin, string baseDirectory)
        {
            Logger.Info(String.Format(Messages.ConfiguringAddin, addin));
            var setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.ConfigureDomain";
            setup.ApplicationBase = baseDirectory;
            AppDomain configureDomain = AppDomain.CreateDomain("ConfigureDomain", null, setup);

            try
            {
                IApplication app = (IApplication)configureDomain.CreateInstanceAndUnwrap("Framework",
                                                                                         "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(configureDomain);
                IConfigAddin addinConfig = app.Resolve <IConfigAddin>();
                addinConfig.ConfigureAddin(addin.Name);
            }
            finally
            {
                AppDomain.Unload(configureDomain);
            }
        }
示例#15
0
        public int CompareTo(MenuAttribute other)
        {
            SAPbouiCOM.Application app = SAPServiceFactory.ApplicationFactory();

            bool thisExists  = app.Menus.Exists(this.FatherUID);
            bool otherExists = app.Menus.Exists(other.FatherUID);

            if (thisExists && !otherExists)
            {
                return(-1);
            }

            if (otherExists && !thisExists)
            {
                return(1);
            }

            if (this.FatherUID == other.FatherUID)
            {
                return(this.Position.CompareTo(other.Position));
            }

            return(this.UniqueID.CompareTo(other.UniqueID));
        }