public DataLayer(ConnectionTypeConstants contype) { Debug.Print("DataLayer Initializing..."); WebPermission wp = new WebPermission(); wp.Demand(); switch (Configuration.DatabaseType.ToUpper().Trim()) { case "": case "MYSQL": qAdapter = new MySQLQueryAdapter(); break; case "SQL": case "SQL SERVER": qAdapter = new SQLServerQueryAdapter(); break; } Debug.Assert(qAdapter != null); // if (Configuration.PurgeLogOnStartup) // { String dbgfile = getDebugOutputFilepath(); if (File.Exists(dbgfile)) File.Delete(dbgfile); //} WriteDebugMessage("--DataLayer Initializing-" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "--"); DatabaseName = Configuration.DatabaseName; try { CurrentConString = buildConnectionString(contype); } catch (frmPasswordPrompt.CredentialsNotGivenException exx) { throw; } Debug.Print("Using ConnectionString:" + CurrentConString); //initialize our Type Manager. String[] lookfolders = new String[] { JobClockConfig.GetExportLibFolder()}; mtypemanager = new MultiTypeManager(lookfolders, new Type[] { typeof(BaseDataExporter) }, null, new Nullcallback(), null, new Assembly[] { Assembly.GetCallingAssembly() }); }
private static void GetPermissions() { if (!m_Initialized) { //test RelectionPermission CodeAccessPermission securityTest; try { securityTest = new ReflectionPermission(PermissionState.Unrestricted); securityTest.Demand(); m_ReflectionPermission = true; } catch { //code access security error m_ReflectionPermission = false; } //test WebPermission try { securityTest = new WebPermission(PermissionState.Unrestricted); securityTest.Demand(); m_WebPermission = true; } catch { //code access security error m_WebPermission = false; } //test WebHosting Permission (Full Trust) try { securityTest = new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted); securityTest.Demand(); m_AspNetHostingPermission = true; } catch { //code access security error m_AspNetHostingPermission = false; } m_Initialized = true; //Test for Unmanaged Code permission try { securityTest = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode); securityTest.Demand(); m_UnManagedCodePermission = true; } catch (Exception e) { m_UnManagedCodePermission = false; } } }
internal static void EnsureUrlConnectPermission(Uri url) { // WebPermission permission = new WebPermission(NetworkAccess.Connect, url.AbsoluteUri); permission.Demand(); }
private void DoSubmit() { try { using (new WaitCursor()) { if (!ValidateData()) return; m_statusBar.Text = "Submitting bug..."; WebPermission myWebPermission = new WebPermission(PermissionState.Unrestricted); myWebPermission.Demand(); string desc = m_descTextBox.Text; // if the exception was set, append the stack trace if (m_exception != null) { desc += "\n\n-----------------------------------\n"; desc += "Exception:\n"; desc += m_exception.ToString(); } // append versions of all modules desc += "\n\n-----------------------------------\n"; desc += "Modules:\n"; foreach (ProcessModule module in Process.GetCurrentProcess().Modules) { // Get version info FileVersionInfo fileVersionInfo = module.FileVersionInfo; if (fileVersionInfo.FileVersion == "") continue; desc += String.Format("{0} {1}\n", module.ModuleName, fileVersionInfo.FileVersion); } if (m_anonymous) { string dsc = "Reported by: " + m_txtEmail.Text + "\n" + desc; m_bugService.submitBug(m_mappingName, m_titleTextBox.Text, dsc, m_cmbPriority.SelectedIndex); } else { m_bugService.submitBug(m_mappingName, m_userTextBox.Text, m_passwordTextBox.Text, m_titleTextBox.Text, desc, m_cmbPriority.SelectedIndex); } Close(); } } catch(Exception ex) { m_statusBar.Text = "Bug not submitted."; MessageBox.Show("There were errors while submitting this bug\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
[SuppressMessage("Microsoft.Security", "CA2103:ReviewImperativeSecurity")] // WebPermission based on URI path, but path isn't gonna change during scope of Demand private void LoadSync() { Debug.Assert((uri == null || !uri.IsFile), "we only load streams"); // first make sure that any possible download ended if (!semaphore.WaitOne(LoadTimeout, false)) { if (copyThread != null) copyThread.Abort(); CleanupStreamData(); throw new TimeoutException(SR.GetString(SR.SoundAPILoadTimedOut)); } // if we have data, then we are done if (streamData != null) return; // setup the http stream if (uri != null && !uri.IsFile && stream == null) { WebPermission webPerm = new WebPermission(NetworkAccess.Connect, uri.AbsolutePath); webPerm.Demand(); WebRequest webRequest = WebRequest.Create(uri); webRequest.Timeout = LoadTimeout; WebResponse webResponse; webResponse = webRequest.GetResponse(); // now get the stream stream = webResponse.GetResponseStream(); } if (stream.CanSeek) { // if we can get data synchronously, then get it LoadStream(true); } else { // the data can't be loaded synchronously // load it async, then wait for it to finish doesLoadAppearSynchronous = true; // to avoid OnFailed call. LoadStream(false); if(!semaphore.WaitOne(LoadTimeout, false)) { if (copyThread != null) copyThread.Abort(); CleanupStreamData(); throw new TimeoutException(SR.GetString(SR.SoundAPILoadTimedOut)); } doesLoadAppearSynchronous = false; if (lastLoadException != null) { throw lastLoadException; } } // we don't need the worker copyThread anymore this.copyThread = null; }