public static bool optional(keys key) { return((key == keys.append) || (key == keys.pagesize) || (key == keys.type) || (key == keys.id)); }
public void instance_disposed(keysDataReader keys_reader, DDS.SampleInfo info, keys msg) { Console.WriteLine("Instance disposed; code = {0}", msg.code); states[msg.code] = Instance_State.disposed; }
public void set(int i) { Debug.Log(i); keys key = (keys)i; this.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Textures/" + Enum.GetName(key.GetType(), key)); }
public void instance_lost_writers(keysDataReader keys_reader, DDS.SampleInfo info, keys msg) { Console.WriteLine("Instance has no writers; code = {0}", msg.code); states[msg.code] = Instance_State.no_writers; }
/* Called to handle relevant data samples */ public void handle_data(keysDataReader keys_reader, DDS.SampleInfo info, keys msg) { Console.WriteLine("code: {0}, x: {1}, y: {2}", msg.code, msg.x, msg.y); }
public ActionResult ChangePassword(String password) { var employeeId = Int64.Parse(Session["employeeId"].ToString()); keys _keys = new keys(); data.AES aes = new data.AES(); var key = _keys.GetOneById(1); users _users = new users(); var user = _users.GetOneByEmployeeId(employeeId); user.userPassword = aes.Encriptar(password, key.C_Key, key.C_IV); //I need a second BS user for update users _users02 = new users(); try { _users02.Update(user); return(Json(new { sucess = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(null); } }
public ActionResult SingIn(String userName, String password) { keys _keys = new keys(); data.AES aes = new data.AES(); var key = _keys.GetOneById(1); var employee = _employees.SingIn(aes.Encriptar(userName, key.C_Key, key.C_IV), aes.Encriptar(password, key.C_Key, key.C_IV)); if (employee != null) { //save employee ID in Session HttpContext.Session.Add("employeeId", employee.employeeId); users_x_rols _users_x_rols = new users_x_rols(); //find rols by user id byte[] rols = _users_x_rols.GetAllByUserId(employee.users.FirstOrDefault().userId).Select(x => x.rolId).ToArray(); //save rols in Session HttpContext.Session.Add("rols", rols); return(Json(new { rols }, JsonRequestBehavior.AllowGet)); } else { return(null); } }
/// <summary> /// 插入方法 /// </summary> /// <param name="keys">keys表实例</param> /// <returns>int</returns> public int Insert(keys keysExample) { DBHelper.sqlstr = "insert into keys (kname,krenqi,kSSzhanbi,kdianjilv,kSCzhanbi,kgoodsnum,kZTCjiage,kzhuanhualv,kZTCzhanxian,kZTCdianji,kZTCdianjilv,kZTCzhuanhualv,kZTCjunjia,kZTCjingzhengdu,kZTCDY_dianjilv,kZTCDY_zhanxian,kZTCDY_dianji,kZTCDY_zhuanhua,kZTCDY_junjia,ktype,kstate,klevel,kremark1,kremark2,kremark3,kremark4,kremark5,kremark6,kremark7,kremark8,kremark9,kdate,klid)values(@kname,@krenqi,@kSSzhanbi,@kdianjilv,@kSCzhanbi,@kgoodsnum,@kZTCjiage,@kzhuanhualv,@kZTCzhanxian,@kZTCdianji,@kZTCdianjilv,@kZTCzhuanhualv,@kZTCjunjia,@kZTCjingzhengdu,@kZTCDY_dianjilv,@kZTCDY_zhanxian,@kZTCDY_dianji,@kZTCDY_zhuanhua,@kZTCDY_junjia,@ktype,@kstate,@klevel,@kremark1,@kremark2,@kremark3,@kremark4,@kremark5,@kremark6,@kremark7,@kremark8,@kremark9,@kdate,@klid)"; return(DBHelper.ExecuteNonQuery(GetSqlParameters(keysExample))); //DBHelper.sqlstr = "insert into keys (kname,krenqi,kSSzhanbi,kdianjilv,kSCzhanbi,kgoodsnum,kZTCjiage,kzhuanhualv,kZTCzhanxian,kZTCdianji,kZTCdianjilv,kZTCzhuanhualv,kZTCjunjia,kZTCjingzhengdu,kZTCDY_dianjilv,kZTCDY_zhanxian,kZTCDY_dianji,kZTCDY_zhuanhua,kZTCDY_junjia,ktype,kstate,klevel,kremark1,kremark2,kremark3,kremark4,kremark5,kremark6,kremark7,kremark8,kremark9,kdate,klid)values(" + keysExample.kname + "," + keysExample.krenqi + "," + keysExample.kSSzhanbi + "," + keysExample.kdianjilv + "," + keysExample.kSCzhanbi + "," + keysExample.kgoodsnum + "," + keysExample.kZTCjiage + "," + keysExample.kzhuanhualv + "," + keysExample.kZTCzhanxian + "," + keysExample.kZTCdianji + "," + keysExample.kZTCdianjilv + "," + keysExample.kZTCzhuanhualv + "," + keysExample.kZTCjunjia + "," + keysExample.kZTCjingzhengdu + "," + keysExample.kZTCDY_dianjilv + "," + keysExample.kZTCDY_zhanxian + "," + keysExample.kZTCDY_dianji + "," + keysExample.kZTCDY_zhuanhua + "," + keysExample.kZTCDY_junjia + "," + keysExample.ktype + "," + keysExample.kstate + "," + keysExample.klevel + "," + keysExample.kremark1 + "," + keysExample.kremark2 + "," + keysExample.kremark3 + "," + keysExample.kremark4 + "," + keysExample.kremark5 + "," + keysExample.kremark6 + "," + keysExample.kremark7 + "," + keysExample.kremark8 + "," + keysExample.kremark9 + "," + keysExample.kdate + "," + keysExample.klid + ")"; //return DBHelper.ExecuteNonQuery(); }
public ActionResult Register(data.employee employee, String countryCode, Boolean isAdmin, Boolean isSeller) { employee.phone = "+" + countryCode + employee.phone; employee.registerDate = DateTime.Now; employee.isActive = true; _employees.Insert(employee); #region user //import AES data.AES aes = new data.AES(); //get keys for encrypt keys _keys = new keys(); data.key key = new data.key(); key = _keys.GetOneById(1); //create and encrypt user data.user user = new data.user(); users _user = new users(); var dateTime = DateTime.Now; String userName = CreatePassword(3) + dateTime.Day + dateTime.Month + dateTime.Second; String password = CreatePassword(6); user.employeeId = _employees.GetLastOrDefault().employeeId; user.userName = aes.Encriptar(userName, key.C_Key, key.C_IV); user.userPassword = aes.Encriptar(password, key.C_Key, key.C_IV); user.expireDate = DateTime.Now.AddDays(1); _user.Insert(user); //add rols data.user_x_rols user_x_rols = new data.user_x_rols(); users_x_rols _users_x_rols = new users_x_rols(); user_x_rols.userId = _user.GetLastOrDefault().userId; for (int i = 0; i < 2; i++) { if (isAdmin) { isAdmin = false; user_x_rols.rolId = 1; _users_x_rols.Insert(user_x_rols); } else if (isSeller) { isSeller = false; user_x_rols.rolId = 2; _users_x_rols.Insert(user_x_rols); } } #endregion user //send email with the credentials String from = WebConfigurationManager.AppSettings["email"]; String fromPassword = WebConfigurationManager.AppSettings["password"]; data.sendEmail.sendEmailOutlook(from, fromPassword, employee.email, "", "Credentials CRM", "Credentials for CRM:\nUser Name: " + userName + "\nPassword: "******"Index")); }
public void ModKey(int x, int y, bool down, keys key) { events val = (down) ? events.ModKeyDown : events.ModKeyUp; string log = "Modifier Key pressed"; Debug.Log(log); SendPack(x, y, (int)val, (int)key); receiveToBytes(); }
private string val(keys key) { if (parameters.ContainsKey(key.ToString())) { return(parameters[key.ToString()]); } else { return(string.Empty); } }
public ActionResult UserNameExist(String userName) { keys _keys = new keys(); data.AES aes = new data.AES(); var key = _keys.GetOneById(1); users _users = new users(); return(Json(new { userNameExist = _users.UserNameExist(aes.Encriptar(userName, key.C_Key, key.C_IV)) }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); float keyHeight = displayHeight / 8; float keyTop = displayHeight - keyHeight; foreach (string noteName in notes) { keys newKey = new keys(); newKey.sound = Content.Load <SoundEffect>(noteName); if (noteName.Contains("s")) { // Draw the black keys across half of the screen offset from // the white keys newKey.keyRect = new Rectangle(0, (int)((keyTop + (keyHeight / 2)) + 0.5f), (int)(displayWidth / 2), (int)(keyHeight + 0.5f)); newKey.keyTexture = Content.Load <Texture2D>("BlackKey"); // Insert black keys at the head of the key list keynotes.Insert(0, newKey); } else { // Draw the white key across the whole screen // using the white key texture newKey.keyRect = new Rectangle(0, (int)(keyTop + 0.5f), (int)displayWidth, (int)(keyHeight + 0.5f)); newKey.keyTexture = Content.Load <Texture2D>("WhiteKey"); // Move down to the next key on the screen keyTop = keyTop - keyHeight; // Insert the white keys into the end of the key list // This is because black keys are "on top" of the white // ones and we need to find and play them first if (keynotes.Count > 0) { keynotes.Insert(keynotes.Count - 1, newKey); } else { keynotes.Add(newKey); } } } SoundEffect sound = Content.Load <SoundEffect>("song"); // TODO: use this.Content to load your game content here }
/// <summary> /// 查询全部数据 /// </summary> /// <returns>IList</returns> /*查看是否为视图*/ public IList <keys> SearchAll() { DBHelper.sqlstr = "select * from keys "; List <keys> list = new List <keys>(); MySqlDataReader reader = DBHelper.ExecuteReader(); while (reader.Read()) { keys Obj = GetByReader(reader); list.Add(Obj); } reader.Close(); return(list); }
public ActionResult PasswordExist(String password) { var employeeId = Int64.Parse(Session["employeeId"].ToString()); keys _keys = new keys(); data.AES aes = new data.AES(); var key = _keys.GetOneById(1); users _users = new users(); return(Json(new { passwordExist = _users.PasswordExist(aes.Encriptar(password, key.C_Key, key.C_IV), employeeId) }, JsonRequestBehavior.AllowGet)); }
public void KeyCounter() { keysGeted++; UpdateScore(); keysCola.Dequeue(); if (keysCola.Count > 0) { keys llave = keysCola.Peek(); llave.Active = true; apuntador.position = new Vector3(keysCola.Peek().transform.position.x, apuntador.position.y, keysCola.Peek().transform.position.z); } else { apuntador.position = new Vector3(transporterEnd.position.x, apuntador.position.y, transporterEnd.position.z); } }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); for (int i = keynotes.Count - 1; i >= 0; i--) { keys key = keynotes[i]; spriteBatch.Draw(key.keyTexture, key.keyRect, Color.White); } spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// 根据kid,查询一条数据 /// </summary> /// <param name="kid">编号</param> /// <returns></returns> /*查看是否为视图*/ public keys SearchByID(int kid) { DBHelper.sqlstr = "select * from keys where kid = @kid"; MySqlParameter[] param = new MySqlParameter[] { new MySqlParameter("@kid", kid) }; MySqlDataReader reader = DBHelper.ExecuteReader(param); keys Obj = null; if (reader.Read()) { Obj = GetByReader(reader); } reader.Close(); return(Obj); }
void _ThreadProc() { WindowsHook hk = null, hm = null; WinEventHook hwe = null; try { try { if (_block.Has(BIEvents.Keys)) { hk = WindowsHook.Keyboard(_keyHookProc ??= _KeyHookProc); } if (_block.HasAny(BIEvents.MouseClicks | BIEvents.MouseMoving)) { hm = WindowsHook.Mouse(_mouseHookProc ??= _MouseHookProc); } } catch (AuException e1) { Debug_.Print(e1); _block = 0; return; } //failed to hook //This prevents occassional inserting a foreign key after the first our-script-pressed key. //To reproduce, let our script send small series of chars in loop, and simultaneously a foreign script send other chars. wait.doEvents(); //print.it("started"); Api.SetEvent(_syncEvent); //the hook detects Ctrl+Alt+Del, Win+L, UAC consent, etc. SystemEvents.SessionSwitch only Win+L. try { hwe = new WinEventHook(EEvent.SYSTEM_DESKTOPSWITCH, 0, _winEventProc ??= _WinEventProc); } catch (AuException e1) { Debug_.Print(e1); } //failed to hook wait.Wait_(-1, WHFlags.DoEvents, _stopEvent, _threadHandle); if (_blockedKeys != null) { bool onlyUp = _discardBlockedKeys || Environment.TickCount64 - _startTime > c_maxResendTime; _blockedKeys.SendBlocked_(onlyUp); } //print.it("ended"); } finally { _blockedKeys = null; hk?.Dispose(); hm?.Dispose(); hwe?.Dispose(); Api.SetEvent(_syncEvent); } GC.KeepAlive(this); }
/* These are not called by DDS. on_data_available() calls * the appropriate function when it gets updates about * an instances' status */ public void new_instance_found(keysDataReader keys_reader, DDS.SampleInfo info, keys msg) { /* There are really three cases here: * 1.) truly new instance * 2.) instance lost all writers, but now we're getting data again * 3.) instance was disposed, but a new one has been created * * We distinguish these cases by examining generation counts, BUT * note that if the instance resources have been reclaimed, the * generation counts may be reset to 0. * * Instances are eligible for resource cleanup if there are no * active writers and all samples have been taken. To reliably * determine which case a 'new' instance falls into, the application * must store state information on a per-instance basis. * * Note that this example assumes that state changes only occur via * explicit register_instance(), unregister_instance() and dispose() * calls from the datawriter. In reality, these changes could also * occur due to lost liveliness or missed deadlines, so those * listeners would also need to update the instance state. */ switch (states[msg.code]) { case Instance_State.inactive: Console.WriteLine("New instance found; code = {0}", msg.code); break; case Instance_State.active: /* An active instance should never be interpreted as new */ Console.WriteLine("Error, 'new' already-active instance found; code = {0}", msg.code); break; case Instance_State.no_writers: Console.WriteLine("Found writer for instance; code = {0}", msg.code); break; case Instance_State.disposed: Console.WriteLine("Found reborn instance; code = {0}", msg.code); break; } states[msg.code] = Instance_State.active; }
/// <summary> /// Creates the key. /// </summary> /// <param name="userId">The user identifier.</param> /// <param name="requests"></param> public static int CreateKey(int userId, int requests) { using (var db = new GenderEnt()) { var newKey = new keys { user_id = userId, key = Guid.NewGuid().ToString(), requests = 0, requests_allowed = requests }; db.keys.Add(newKey); db.SaveChanges(); return(newKey.id); } }
/// <summary> /// 从一个MySqlDataReader里读数据 /// </summary> /// <param name="Reader">MySqlDataReader</param> /// <returns>keysExample</returns> public static keys GetByReader(MySqlDataReader Reader) { keys keysExample = new keys(); keysExample.kid = Reader["kid"] == DBNull.Value ? 0 : (int)Reader["kid"]; keysExample.kname = Reader["kname"] == DBNull.Value ? null : Reader["kname"].ToString(); keysExample.krenqi = Reader["krenqi"] == DBNull.Value ? 0 : (int)Reader["krenqi"]; keysExample.kSSzhanbi = Reader["kSSzhanbi"] == DBNull.Value ? new Decimal() : Convert.ToDecimal(Reader["kSSzhanbi"]); keysExample.kdianjilv = Reader["kdianjilv"] == DBNull.Value ? new Decimal() : Convert.ToDecimal(Reader["kdianjilv"]); keysExample.kSCzhanbi = Reader["kSCzhanbi"] == DBNull.Value ? new Decimal() : Convert.ToDecimal(Reader["kSCzhanbi"]); keysExample.kgoodsnum = Reader["kgoodsnum"] == DBNull.Value ? 0 : (int)Reader["kgoodsnum"]; keysExample.kZTCjiage = Reader["kZTCjiage"] == DBNull.Value ? new Decimal() : Convert.ToDecimal(Reader["kZTCjiage"]); keysExample.kzhuanhualv = Reader["kzhuanhualv"] == DBNull.Value ? new Decimal() : Convert.ToDecimal(Reader["kzhuanhualv"]); keysExample.kZTCzhanxian = Reader["kZTCzhanxian"] == DBNull.Value ? 0 : (int)Reader["kZTCzhanxian"]; keysExample.kZTCdianji = Reader["kZTCdianji"] == DBNull.Value ? 0 : (int)Reader["kZTCdianji"]; keysExample.kZTCdianjilv = Reader["kZTCdianjilv"] == DBNull.Value ? new Decimal() : Convert.ToDecimal(Reader["kZTCdianjilv"]); keysExample.kZTCzhuanhualv = Reader["kZTCzhuanhualv"] == DBNull.Value ? new Decimal() : Convert.ToDecimal(Reader["kZTCzhuanhualv"]); keysExample.kZTCjunjia = Reader["kZTCjunjia"] == DBNull.Value ? new Decimal() : Convert.ToDecimal(Reader["kZTCjunjia"]); keysExample.kZTCjingzhengdu = Reader["kZTCjingzhengdu"] == DBNull.Value ? 0 : (int)Reader["kZTCjingzhengdu"]; keysExample.kZTCDY_dianjilv = Reader["kZTCDY_dianjilv"] == DBNull.Value ? null : Reader["kZTCDY_dianjilv"].ToString(); keysExample.kZTCDY_zhanxian = Reader["kZTCDY_zhanxian"] == DBNull.Value ? null : Reader["kZTCDY_zhanxian"].ToString(); keysExample.kZTCDY_dianji = Reader["kZTCDY_dianji"] == DBNull.Value ? null : Reader["kZTCDY_dianji"].ToString(); keysExample.kZTCDY_zhuanhua = Reader["kZTCDY_zhuanhua"] == DBNull.Value ? null : Reader["kZTCDY_zhuanhua"].ToString(); keysExample.kZTCDY_junjia = Reader["kZTCDY_junjia"] == DBNull.Value ? null : Reader["kZTCDY_junjia"].ToString(); keysExample.ktype = Reader["ktype"] == DBNull.Value ? null : Reader["ktype"].ToString(); keysExample.kstate = Reader["kstate"] == DBNull.Value ? null : Reader["kstate"].ToString(); keysExample.klevel = Reader["klevel"] == DBNull.Value ? null : Reader["klevel"].ToString(); keysExample.kremark1 = Reader["kremark1"] == DBNull.Value ? new Decimal() : Convert.ToDecimal(Reader["kremark1"]); keysExample.kremark2 = Reader["kremark2"] == DBNull.Value ? null : Reader["kremark2"].ToString(); keysExample.kremark3 = Reader["kremark3"] == DBNull.Value ? null : Reader["kremark3"].ToString(); keysExample.kremark4 = Reader["kremark4"] == DBNull.Value ? null : Reader["kremark4"].ToString(); keysExample.kremark5 = Reader["kremark5"] == DBNull.Value ? null : Reader["kremark5"].ToString(); keysExample.kremark6 = Reader["kremark6"] == DBNull.Value ? null : Reader["kremark6"].ToString(); keysExample.kremark7 = Reader["kremark7"] == DBNull.Value ? null : Reader["kremark7"].ToString(); keysExample.kremark8 = Reader["kremark8"] == DBNull.Value ? null : Reader["kremark8"].ToString(); keysExample.kremark9 = Reader["kremark9"] == DBNull.Value ? null : Reader["kremark9"].ToString(); keysExample.kdate = Reader["kdate"] == DBNull.Value ? new DateTime() : Convert.ToDateTime(Reader["kdate"]); keysExample.klid = Reader["klid"] == DBNull.Value ? 0 : (int)Reader["klid"]; return(keysExample); }
/// <summary> /// 根据klid打开选中词库 /// </summary> /// <returns>IList</returns> /*查看是否为视图*/ public IList <keys> SearchByKlids(List <int> listid) { DBHelper.sqlstr = "select* from keys where "; foreach (int temp in listid) { DBHelper.sqlstr += " klid= " + temp.ToString() + " or "; } DBHelper.sqlstr = DBHelper.sqlstr.Substring(0, DBHelper.sqlstr.Length - 5); List <keys> list = new List <keys>(); MySqlDataReader reader = DBHelper.ExecuteReader(); while (reader.Read()) { keys Obj = GetByReader(reader); list.Add(Obj); } reader.Close(); return(list); }
public static string GetCodeKey(keys key) { string resul = string.Empty; switch (key) { case keys.enter: resul = WordParts.tagEnter; break; case keys.SI: resul = WordParts.tagOK; break; case keys.NO: resul = WordParts.tagNO; break; default: break; } return(resul); }
/// <summary> /// 模糊搜索 /// </summary> /// <param name="key">关键词</param> /// <param name="state">状态</param> /// <param name="id">int字段</param> /// <param name="startdate">起始时间</param> /// <param name="enddate">结束时间</param> /// <param name="orderby">排序</param> /// <returns>IList<keys></returns> public IList <keys> Search(int s, int e, string key, string state, int id, DateTime startdate, DateTime enddate, string orderby) { string sql1 = "select * from keys where "; string sql2 = string.IsNullOrEmpty(key) ? " 1=1 " : " ( kname like '%" + key + "%' or kZTCDY_dianjilv like '%" + key + "%' or kZTCDY_zhanxian like '%" + key + "%' or kZTCDY_dianji like '%" + key + "%' or kZTCDY_zhuanhua like '%" + key + "%' or kZTCDY_junjia like '%" + key + "%' or ktype like '%" + key + "%' or kstate like '%" + key + "%' or klevel like '%" + key + "%' or kremark1 like '%" + key + "%' or kremark2 like '%" + key + "%' or kremark3 like '%" + key + "%' or kremark4 like '%" + key + "%' or kremark5 like '%" + key + "%' or kremark6 like '%" + key + "%' or kremark7 like '%" + key + "%' or kremark8 like '%" + key + "%' or kremark9 like '%" + key + "%' )"; //删除无用字段,删除最后一个or string sql3 = string.IsNullOrEmpty(state) ? "" : " and kstate= '" + state + "' "; //状态字段,无用删除 string sql4 = id == 0 ? "" : " and klid='" + id.ToString() + "' "; //Int字段,无用删除 string sql5 = startdate == new DateTime() ? "" : " and DATEDIFF(D,'" + startdate.ToString("yyyy-MM-dd") + "',kdate)>=0 "; //时间字段,无用删除 string sql6 = enddate == new DateTime() ? "" : " and DATEDIFF(D,'" + enddate.ToString("yyyy-MM-dd") + "',kdate)<=0 "; //时间字段,无用删除 string sql7 = string.IsNullOrEmpty(orderby) ? " order by kid desc " : " order by " + orderby; // string sql8 = s == 1 ? "" : " and kid not in ( select top " + (s - 1).ToString() + " kid from keys where " + sql2 + sql3 + sql4 + sql5 + sql6 + sql7 + " ) "; string sql9 = e == 0 ? " " : " limit " + s + "," + e; DBHelper.sqlstr = sql1 + sql2 + sql3 + sql4 + sql5 + sql6 + sql7 + sql9; List <keys> list = new List <keys>(); MySqlDataReader reader = DBHelper.ExecuteReader(); while (reader.Read()) { keys Obj = GetByReader(reader); list.Add(Obj); } reader.Close(); return(list); }
/* Called to determine if a key is relevant to this application */ public bool key_is_relevant(keys msg) { /* For this example we just care about codes > 0, which are the ones related to instances ins1 and ins2 .*/ return (msg.code > 0); }
static void publish(int domain_id, int sample_count) { // --- Create participant --- // /* To customize participant QoS, use the configuration file USER_QOS_PROFILES.xml */ DDS.DomainParticipant participant = DDS.DomainParticipantFactory.get_instance().create_participant( domain_id, DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT, null /* listener */, DDS.StatusMask.STATUS_MASK_NONE); if (participant == null) { shutdown(participant); throw new ApplicationException("create_participant error"); } // --- Create publisher --- // /* To customize publisher QoS, use the configuration file USER_QOS_PROFILES.xml */ DDS.Publisher publisher = participant.create_publisher( DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT, null /* listener */, DDS.StatusMask.STATUS_MASK_NONE); if (publisher == null) { shutdown(participant); throw new ApplicationException("create_publisher error"); } // --- Create topic --- // /* Register type before creating topic */ System.String type_name = keysTypeSupport.get_type_name(); try { keysTypeSupport.register_type( participant, type_name); } catch (DDS.Exception e) { Console.WriteLine("register_type error {0}", e); shutdown(participant); throw e; } /* To customize topic QoS, use the configuration file USER_QOS_PROFILES.xml */ DDS.Topic topic = participant.create_topic( "Example keys", type_name, DDS.DomainParticipant.TOPIC_QOS_DEFAULT, null /* listener */, DDS.StatusMask.STATUS_MASK_NONE); if (topic == null) { shutdown(participant); throw new ApplicationException("create_topic error"); } // --- Create writer --- // /* We are going to load different QoS profiles for the two DWs */ DDS.DataWriterQos writerQos = new DDS.DataWriterQos(); /* To customize data writer QoS, use the configuration file USER_QOS_PROFILES.xml */ DDS.DataWriter writer = publisher.create_datawriter( topic, DDS.Publisher.DATAWRITER_QOS_DEFAULT, null /* listener */, DDS.StatusMask.STATUS_MASK_NONE); DDS.DomainParticipantFactory.get_instance().get_datawriter_qos_from_profile(writerQos, "keys_Library", "keys_Profile_dw2"); /* If you want to set the writer_data_lifecycle QoS settings * programmatically rather than using the XML, you will need to add * the following lines to your code and comment out the create_datawriter * and get_datawriter_qos_from_profile calls above. */ /* publisher.get_default_datawriter_qos(writerQos); writerQos.writer_data_lifecycle.autodispose_unregistered_instances = false; writerQos.ownership.kind = DDS.OwnershipQosPolicyKind.EXCLUSIVE_OWNERSHIP_QOS; writerQos.ownership_strength.value = 10; DDS.DataWriter writer = publisher.create_datawriter( topic, writerQos, null, DDS.StatusMask.STATUS_MASK_NONE); writerQos.ownership_strength.value = 5; */ DDS.DataWriter writer2 = publisher.create_datawriter( topic, writerQos, null /* listener */, DDS.StatusMask.STATUS_MASK_NONE); if (writer == null) { shutdown(participant); throw new ApplicationException("create_datawriter error"); } keysDataWriter keys_writer = (keysDataWriter)writer; if (writer2 == null) { shutdown(participant); throw new ApplicationException("create_datawriter error"); } keysDataWriter keys_writer2 = (keysDataWriter)writer2; // --- Write --- // /* Creates three instances */ keys[] instance = new keys[3] { null, null, null }; /* Create data sample for writing */ instance[0] = keysTypeSupport.create_data(); instance[1] = keysTypeSupport.create_data(); instance[2] = keysTypeSupport.create_data(); if ((instance[0] == null) || (instance[1] == null) || (instance[2] == null) ) { shutdown(participant); throw new ApplicationException( "keysTypeSupport.create_data error"); } /* RTI Connext could examine the key fields each time it needs to determine * which data-instance is being modified. * However, for performance and semantic reasons, it is better * for your application to declare all the data-instances it intends to * modify prior to actually writing any samples. This is known as registration. */ /* In order to register the instances, we must set their associated keys first */ instance[0].code = 0; instance[1].code = 1; instance[2].code = 2; /* For a data type that has a key, if the same instance is going to be written multiple times, initialize the key here and register the keyed instance prior to writing */ DDS.InstanceHandle_t[] handle = new DDS.InstanceHandle_t[3]; Console.WriteLine("----DW1 registering instance handle", instance[0].code); handle[0] = keys_writer.register_instance(instance[0]); // Init coordinates instance[0].x = 1; instance[1].x = 1; instance[2].x = 1; int[] active = new int[] { 1, 0, 0 }; // Only send active keys. /* Make variables for the instance for the second datawriter to use. Note that it actually refers to the same logical instance, but because we're running both datawriters in the same thread, we to create separate variables so they don't clobber each other. */ keys instance_dw2 = null; instance_dw2 = keysTypeSupport.create_data(); if (instance_dw2 == null) { shutdown(participant); throw new ApplicationException("keysTypeSupport.create_data error"); } /* instance_dw2 and instance[1] have the same key, and thus will write to the same instance (ins1). */ instance_dw2.code = instance[1].code; instance_dw2.x = 2; DDS.InstanceHandle_t handle_dw2 = keys_writer2.register_instance(instance_dw2); int active_dw2 = 1; /* Main loop */ const System.Int32 send_period = 1000; // milliseconds for (int count = 0; (sample_count == 0) || (count < sample_count); ++count) { System.Threading.Thread.Sleep(send_period); /* Modify the data to be sent here */ instance[0].y = count; instance[1].y = count + 1000; instance[2].y = count + 2000; instance_dw2.y = -count - 1000; /* We control two datawriters via a state machine here rather than introducing separate threads. */ /* Control first DataWriter */ switch (count) { case 4: { /* Start sending the second (ins1) and third instances (ins2) */ Console.WriteLine("----DW1 registering instance {0}", instance[1].code); Console.WriteLine("----DW1 registering instance {0}", instance[2].code); handle[1] = keys_writer.register_instance(instance[1]); handle[2] = keys_writer.register_instance(instance[2]); active[1] = 1; active[2] = 1; } break; case 8: { /* Dispose the second instance (ins1) */ Console.WriteLine("----DW1 disposing instance {0}", instance[1].code); try { keys_writer.dispose(instance[1], ref handle[1]); } catch (DDS.Exception e) { Console.WriteLine("dispose instance error: {0}", e); return; } active[1] = 0; } break; case 10: { /* Unregister the second instance (ins1) */ Console.WriteLine("----DW1 unregistering instance {0}", instance[1].code); try { keys_writer.unregister_instance(instance[1], ref handle[1]); } catch (DDS.Exception e) { Console.WriteLine("unregister instance error: {0}", e); return; } active[1] = 0; } break; case 12: { /* Unregister the third instance (ins2) */ Console.WriteLine("----DW1 unregistering instance {0}", instance[2].code); try { keys_writer.unregister_instance(instance[2], ref handle[2]); } catch (DDS.Exception e) { Console.WriteLine("unregister instance error: {0}", e); return; } active[2] = 0; /* Re-register the second instance (ins1) */ Console.WriteLine("----DW1 re-registering instance {0}", instance[1].code); handle[1] = keys_writer.register_instance(instance[1]); active[1] = 1; } break; case 16: { /* Re-register the third instance (ins2) */ Console.WriteLine("----DW1 re-registering instance {0}", instance[2].code); handle[2] = keys_writer.register_instance(instance[2]); active[2] = 1; } break; } for (int i = 0; i < 3; ++i) { if (active[i] == 1) { Console.WriteLine("DW1 write; code: {0}, x: {1}, y: {2}", instance[i].code, instance[i].x, instance[i].y); try { keys_writer.write(instance[i], ref handle[i]); } catch (DDS.Exception e) { Console.WriteLine("write error {0}", e); return; } } } /* Control second datawriter */ switch (count) { case 16: { /* Dispose the instance (ins1). Since it has lower ownership strength, this does nothing */ Console.WriteLine("----DW2 disposing instance {0}", instance_dw2.code); try { keys_writer2.dispose(instance_dw2, ref handle_dw2); } catch (DDS.Exception e) { Console.WriteLine("dispose error {0}", e); return; } active_dw2 = 0; } break; } if (active_dw2 == 1) { Console.WriteLine("DW2 write; code: {0}, x: {1}, y: {2}", instance_dw2.code, instance_dw2.x, instance_dw2.y); try { keys_writer2.write(instance_dw2, ref handle_dw2); } catch (DDS.Exception e) { Console.WriteLine("write error {0}", e); return; } } } // --- Shutdown --- // /* Delete data sample */ for (int i = 0; i < 3; i++) { try { keysTypeSupport.delete_data(instance[i]); } catch (DDS.Exception e) { Console.WriteLine( "keysTypeSupport.delete_data error: {0}", e); } } try { keysTypeSupport.delete_data(instance_dw2); } catch (DDS.Exception e) { Console.WriteLine( "keysTypeSupport.delete_data error: {0}", e); } /* Delete all entities */ shutdown(participant); }
/**** Start changes for Advanced_Keys ****/ public override void on_data_available(DDS.DataReader reader) { keysDataReader keys_reader = (keysDataReader)reader; //// Start changes for Advanced_Keys while (true) { /* Given DDS_HANDLE_NIL as a parameter, take_next_instance returns * a sequence containing samples from only the next (in a well-determined * but unspecified order) un-taken instance. */ try { keys_reader.take_next_instance( data_seq, info_seq, DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED, ref DDS.InstanceHandle_t.HANDLE_NIL, DDS.SampleStateKind.ANY_SAMPLE_STATE, DDS.ViewStateKind.ANY_VIEW_STATE, DDS.InstanceStateKind.ANY_INSTANCE_STATE); } catch (DDS.Retcode_NoData) { break; } catch (DDS.Exception e) { Console.WriteLine("take error {0}", e); return; } System.Int32 data_length = data_seq.length; /* We process all the obtained samples for a particular instance */ for (int i = 0; i < data_length; ++i) { /* We first check if the sample includes valid data */ if (info_seq.get_at(i).valid_data) { if (info_seq.get_at(i).view_state == DDS.ViewStateKind.NEW_VIEW_STATE) { new_instance_found(keys_reader, info_seq.get_at(i), data_seq.get_at(i)); } /* We check if the obtained samples are associated to one * of the instances of interest. * Since take_next_instance gives sequences of the same instance, * we only need to test this for the first sample obtained. */ if (i == 0 && !key_is_relevant(data_seq.get_at(i))) { break; } handle_data(keys_reader, info_seq.get_at(i), data_seq.get_at(i)); } else { /* Since there is not valid data, it may include metadata */ keys dummy = null;; dummy = keysTypeSupport.create_data(); if (dummy == null) { throw new ApplicationException( "keysTypeSupport.create_data error"); } DDS.InstanceHandle_t handle = info_seq.get_at(i).instance_handle; try { keys_reader.get_key_value(dummy, ref handle); } catch (DDS.Exception e) { Console.WriteLine(" get_key_value error {0}", e); } /* Here we print a message and change the instance state * if the instance state is ALIVE_NO_WRITERS or ALIVE_DISPOSED */ if (info_seq.get_at(i).instance_state == DDS.InstanceStateKind.NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) { instance_lost_writers(keys_reader, info_seq.get_at(i), dummy); } else if (info_seq.get_at(i).instance_state == DDS.InstanceStateKind.NOT_ALIVE_DISPOSED_INSTANCE_STATE) { instance_disposed(keys_reader, info_seq.get_at(i), dummy); } } } try { keys_reader.return_loan(data_seq, info_seq); } catch (DDS.Exception e) { Console.WriteLine("return loan error {0}", e); } } }
inputs[startIndex++] = buildInput(keys[i]);
var(keys, vals) = rel;
/* These are not called by DDS. on_data_available() calls the appropriate function when it gets updates about an instances' status */ public void new_instance_found(keysDataReader keys_reader, DDS.SampleInfo info, keys msg) { /* There are really three cases here: 1.) truly new instance 2.) instance lost all writers, but now we're getting data again 3.) instance was disposed, but a new one has been created We distinguish these cases by examining generation counts, BUT note that if the instance resources have been reclaimed, the generation counts may be reset to 0. Instances are eligible for resource cleanup if there are no active writers and all samples have been taken. To reliably determine which case a 'new' instance falls into, the application must store state information on a per-instance basis. Note that this example assumes that state changes only occur via explicit register_instance(), unregister_instance() and dispose() calls from the datawriter. In reality, these changes could also occur due to lost liveliness or missed deadlines, so those listeners would also need to update the instance state. */ switch (states[msg.code]) { case Instance_State.inactive: Console.WriteLine("New instance found; code = {0}", msg.code); break; case Instance_State.active: /* An active instance should never be interpreted as new */ Console.WriteLine("Error, 'new' already-active instance found; code = {0}", msg.code); break; case Instance_State.no_writers: Console.WriteLine("Found writer for instance; code = {0}", msg.code); break; case Instance_State.disposed: Console.WriteLine("Found reborn instance; code = {0}", msg.code); break; } states[msg.code] = Instance_State.active; }
static void publish(int domain_id, int sample_count) { // --- Create participant --- // /* To customize participant QoS, use the configuration file USER_QOS_PROFILES.xml */ DDS.DomainParticipant participant = DDS.DomainParticipantFactory.get_instance().create_participant( domain_id, DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT, null /* listener */, DDS.StatusMask.STATUS_MASK_NONE); if (participant == null) { shutdown(participant); throw new ApplicationException("create_participant error"); } // --- Create publisher --- // /* To customize publisher QoS, use the configuration file USER_QOS_PROFILES.xml */ DDS.Publisher publisher = participant.create_publisher( DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT, null /* listener */, DDS.StatusMask.STATUS_MASK_NONE); if (publisher == null) { shutdown(participant); throw new ApplicationException("create_publisher error"); } // --- Create topic --- // /* Register type before creating topic */ System.String type_name = keysTypeSupport.get_type_name(); try { keysTypeSupport.register_type( participant, type_name); } catch(DDS.Exception e) { Console.WriteLine("register_type error {0}", e); shutdown(participant); throw e; } /* To customize topic QoS, use the configuration file USER_QOS_PROFILES.xml */ DDS.Topic topic = participant.create_topic( "Example keys", type_name, DDS.DomainParticipant.TOPIC_QOS_DEFAULT, null /* listener */, DDS.StatusMask.STATUS_MASK_NONE); if (topic == null) { shutdown(participant); throw new ApplicationException("create_topic error"); } // --- Create writer --- // /* To customize data writer QoS, use the configuration file USER_QOS_PROFILES.xml */ DDS.DataWriter writer = publisher.create_datawriter( topic, DDS.Publisher.DATAWRITER_QOS_DEFAULT, null /* listener */, DDS.StatusMask.STATUS_MASK_NONE); /* If you want to set the writer_data_lifecycle QoS settings * programmatically rather than using the XML, you will need to add * the following lines to your code and comment out the create_datawriter * call above. */ /*DDS.DataWriterQos datawriter_qos = new DDS.DataWriterQos(); try { publisher.get_default_datawriter_qos(datawriter_qos); } catch (DDS.Exception e) { Console.WriteLine("get_default_datawriter_qos error", e); } datawriter_qos.writer_data_lifecycle.autodispose_unregistered_instances = false; DDS.DataWriter writer = publisher.create_datawriter( topic, datawriter_qos, null, DDS.StatusMask.STATUS_MASK_NONE); */ if (writer == null) { shutdown(participant); throw new ApplicationException("create_datawriter error"); } keysDataWriter keys_writer = (keysDataWriter)writer; // --- Write --- // /* For a data type that has a key, if the same instance is going to be written multiple times, initialize the key here and register the keyed instance prior to writing */ DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL; /* Creates three instances */ keys[] instance = new keys[3] { null, null, null }; /* Create data samples for writing */ instance[0] = keysTypeSupport.create_data(); instance[1] = keysTypeSupport.create_data(); instance[2] = keysTypeSupport.create_data(); if (instance[0] == null || instance[1] == null || instance[2] == null) { shutdown(participant); throw new ApplicationException( "keysTypeSupport::create_data error\n"); } /* RTI Connext could examine the key fields each time it needs to determine * which data-instance is being modified. * However, for performance and semantic reasons, it is better * for your application to declare all the data-instances it intends to * modify prior to actually writing any samples. This is known as registration. */ /* In order to register the instances, we must set their associated keys first */ instance[0].code = 0; instance[1].code = 1; instance[2].code = 2; /* Creates three handles for managing the registrations */ DDS.InstanceHandle_t[] handle = new DDS.InstanceHandle_t[] {DDS.InstanceHandle_t.HANDLE_NIL, DDS.InstanceHandle_t.HANDLE_NIL, DDS.InstanceHandle_t.HANDLE_NIL}; /* The keys must have been set before making this call */ Console.WriteLine("Registering instance {0}", instance[0].code); handle[0] = keys_writer.register_instance(instance[0]); /* Modify the data to be sent here */ instance[0].x = 1000; instance[1].x = 2000; instance[2].x = 3000; /* We only will send data over the instances marked as active */ int[] active = new int[] { 1, 0, 0 }; // Only send active tracks. /* Main loop */ const System.Int32 send_period = 1000; // milliseconds for (int count=0; (sample_count == 0) || (count < sample_count); ++count) { //Console.WriteLine("Writing keys, count {0}", count); switch (count) { case 5: { /* Start sending the second and third instances */ Console.WriteLine("----Registering instance {0}", instance[1].code); Console.WriteLine("----Registering instance {0}", instance[2].code); handle[1] = keys_writer.register_instance(instance[1]); handle[2] = keys_writer.register_instance(instance[2]); active[1] = 1; active[2] = 1; } break; case 10: { /* Unregister the second instance */ Console.WriteLine("----Unregistering instance {0}", instance[1].code); try { keys_writer.unregister_instance(instance[1], ref handle[1]); } catch (DDS.Exception e) { Console.WriteLine("unregister instance error {0}", e); } active[1] = 0; } break; case 15: { /* Dispose the third instance */ Console.WriteLine("----Disposing instance {0}", instance[2].code); try { keys_writer.dispose(instance[2], ref handle[2]); } catch (DDS.Exception e) { Console.WriteLine("dispose instance error {0}", e); } active[2] = 0; } break; } /* Modify the data to be sent here */ instance[0].y = count; instance[1].y = count; instance[2].y = count; for (int i = 0; i < 3; ++i) { if (active[i] == 1) { Console.WriteLine("Writing instance {0}, x: {1}, y: {2}", instance[i].code, instance[i].x, instance[i].y); try { keys_writer.write(instance[i], ref handle[i]); } catch (DDS.Exception e) { Console.WriteLine("write error {0}", e); } } } System.Threading.Thread.Sleep(send_period); } // --- Shutdown --- // /* Delete data samples */ try { keysTypeSupport.delete_data(instance[0]); } catch (DDS.Exception e) { Console.WriteLine("keysTypeSupport.delete_data error: {0}", e); } try { keysTypeSupport.delete_data(instance[1]); } catch (DDS.Exception e) { Console.WriteLine("keysTypeSupport.delete_data error: {0}", e); } try { keysTypeSupport.delete_data(instance[2]); } catch (DDS.Exception e) { Console.WriteLine("keysTypeSupport.delete_data error: {0}", e); } /* Delete all entities */ shutdown(participant); }
$"mapping ({MappingToString(keys, expressions.SpecializeToCommonTypes(out var specializedTypes, out var specializedExpressions))})",
// Use this for initialization void Start () { var player = GameObject.FindGameObjectWithTag("Player"); keyRing = player.GetComponent<keys>(); }
public override void on_data_available(DDS.DataReader reader) { keysDataReader keys_reader = (keysDataReader)reader; try { keys_reader.take( data_seq, info_seq, DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED, DDS.SampleStateKind.ANY_SAMPLE_STATE, DDS.ViewStateKind.ANY_VIEW_STATE, DDS.InstanceStateKind.ANY_INSTANCE_STATE); } catch(DDS.Retcode_NoData) { return; } catch(DDS.Exception e) { Console.WriteLine("take error {0}", e); return; } System.Int32 data_length = data_seq.length; for (int i = 0; i < data_length; ++i) { /* Start changes for Keyed_Data */ /* We first check if the sample includes valid data */ if (info_seq.get_at(i).valid_data) { if (info_seq.get_at(i).view_state == DDS.ViewStateKind.NEW_VIEW_STATE) { Console.WriteLine("Found new instance; code = {0}", data_seq.get_at(i).code); } Console.WriteLine("Instance {0}: x: {1}, y: {2}", data_seq.get_at(i).code, data_seq.get_at(i).x, data_seq.get_at(i).y); } else { /* Since there is not valid data, it may include metadata */ keys dummy = new keys(); try { DDS.InstanceHandle_t temp = info_seq.get_at(i).instance_handle; keys_reader.get_key_value(dummy, ref temp); } catch (DDS.Exception e) { Console.WriteLine("get_key_value error {0}", e); } /* Here we print a message if the instance state is ALIVE_NO_WRITERS or ALIVE_DISPOSED */ if (info_seq.get_at(i).instance_state == DDS.InstanceStateKind.NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) { Console.WriteLine("Instance {0} has no writers", dummy.code); } else if (info_seq.get_at(i).instance_state == DDS.InstanceStateKind.NOT_ALIVE_DISPOSED_INSTANCE_STATE) { Console.WriteLine("Instance {0} disposed", dummy.code); } } /* End changes for Keyed_Data */ } try { keys_reader.return_loan(data_seq, info_seq); } catch(DDS.Exception e) { Console.WriteLine("return loan error {0}", e); } }
/* Called to determine if a key is relevant to this application */ public bool key_is_relevant(keys msg) { /* For this example we just care about codes > 0, * which are the ones related to instances ins1 and ins2 .*/ return(msg.code > 0); }