// Extracts and loads a resource with the base name into the same directory with the base output name public static void LoadUnmanagedLibrary(string resourceBaseName, string outFile) { if (s_loadedLibs.ContainsKey(resourceBaseName)) { return; } string resName = GetResourceName(resourceBaseName); if (!s_resourceList.Contains(resName)) { throw new Exception($"The native library {resourceBaseName} does not exist as an embedded resource."); } Stopwatch timer = Stopwatch.StartNew(); string outPath = Path.Combine(s_thisDir, outFile); try { WriteResourceStream(resName, outPath); } catch (Exception) { throw; } IntPtr handle = IntPtr.Zero; if (s_platform == PlatformOS.Windows) { handle = Kernel32.LoadLibrary(outPath); if (handle == IntPtr.Zero) { int err = Marshal.GetLastWin32Error(); string errstr = (new Win32Exception(err)).Message; throw new Exception(errstr); } } else { handle = Dl.Open(outPath, Dl.RTLD_NOW); if (handle == IntPtr.Zero) { IntPtr err = Dl.Error(); string errstr = Marshal.PtrToStringAuto(err); throw new Exception(errstr); } } if (s_loadedLibs.Count == 0) { // Unloads the libraries in the event of a crash (or the user forgets) AppDomain.CurrentDomain.ProcessExit += (sender, e) => UnloadLibraries(); } s_loadedLibs.Add(resourceBaseName, handle); s_libPaths.Add(resourceBaseName, outPath); LastLoadTime = timer.Elapsed; }
// Called when the process exits private static void Release() { // Release the handles foreach (var pair in s_loadedLibs) { if (s_platform == PlatformOS.Windows) { // Twice is needed Kernel32.FreeLibrary(pair.Value); Kernel32.FreeLibrary(pair.Value); } else { // Twice is needed Dl.Close(pair.Value); Dl.Close(pair.Value); } } // Delete the extracted files foreach (var path in s_libPaths) { File.Delete(path); } }
static bool TryLoadDl(string path) { try { return(Dl.TryLoadDl(path)); } catch (DllNotFoundException) { return(DlSo2.TryLoadDl(path)); } }
public void Merge(params DocumentStyle[] styles) { if (styles != null) { foreach (var style in styles) { Section.Merge(style.Section); Article.Merge(style.Article); Header.Merge(style.Header); Footer.Merge(style.Footer); Main.Merge(style.Main); Figure.Merge(style.Figure); Details.Merge(style.Details); Summary.Merge(style.Summary); Div.Merge(style.Div); Ul.Merge(style.Ul); Ol.Merge(style.Ol); Dl.Merge(style.Dl); Td.Merge(style.Td); Table.Merge(style.Table); Img.Merge(style.Img); YouTube.Merge(style.YouTube); Channel9.Merge(style.Channel9); H1.Merge(style.H1); H2.Merge(style.H2); H3.Merge(style.H3); H4.Merge(style.H4); H5.Merge(style.H5); H6.Merge(style.H6); BlockQuote.Merge(style.BlockQuote); P.Merge(style.P); FigCaption.Merge(style.FigCaption); Pre.Merge(style.Pre); Dt.Merge(style.Dt); Dd.Merge(style.Dd); Li.Merge(style.Li); A.Merge(style.A); Span.Merge(style.Span); Label.Merge(style.Label); Q.Merge(style.Q); Cite.Merge(style.Cite); I.Merge(style.I); Em.Merge(style.Em); Mark.Merge(style.Mark); Time.Merge(style.Time); Code.Merge(style.Code); Strong.Merge(style.Strong); } } }
protected void changePasswordPushButton_Click(object sender, EventArgs e) { DBLayare.Dl dataLayer = new Dl(); bool result = dataLayer.changePass((string)Session["UserName"], CurrentPassword.Text, NewPassword.Text); if (!result) { FailureText.Text = "رمز عبور تغییر نکرد"; } else { FailureText.Text = "عملیات با موفقیت انجام شد."; } }
public override int GetHashCode() { int hash = 1; if (L != 0D) { hash ^= L.GetHashCode(); } if (Dl != 0D) { hash ^= Dl.GetHashCode(); } if (Ddl != 0D) { hash ^= Ddl.GetHashCode(); } return(hash); }
protected void loginButton_Click(object sender, EventArgs e) { DBLayare.Dl dataLayerClass = new Dl(); var dataTable = dataLayerClass.systemLogin(UserName.Text, Password.Text); if (dataTable != null && dataTable.Rows.Count != 0) { Session.Add("UserName", UserName.Text); Session.Add("AccountId", Convert.ToDecimal(dataTable.Rows[0][3].ToString())); Session.Add("ClientFirstName", dataTable.Rows[0][0].ToString()); Session.Add("ClientLastName", dataTable.Rows[0][1].ToString()); Response.Redirect("~/main.aspx"); } else { Session.RemoveAll(); FailureText.Text = "شناسه کاربری و یا رمز اشتباه می باشد"; } }
private void Selection(Rectangle rect, Rectangle intersect, Dl func) { if (intersect.Size != rect.Size) { if (rect.Top < intersect.Top) { int dh = rect.Height - intersect.Height; func(rect.X, rect.Y, rect.Width, dh); if (rect.Left < intersect.Left) { func(rect.X, rect.Y + dh, rect.Width - intersect.Width, intersect.Height); } else if (rect.Right > intersect.Right) { func(rect.X + intersect.Width, rect.Y + dh, rect.Width - intersect.Width, intersect.Height); } } else if (rect.Bottom > intersect.Bottom) { func(rect.X, intersect.Bottom, rect.Width, rect.Height - intersect.Height); if (rect.Left < intersect.Left) { func(rect.X, rect.Y, rect.Width - intersect.Width, intersect.Height); } else if (rect.Right > intersect.Right) { func(intersect.Right, rect.Y, rect.Width - intersect.Width, intersect.Height); } } else if (rect.Left < intersect.Left) { func(rect.X, rect.Y, rect.Width - intersect.Width, rect.Height); } else { func(intersect.Right, rect.Y, rect.Width - intersect.Width, rect.Height); } } }
// Unloads all of the loaded libraries // Note that each library needs to be freed twice, since their use counter is increased by 2 by the use of // both the manual loader, as well as DllImport. If the count was not increased by 2, then the second call // is not dangerous. public static void UnloadLibraries() { if (s_loadedLibs.Count == 0) { return; } if (s_platform == PlatformOS.Windows) { foreach (var pair in s_loadedLibs) { Kernel32.FreeLibrary(pair.Value); Kernel32.FreeLibrary(pair.Value); } } else { foreach (var pair in s_loadedLibs) { Dl.Close(pair.Value); Dl.Close(pair.Value); } } foreach (var pair in s_libPaths) { try { // This will sometimes throw an exception for reasons unknown, take a look at this later File.Delete(pair.Value); } catch (Exception e) { Logger?.Invoke($"Unable to clean native library '{pair.Key}' at '{pair.Value}'."); Logger?.Invoke($" Reason: {e.Message}."); } } s_loadedLibs.Clear(); s_libPaths.Clear(); }
// Loads a function from the passed C library handle (see GetLibraryHandle()) public static T LoadFunction <T>(IntPtr library, string function) where T : Delegate { IntPtr handle = (s_platform == PlatformOS.Windows) ? Kernel32.GetProcAddress(library, function) : Dl.Symbol(library, function); return((handle == IntPtr.Zero) ? null : Marshal.GetDelegateForFunctionPointer(handle, typeof(T)) as T); }
// Extract the resource into the path and load it private static void ExtractAndLoad(string name) { var rName = GetResourceName(name); var rPath = Path.Combine(s_thisDir, $"{name}.nl"); // Extract using (var reader = s_this.GetManifestResourceStream(rName)) { using (var writer = File.Open(rPath, FileMode.Create, FileAccess.Write, FileShare.None)) { reader.CopyTo(writer); } } s_libPaths.Add(rPath); // Load var handle = (s_platform == PlatformOS.Windows) ? Kernel32.LoadLibrary(rPath) : Dl.Open(rPath, Dl.RTLD_NOW); s_loadedLibs.Add(name, handle); }