Esempio n. 1
0
        static void Main()
        {
            string resource1 = "WiseGuysFrameWork2015.SkinSoft.VisualStyler.dll";
            string resource2 = "RaidTheCageCtrl.hasp_net_windows.dll";
            string resource4 = "WiseGuysFrameWork2015.Softgroup.NetResize.dll";

            EmbeddedAssemblyFrameWork.Load(resource1, "SkinSoft.VisualStyler.dll");

            EmbeddedAssembly2.Load(resource2, "hasp_net_windows.dll");
            EmbeddedDllClass.ExtractEmbeddedDlls("SocketTools9.Interop.dll", resourcesfromdll.gethandletoSocketTools());
            EmbeddedAssemblyFrameWork.Load(resource4, "Softgroup.NetResize.dll");

            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            // Creating a Global culture specific to our application.
            System.Globalization.CultureInfo cultureInfo =
                new System.Globalization.CultureInfo("en-GB");
            // Creating the DateTime Information specific to our application.
            System.Globalization.DateTimeFormatInfo dateTimeInfo =
                new System.Globalization.DateTimeFormatInfo();
            // Defining various date and time formats.
            dateTimeInfo.DateSeparator    = "/";
            dateTimeInfo.LongDatePattern  = "dd-MMM-yyyy";
            dateTimeInfo.ShortDatePattern = "dd-MMM-yy";
            dateTimeInfo.LongTimePattern  = "hh:mm:ss tt";
            dateTimeInfo.ShortTimePattern = "hh:mm tt";
            // Setting application wide date time format.
            cultureInfo.DateTimeFormat = dateTimeInfo;
            // Assigning our custom Culture to the application.
            Application.CurrentCulture            = cultureInfo;
            Thread.CurrentThread.CurrentCulture   = cultureInfo;
            Thread.CurrentThread.CurrentUICulture = cultureInfo;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            try
            {
                // put this in a try, because stopping the application from running result in an Exception... just let it :)
                Application.Run(new MainForm());
            }
            catch (Exception)
            {
            }
        }
Esempio n. 2
0
        public static void Initialize()
        {
            UnmanagedHandler = HandleUnmanagedException;

            //  var msvcr = Resources.msvcr120_x86;
            var gsl = Resources.gsl_x86;

            //  var cblas = Resources.cblas_x86;

            if (Environment.Is64BitProcess && IntPtr.Size == 8)
            {
                //msvcr = Resources.msvcr120_x64;
                gsl = Resources.gsl_x64;
                //    cblas = Resources.cblas_x64;
            }
            //else if (!Environment.Is64BitProcess && IntPtr.Size == 4)

            //else
            //  throw new Exception("Inconsistent system - IntPtr.Size and Environment.Is64BitProcess dont match");

            try
            {
                //       EmbeddedDllClass.ExtractEmbeddedDlls(GlobalConfig.msvcrDllName, msvcr);
                EmbeddedDllClass.ExtractEmbeddedDlls(GlobalConfig.gslDllName, gsl);
                //    EmbeddedDllClass.ExtractEmbeddedDlls(GlobalConfig.gslCblasDllName, cblas);
                //   System.Threading.Thread.Sleep(1000);
                NativeMethods.gsl_set_error_handler(UnmanagedHandler);
            }
            catch (Exception exception)
            {
                logger.Log("ExtractEmbeddedDlls failed", ErrorType.General, exception);
                try
                {
                    //  string msvcrTempPath = Path.Combine(Path.GetTempPath(), GlobalConfig.msvcrDllName);
                    var gslTempPath = Path.Combine(Path.GetTempPath(), GlobalConfig.gslDllName);
                    //  string cblasTempPath = Path.Combine(Path.GetTempPath(), GlobalConfig.gslCblasDllName);

                    //     File.WriteAllBytes(msvcrTempPath, msvcr);
                    // File.WriteAllBytes(cblasTempPath, cblas);
                    File.WriteAllBytes(gslTempPath, gsl);

                    //  var h0 = NativeMethods.LoadLibrary(msvcrTempPath);
                    //    var h1 = NativeMethods.LoadLibrary(cblasTempPath);
                    var h2 = NativeMethods.LoadLibrary(gslTempPath);

                    if (/*h0 == IntPtr.Zero || h1 == IntPtr.Zero ||*/ h2 == IntPtr.Zero)
                    {
                        throw new Win32Exception(
                                  $"{Strings.GSLInitializer_Initialize_Could_not_load_the_Computator_NET_modules_at_the_paths} '{gslTempPath}'{Environment.NewLine}.",
                                  new Win32Exception()); // Calls GetLastError
                    }

                    NativeMethods.gsl_set_error_handler(UnmanagedHandler);
                }
                catch (Exception exception2)
                {
                    logger.Log("LoadLibrary failed", ErrorType.General, exception2);
                    MessageBox.Show(
                        $"{Strings.Program_Main_Exception_during_startup}.{Environment.NewLine}ExtractEmbeddedDlls {Strings.Exception}:{Environment.NewLine}{exception}{Environment.NewLine}LoadLibrary {Strings.Exception}:{Environment.NewLine}{exception2}",
                        Strings.Error);
                }
            }
        }
Esempio n. 3
0
        public static void Initialize(IMessagingService messagingService)
        {
            UnmanagedHandler = HandleUnmanagedException;


            byte[] gsl;

            if (Environment.Is64BitProcess && IntPtr.Size == 8)
            {
                gsl = GlobalConfig.IsUnix
                    ? (GlobalConfig.IsMacOS ? Resources.libgsl_osx_amd64 : Resources.libgsl_amd64)
                    : Resources.gsl_x64;
            }
            else if (!Environment.Is64BitProcess && IntPtr.Size == 4)
            {
                gsl = GlobalConfig.IsUnix
                    ? (GlobalConfig.IsMacOS ? Resources.libgsl_osx_i686 : Resources.libgsl_i686)
                    : Resources.gsl_x86;
            }
            else
            {
                throw new PlatformNotSupportedException("Inconsistent operating system. Handles only 32 and 64 bit OS.");
            }

            var cblas = Environment.Is64BitProcess
                ? (GlobalConfig.IsMacOS ? Resources.libgslcblas_osx_amd64 : Resources.libgslcblas_amd64)
                : (GlobalConfig.IsMacOS ? Resources.libgslcblas_osx_i686 : Resources.libgslcblas_i686);

            try
            {
                EmbeddedDllClass.ExtractEmbeddedDlls(GlobalConfig.GslDllName, gsl);


                if (GlobalConfig.IsUnix)
                {
                    EmbeddedDllClass.ExtractEmbeddedDlls(GlobalConfig.GslCblasDllName, cblas);
                }

                switch (Settings.Default.CalculationsErrors)
                {
                case CalculationsErrors.ReturnNAN:
                    NativeMethods.gsl_set_error_handler_off();
                    break;

                case CalculationsErrors.ShowError:
                    NativeMethods.gsl_set_error_handler(UnmanagedHandler);
                    break;
                }
            }
            catch (Exception exception)
            {
                logger.Log("ExtractEmbeddedDlls failed", ErrorType.General, exception);
                try
                {
                    var gslTempPath = Path.Combine(Path.GetTempPath(), GlobalConfig.GslDllName);

                    File.WriteAllBytes(gslTempPath, gsl);

                    if (GlobalConfig.IsUnix)
                    {
                        var cblasTempPath = Path.Combine(Path.GetTempPath(), GlobalConfig.GslCblasDllName);
                        File.WriteAllBytes(cblasTempPath, cblas);

                        var h1 = NativeMethods.dlopen(cblasTempPath, NativeMethods.RTLD.RTLD_GLOBAL);
                        if (h1 == IntPtr.Zero)
                        {
                            throw new Win32Exception(
                                      $"{Strings.GSLInitializer_Initialize_Could_not_load_the_Computator_NET_modules_at_the_paths} '{cblasTempPath}'{Environment.NewLine}.",
                                      new Win32Exception()); // Calls GetLastError
                        }
                    }

                    var h2 = GlobalConfig.IsUnix ? NativeMethods.dlopen(gslTempPath, NativeMethods.RTLD.RTLD_GLOBAL) : NativeMethods.LoadLibrary(gslTempPath);

                    if (h2 == IntPtr.Zero)
                    {
                        throw new Win32Exception(
                                  $"{Strings.GSLInitializer_Initialize_Could_not_load_the_Computator_NET_modules_at_the_paths} '{gslTempPath}'{Environment.NewLine}.",
                                  new Win32Exception()); // Calls GetLastError
                    }

                    NativeMethods.gsl_set_error_handler(UnmanagedHandler);
                }
                catch (Exception exception2)
                {
                    var funcName = GlobalConfig.IsUnix ? "dlopen" : "LoadLibrary";
                    logger.Log($"{funcName} failed", ErrorType.General, exception2);
                    messagingService.Show(
                        $"{Strings.Program_Main_Exception_during_startup}.{Environment.NewLine}ExtractEmbeddedDlls {Strings.Exception}:{Environment.NewLine}{exception}{Environment.NewLine}{funcName} {Strings.Exception}:{Environment.NewLine}{exception2}",
                        Strings.Error);
                }
            }
        }