Пример #1
0
        static void Main()
        {
#if RELEASE
            try {
#endif
//		  System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ml-IN");
//		  System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ml-IN");

            // The application should be run in full trust mode; but just in case!
            System.Security.Permissions.EnvironmentPermission envPermission = new System.Security.Permissions.EnvironmentPermission(System.Security.Permissions.PermissionState.Unrestricted);
            envPermission.Demand();

            LoadRuntimeData();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
#if RELEASE
        }
        catch (Exception ex) {
            System.Security.Permissions.FileIOPermission ioperm = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.AllAccess, System.Security.AccessControl.AccessControlActions.Change, Utility.DEBUG_FILE_PATH);
            ioperm.Demand();
            using (FileStream fs = new FileStream(Utility.DEBUG_FILE_PATH, FileMode.Append, FileAccess.Write, FileShare.None)) {
                string debugMessage = "-------------------------------------------" + Environment.NewLine;
                debugMessage += DateTime.UtcNow.ToLongDateString() + " " + DateTime.UtcNow.ToLongTimeString() + " UTC" + Environment.NewLine + Environment.NewLine;
                debugMessage += ex.Message + Environment.NewLine;
                debugMessage += ex.StackTrace + Environment.NewLine + Environment.NewLine;
                byte[] buffer = System.Text.UTF8Encoding.UTF8.GetBytes(debugMessage);
                fs.Write(buffer, 0, buffer.Length);
                fs.Flush();
            }
            MessageBox.Show("An unhandled error has occured in SMOz. SMOz cannot continue.\n\nMore information is available in the file '" + Utility.DEBUG_FILE_PATH + "'. Please include the contents of that file when requesting support. Sorry about the inconvenience.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
#endif
        }
Пример #2
0
        public static void AddCheminServeur()
        {
            RegistryKey Nkey = Registry.LocalMachine;

            try
            {
                RegistryKey mesCles = Nkey.OpenSubKey(@"Software\PostgreSQL\Installations", false);
                if (mesCles != null)
                {
                    var      h     = 0;
                    String[] names = mesCles.GetSubKeyNames();
                    foreach (string n in names)
                    {
                        mesCles = Nkey.OpenSubKey(@"Software\PostgreSQL\Installations\" + n, false);
                        if (mesCles != null)
                        {
                            string chemin = (string)mesCles.GetValue("Base directory");
                            if (chemin != null)
                            {
                                string v_      = chemin + "\\bin";
                                string keyName = @"SYSTEM\CurrentControlSet\Control\Session Manager\Environment";
                                System.Security.Permissions.EnvironmentPermission permissions = new System.Security.Permissions.EnvironmentPermission(System.Security.Permissions.EnvironmentPermissionAccess.Write, "Path");
                                permissions.Demand();
                                string path_ = (string)Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
                                //Environment.SetEnvironmentVariable("Path", path_ + ";" + v_, EnvironmentVariableTarget.Machine);

                                using (RegistryKey regPath = Registry.LocalMachine.OpenSubKey(keyName, true))
                                {
                                    string path = (string)regPath.GetValue("Path", "", RegistryValueOptions.DoNotExpandEnvironmentNames);
                                    foreach (string v in path.Split(';'))
                                    {
                                        if (v.Trim().Equals((string)(v_).Trim(), StringComparison.OrdinalIgnoreCase))
                                        {
                                            return;
                                        }
                                    }
                                    regPath.SetValue("Path", path + ";" + v_, RegistryValueKind.ExpandString);
                                }
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception er)
            {
                Messages.Exception(er);
            }
            finally
            {
                Nkey.Close();
            }
        }
Пример #3
0
        static ConnectionBuilder()
        {
            if (SqlContext.IsAvailable)
            {
                System.Security.Permissions.EnvironmentPermission envPerm =
                    new System.Security.Permissions.EnvironmentPermission(System.Security.Permissions.PermissionState.Unrestricted);
                envPerm.Assert();

                string instanceName = getInstanceName();
                if (instanceName == "MSSQLSERVER")
                {
                    instanceName = null;
                }

                System.Security.CodeAccessPermission.RevertAll();

                System.Security.Permissions.SecurityPermission secPerm =
                    new System.Security.Permissions.SecurityPermission(System.Security.Permissions.PermissionState.Unrestricted);
                secPerm.Assert();

                GetDbName g = new GetDbName(
                    instanceName,
                    new ManualResetEvent(false));

                System.Threading.Thread t = new Thread(new ThreadStart(g.DoIt));
                //t.Name = "QueryParallelizer: ConnectionBuilder Loopback Database Name";
                t.Start();
                g.m.WaitOne();

                if (null != g.E)
                {
                    e = new Exception("Error in creating loopback connection", g.E);
                }
                else
                {
                    connectionString = g.sb.ConnectionString;
                }
            }
            else
            {
                connectionString = null;
            }
        }