/// <summary> /// Release the COM reference /// </summary> /// <param name="disposing"> /// <see langword="true"/> if this was called from the /// <see cref="IDisposable"/> interface. /// </param> private void Dispose(bool disposing) { if (null != _COMObject) { LOG.DebugFormat("Disposing {0}", _interceptType); if (Marshal.IsComObject(_COMObject)) { try { int count; do { count = Marshal.ReleaseComObject(_COMObject); LOG.DebugFormat("RCW count for {0} now is {1}", _interceptType, count); } while (count > 0); } catch (Exception ex) { LOG.WarnFormat("Problem releasing COM object {0}", _COMType); LOG.Warn("Error: ", ex); } } else { LOG.WarnFormat("{0} is not a COM object", _COMType); } _COMObject = null; } }
/// <summary> /// Get ImageFilenames from the IDataObject /// </summary> /// <param name="dataObject">IDataObject</param> /// <returns></returns> public static List <string> GetImageFilenames(IDataObject dataObject) { List <string> filenames = new List <string>(); string[] dropFileNames = (string[])dataObject.GetData(DataFormats.FileDrop); try { if (dropFileNames != null && dropFileNames.Length > 0) { foreach (string filename in dropFileNames) { string ext = Path.GetExtension(filename).ToLower(); if ((ext == ".jpg") || (ext == ".jpeg") || (ext == ".tiff") || (ext == ".gif") || (ext == ".png") || (ext == ".bmp") || (ext == ".ico") || (ext == ".wmf")) { filenames.Add(filename); } } } } catch (Exception ex) { LOG.Warn("Ignoring an issue with getting the dropFilenames from the clipboard: ", ex); } return(filenames); }
public void Unlock() { if (IsDisposed() || id == null) { return; } try { Zookeeper.Delete(id, -1); } catch (ThreadInterruptedException e) { Thread.CurrentThread.Interrupt(); } catch (KeeperException.NoNodeException e) { //do nothing } catch (KeeperException e) { LOG.Warn("Caught: " + e, e); throw; } finally { OnLockReleased(); id = null; } }
/// <summary> /// Reload the Ini file /// </summary> public static void Reload() { // Clear the current properties sections = new Dictionary <string, Dictionary <string, string> >(); // Load the defaults Read(CreateIniLocation(configName + DEFAULTS_POSTFIX + INI_EXTENSION)); // Load the normal Read(CreateIniLocation(configName + INI_EXTENSION)); // Load the fixed settings fixedProperties = Read(CreateIniLocation(configName + FIXED_POSTFIX + INI_EXTENSION)); foreach (IniSection section in sectionMap.Values) { try { section.Fill(PropertiesForSection(section)); FixProperties(section); } catch (Exception ex) { string sectionName = "unknown"; if (section != null && section.IniSectionAttribute != null && section.IniSectionAttribute.Name != null) { sectionName = section.IniSectionAttribute.Name; } LOG.WarnFormat("Problem reading the ini section {0}", sectionName); LOG.Warn("Exception", ex); } } }
/// <summary> /// Get the current "ClipboardOwner" but only if it isn't us! /// </summary> /// <returns>current clipboard owner</returns> private static string GetClipboardOwner() { string owner = null; try { IntPtr hWnd = User32.GetClipboardOwner(); if (hWnd != IntPtr.Zero) { IntPtr pid = IntPtr.Zero; IntPtr tid = User32.GetWindowThreadProcessId(hWnd, out pid); Process me = Process.GetCurrentProcess(); Process ownerProcess = Process.GetProcessById(pid.ToInt32()); // Exclude myself if (ownerProcess != null && me.Id != ownerProcess.Id) { // Get Process Name owner = ownerProcess.ProcessName; // Try to get the starting Process Filename, this might fail. try { owner = ownerProcess.Modules[0].FileName; } catch (Exception) { } } } } catch (Exception e) { LOG.Warn("Non critical error: Couldn't get clipboard owner.", e); } return(owner); }
public string getString(string key, string defvalue) { if (m_config.ContainsKey(key)) { return((string)m_config[key]); } LOG.Warn("getString, 找不到关键字[{0}], 将使用默认值[{1}]", key, defvalue); return(defvalue); }
public double getDouble(string key, double defvalue) { if (m_config.ContainsKey(key)) { return((double)m_config[key]); } LOG.Warn("getDouble, 找不到关键字[{0}], 将使用默认值[{1}]", key, defvalue); return(defvalue); }
public float getFloat(string key, float defvalue) { if (m_config.ContainsKey(key)) { return((float)m_config[key]); } LOG.Warn("getFloat, 找不到关键字[{0}], 将使用默认值[{1}]", key, defvalue); return(defvalue); }
public uint getUInt(string key, uint defvalue) { if (m_config.ContainsKey(key)) { return((uint)m_config[key]); } LOG.Warn("getUInt, 找不到关键字[{0}], 将使用默认值[{1}]", key, defvalue); return(defvalue); }
public char getChar(string key, char defvalue) { if (m_config.ContainsKey(key)) { return((char)m_config[key]); } LOG.Warn("getChar, 找不到关键字[{0}], 将使用默认值[{1}]", key, defvalue); return(defvalue); }
// 存在关键字为key的值,则返回,否则返回默认值defvalue public byte getByte(string key, byte defvalue) { if (m_config.ContainsKey(key)) { return((byte)m_config[key]); } LOG.Warn("getByte, 找不到关键字[{0}], 将使用默认值[{1}]", key, defvalue); return(defvalue); }
public bool getBool(string key, bool defvalue) { if (m_config.ContainsKey(key)) { return((bool)m_config[key]); } LOG.Warn("getBool, 找不到关键字[{0}], 将使用默认值[{1}]", key, defvalue); return(defvalue); }
/// <summary> /// Supply values we can't put as defaults /// </summary> /// <param name="property">The property to return a default for</param> /// <returns>object with the default value for the supplied property</returns> public override object GetDefault(string property) { switch (property) { case "PluginWhitelist": case "PluginBacklist": return(new List <string>()); case "OutputFileAsFullpath": if (IniConfig.IsPortable) { return(Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots\dummy.png")); } return(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "dummy.png")); case "OutputFilePath": if (IniConfig.IsPortable) { string pafOutputFilePath = Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots"); if (!Directory.Exists(pafOutputFilePath)) { try { Directory.CreateDirectory(pafOutputFilePath); return(pafOutputFilePath); } catch (Exception ex) { LOG.Warn(ex); // Problem creating directory, fallback to Desktop } } else { return(pafOutputFilePath); } } return(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); case "DWMBackgroundColor": return(Color.Transparent); case "ActiveTitleFixes": return(new List <string> { "Firefox", "IE", "Chrome" }); case "TitleFixMatcher": return(new Dictionary <string, string> { { "Firefox", " - Mozilla Firefox.*" }, { "IE", " - (Microsoft|Windows) Internet Explorer.*" }, { "Chrome", " - Google Chrome.*" } }); case "TitleFixReplacer": return(new Dictionary <string, string> { { "Firefox", "" }, { "IE", "" }, { "Chrome", "" } }); } return(null); }
// 设置key的值为val public bool setValue(string key, object val) { if (m_config.ContainsKey(key)) { m_config[key] = val; return(true); } LOG.Warn("setValue, 找不到关键字[{0}]", key); return(false); }
public void Call(AbstractDBQuery query, int index, string tableName = DBProxyDefault.DefaultTableName, DBOperateType type = DBProxyDefault.DefaultOperateType, DBCallback callback = null) { DBManagerPool dbPool = GetDbByTable(tableName, type); if (dbPool == null) { LOG.Warn("db call {0} failed:can not find table{1} type {2} db", query.GetCmd(), tableName, type.ToString()); return; } dbPool.Call(query, index, callback); }
public void Dispose() { try { action(); sentinel.Dispose(); } catch (Exception ex) { LOG.Warn("Error disposing {0} : {1}", this.GetType().FullName, ex.Message); } }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="stream"></param> public void OnResponse(uint id, MemoryStream stream) { Responser responser = null; if (ResponserList.TryGetValue(id, out responser)) { responser(stream); } else { LOG.Warn("{0} get battle {1} subId {2} unsupported package id {3}", Api.ServerName, MainId, SubId, id); } }
static NetworkHelper() { try { // Disable certificate checking ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); }; } catch (Exception ex) { LOG.Warn("An error has occured while allowing self-signed certificates:", ex); } }
public IHttpContext API(IHttpContext context) { LOG.Info("API server command received"); context.Response.ContentType = ContentType.TEXT; string responseText = "No valid API command received."; string command = context.Request.QueryString["command"] ?? ""; string force = context.Request.QueryString["force"] ?? "false"; if (!string.IsNullOrEmpty(command)) { LOG.Info($"Processing API command: {command}"); // Only process valid commands if (command == "ON" || command == "OFF") { // Check for deactivate API between certain times if (SettingsManager.ApiExcludedTimesEnabled && force.ToLower() == "false") { if ((DateTime.Now.TimeOfDay >= SettingsManager.ApiExcludeTimeStart.TimeOfDay && DateTime.Now.TimeOfDay <= SettingsManager.ApiExcludeTimeEnd.TimeOfDay) || ((SettingsManager.ApiExcludeTimeStart.TimeOfDay > SettingsManager.ApiExcludeTimeEnd.TimeOfDay) && ((DateTime.Now.TimeOfDay <= SettingsManager.ApiExcludeTimeStart.TimeOfDay && DateTime.Now.TimeOfDay <= SettingsManager.ApiExcludeTimeEnd.TimeOfDay) || (DateTime.Now.TimeOfDay >= SettingsManager.ApiExcludeTimeStart.TimeOfDay && DateTime.Now.TimeOfDay >= SettingsManager.ApiExcludeTimeEnd.TimeOfDay)))) { responseText = "API exclude times enabled and within time range."; LOG.Info($"Sending response: {responseText}"); context.Response.SendResponse(responseText); return(context); } } MainForm.ToggleCapture((MainForm.CaptureCommand)Enum.Parse(typeof(MainForm.CaptureCommand), command)); responseText = $"API command {command} completed successfully."; } if (command == "STATE") { responseText = $"{MainForm.IsScreenCaptureRunning()}"; } } else { LOG.Warn("API Command Empty / Invalid"); } LOG.Info($"Sending response: {responseText}"); context.Response.SendResponse(responseText); return(context); }
public override void Process(WatchedEvent @event) { base.Process(@event); if (@event.Type != EventType.None) { try { events.TryAdd(@event, TimeSpan.FromMilliseconds(10000)); } catch (ThreadInterruptedException) { LOG.Warn("ignoring interrupt during @event.put"); } } }
public void Process(WatchedEvent @event) { if (LOG.IsDebugEnabled) { LOG.Debug(string.Format("Watcher fired on path: {0} state: {1} type {2}", @event.Path, @event.State, @event.Type)); } try { writeLock.Lock(); } catch (Exception e) { LOG.Warn("Failed to acquire lock: " + e, e); } }
/// <summary> /// Get the OutputFormat for a filename /// </summary> /// <param name="fullPath">filename (can be a complete path)</param> /// <returns>OutputFormat</returns> public static OutputFormat FormatForFilename(string fullPath) { // Fix for bug 2912959 string extension = fullPath.Substring(fullPath.LastIndexOf(".") + 1); OutputFormat format = OutputFormat.png; try { format = (OutputFormat)Enum.Parse(typeof(OutputFormat), extension.ToLower()); } catch (ArgumentException ae) { LOG.Warn("Couldn't parse extension: " + extension, ae); } return(format); }
private String GetPresenceServiceUri(rlsservices services, String presList) { if (services == null || services.service == null || String.IsNullOrEmpty(presList)) { LOG.Warn("Invalid RLS document"); return(String.Empty); } String resourceList; // e.g.:http://doubango.org:8080/services/resource-lists/users/sip%3Amamadou%40colibria.com/index/~~/resource-lists/list%5B%40name%3D%22rcs%22%5D if (this.xcapDocumentsUris.ContainsKey(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID)) { resourceList = String.Format("{0}/~~/resource-lists/list%5B%40name%3D%22{1}%22%5D", this.xcapDocumentsUris[XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID], presList); } else { lock (this.xcapSelector) { this.xcapSelector.reset(); this.xcapSelector.setAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID) .setAttribute("list", "name", presList); resourceList = this.xcapSelector.getString(); } } foreach (serviceType service in services.service) { if (service.packages == null || String.IsNullOrEmpty(service.uri)) { continue; } String _resourceList = service.Item as String; if (!String.IsNullOrEmpty(_resourceList) && _resourceList.Equals(resourceList)) { if (service.packages.Packages.Contains("presence")) { return(service.uri); } } } return(String.Empty); }
/// <summary> /// Remove a tmpfile which was created by SaveNamedTmpFile /// Used e.g. by the email export /// </summary> /// <param name="tmpfile"></param> /// <returns>true if it worked</returns> public static bool DeleteNamedTmpFile(string tmpfile) { LOG.Debug("Deleting TMP File: " + tmpfile); try { if (File.Exists(tmpfile)) { File.Delete(tmpfile); tmpFileCache.Remove(tmpfile); } return(true); } catch (Exception ex) { LOG.Warn("Error deleting tmp file: ", ex); } return(false); }
/// <summary> /// Helper method to check if it is allowed to capture the process using GDI /// </summary> /// <param name="processName">Process owning the window</param> /// <returns>true if it's allowed</returns> public bool isGDIAllowed(Process process) { if (process != null) { if (NoGDICaptureForProduct != null && NoGDICaptureForProduct.Count > 0) { try { string productName = process.MainModule.FileVersionInfo.ProductName; if (productName != null && NoGDICaptureForProduct.Contains(productName.ToLower())) { return(false); } } catch (Exception ex) { LOG.Warn(ex); } } } return(true); }
public Image Apply(Image sourceImage, Matrix matrix) { using (WuQuantizer quantizer = new WuQuantizer((Bitmap)sourceImage)) { int colorCount = quantizer.GetColorCount(); if (colorCount > Colors) { try { return(quantizer.GetQuantizedImage(Colors)); } catch (Exception e) { LOG.Warn("Error occurred while Quantizing the image, ignoring and using original. Error: ", e); } } } return(null); }
public void UpdateLogList() { lock (LogList) { while (LogList[LogType.INFO].Count > 0) { try { string log = LogList[LogType.INFO].Dequeue(); LOG.Info(log); } catch (Exception e) { LOG.Error(e.ToString()); } } while (LogList[LogType.WARN].Count > 0) { try { string log = LogList[LogType.WARN].Dequeue(); LOG.Warn(log); } catch (Exception e) { LOG.Error(e.ToString()); } } while (LogList[LogType.ERROR].Count > 0) { try { string log = LogList[LogType.ERROR].Dequeue(); LOG.Error(log); } catch (Exception e) { LOG.Error(e.ToString()); } } } }
/// <summary> /// Get LastModified for a URI /// </summary> /// <param name="uri">Uri</param> /// <returns>DateTime</returns> public static DateTime GetLastModified(Uri uri) { try { HttpWebRequest webRequest = CreateWebRequest(uri); webRequest.Method = HTTPMethod.HEAD.ToString(); using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse()) { LOG.DebugFormat("RSS feed was updated at {0}", webResponse.LastModified); return(webResponse.LastModified); } } catch (Exception wE) { LOG.WarnFormat("Problem requesting HTTP - HEAD on uri {0}", uri); LOG.Warn(wE.Message); // Pretend it is old return(DateTime.MinValue); } }
/// <summary> /// Helper method to check if it is allowed to capture the process using DWM /// </summary> /// <param name="process">Process owning the window</param> /// <returns>true if it's allowed</returns> public static bool IsDwmAllowed(Process process) { if (process != null) { if (Configuration.NoDWMCaptureForProduct != null && Configuration.NoDWMCaptureForProduct.Count > 0) { try { string productName = process.MainModule.FileVersionInfo.ProductName; if (productName != null && Configuration.NoDWMCaptureForProduct.Contains(productName.ToLower())) { return(false); } } catch (Exception ex) { LOG.Warn(ex.Message); } } } return(true); }
private string GetSaveFileName(string prefix) { string path = string.Format("{0}{1}{2}", baseDir, DateTime.Now.ToString("yyyy_MM_dd"), "/"); try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } } catch (Exception e) { LOG.Warn("Could not create save directory for log/ See Logger.cs."); LOG.Error("{0}", e.ToString()); } string assemblyFullName = Assembly.GetExecutingAssembly().FullName; Int32 index = assemblyFullName.IndexOf(','); string dt = string.Format("{0}{1}", "", DateTime.Now.ToString("yyyy-MM-dd_HH_mm_ss")); return(string.Format("{0}{1}{2}{3}{4}", path, prefix, "_", dt, ".txt")); }