public static string GetDeleteSqlByParmDic <T>(T t) { var whereSql = new StringBuilder(); var tis = CommDbHelper.GetModelDataTableInfo(typeof(T)); foreach (var keys in tis.KeysName) { var ks = keys.Split('|'); foreach (var s in ks) { var pis = tis.AllPropertyInfos.Find(m => String.Equals(m.ColumnName, s, StringComparison.CurrentCultureIgnoreCase) || String.Equals(m.PropertyName, s, StringComparison.CurrentCultureIgnoreCase)); if (pis == null) { throw new Exception("ERROR DELETE KEY: " + s + " IN TABLE: " + tis.TableName); } var val = ReflectionHandler.PropertyFastGetValue(pis.PropertyInfo, t); if (pis.PropertyType == typeof(DateTime)) { whereSql.AppendFormat("{0}=to_date('{1}','{2}')", pis.ColumnName, ((DateTime)val).ToString(DateTimeHandler.LongDateTimeStyleToOracleString), DateTimeHandler.LongDateTimeStyleForOracle); } else { whereSql.AppendFormat("{0}='{1}' and ", pis.ColumnName, val); } } whereSql.AppendFormat("1=1 or "); } whereSql.Append("1=0"); return(String.Format("delete from {0} where {1}", tis.TableName, whereSql)); }
/// <summary> /// Serializeas a list of objects /// </summary> /// <param name="_object">The object to serialize</param> /// <param name="_filePath">path where the xml file should be located</param> /// <returns></returns> public static void Serialize(Object _object, String _filePath) { // XML objects XmlWriter xmlWriter = null; XmlSerializer xmlSerializer = null; Type[] propertyTypes = null; try { //Create XMLWriter with the specific path and ItemName xmlWriter = XmlWriter.Create(_filePath); //xmlWriter.Settings.Encoding = Encoding.UTF8; propertyTypes = ReflectionHandler.GetPropertyTypes(_object).ToArray(); // Serialize the object xmlSerializer = new XmlSerializer(_object.GetType(), propertyTypes); xmlSerializer.Serialize(xmlWriter, _object); } catch (Exception exception) { throw exception; } finally { if (xmlWriter != null) { // Close the XMLWriter xmlWriter.Close(); } } }
/// <summary> /// Serializeas a list of objects /// </summary> /// <param name="_object">The object to serialize</param> /// <param name="_filePath">path where the xml file should be located</param> /// <returns></returns> public static Boolean TrySerialize(Object _object, String _filePath) { // XML objects XmlWriter xmlWriter; XmlSerializer xmlSerializer; Type[] propertyTypes; //Create XMLWriter with the specific path and ItemName xmlWriter = XmlWriter.Create(_filePath); try { propertyTypes = ReflectionHandler.GetPropertyTypes(_object).ToArray(); // Serialize the object xmlSerializer = new XmlSerializer(_object.GetType(), propertyTypes); xmlSerializer.Serialize(xmlWriter, _object); } catch { return(false); } finally { // Close the XMLWriter xmlWriter.Close(); } return(true); }
private void fillDllsListBox(string fileSystemRoute) { ReflectionHandler handler = new ReflectionHandler(fileSystemRoute); List <string> dlls = handler.getMatchingDlls(); List <string> shortNameDll = getShortDllNameFromPath(dlls); listDlls.DataSource = shortNameDll; }
public int Delete <T>(object kv) { if (!ReflectionHandler.IsValueType(kv)) { return(Delete((T)kv)); } var delSql = SqlConstructor.GetDeleteSqlByParmDic <T>(kv); var result = DbHelper.ExecuteNonQuery(delSql); return(result); }
private void btnSelectDll_Click(object sender, EventArgs e) { try { string selectedPath = (string)listDlls.SelectedItem; ReflectionHandler reflectionHandler = new ReflectionHandler(textDllsRoute.Text + "\\" + selectedPath); ProductsInterface = reflectionHandler.getInterfaceInstance(); loadProductPanel(); } catch (FileNotFoundException) { MessageBox.Show("Debe seleccionar la dll a utilizar"); } }
/// <summary> /// The HotKeyMangaer detects, if a hotkey has been pressed in the given control object /// </summary> /// <param name="_control">The control on which the hotkeyManger should listen for hotkeys</param> public HotKeyHandler(Control _control) { // set the control this.control = _control; // initialze the eventhandler, which listens on key down events this.control.PreviewKeyDown += this.KeyDownEvent; // get all hotKey combinations this.hotKeys = ReflectionHandler.GetProperties <HotKeyT>(); // get a instance of the hotKey class which contains all defined hotKeys this.hotKeyT = ReflectionHandler.GetInstance <HotKeyT>(); }
/// <summary> /// Main loop, runs the WebSocket connection. /// </summary> protected void RunSocket() { //We don't really need to store the handlers; //just create them and let them call our EnqueueMessage method. //XXX automatically find these like WebServer does. Log($"Creating socket handlers (thread: {Thread.CurrentThread.Name})"); BudgetHandler budgetHandler = new BudgetHandler(this); BuildingHandler buildingHandler = new BuildingHandler(this); CameraHandler cameraHandler = new CameraHandler(this); ChirperHandler chirperHandler = new ChirperHandler(this); CitizenHandler citizenHandler = new CitizenHandler(this); CityInfoHandler cityInfoHandler = new CityInfoHandler(this); DebugHandler debugHandler = new DebugHandler(this); DistrictHandler districtHandler = new DistrictHandler(this); FlagsHandler flagsHandler = new FlagsHandler(this); InstancesHandler instancesHandler = new InstancesHandler(this); LimitsHandler limitsHandler = new LimitsHandler(this); NotificationHandler notificationHandler = new NotificationHandler(this); ReflectionHandler reflectionHandler = new ReflectionHandler(this); TerrainHandler terrainHandler = new TerrainHandler(this); TransportHandler transportHandler = new TransportHandler(this); VehicleHandler vehicleHandler = new VehicleHandler(this); Log("Waiting for messages"); try { while (true) { if (stream.DataAvailable) { HandleNextMessage(); } String msg = GetNextOutgoingMessage(); if (msg != null) { byte[] buf = Encoding.UTF8.GetBytes(msg); SendFrame(buf); } Thread.Sleep(100); } } catch (ObjectDisposedException) { //we're done, stream is closed Log("Connection closed"); } catch (OperationCanceledException) { Log("Connection closed"); } }
public static List <T> Get_FromData <T>(String _data, Char _seperator) where T : class { List <T> rows = new List <T>(); List <PropertyInfo> properties = ReflectionHandler.GetProperties <T>(); try { String[] row; Int32 valuesCount = new Int32(); Int32 endIndex = new Int32(); while ((endIndex = _data.IndexOf((Char)10)) != -1) { row = _data.Substring(0, endIndex).Split(_seperator); valuesCount = row.Count <String>(); _data = _data.Remove(0, endIndex + 1); T tupel = ReflectionHandler.GetInstance <T>(); Type tupelType = tupel.GetType(); for (Int32 i = new Int32(); i < valuesCount; i++) { PropertyInfo propertyInfo = tupelType.GetProperty(properties[i].Name); Object value = CSVManager.getObject(row[i], propertyInfo.PropertyType); propertyInfo.SetValue(tupel, value, null); } rows.Add(tupel); } } catch (IOException ioexeption) { System.Console.WriteLine(ioexeption.Message); } return(rows); }
/// <summary> /// Reads and splits the given csv file /// </summary> /// <param name="_csvData">The data to split</param> /// <param name="_seperator">The char which is the seperator between the values</param> /// <returns>A List which contains the rows as T Object</returns> public static List <T> Get_FromFile <T>(String _filePath, Char _seperator) where T : class { List <T> rows = new List <T>(); List <PropertyInfo> properties = ReflectionHandler.GetProperties <T>(); using (StreamReader streamReader = new StreamReader(_filePath)) { try { String[] row; Int32 valuesCount = new Int32(); while (streamReader.Peek() != -1) { row = streamReader.ReadLine().Split(_seperator); valuesCount = row.Count <String>(); T tupel = ReflectionHandler.GetInstance <T>(); Type tupelType = tupel.GetType(); for (Int32 i = new Int32(); i < valuesCount; i++) { PropertyInfo propertyInfo = tupelType.GetProperty(properties[i].Name); Object value = CSVManager.getObject(row[i], propertyInfo.PropertyType); propertyInfo.SetValue(tupel, value, null); } rows.Add(tupel); } } catch (IOException ioexeption) { System.Console.WriteLine(ioexeption.Message); } } return(rows); }
/// <summary> /// Deserializes an object readed from an xml file /// </summary> /// <typeparam name="T">The type of the object</typeparam> /// <param name="_filePath">The path + name of the xml file</param> /// <returns>The deserialized object from type T</returns> public static T Deserialize <T>(String _filePath) where T : class { //objects XmlSerializer xmlSerializer; StreamReader streamReader; T resultObject; // initialization if (System.IO.File.Exists(_filePath)) { xmlSerializer = new XmlSerializer(typeof(T)); streamReader = new StreamReader(_filePath); resultObject = ReflectionHandler.GetInstance <T>(); try { // return the object readed from the file resultObject = (T)xmlSerializer.Deserialize(streamReader); // close the streamReader connection streamReader.Close(); // return the deserialized object return(resultObject); } catch (Exception exception) { // close the streamReader connection streamReader.Close(); throw exception; } } else { return(null); } }
public WebSession(ReflectionHandler handler = null, NameValueCollection customHeader = null, bool AllowRedirect = false, int Timeout = 10000, string Proxy = "") { if (handler != null) { DataHandler = handler; } else { DataHandler = new PlainTextHandler(Encoding.UTF8); } if (customHeader != null) { Headers = customHeader; } else { Headers = new NameValueCollection(); } this.AllowRedirect = AllowRedirect; this.Timeout = Timeout; this.Proxy = Proxy; }
/// <summary> /// Dedects if an hotKey has been pressed an which hotKey has been pressed /// </summary> /// <param name="_key"></param> /// <param name="_hotKey">The pressed hotKey</param> /// <returns>Returns true if an hotKey has been pressed otherwise false</returns> public Boolean get_Event(Key _key, out TEnum _hotKey) { // set the _hotKey to the default HoKey None _hotKey = (TEnum)((HotKeyAttribute)this.hotKeys[0].GetCustomAttributes(typeof(HotKeyAttribute), true)[0]).HotKey; // if the class which contains all hotKeys isn't null if (this.hotKeyT != null) { // for each hotkey in the list of hotKeys foreach (PropertyInfo hotKey in this.hotKeys) { // get the value of the current hotKey to check String hotKeyValue = hotKey.GetValue(this.hotKeyT, null) as String; // if the current combination of keys are a hotKey if (this.is_HotKeyEvent(_key, hotKeyValue)) { // initialize a hotKeyAttribute which contains the enum value of the hotKey HotKeyAttribute hotKeyAttribute = ReflectionHandler.GetCustomAttribute <HotKeyAttribute>(hotKey, true); if (hotKeyAttribute == null || (TEnum)hotKeyAttribute.HotKey == null) { return(false); } // get the enum value of the hotKey _hotKey = (TEnum)hotKeyAttribute.HotKey; // return true, means a hotKey has been pressed return(true); } } } return(false); }
public WebConnection SetProcessor(ReflectionHandler handler) { Processor = handler; return(this); }
public WebConnection(string Url) { Processor = new PlainTextHandler(); InitRequest(Url); }
public WebConnection(string Url, ReflectionHandler Handle) { Processor = Handle; InitRequest(Url); }
private void MakeMesh() { timer += Time.deltaTime; if (timer < maxTime) { return; } if (beams.Count <= 0) { return; } lightup.Light(); foreach (BeamPair pair in beams) { Vector3 left = pair.Beam1.Point; Vector3 leftEnd; Vector3 right = pair.Beam2.Point; Vector3 rightEnd; RaycastHit2D leftHit = new RaycastHit2D(); RaycastHit2D rightHit = new RaycastHit2D(); bool reflectL = false; bool reflectR = false; ReflectionHandler l = null; ReflectionHandler r = null; BeamFOV.Beam point1 = new BeamFOV.Beam(); BeamFOV.Beam point2 = new BeamFOV.Beam(); col.enabled = false; leftHit = Physics2D.Raycast(left, pair.Beam1.Dir, pair.Beam1.Distance, ObstacleMask + CharacterMask + InteractableMask); rightHit = Physics2D.Raycast(right, pair.Beam2.Dir, pair.Beam2.Distance, ObstacleMask + CharacterMask + InteractableMask); //myHandler.handler.AddHit(leftHit); //myHandler.handler.AddHit(rightHit); if (myHandler.handler.bulb.power == Bulb.Power.XRAY) { rightHit = Physics2D.Raycast(right, pair.Beam2.Dir, pair.Beam2.Distance, CharacterMask + InteractableMask); } if (myHandler.handler.bulb.power == Bulb.Power.XRAY) { leftHit = Physics2D.Raycast(left, pair.Beam1.Dir, pair.Beam1.Distance, CharacterMask + InteractableMask); } if (leftHit.collider == null) { leftEnd = left + pair.Beam1.Dir * pair.Beam1.Distance; } else if (InteractableMask == (InteractableMask | (1 << leftHit.collider.gameObject.layer))) { myHandler.handler.AddInteractable(leftHit.collider.gameObject.transform); if (myHandler.handler.bulb.power == Bulb.Power.XRAY) { leftHit = Physics2D.Raycast(left, pair.Beam1.Dir, pair.Beam1.Distance, CharacterMask); } else { leftHit = Physics2D.Raycast(left, pair.Beam1.Dir, pair.Beam1.Distance, ObstacleMask + CharacterMask); } } else { myHandler.handler.AddHit(leftHit); } if (rightHit.collider == null) { rightEnd = right + pair.Beam2.Dir * pair.Beam2.Distance; } else if (InteractableMask == (InteractableMask | (1 << rightHit.collider.gameObject.layer))) { myHandler.handler.AddInteractable(rightHit.collider.gameObject.transform); if (myHandler.handler.bulb.power == Bulb.Power.XRAY) { rightHit = Physics2D.Raycast(right, pair.Beam2.Dir, pair.Beam2.Distance, CharacterMask); } else { rightHit = Physics2D.Raycast(right, pair.Beam2.Dir, pair.Beam2.Distance, ObstacleMask + CharacterMask); } } else { myHandler.handler.AddHit(rightHit); } col.enabled = true; if (leftHit.collider == null) { leftEnd = left + pair.Beam1.Dir * pair.Beam1.Distance; } else { leftEnd = leftHit.point; reflectL = true; l = leftHit.collider.GetComponent <ReflectionHandler>(); float deltaD = pair.Beam1.Distance - (leftEnd - left).magnitude; point1 = new BeamFOV.Beam(leftEnd, deltaD, Vector3.Reflect(pair.Beam1.Dir, leftHit.normal)); } if (rightHit.collider == null) { rightEnd = right + pair.Beam2.Dir * pair.Beam2.Distance; } else { rightEnd = rightHit.point; reflectR = true; r = rightHit.collider.GetComponent <ReflectionHandler>(); float deltaD = pair.Beam2.Distance - (rightEnd - right).magnitude; point2 = new BeamFOV.Beam(rightEnd, deltaD, Vector3.Reflect(pair.Beam2.Dir, rightHit.normal)); } if (reflectL && reflectR && l != null) { if (l == r) { l.AddBeam(point1, point2); } } int topLeft = AddPoint(leftEnd); int topRight = AddPoint(rightEnd); int botLeft = AddPoint(left); int botRight = AddPoint(right); AddRect(topLeft, topRight, botLeft, botRight); } }
/// <summary> /// /// </summary> /// <param name="baseHandler">基础handler解压缩后使用这个handler处理</param> public GzipHandler(ReflectionHandler baseHandler) { this.baseHandler = baseHandler; }
private void MakeMesh() { left = transform.position; left -= transform.right * width / 2.0f; right = transform.position; right += transform.right * width / 2.0f; leftHit = new RaycastHit2D(); rightHit = new RaycastHit2D(); bool reflectL = false; bool reflectR = false; ReflectionHandler l = null; ReflectionHandler r = null; Beam point1 = new Beam(); Beam point2 = new Beam(); leftHit = Physics2D.Raycast(left, transform.up, distance, ObstacleMask + CharacterMask + InteractableMask + xrayProof); rightHit = Physics2D.Raycast(right, transform.up, distance, ObstacleMask + CharacterMask + InteractableMask + xrayProof); if (handler.bulb.power == Bulb.Power.XRAY) { leftHit = Physics2D.Raycast(left, transform.up, distance, CharacterMask + InteractableMask + xrayProof); } if (handler.bulb.power == Bulb.Power.XRAY) { rightHit = Physics2D.Raycast(right, transform.up, distance, CharacterMask + InteractableMask + xrayProof); } if (leftHit.collider == null) { leftEnd = left + transform.up * distance; } else if (InteractableMask == (InteractableMask | (1 << leftHit.collider.gameObject.layer))) { setLists(leftHit); if (handler.bulb.power == Bulb.Power.XRAY) { leftHit = Physics2D.Raycast(left, transform.up, distance, CharacterMask + xrayProof); } else { leftHit = Physics2D.Raycast(left, transform.up, distance, ObstacleMask + CharacterMask + xrayProof); } if (leftHit.collider == null) { leftEnd = left + transform.up * distance; } else if (xrayProof == (xrayProof | (1 << leftHit.collider.gameObject.layer))) { leftEnd = leftHit.point; } else { leftEnd = leftHit.point; reflectL = true; l = leftHit.collider.GetComponent <ReflectionHandler>(); float deltaD = distance - (leftEnd - left).magnitude; point1 = new Beam(leftEnd, deltaD, Vector3.Reflect(transform.up, leftHit.normal)); } } else if (CharacterMask == (CharacterMask | (1 << leftHit.collider.gameObject.layer))) { setLists(leftHit); leftHit = Physics2D.Raycast(left, transform.up, distance, xrayProof); if (leftHit.collider == null) { leftEnd = left + transform.up * distance; } else if (xrayProof == (xrayProof | (1 << leftHit.collider.gameObject.layer))) { leftEnd = leftHit.point; } else { leftEnd = leftHit.point; reflectL = true; l = leftHit.collider.GetComponent <ReflectionHandler>(); float deltaD = distance - (leftEnd - left).magnitude; point1 = new Beam(leftEnd, deltaD, Vector3.Reflect(transform.up, leftHit.normal)); } } else if (xrayProof == (xrayProof | (1 << leftHit.collider.gameObject.layer))) { leftEnd = leftHit.point; } else { leftEnd = leftHit.point; reflectL = true; l = leftHit.collider.GetComponent <ReflectionHandler>(); float deltaD = distance - (leftEnd - left).magnitude; point1 = new Beam(leftEnd, deltaD, Vector3.Reflect(transform.up, leftHit.normal)); } if (rightHit.collider == null) { rightEnd = right + transform.up * distance; } else if (InteractableMask == (InteractableMask | (1 << rightHit.collider.gameObject.layer))) { setLists(rightHit); if (handler.bulb.power == Bulb.Power.XRAY) { rightHit = Physics2D.Raycast(right, transform.up, distance, CharacterMask + xrayProof); } else { rightHit = Physics2D.Raycast(right, transform.up, distance, ObstacleMask + CharacterMask + xrayProof); } if (rightHit.collider == null) { rightEnd = right + transform.up * distance; } else if (xrayProof == (xrayProof | (1 << rightHit.collider.gameObject.layer))) { rightEnd = rightHit.point; } else { rightEnd = rightHit.point; reflectR = true; r = rightHit.collider.GetComponent <ReflectionHandler>(); float deltaD = distance - (rightEnd - right).magnitude; point2 = new Beam(rightEnd, deltaD, Vector3.Reflect(transform.up, rightHit.normal)); } } else if (CharacterMask == (CharacterMask | (1 << rightHit.collider.gameObject.layer))) { setLists(rightHit); rightHit = Physics2D.Raycast(right, transform.up, distance, xrayProof); if (rightHit.collider == null) { rightEnd = right + transform.up * distance; } else if (xrayProof == (xrayProof | (1 << rightHit.collider.gameObject.layer))) { rightEnd = rightHit.point; } else { rightEnd = rightHit.point; reflectR = true; r = rightHit.collider.GetComponent <ReflectionHandler>(); float deltaD = distance - (rightEnd - right).magnitude; point2 = new Beam(rightEnd, deltaD, Vector3.Reflect(transform.up, rightHit.normal)); } } else if (xrayProof == (xrayProof | (1 << rightHit.collider.gameObject.layer))) { rightEnd = rightHit.point; } else { rightEnd = rightHit.point; reflectR = true; r = rightHit.collider.GetComponent <ReflectionHandler>(); float deltaD = distance - (rightEnd - right).magnitude; point2 = new Beam(rightEnd, deltaD, Vector3.Reflect(transform.up, rightHit.normal)); } if (!init) { init = true; } if (reflectL && reflectR && l != null) { if (l == r) { l.AddBeam(point1, point2); } } setLists(leftHit); setLists(rightHit); }
private static object GetResult(Type retType, Dictionary <string, object> drDic) { var result = Activator.CreateInstance(retType); var curKey = String.Empty; // try // { var pis = CommDbHelper.GetModelDataPropertyInfos(retType); foreach (var propertyInfo in pis) { if (propertyInfo != null) { if (propertyInfo.PropertyType.IsSubclassOf(typeof(BaseModel))) //如果是模型类,则递归获取对象实例 { var parms = new List <Object> { propertyInfo.PropertyType, drDic }; var obj = typeof(SqlGenerator).GetMethod("GetResult", BindingFlags.NonPublic | BindingFlags.Static).Invoke(new object(), parms.ToArray()); ReflectionHandler.PropertyFastSetValue(propertyInfo.PropertyInfo, result, obj); } curKey = (String.IsNullOrEmpty(propertyInfo.ColumnName) ? propertyInfo.PropertyName : propertyInfo.ColumnName).ToUpper().Replace("_", ""); if (!drDic.ContainsKey(curKey)) { continue; } var value = drDic[curKey]; if (value != DBNull.Value) { if (propertyInfo.PropertyType == typeof(DateTime)) { DateTime temp; if (!DateTime.TryParse(value.ToString().Trim(), out temp)) { value = temp.ToString(CultureInfo.InvariantCulture); } } if (propertyInfo.PropertyType == typeof(int?)) { ReflectionHandler.PropertyFastSetValue(propertyInfo.PropertyInfo, result, (int?)value); } else if (propertyInfo.PropertyType == typeof(float?)) { ReflectionHandler.PropertyFastSetValue(propertyInfo.PropertyInfo, result, (float?)value); } else if (propertyInfo.PropertyType == typeof(byte[])) { ReflectionHandler.PropertyFastSetValue(propertyInfo.PropertyInfo, result, (byte[])value); } else if (propertyInfo.PropertyType.IsValueType || propertyInfo.PropertyType == typeof(string)) { ReflectionHandler.PropertyFastSetValue(propertyInfo.PropertyInfo, result, Convert.ChangeType(value, propertyInfo.PropertyType)); } else { //TODO 考虑转换json // var mi = typeof(JsonHandler).GetMethod("GetObjectFromJson"); // var valObj = Activator.CreateInstance(propertyInfo.PropertyType); //var gM = mi.MakeGenericMethod(propertyInfo.PropertyType); //ReflectionHandler.Execute(gM, valObj, value.ToString()); ReflectionHandler.PropertyFastSetValue(propertyInfo.PropertyInfo, result, value.ToString()); } } } } // } // catch (Exception ee) // { // throw new Exception("ERROR KEY:" + curKey + " MSG: " + ee.Message); // } return(result); }
public void SetProcessor(ReflectionHandler handler) { Processor = handler; }
public WebSession(ReflectionHandler handler) { DataHandler = handler; Headers = new NameValueCollection(); }
public WebSession(NameValueCollection customHeader, ReflectionHandler handler) { DataHandler = handler; Headers = customHeader; }