System.Diagnostics.Debug.Assert(bool)

Here are the examples of the csharp api System.Diagnostics.Debug.Assert(bool) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

12000 Examples 7

19 View Source File : Database.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public IEnumerable<T> SelectObjects<T>(string tableName, string condition, string order, int group, params string[] columns)
			where T : new()
		{
			Debug.replacedert(group < columns.Length);
			string sql = MakeSelect(tableName, condition, columns, group, order);
			DataTable dt = InvokeTableQuery(sql, condition);
			foreach (DataRow row in dt.Rows)
				yield return DbConverter.Convert<T>(row);
		}

19 View Source File : Database.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public IEnumerable<T> SelectObjects<T>(string tableName, object condition, string order, int group, params string[] columns)
			where T: new()
		{
			Debug.replacedert(group < columns.Length);
			string sql = MakeSelect(tableName, condition, columns, group, order);
			DataTable dt = InvokeTableQuery(sql, condition);
			foreach (DataRow row in dt.Rows)
				yield return DbConverter.Convert<T>(row);
		}

19 View Source File : TextCaptureEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static string GetWindowUrl(IntPtr hWnd)
		{
			Debug.replacedert(hWnd != IntPtr.Zero);
			string processName = null;
			try
			{
				int pid;
				User32.GetWindowThreadProcessId(hWnd, out pid);
				if (pid > 0)
				{
					var p = Process.GetProcessById(pid);
					if (p != null)
						processName = p.ProcessName.ToLower();
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); }

			string url = null;
			switch (processName.ToLower())
			{
				case "chrome":
					url = GetChromeUrl(hWnd);
					break;
				case "opera":
					GetOperaUrl(hWnd);
					break;
				case "firefox":
					GetFirfoxUrl(hWnd);
					break;
				case "iexplore":
				case "explorer":
					url = GetIExploreUrl(hWnd);
					break;
				case "360se":
					url = Get360SeUrl(hWnd);
					break;
				case "maxthon":
					url = GetMaxthonUrl(hWnd);
					break;
				case "baidubrowser":
					url = GetBaiduUrl(hWnd);
					break;
				case "sogouexplorer":
					url = GetSogouUrl(hWnd);
					break;
				case "miniie":
					url = GetMiniIEUrl(hWnd);
					break;
				case "theworld":	// 世界之窗浏览器
					break;
				default:
					url = GetIExploreUrl(hWnd);		// try
					break;
			}
			return url;
		}

19 View Source File : PeriodTask.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private void ExecuteTask(Task task)
		{
			System.Diagnostics.Debug.replacedert(task != null);
			try
			{
				task.Action(task.Action.Target);
				task.LastEndTime = DateTime.Now;
			}
			catch (Exception ex)
			{
				TraceLogger.Instance.WriteException(ex);
				if (OnException != null)
				{
					try
					{
						OnException(this, new TaskExceptionArgs() { TaskName = task.Name, Target = task.Action.Target, Exception = ex });
					}
					catch (Exception) { }
				}
			}
		}

19 View Source File : CacheManager.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public void WriteSessionEnd(string sessionId)
		{
			///? Is WriteSessionEnd called right?
			try
			{
				string dir = Path.Combine(CachePath, sessionId);
				string rds = Path.Combine(dir, "0.rds");
				string rde = Path.Combine(dir, "0.rde");
				Debug.replacedert(Directory.Exists(dir));
				Debug.replacedert(File.Exists(rds));

				if (Directory.Exists(dir) && !File.Exists(rde))
					File.WriteAllText(rde, sessionId);
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
		}

19 View Source File : Database.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public IEnumerable<T> ReadObjects<T>(string tableName, object condition, string order, int group, params string[] columns)
			where T : new()
		{
			Debug.replacedert(group < columns.Length);
			T obj = new T();
			string sql = MakeSelect(tableName, condition, columns, group, order);
			DbDataReader rdr = InvokeReaderQuery(sql, condition);
			while (rdr.Read())
				yield return DataConverter.Convert<T>(rdr, ref obj);
		}

19 View Source File : Database.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public IEnumerable<T> SelectObjects<T>(string tableName, string condition, string order, int group, params string[] columns)
			where T : new()
		{
			Debug.replacedert(group < columns.Length);
			string sql = MakeSelect(tableName, condition, columns, group, order);
			DataTable dt = InvokeTableQuery(sql, condition);
			T obj = new T();
			foreach (DataRow row in dt.Rows)
				yield return DataConverter.Convert<T>(row, ref obj);
		}

19 View Source File : Database.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public IEnumerable<T> SelectObjects<T>(string tableName, object condition, string order, int group, params string[] columns)
			where T: new()
		{
			Debug.replacedert(group < columns.Length);
			string sql = MakeSelect(tableName, condition, columns, group, order);
			DataTable dt = InvokeTableQuery(sql, condition);
			T obj = new T();
			foreach (DataRow row in dt.Rows)
				yield return DataConverter.Convert<T>(row, ref obj);
		}

19 View Source File : SessionInfo.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public byte[] ToBinary()
		{
			Debug.replacedert(Domain.Length < byte.MaxValue && UserName.Length < byte.MaxValue && ClientName.Length < byte.MaxValue && ClientAddress.Length < byte.MaxValue);
			using (MemoryStream ms = new MemoryStream())
			using (BinaryWriter bw = new BinaryWriter(ms, Encoding.UTF8))
			{
				bw.Write(new byte[] { 1, 2, 6, 0 });
				bw.Write(new Guid(SessionId).ToByteArray());		// 16 bytes.
				bw.Write(CreateTime.ToBinary());					// 8 bytes.
				bw.Write(Domain);
				bw.Write(UserName);
				bw.Write(ClientName);
				bw.Write(ClientAddress);

				bw.Flush();
				return ms.ToArray();
			}
		}

19 View Source File : FileStorage.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public bool Exists(string fpath)
		{
			Debug.replacedert(!string.IsNullOrEmpty(fpath));
			fpath = fpath.TrimStart('/');
			bool exists = false;
			try
			{
				exists = _files.ContainsKey(fpath);
				if (!exists)
				{
					if (File.Exists(WebPackage))
					{
						using (FileStream fs = new FileStream(WebPackage, FileMode.Open, FileAccess.Read, FileShare.Read))
							exists = ZipStream.IsExists(fs, fpath);
					}
					else
					{
						// package not exists.
						using (MemoryStream fs = new MemoryStream(Resources.ResourceManager.GetObject("web") as byte[]))
							exists = ZipStream.IsExists(fs, fpath);
					}
				}
				if (exists)
				{
					if (!_files.ContainsKey(fpath))
						_files[fpath] = Guid.NewGuid().ToString();
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
			return exists;
		}

19 View Source File : FileStorage.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public byte[] Extract(string fpath)
		{
			Debug.replacedert(!string.IsNullOrEmpty(fpath));
			fpath = fpath.TrimStart('/');
			byte[] content = null;
			try
			{
				var fkey = _files[fpath] as string;
				content = _files.ContainsKey(fpath) ? _cache[fkey] as byte[] : null;
				if (content == null)
				{
					if (File.Exists(WebPackage))
					{
						using (FileStream fs = new FileStream(WebPackage, FileMode.Open, FileAccess.Read, FileShare.Read))
							content = ZipStream.Extract(fs, fpath);
					}
					else
					{
						// package not exists.
						using (MemoryStream fs = new MemoryStream(Resources.ResourceManager.GetObject("web") as byte[]))
							content = ZipStream.Extract(fs, fpath);
					}
					// file not exists in _cache.
					if (content != null)
					{
						string key = _files.ContainsKey(fpath) ? _files[fpath] as string : Guid.NewGuid().ToString();
						_cache[key] = content;
						_files[fpath] = key;
					}
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
			return content;
		}

19 View Source File : HttpResponse.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public void SendStaticFile(string fpath, byte[] bsFile)
		{
			Debug.replacedert(!string.IsNullOrEmpty(fpath));
			Debug.replacedert(bsFile != null && bsFile.Length > 0);
			
			SetExpires(0);
			Response.ContentType = ApacheMimeTypes.Get(Path.GetExtension(fpath));
			Response.ContentEncoding = Encoding.UTF8;
			
			SetDebugHeaders();
			if (Response.OutputStream.CanWrite)
			{
				Response.OutputStream.Write(bsFile, 0, bsFile.Length);
				Response.OutputStream.Flush();
			}
			//Response.Close();
		}

19 View Source File : HttpResponse.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public void SendErrorPage(int errCode, string errMsg)
		{
			Debug.replacedert(errCode > 0);

			byte[] bsMsg = Encoding.UTF8.GetBytes(errMsg);
			Response.StatusCode = errCode;
			Response.StatusDescription = errMsg;

			SetExpires(0);
			Response.ContentType = "text/plain";
			Response.ContentEncoding = Encoding.UTF8;

			SetDebugHeaders();
			Response.OutputStream.Write(bsMsg, 0, bsMsg.Length);
			Response.OutputStream.Flush();
			Response.Close();
		}

19 View Source File : JsonServiceHandler.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public void RegisterService(string svcName, object svcObject)
		{
			Debug.replacedert(!string.IsNullOrEmpty(svcName));
			Debug.replacedert(svcObject != null);

			_services[svcName] = svcObject;
		}

19 View Source File : JsonServiceHandler.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public void ProcessRequest(HttpRequest Request, HttpResponse Response)
		{
			try
			{
				string name = System.IO.Path.GetFileNameWithoutExtension(Request.Url.AbsolutePath);
				Debug.replacedert(_services.ContainsKey(name));
				var svc = _services[name];
				if (Request.QueryString.Count == 0)
				{
					// return proxy script of the service.
					var proxy = new JsonServiceScript(svc);
					string script = proxy.GenerateScript(name);
					Response.SendJsonScript(script, false);
				}
				else
				{
					// call method.
					string method = Request.QueryString["$method"] ?? Request.QueryString["$m"];
					MethodInfo mi = svc.GetType().GetMethod(method);
					if (mi != null)
					{
						try
						{
							if (Array.Exists(mi.GetCustomAttributes(false), a => a is RawRequestAttribute))
							{
								var result = mi.Invoke(svc, new object[] { Request });
								Response.SendJsonObject(result, Request.CanCompress);
							}
							else if (Array.Exists(mi.GetCustomAttributes(false), a => a is RawParametersAttribute))
							{
								var result = mi.Invoke(svc, new object[] { Request.Parameters });
								Response.SendJsonObject(result, Request.CanCompress);
							}
							else if (Array.Exists(mi.GetCustomAttributes(false), a => a is RawResponseAttribute))
							{
								mi.Invoke(svc, MakeInvokeParameters(mi, Request.Parameters, Response));
								Response.Close();
							}
							else
							{
								// json response.
								var result = mi.Invoke(svc, MakeInvokeParameters(mi, Request.Parameters));
								Response.SendJsonObject(result, Request.CanCompress);
							}
						}
						catch (Exception ex)
						{
							TraceLogger.Instance.WriteLineError(string.Format(@"Service Exception at: {0}::{1}", svc, method));
							TraceLogger.Instance.WriteException(ex.InnerException == null ? ex : ex.InnerException); throw;
						}
					}
					else
						throw new NotImplementedException("Service method not found: " + method);
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
		}

19 View Source File : ImageCompressEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static Image ShortColorImage(Image srcImage)
		{
			Debug.replacedert(srcImage != null && srcImage.PixelFormat == PixelFormat.Format32bppArgb);
			Bitmap bmp = new Bitmap(srcImage.Width, srcImage.Height, PixelFormat.Format16bppRgb555);
			using (Graphics g = Graphics.FromImage(bmp))
			{
				g.DrawImage(srcImage, 0, 0);
			}
			return bmp;
		}

19 View Source File : ImageCompressEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static Image GrayScaleImage(Image srcImage)
		{
			try
			{
				int width = srcImage.Width;
				int height = srcImage.Height;
				Rectangle rect = new Rectangle(0, 0, width, height);

				Bitmap newBmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed) { Palette = GrayScalePalette };
				using (Bitmap srcBmp = new Bitmap(width, height, PixelFormat.Format32bppArgb))
				{
					using (Graphics g = Graphics.FromImage(srcBmp))
						g.DrawImage(srcImage, 0, 0);

					BitmapData srcData = srcBmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
					BitmapData newData = newBmp.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
					Debug.replacedert(srcData.Stride > 0);
					Debug.replacedert(newData.Stride > 0);
					int srcStride = srcData.Stride;
					int newStride = newData.Stride;
					unsafe
					{
						byte* pSrc = (byte*)srcData.Scan0.ToPointer();
						byte* pNew = (byte*)newData.Scan0.ToPointer();
						Argb* ps;
						byte* pn;
						for (int y = 0; y < height; ++y)
						{
							ps = (Argb*)(pSrc + (srcStride * y));
							pn = (byte*)(pNew + (newStride * y));
							for (int x = 0; x < width; ++x)
							{
								Argb color = *ps;
								*pn = (byte)((color.red * 0.299) + (color.green * 0.587) + (color.blue * 0.114) + 0.5);
								++ps;
								++pn;
							}
						}
					}
					srcBmp.UnlockBits(srcData);
					newBmp.UnlockBits(newData);
				}
				return newBmp;
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
		}

19 View Source File : ImageCompressEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static Image TransparentColorImage(Image bgImage, Image srcImage, float ratio)
		{
			Debug.replacedert(srcImage != null && srcImage.PixelFormat == PixelFormat.Format16bppRgb555);
			Debug.replacedert(bgImage != null && bgImage.PixelFormat == PixelFormat.Format16bppRgb555);
			Debug.replacedert(srcImage.Width == bgImage.Width && srcImage.Height == bgImage.Height);
			Debug.replacedert(0 < ratio && ratio < 1);

			Image newImage = null;
			try
			{
				int width = bgImage.Width;
				int height = bgImage.Height;
				Rectangle rect = new Rectangle(0, 0, width, height);
				long diffMax = (int)(width * height * ratio);
				long diffCount = 0;

				Bitmap newBmp = new Bitmap(width, height, PixelFormat.Format16bppArgb1555);
				using (Bitmap srcBmp = new Bitmap(srcImage))
				using (Bitmap bgBmp = new Bitmap(bgImage))
				{
					BitmapData srcData = srcBmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format16bppRgb555);
					BitmapData bgData = bgBmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format16bppRgb555);
					BitmapData newData = newBmp.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);
					Debug.replacedert(srcData.Stride == bgData.Stride && srcData.Stride == newData.Stride);
					int stride = srcData.Stride;
					unsafe
					{
						byte* pSrc = (byte*)srcData.Scan0.ToPointer();
						byte* pBkg = (byte*)bgData.Scan0.ToPointer();
						byte* pNew = (byte*)newData.Scan0.ToPointer();
						ushort* ps, pg, pn;
						for (int y = 0; y < height; ++y)
						{
							ps = (ushort*)(pSrc + (stride * y));
							pg = (ushort*)(pBkg+ (stride * y));
							pn = (ushort*)(pNew + (stride * y));
							for (int x = 0; x < width; ++x)
							{
								//if (0 == *ps)
								//    *pn = (ushort)(*ps | 0x8000);
								//else
									*pn = (ushort)((*pg == *ps) ? 0 : (*ps | 0x8000));
								++ps;
								++pg;
								++pn;

								diffCount += ((*pg == *ps) ? 0 : 1);
							}
							if (diffCount >= diffMax)
								break;
						}
					}
					srcBmp.UnlockBits(srcData);
					bgBmp.UnlockBits(bgData);
					newBmp.UnlockBits(newData);
				}

				if (diffCount < diffMax)
				{
					//newBmp.MakeTransparent(Color.Empty);
					newImage = newBmp;
				}
				else
				{
					newBmp.Dispose();
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
			return newImage;
		}

19 View Source File : ImageCompressEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static byte[] XorGrayscaleImage(Image bgImage, Image srcImage, float ratio)
		{
			Debug.replacedert(srcImage != null && srcImage.PixelFormat == PixelFormat.Format8bppIndexed);
			Debug.replacedert(bgImage != null && bgImage.PixelFormat == PixelFormat.Format8bppIndexed);
			Debug.replacedert(srcImage.Width == bgImage.Width && srcImage.Height == bgImage.Height);
			Debug.replacedert(0 < ratio && ratio < 1);

			byte[] bsXor = null;
			try
			{
				int width = bgImage.Width;
				int height = bgImage.Height;
				Rectangle rect = new Rectangle(0, 0, width, height);
				long diffMax = (int)(width * height * ratio);
				long diffCount = 0;

				using (Bitmap srcBmp = new Bitmap(srcImage))
				using (Bitmap bkgBmp = new Bitmap(bgImage))
				using (Bitmap newBmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed))
				{
					BitmapData srcData = srcBmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
					BitmapData bkgData = bkgBmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
					BitmapData newData = newBmp.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
					Debug.replacedert(srcData.Stride == bkgData.Stride && srcData.Stride == newData.Stride);
					Debug.replacedert(srcData.Stride % 4 == 0);
					int stride = srcData.Stride;
					unsafe
					{
						byte* pSrc = (byte*)srcData.Scan0.ToPointer();
						byte* pBkg = (byte*)bkgData.Scan0.ToPointer();
						byte* pNew = (byte*)newData.Scan0.ToPointer();
						uint* ps, pg, pn;
						for (int y = 0; y < height; ++y)
						{
							ps = (uint*)(pSrc + (stride * y));
							pg = (uint*)(pBkg + (stride * y));
							pn = (uint*)(pNew + (stride * y));
							for (int x = 0; x < width; x += 4)
							{
								*pn = *pg ^ *ps;
								++ps;
								++pg;
								++pn;

								diffCount += ((*pg == *ps) ? 0 : 4);
							}
							if (diffCount >= diffMax)
								break;
						}
					}
					if (diffCount < diffMax)
					{
						bsXor = new byte[newData.Stride * newData.Height];
						Marshal.Copy(newData.Scan0, bsXor, 0, bsXor.Length);
					}
					srcBmp.UnlockBits(srcData);
					bkgBmp.UnlockBits(bkgData);
					newBmp.UnlockBits(newData);
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
			return bsXor;
		}

19 View Source File : ImageCompressEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static Image CombineGrayscaleXor(Image srcImage, byte[] bsXor)
		{
			Debug.replacedert(srcImage != null && srcImage.PixelFormat == PixelFormat.Format8bppIndexed);
			Image newImage = null;
			try
			{
				int width = srcImage.Width;
				int height = srcImage.Height;
				Rectangle rect = new Rectangle(0, 0, width, height);

				Bitmap srcBmp = new Bitmap(srcImage);
				srcBmp.Palette = GrayScalePalette;
				BitmapData srcData = srcBmp.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
				Debug.replacedert(srcData.Stride * srcData.Height == bsXor.Length);
				Debug.replacedert(srcData.Stride % 4 == 0);
				int stride = srcData.Stride;
				unsafe
				{
					fixed (byte* pXor = bsXor)
					{
						byte* pSrc = (byte*)srcData.Scan0.ToPointer();
						uint* ps, px;
						for (int y = 0; y < height; ++y)
						{
							ps = (uint*)(pSrc + (stride * y));
							px = (uint*)(pXor + (stride * y));
							for (int x = 0; x < width; x += 4)
							{
								*ps = (*ps ^ *px);
								++ps;
								++px;
							}
						}
					}
				}
				srcBmp.UnlockBits(srcData);
				newImage = srcBmp;
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
			return newImage;
		}

19 View Source File : ImageCompressEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static Image TransparentImage8(Image bgImage, Image srcImage, float ratio)
		{
			Debug.replacedert(srcImage != null && srcImage.PixelFormat == PixelFormat.Format8bppIndexed);
			Debug.replacedert(bgImage != null && bgImage.PixelFormat == PixelFormat.Format8bppIndexed);
			Debug.replacedert(srcImage.Width == bgImage.Width && srcImage.Height == bgImage.Height);
			Debug.replacedert(0 < ratio && ratio < 1);

			Image newImage = null;
			try
			{
				int width = bgImage.Width;
				int height = bgImage.Height;
				Rectangle rect = new Rectangle(0, 0, width, height);
				long diffMax = (int)(width * height * ratio);
				long diffCount = 0;

				Bitmap newBmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
				newBmp.Palette = srcImage.Palette;
				using (Bitmap srcBmp = new Bitmap(srcImage))
				using (Bitmap bkgBmp = new Bitmap(bgImage))
				{
					BitmapData srcData = srcBmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
					BitmapData bkgData = bkgBmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
					BitmapData newData = newBmp.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
					unsafe
					{
						byte* pSrc = (byte*)srcData.Scan0.ToPointer();
						byte* pBkg = (byte*)bkgData.Scan0.ToPointer();
						byte* pNew = (byte*)newData.Scan0.ToPointer();
						byte* ps, pg, pn;
						for (int y = 0; y < height; ++y)
						{
							ps = pSrc + (y * srcData.Stride);
							pg = pBkg + (y * bkgData.Stride);
							pn = pNew + (y * newData.Stride);
							for (int x = 0; x < width; ++x)
							{
								if (0 == *ps)
									*pn = 0xFF;
								else
									*pn = (byte)((*pg == *ps) ? 0 : *ps);
								++ps;
								++pg;
								++pn;

								diffCount += ((*pg == *ps) ? 0 : 1);
							}
							if (diffCount >= diffMax)
								break;
						}
					}
					srcBmp.UnlockBits(srcData);
					bkgBmp.UnlockBits(bkgData);
					newBmp.UnlockBits(newData);
				}

				if (diffCount < diffMax)
				{
					newBmp.MakeTransparent(Color.Empty);
					newImage = newBmp;
				}
				else
				{
					newBmp.Dispose();
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
			return newImage;
		}

19 View Source File : ImageCompressEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static Image _TransparentImage8(Image bgImage, Image srcImage, float ratio, out bool transparent)
		{
			Debug.replacedert(srcImage != null && srcImage.PixelFormat == PixelFormat.Format8bppIndexed);
			Debug.replacedert(bgImage != null && bgImage.PixelFormat == PixelFormat.Format8bppIndexed);
			Debug.replacedert(srcImage.Width == bgImage.Width && srcImage.Height == bgImage.Height);
			Debug.replacedert(0 < ratio && ratio < 1);

			transparent = false;
			Image newImage = srcImage;
			try
			{
				int width = bgImage.Width;
				int height = bgImage.Height;
				Rectangle rect = new Rectangle(0, 0, width, height);
				long diffMax = (int)(width * height * ratio);
				long diffCount = 0;

				Bitmap newBmp = new Bitmap(srcImage);
				using (Bitmap bgBmp = new Bitmap(bgImage))
				{
					BitmapData bgData = bgBmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
					BitmapData newData = newBmp.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
					unsafe
					{
						byte* pBkg = (byte*)bgData.Scan0.ToPointer();
						byte* pNew = (byte*)newData.Scan0.ToPointer();
						byte* pg = pBkg;
						byte* pn = pNew;
						for (int y = 0; y < height; ++y)
						{
							pg = pBkg + (y * bgData.Stride);
							pn = pNew + (y * newData.Stride);
							for (int x = 0; x < width; ++x)
							{
								diffCount += ((*pg == *pn) ? 0 : 1);
								if (0 == *pn)
									*pn = 1;
								else
									*pn = (byte)((*pg == *pn) ? 0 : *pn);
								++pg;
								++pn;
							}
							if (diffCount >= diffMax)
								break;
						}
					}
					newBmp.UnlockBits(newData);
					bgBmp.UnlockBits(bgData);
				}

				if (diffCount < diffMax)
				{
					newBmp.MakeTransparent(Color.Empty);
					newImage = newBmp;
					transparent = true;
				}
				else
				{
					newBmp.Dispose();
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
			return newImage;
		}

19 View Source File : UserPolicy.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private static bool ContainsADGroup(string[] groups)
		{
			bool contains = false;
			Debug.replacedert(groups != null);
			foreach (var g in groups)
			{
				if (g.Contains(@"\"))
				{
					var domain = g.Substring(0, g.IndexOf('\\'));
					if (!string.Equals(domain, DomainUser.CurrentDomain, StringComparison.OrdinalIgnoreCase))
					{
						contains = true;
						break;
					}
				}
			}
			return contains;
		}

19 View Source File : ImageCompressor.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private byte[] CompressImageData(string ssid, Bitmap bmp, out bool isBackground)
		{
			byte[] bsData;
			isBackground = true;
			try
			{
				int width = bmp.Width;
				int height = bmp.Height;
				bool indexed = (bmp.PixelFormat == PixelFormat.Format8bppIndexed);
				byte[] data = ImageCompressEngine.ExtractImageData(bmp);

				if (_background != null)
				{
					if (width == _background.Width && height == _background.Height || indexed != _background.IsIndexed)
					{
						Debug.replacedert(_background.Data.Length == data.Length);
						float diff = ImageCompressEngine.XorImageData(_background.Data, 0, data, 0, _background.Data.Length);
						if (diff < _ratio)
						{
							bsData = Compress.Deflate(data, true);
							isBackground = false;
						}
						else
						{
							data = ImageCompressEngine.ExtractImageData(bmp);
							UpdateBackground(ssid, width, height, indexed, data);
							bsData = Compress.Deflate(data, true);
						}
					}
					else
					{
						UpdateBackground(ssid, width, height, indexed, data);
						bsData = Compress.Deflate(data, true);
					}
				}
				else
				{
					UpdateBackground(ssid, width, height, indexed, data);
					bsData = Compress.Deflate(data, true);
				}
			}
			catch (Exception ex)
			{
				bsData = null;
				TraceLogger.Instance.WriteException(ex);
				throw;
			}
			return bsData;
		}

19 View Source File : CompressStorage.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private void CompressImageData(Snapshot sshot)
		{
			Debug.replacedert(sshot.ImageData != null && sshot.ImageData.Length > 0);
			Debug.replacedert(sshot.BackgroundId == null);
			try
			{
				Image img = null;
				using (MemoryStream ms = new MemoryStream(sshot.ImageData))
					img = Image.FromStream(ms);
				Debug.replacedert(img.PixelFormat != PixelFormat.Format8bppIndexed);

				if (_backgroundImage == null)
				{
					_backgroundId = sshot.SnapshotId;
					_backgroundImage = img;
				}
				else
				{
					Debug.replacedert(_backgroundImage != null && _backgroundImage != img);
					Debug.replacedert(_backgroundImage.PixelFormat == img.PixelFormat);

					Rectangle rc = CompareImageDifference(_backgroundImage, img);
					if (rc.Width * rc.Height * 100 / img.Width * img.Height > 80)
					{
						// change background.
						_backgroundId = sshot.SnapshotId;
						_backgroundImage = img;
					}
					else
					{
						// clip
						Bitmap bmp = new Bitmap(rc.Width, rc.Height);
						using (Graphics g = Graphics.FromImage(bmp))
						{
							g.DrawImage(img, 0, 0, rc, GraphicsUnit.Pixel);
						}
						sshot.BackgroundId = _backgroundId;
						sshot.WindowRect = rc;
						using (MemoryStream ms = new MemoryStream())
						{
							bmp.Save(ms, ImageFormat.Png);
							sshot.ImageData = ms.ToArray();
						}
					}
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
		}

19 View Source File : CompressStorage.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private Rectangle CompareImageDifference(Image src, Image dst)
		{
			Debug.replacedert(src != null && dst != null);
			Debug.replacedert(src.Width == dst.Width && src.Height == dst.Height);
			Debug.replacedert(src.PixelFormat == dst.PixelFormat);

			int width = src.Width;
			int height = src.Height;
			Rectangle rect = new Rectangle(0, 0, width, height);
			try
			{
				int minX = -1, maxX = -1, minY = -1, maxY = -1;
				Bitmap b0 = new Bitmap(src);
				BitmapData d0 = b0.LockBits(rect, ImageLockMode.ReadOnly, src.PixelFormat);
				Bitmap b1 = new Bitmap(dst);
				BitmapData d1 = b1.LockBits(rect, ImageLockMode.ReadOnly, dst.PixelFormat);
				unsafe
				{
					int* p0 = (int*)d0.Scan0;
					int* p1 = (int*)d1.Scan0;
					int offset = 0;
					for (int y = 0; y < height; ++y)
					{
						for (int x = 0; x < width; ++x)
						{
							offset = width * y + x;
							if ((*(p0 + offset)) != (*(p1 + offset)))
							{
								minX = minX < 0 ? x : (x < minX ? x : minX);
								maxX = maxX < 0 ? x : (x > maxX ? x : maxX);
								minY = minY < 0 ? y : (y < minY ? y : minY);
								maxY = maxY < 0 ? y : (y > maxY ? y : maxY);
							}
						}
					}
				}
				b0.UnlockBits(d0);
				b1.UnlockBits(d1);

				minX = minX < 0 ? 0 : minX;
				maxX = maxX < 0 ? 0 : maxX;
				minY = minY < 0 ? 0 : minY;
				maxY = maxY < 0 ? 0 : maxY;
				Debug.replacedert(minX <= maxX && minY <= maxY);

				rect.X = minX;
				rect.Y = minY;
				rect.Width = (maxX == minX) ? 1 : (maxX - minX);
				rect.Height = (maxY == minY) ? 1 : (maxY - minY);
				Debug.replacedert(0 <= rect.X && rect.X < width && 0 <= rect.Y && rect.Y < height);
				Debug.replacedert(rect.Width > 0 && rect.Height > 0);
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); }
			return rect;
		}

19 View Source File : StatisticService.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public object[] HostVisit(DateTime start, DateTime end, string user)
		{
			Debug.replacedert(!string.IsNullOrEmpty(user));
			StringBuilder filter = new StringBuilder();
			filter.AppendFormat(" '{0:yyyy-MM-dd}'<=SessionDate AND SessionDate<='{1:yyyy-MM-dd}' ", start, end);
			filter.AppendFormat(" AND Domain='{0}'", user.Contains(@"\") ? user.Split('\\')[0] : Environment.MachineName);
			filter.AppendFormat(" AND UserName='{0}'", user.Contains(@"\") ? user.Split('\\')[1] : user);
			filter.AppendFormat(" AND UrlHost NOT LIKE '_:'");

			var groups = Database.Execute(db => db.ReadObjects<SnapGroup>("StatisticView", filter.ToString(), null, 4,
					"Domain", "UserName", "SessionDate", "UrlHost", "Sum(SnapCount) AS SnapCount"));

			List<object> array = new List<object>();
			foreach (var g in groups)
			{
				if (string.IsNullOrEmpty(g.UrlHost))
					continue;
				array.Add(new
					{
						User = g.User,
						Date = g.SessionDate,
						Host = g.UrlHost,
						Count = g.SnapCount,
					});
			}
			return array.ToArray();
		}

19 View Source File : _CompressEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private Rectangle CompareImage(Image src, Image dst)
		{
			Debug.replacedert(src != null && dst != null);
			Debug.replacedert(src.Width == dst.Width && src.Height == dst.Height);
			Debug.replacedert(src.PixelFormat == dst.PixelFormat);

			int width = src.Width;
			int height = src.Height;
			Rectangle rect = new Rectangle(0, 0, width, height);

			int minX = -1, maxX = -1, minY = -1, maxY = -1;
			Bitmap b0 = new Bitmap(src);
			BitmapData d0 = b0.LockBits(rect, ImageLockMode.ReadOnly, src.PixelFormat);
			Bitmap b1 = new Bitmap(dst);
			BitmapData d1 = b1.LockBits(rect, ImageLockMode.ReadOnly, dst.PixelFormat);
			unsafe
			{
				int* p0 = (int*)d0.Scan0;
				int* p1 = (int*)d1.Scan0;
				int offset = 0;
				for (int y = 0; y < height; ++y)
				{
					for (int x = 0; x < width; ++x)
					{
						offset = width * y + x;
						if ((*(p0 + offset)) != (*(p1 + offset)))
						{
							minX = minX < 0 ? x : (x < minX ? x : minX);
							maxX = maxX < 0 ? x : (x > maxX ? x : maxX);
							minY = minY < 0 ? y : (y < minY ? y : minY);
							maxY = maxY < 0 ? y : (y > maxY ? y : maxY);
						}
					}
				}
				minX = minX < 0 ? 0 : minX;
				maxX = maxX < 0 ? 0 : maxX;
				minY = minY < 0 ? 0 : minY;
				maxY = maxY < 0 ? 0 : maxY;
				Debug.replacedert(minX <= maxX && minY <= maxY);
			}
			b0.UnlockBits(d0);
			b1.UnlockBits(d1);

			rect.X = minX;
			rect.Y = minY;
			rect.Width = maxX - minX;
			rect.Height = maxY - minY;
			return rect;
		}

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static T Convert<T>(NameValueCollection vals, object obj = null)
		{
			if (obj == null)
				obj = System.Activator.CreateInstance<T>();
			Debug.replacedert(obj is T);
			return (T)StructFromValues(obj, (s) => vals[s], true, false);
		}

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private static object StructFromString(string str, Type type)
		{
			Debug.replacedert(!string.IsNullOrEmpty(str));
			Debug.replacedert(type.IsValueType);

			var flds = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (flds.Length > 0)
			{
				object result = System.Activator.CreateInstance(type);
				string[] vals = str.Split(FieldSeparator);
				for (int i = 0; i < flds.Length && i < vals.Length; ++i)
				{
					object v = ObjectFromString(vals[i], flds[i].FieldType);
					flds[i].SetValue(result, v);
				}
				return result;
			}
			else
			{
				return System.Convert.ChangeType(str, type);
			}
		}

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private static string StructToString(object obj)
		{
			Debug.replacedert(obj != null);
			Debug.replacedert(obj.GetType().IsValueType);

			var flds = obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (flds.Length > 0)
			{
				StringBuilder sb = new StringBuilder();
				foreach (var fld in flds)
				{
					sb.Append(ObjectToString(fld.GetValue(obj)));
					sb.Append(FieldSeparator);
				}
				return sb.ToString().TrimEnd(FieldSeparator);
			}
			else
			{
				return obj.ToString();
			}
		}

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private static object ArrayFromString(string str, Type type)
		{
			Debug.replacedert(!string.IsNullOrEmpty(str));
			Debug.replacedert(type.IsArray);

			string[] vals = str.Split(new char[] { ArraySeparator });
			var list = new System.Collections.ArrayList(vals.Length);
			var t = type.GetElementType();
			for (int i = 0; i < vals.Length; ++i)
				list.Add(ObjectFromString(vals[i], t));
			return list.ToArray(t);
		}

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private static string ArrayToString(object objs)
		{
			Debug.replacedert(objs != null);
			Debug.replacedert(objs.GetType().IsArray);

			StringBuilder sb = new StringBuilder();
			foreach (var obj in (Array)objs)
			{
				sb.Append(ObjectToString(obj));
				sb.Append(ArraySeparator);
			}
			return sb.ToString().TrimEnd(ArraySeparator);
		}

19 View Source File : DebugLog.cs
License : GNU General Public License v3.0
Project Creator : aiportal

[Conditional("DEBUG")]
		public static void replacedert(bool condition) { Debug.replacedert(condition); }

19 View Source File : ResponseExtension.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static void SendErrorPage(this HttpListenerResponse resp, int errCode, string errMsg)
		{
			Debug.replacedert(errCode > 0);

			byte[] bsMsg = Encoding.UTF8.GetBytes(errMsg);
			resp.StatusCode = errCode;
			resp.StatusDescription = errMsg;

			SetExpireTime(resp, 0);
			WriteFileContent(resp, bsMsg, "text/plain", false);
		}

19 View Source File : IPAddressRange.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static bool TryParse(string strRange, out IPAddressRange range)
		{
			range = null;
			if (string.IsNullOrEmpty(strRange))
				return false;

			string[] ss = strRange.Split('-');
			if (ss.Length == 2)
			{
				IPAddress ip1, ip2;
				if (IPAddress.TryParse(ss[0], out ip1) && IPAddress.TryParse(ss[1], out ip2))
				{
					Debug.replacedert(ip1.AddressFamily == AddressFamily.InterNetwork && ip2.AddressFamily == AddressFamily.InterNetwork);
					bool order = BitConverter.ToUInt32(ip1.GetAddressBytes(), 0) < BitConverter.ToUInt32(ip2.GetAddressBytes(), 0);
					range = new IPAddressRange()
					{
						AddressMin = (order ? ip1 : ip2),
						AddressMax = (order ? ip2 : ip1)
					};
					return true;
				}
			}
			return false;
		}

19 View Source File : TcpEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static int GetConnectedProcess(IPEndPoint remoteEndPoint)
		{
			Debug.replacedert(IPAddress.IsLoopback(remoteEndPoint.Address));
			{
				byte[] bsPort = BitConverter.GetBytes(remoteEndPoint.Port);
				int dwPort = BitConverter.ToUInt16(new byte[] { bsPort[1], bsPort[0] }, 0);
				if (remoteEndPoint.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
				{
					foreach (var conn in EnumTcpConnectionsV4())
					{
						if (conn.dwLocalPort == dwPort)
							return conn.dwOwningPid;
					}
				}
				if (remoteEndPoint.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
				{
					foreach (var conn in EnumTcpConnectionsV6())
					{
						if (conn.dwLocalPort == dwPort)
							return conn.dwOwningPid;
					}
				}
				return 0;
			}
		}

19 View Source File : LocalStorage.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private void WriteHostInfo(WindowUrl host, Database db)
		{
			Debug.replacedert(host != null);
			if (!host.IsFile && !string.IsNullOrEmpty(host.HostName))
			{
				if (!db.IsExist("HostInfo", new { HostUrl = host.HostName }))
					db.Insert("HostInfo", new { HostUrl = host.HostName, HostName = host.HostSimpleName });
			}
		}

19 View Source File : ImageCompressEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static Image CreateImageByData(byte[] bsData, int width, int height, ColorPalette palette)
		{
			Image img;
			try
			{
				Rectangle rect = new Rectangle(0, 0, width, height);
				PixelFormat format = palette == null ? PixelFormat.Format16bppRgb555 : PixelFormat.Format8bppIndexed;

				Bitmap bmp = new Bitmap(width, height, format);
				if (palette != null)
					bmp.Palette = palette;

				var bmpData = bmp.LockBits(rect, ImageLockMode.WriteOnly, format);
				{
					int length = Math.Abs(bmpData.Stride) * bmpData.Height;
					IntPtr pData = new IntPtr(bmpData.Scan0.ToInt64() + (bmpData.Stride > 0 ? 0 : bmpData.Stride * (bmpData.Height - 1)));

					Debug.replacedert(bsData.Length >= length);
					Marshal.Copy(bsData, 0, pData, length);
				}
				bmp.UnlockBits(bmpData);
				img = bmp;
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
			return img;
		}

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static T Convert<T>(IDictionary<string, object> vals, object obj, bool hasInternal)
		{
			if (obj == null)
				obj = System.Activator.CreateInstance<T>();
			Debug.replacedert(obj is T);
			return (T)StructFromValues(obj, (k) => vals.ContainsKey(k) ? vals[k] : null, true, hasInternal);
		}

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private static object StructFromValues(object obj, GetValueCallback getValue, bool hasField, bool hasInternal)
		{
			Debug.replacedert(obj != null);
			try
			{
				// properties
				{
					var flags = BindingFlags.Instance | BindingFlags.Public | (hasInternal ? BindingFlags.NonPublic : 0);
					var props = obj.GetType().GetProperties(flags);
					foreach (var p in props)
					{
						if (hasInternal)
						{
							var m = p.GetSetMethod(true);
							if (m.IsPrivate || m.IsFamily)
								continue;
						}
						if (p.CanWrite)
						{
							var v = getValue(p.Name);
							if (v != null)
								p.SetValue(obj, ChangeType(v, p.PropertyType), null);
						}
					}
				}
				// fields
				if (hasField)
				{
					var flags = BindingFlags.Instance | BindingFlags.Public | (hasInternal ? BindingFlags.NonPublic : 0);
					var flds = obj.GetType().GetFields(flags);
					foreach (var f in flds)
					{
						if (f.IsPrivate || f.IsFamily || f.IsInitOnly)
							continue;
		
						var v = getValue(f.Name);
						if (v != null)
							f.SetValue(obj, ChangeType(v, f.FieldType));
					}
				}
			}
			catch (Exception ex) { TraceLog.WriteException(ex); throw; }
			return obj;
		}

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private static void StructToValues(object obj, SetValueCallback setValue, bool hasField, bool hasInternal)
		{
			Debug.replacedert(obj != null);
			try
			{
				// properties
				{
					var flags = BindingFlags.Instance | BindingFlags.Public | (hasInternal ? BindingFlags.NonPublic : 0);
					var props = obj.GetType().GetProperties(flags);
					foreach (var p in props)
					{
						if (hasInternal)
						{
							var m = p.GetSetMethod(true);
							if (m.IsPrivate || m.IsFamily)
								continue;
						}
						if (p.CanRead)
						{
							setValue(p.Name, p.GetValue(obj, null));
						}
					}
				}
				// fields
				if (hasField)
				{
					var flags = BindingFlags.Instance | BindingFlags.Public | (hasInternal ? BindingFlags.NonPublic : 0);
					var flds = obj.GetType().GetFields(flags);
					foreach (var f in flds)
					{
						if (f.IsPrivate || f.IsFamily || f.IsInitOnly)
							continue;
						setValue(f.Name, f.GetValue(obj));
					}
				}
			}
			catch (Exception ex) { TraceLog.WriteException(ex); throw; }
		}

19 View Source File : CacheManager.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public void WriteSnapshot(SessionInfo session, Snapshot sshot)
		{
			try
			{
				string dir = Path.Combine(CachePath, session.SessionId);
				string rds = Path.Combine(dir, "0.rds");
				string rdi = Path.Combine(dir, sshot.SnapshotId + ".rdi");
				Debug.replacedert(Directory.Exists(dir));
				Debug.replacedert(File.Exists(rds));
				Debug.replacedert(!File.Exists(rdi));

				if (!Directory.Exists(dir) || !File.Exists(rds))
				{
					Directory.CreateDirectory(dir);
					SerializeEngine.Serialize(session, rds);
				}
				SerializeEngine.Serialize(sshot, rdi);
			}
			catch (Exception ex) { TraceLog.WriteException(ex); throw; }
		}

19 View Source File : CacheManager.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public void WriteSessionEnd(string sessionId)
		{
			///? Is WriteSessionEnd called right?
			try
			{
				string dir = Path.Combine(CachePath, sessionId);
				string rds = Path.Combine(dir, "0.rds");
				string rde = Path.Combine(dir, "0.rde");
				Debug.replacedert(Directory.Exists(dir));
				Debug.replacedert(File.Exists(rds));

				if (Directory.Exists(dir) && !File.Exists(rde))
					File.WriteAllText(rde, sessionId);
			}
			catch (Exception ex) { TraceLog.WriteException(ex); throw; }
		}

19 View Source File : UserManager.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static void SetUserLogonHours(string username, byte[] bsHours)
		{
			Debug.replacedert(bsHours.Length == 21);

			int ret = 0;
			USER_INFO_4 u = new USER_INFO_4();
			{
				IntPtr pu = new IntPtr();
				ret = netapi.NetUserGetInfo(null, username, 4, out pu);
				if (ret != 0)
					throw new Win32Exception(ret);
				Marshal.PtrToStructure(pu, u);
				netapi.NetApiBufferFree(pu);
			}
			Marshal.Copy(bsHours, 0, u.logon_hours, 21);
			ret = netapi.NetUserSetInfo(null, username, 4, u, 0);
			if (ret != 0)
				throw new Win32Exception(ret);
		}

19 View Source File : MimeTypes.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static string Get(string path)
		{
			Debug.replacedert(!string.IsNullOrEmpty(path));
			var ext = Path.GetExtension(path).ToLower().TrimStart('.');
			return _values.ContainsKey(ext) ? _values[ext] : "unknown/unknown";
		}

19 View Source File : ResponseExtension.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static void SendStaticFile(this HttpListenerResponse resp, string fpath, byte[] bsFile, int expireMinutes = 24*60)
		{
			Debug.replacedert(!string.IsNullOrEmpty(fpath));
			Debug.replacedert(bsFile != null && bsFile.Length > 0);

			var mime = MimeTypes.Get(Path.GetExtension(fpath));
			SetExpireTime(resp, expireMinutes);
			WriteFileContent(resp, bsFile, mime, false);
		}

19 View Source File : AccessPolicy.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private bool IsPermitedUser(IPEndPoint remote)
		{
			Debug.replacedert(IPAddress.IsLoopback(remote.Address));
			if (string.IsNullOrEmpty(PermitUser))
				return true;

			int pid = TcpEngine.GetConnectedProcess(remote);
			if (pid > 0)
			{
				string user = WtsEngine.GetProcessOwner(pid);
				return string.Equals(user, PermitUser, StringComparison.OrdinalIgnoreCase);
			}
			else
			{
				return false;
			}
		}

19 View Source File : AccessPolicy.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private bool IsPermitedProcess(IPEndPoint remote)
		{
			Debug.replacedert(IPAddress.IsLoopback(remote.Address));
			if (string.IsNullOrEmpty(PermitProcess))
				return true;

			int pid = TcpEngine.GetConnectedProcess(remote);
			if (pid > 0)
			{
				string name = Process.GetProcessById(pid).ProcessName;
				return string.Equals(name, PermitProcess, StringComparison.OrdinalIgnoreCase);
			}
			else
				return false;
		}

19 View Source File : IPAddressRange.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public bool Contains(IPAddress addr)
		{
			Debug.replacedert(AddressMin.AddressFamily == AddressFamily.InterNetwork && AddressMax.AddressFamily == AddressFamily.InterNetwork);
			Debug.replacedert(addr.AddressFamily == AddressFamily.InterNetwork);

			uint min = BitConverter.ToUInt32(AddressMin.GetAddressBytes(), 0);
			uint max = BitConverter.ToUInt32(AddressMax.GetAddressBytes(), 0);
			uint ip = BitConverter.ToUInt32(addr.GetAddressBytes(), 0);
			return (min <= ip && ip <= max);
		}

See More Examples