public void GetCityId() { ManagedCountry c = new ManagedCountry(Session); ManagedState t = new ManagedState(Session); ManagedCity s = new ManagedCity(Session); try { TransitCountry tc = new TransitCountry(); tc.Name = GetNewString(); TransitState tt = new TransitState(); tt.Name = GetNewString(); tt.Country = tc.Name; TransitCity ts = new TransitCity(); ts.Name = GetNewString(); ts.Country = tc.Name; ts.State = tt.Name; c.CreateOrUpdate(tc, AdminSecurityContext); t.CreateOrUpdate(tt, AdminSecurityContext); Session.Flush(); s.CreateOrUpdate(ts, AdminSecurityContext); Session.Flush(); ManagedCity.GetCityId(Session, ts.Name, tt.Name, tc.Name); } finally { s.Delete(AdminSecurityContext); t.Delete(AdminSecurityContext); c.Delete(AdminSecurityContext); } }
public string[] GetCitiesCompletionList(string prefixText, int count, string contextKey) { // TODO: manufacture a guest ticket and run this through WebServiceImpl // country;state string[] context_parts = contextKey.Split(";,|".ToCharArray(), 2); if (context_parts.Length != 2) { return(null); } using (SnCore.Data.Hibernate.Session.OpenConnection()) { ISession session = SnCore.Data.Hibernate.Session.Current; int country_id = 0; if (!string.IsNullOrEmpty(context_parts[0])) { if (!ManagedCountry.TryGetCountryId(session, context_parts[0], out country_id)) { return(null); } } int state_id = 0; if (!string.IsNullOrEmpty(context_parts[1])) { if (!ManagedState.TryGetStateId(session, context_parts[1], context_parts[0], out state_id)) { return(null); } } ICriteria ic = session.CreateCriteria(typeof(City)) .Add(Expression.Like("Name", string.Format("{0}%", Renderer.SqlEncode(prefixText)))); if (country_id != 0) { ic.Add(Expression.Eq("Country.Id", country_id)); } if (state_id != 0) { ic.Add(Expression.Eq("State.Id", state_id)); } IList <City> nhs = ic.AddOrder(Order.Asc("Name")) .SetMaxResults(count) .List <City>(); List <string> result = new List <string>(nhs.Count); foreach (City nh in nhs) { result.Add(nh.Name); } return(result.ToArray()); } }
public void CreateManyPlaces(int count) { Random r = new Random(); ManagedSecurityContext sec = ManagedAccount.GetAdminSecurityContext(Session); // country TransitCountry t_country = new TransitCountry(); t_country.Name = Guid.NewGuid().ToString(); ManagedCountry country = new ManagedCountry(Session); country.CreateOrUpdate(t_country, sec); // state TransitState t_state = new TransitState(); t_state.Name = Guid.NewGuid().ToString(); t_state.Country = t_country.Name; ManagedState state = new ManagedState(Session); state.CreateOrUpdate(t_state, sec); // city TransitCity t_city = new TransitCity(); t_city.Name = Guid.NewGuid().ToString(); t_city.State = t_state.Name; t_city.Country = t_country.Name; ManagedCity city = new ManagedCity(Session); city.CreateOrUpdate(t_city, sec); // place type TransitPlaceType t_placetype = new TransitPlaceType(); t_placetype.Name = Guid.NewGuid().ToString(); ManagedPlaceType placetype = new ManagedPlaceType(Session); placetype.CreateOrUpdate(t_placetype, sec); for (int i = 0; i < count; i++) { TransitPlace t_place = new TransitPlace(); t_place.Name = Guid.NewGuid().ToString(); t_place.AccountId = sec.Account.Id; t_place.City = t_city.Name; t_place.Country = t_country.Name; t_place.State = t_state.Name; t_place.Street = string.Format("{0} {1} St.", r.Next(), Guid.NewGuid().ToString()); t_place.Zip = r.Next().ToString(); t_place.Type = t_placetype.Name; ManagedPlace place = new ManagedPlace(Session); place.CreateOrUpdate(t_place, sec); } }
private void Start() { this.agentTypeManager = AgentTypeScript.Instance; this.endScreenManager.Disable(); this.currentGameEngine = initialize(); reset(this.currentGameEngine); this.mState = new ManagedState(); send_type_p1(this.currentGameEngine, (sbyte)this.agentTypeManager.Types[0], AgentTypeScript.Instance.nbFrames1, AgentTypeScript.Instance.nbSim1); send_type_p2(this.currentGameEngine, (sbyte)this.agentTypeManager.Types[1], AgentTypeScript.Instance.nbFrames2, AgentTypeScript.Instance.nbSim2); }
public void CreateManyPlaces(int count) { Random r = new Random(); ManagedSecurityContext sec = ManagedAccount.GetAdminSecurityContext(Session); // country TransitCountry t_country = new TransitCountry(); t_country.Name = Guid.NewGuid().ToString(); ManagedCountry country = new ManagedCountry(Session); country.CreateOrUpdate(t_country, sec); // state TransitState t_state = new TransitState(); t_state.Name = Guid.NewGuid().ToString(); t_state.Country = t_country.Name; ManagedState state = new ManagedState(Session); state.CreateOrUpdate(t_state, sec); // city TransitCity t_city = new TransitCity(); t_city.Name = Guid.NewGuid().ToString(); t_city.State = t_state.Name; t_city.Country = t_country.Name; ManagedCity city = new ManagedCity(Session); city.CreateOrUpdate(t_city, sec); // place type TransitPlaceType t_placetype = new TransitPlaceType(); t_placetype.Name = Guid.NewGuid().ToString(); ManagedPlaceType placetype = new ManagedPlaceType(Session); placetype.CreateOrUpdate(t_placetype, sec); for (int i = 0; i < count; i++) { TransitPlace t_place = new TransitPlace(); t_place.Name = Guid.NewGuid().ToString(); t_place.AccountId = sec.Account.Id; t_place.City = t_city.Name; t_place.Country = t_country.Name; t_place.State = t_state.Name; t_place.Street = string.Format("{0} {1} St.", r.Next(), Guid.NewGuid().ToString()); t_place.Zip = r.Next().ToString(); t_place.Type = t_placetype.Name; ManagedPlace place = new ManagedPlace(Session); place.CreateOrUpdate(t_place, sec); } }
public void CreateManyAccounts(int count) { ManagedSecurityContext sec = ManagedAccount.GetAdminSecurityContext(Session); TransitCountry tc = new TransitCountry(); tc.Name = Guid.NewGuid().ToString(); TransitState ts = new TransitState(); ts.Name = Guid.NewGuid().ToString(); ts.Country = tc.Name; ManagedCountry c = new ManagedCountry(Session); c.CreateOrUpdate(tc, sec); ManagedState s = new ManagedState(Session); s.CreateOrUpdate(ts, sec); TransitAccountAddress ta = new TransitAccountAddress(); ta.Apt = "123"; ta.City = "New York"; ta.Country = tc.Name; ta.Name = "My Address"; ta.State = ts.Name; ta.Street = "Houston St."; ta.Zip = "10001"; for (int i = 0; i < count; i++) { ManagedAccount a = new ManagedAccount(Session); string name = Guid.NewGuid().ToString(); a.Create( name, "password", string.Format("{0}@localhost.com", name), DateTime.UtcNow, sec); ManagedAccountAddress ma = new ManagedAccountAddress(Session); ma.CreateOrUpdate(ta, a.GetSecurityContext()); } }
public List <TransitCity> GetCitiesByLocation(string ticket, string country, string state, ServiceQueryOptions options) { using (SnCore.Data.Hibernate.Session.OpenConnection()) { ISession session = SnCore.Data.Hibernate.Session.Current; ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket); List <TransitCity> result = new List <TransitCity>(); if (string.IsNullOrEmpty(country)) { return(result); } Country t_country = ManagedCountry.Find(session, country); ICriteria cr = session.CreateCriteria(typeof(City)) .Add(Expression.Eq("Country.Id", t_country.Id)); if (t_country.States != null && t_country.States.Count > 0 && string.IsNullOrEmpty(state)) { // no state specified but country has states return(result); } if (!string.IsNullOrEmpty(state)) { // state specified State t_state = ManagedState.Find(session, state, country); cr.Add(Expression.Eq("State.Id", t_state.Id)); } if (options != null) { cr.SetFirstResult(options.FirstResult); cr.SetMaxResults(options.PageSize); } return(WebServiceImpl <TransitCity, ManagedCity, City> .GetTransformedList( session, sec, cr.List <City>())); } }
public void CreateManyAccounts(int count) { ManagedSecurityContext sec = ManagedAccount.GetAdminSecurityContext(Session); TransitCountry tc = new TransitCountry(); tc.Name = Guid.NewGuid().ToString(); TransitState ts = new TransitState(); ts.Name = Guid.NewGuid().ToString(); ts.Country = tc.Name; ManagedCountry c = new ManagedCountry(Session); c.CreateOrUpdate(tc, sec); ManagedState s = new ManagedState(Session); s.CreateOrUpdate(ts, sec); TransitAccountAddress ta = new TransitAccountAddress(); ta.Apt = "123"; ta.City = "New York"; ta.Country = tc.Name; ta.Name = "My Address"; ta.State = ts.Name; ta.Street = "Houston St."; ta.Zip = "10001"; for (int i = 0; i < count; i++) { ManagedAccount a = new ManagedAccount(Session); string name = Guid.NewGuid().ToString(); a.Create( name, "password", string.Format("{0}@localhost.com", name), DateTime.UtcNow, sec); ManagedAccountAddress ma = new ManagedAccountAddress(Session); ma.CreateOrUpdate(ta, a.GetSecurityContext()); } }
public void CreateAccountAddress() { ManagedAccount a = new ManagedAccount(Session); ManagedCountry c = new ManagedCountry(Session); ManagedState s = new ManagedState(Session); try { a.Create("Test User", "testpassword", "*****@*****.**", DateTime.UtcNow, AdminSecurityContext); TransitCountry tc = new TransitCountry(); tc.Name = GetNewString(); TransitState ts = new TransitState(); ts.Name = GetNewString(); ts.Country = tc.Name; c.CreateOrUpdate(tc, AdminSecurityContext); s.CreateOrUpdate(ts, AdminSecurityContext); TransitAccountAddress ta = new TransitAccountAddress(); ta.Apt = "123"; ta.City = "New York"; ta.Country = tc.Name; ta.Name = "My Address"; ta.State = ts.Name; ta.Street = "Houston St."; ta.Zip = "10001"; ManagedAccountAddress m_a = new ManagedAccountAddress(Session); m_a.CreateOrUpdate(ta, new ManagedSecurityContext(a.Instance)); } finally { a.Delete(AdminSecurityContext); s.Delete(AdminSecurityContext); c.Delete(AdminSecurityContext); Session.Flush(); } }
public void CreateAccountAddress() { ManagedAccount a = new ManagedAccount(Session); ManagedCountry c = new ManagedCountry(Session); ManagedState s = new ManagedState(Session); try { a.Create("Test User", "testpassword", "*****@*****.**", DateTime.UtcNow, AdminSecurityContext); TransitCountry tc = new TransitCountry(); tc.Name = GetNewString(); TransitState ts = new TransitState(); ts.Name = GetNewString(); ts.Country = tc.Name; c.CreateOrUpdate(tc, AdminSecurityContext); s.CreateOrUpdate(ts, AdminSecurityContext); TransitAccountAddress ta = new TransitAccountAddress(); ta.Apt = "123"; ta.City = "New York"; ta.Country = tc.Name; ta.Name = "My Address"; ta.State = ts.Name; ta.Street = "Houston St."; ta.Zip = "10001"; ManagedAccountAddress m_a = new ManagedAccountAddress(Session); m_a.CreateOrUpdate(ta, new ManagedSecurityContext(a.Instance)); } finally { a.Delete(AdminSecurityContext); s.Delete(AdminSecurityContext); c.Delete(AdminSecurityContext); Session.Flush(); } }
/// <summary> /// Perform the WebDAV call and fire the callback when finished. /// </summary> private void BeginHttpRequest <TUserState>( Uri uri, string requestMethod, AsyncCallback callback, IDictionary <string, string> headers = null, byte[] content = null, string uploadFilePath = null, TUserState userState = null) where TUserState : class { var httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(uri); var managedState = new ManagedState <TUserState> { UserState = userState, HttpWebRequest = httpWebRequest }; // The server may use authentication this.SetCredentials(httpWebRequest); httpWebRequest.Method = requestMethod; httpWebRequest.ContentType = "text/xml"; // Need to send along headers? if (headers != null) { foreach (string key in headers.Keys) { httpWebRequest.Headers.Set(key, headers[key]); } } // Need to send along content? if (content != null || uploadFilePath != null) { var asyncState = new RequestState { Request = httpWebRequest, UserCallback = callback, UserState = managedState }; if (content != null) { // The request either contains actual content... httpWebRequest.ContentLength = content.Length; asyncState.Content = content; } else { // ...or a reference to the file to be added as content. httpWebRequest.ContentLength = new FileInfo(uploadFilePath).Length; asyncState.UploadFilePath = uploadFilePath; } // Perform asynchronous request. IAsyncResult r = (IAsyncResult)asyncState.Request.BeginGetRequestStream(new AsyncCallback(ReadCallback), asyncState); } else { // Begin async communications httpWebRequest.BeginGetResponse(callback, managedState); } }
public void CreatePlace() { ManagedPlaceType type = new ManagedPlaceType(Session); ManagedCountry c = new ManagedCountry(Session); ManagedState t = new ManagedState(Session); ManagedCity s = new ManagedCity(Session); ManagedAccount a = new ManagedAccount(Session); try { a.Create("Test User", "testpassword", "*****@*****.**", DateTime.UtcNow, AdminSecurityContext); a.VerifyAllEmails(); a.AddDefaultPicture(); TransitCountry tc = new TransitCountry(); tc.Name = GetNewString(); TransitState tt = new TransitState(); tt.Name = GetNewString(); tt.Country = tc.Name; TransitCity ts = new TransitCity(); ts.Name = GetNewString(); ts.Country = tc.Name; ts.State = tt.Name; c.CreateOrUpdate(tc, AdminSecurityContext); t.CreateOrUpdate(tt, AdminSecurityContext); s.CreateOrUpdate(ts, AdminSecurityContext); TransitPlaceType t_type = new TransitPlaceType(); t_type.Name = GetNewString(); type.CreateOrUpdate(t_type, AdminSecurityContext); TransitPlace t_place = new TransitPlace(); t_place.Name = GetNewString(); t_place.Type = t_type.Name; t_place.City = ts.Name; t_place.Country = tc.Name; t_place.State = tt.Name; t_place.AccountId = a.Id; ManagedPlace m_place = new ManagedPlace(Session); m_place.CreateOrUpdate(t_place, a.GetSecurityContext()); } finally { try { a.Delete(AdminSecurityContext); type.Delete(AdminSecurityContext); s.Delete(AdminSecurityContext); t.Delete(AdminSecurityContext); c.Delete(AdminSecurityContext); } catch { } } }
private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { if (pauseScreenManager.isActived) { pauseScreenManager.Disable(); } else { pauseScreenManager.Enable(); this.pauseScreenManager.SetScore((int)this.mState.p1_score, (int)this.mState.p2_score); } } if (!pauseScreenManager.isActived) { this.inputs[0] = HumanInput.Idle; this.inputs[1] = HumanInput.Idle; for (var i = 0; i < this.agentTypeManager.Types.Length; i++) { var t = this.agentTypeManager.Types[i]; if (t == AgentTypeScript.AgentType.Human) { this.CollectInput(i); } } epoch(this.currentGameEngine, (sbyte)this.inputs[0], (sbyte)this.inputs[1]); this.mState = get_state(this.currentGameEngine); if (mState.time > 1.0 && !endScreenManager.isActived) { if (this.mState.p1_score < 10) { this.p1Score.text = "0" + this.mState.p1_score; } else { this.p1Score.text = "" + this.mState.p1_score; } if (this.mState.p2_score < 10) { this.p2Score.text = "0" + this.mState.p2_score; } else { this.p2Score.text = "" + this.mState.p2_score; } } this.p1Transform.position = new Vector3((float)this.mState.p1_x, this.p1Transform.position.y, (float)this.mState.p1_y); this.p2Transform.position = new Vector3((float)this.mState.p2_x, this.p2Transform.position.y, (float)this.mState.p2_y); if (!this.frisbeeHeld) { if (this.mState.zbee_held == 0) { this.frisbeeTransform.parent = this.p1Hands; this.frisbeeTransform.localPosition = Vector3.zero; this.frisbeeHeld = true; } else if (this.mState.zbee_held == 1) { this.frisbeeTransform.parent = this.p2Hands; this.frisbeeTransform.localPosition = Vector3.zero; this.frisbeeHeld = true; } } else { if (this.mState.zbee_held == -1) { this.frisbeeTransform.parent = null; this.frisbeeHeld = false; } } if (!this.frisbeeHeld) { this.frisbeeTransform.position = new Vector3((float)this.mState.zbee_x, 1.3f, (float)this.mState.zbee_y); } if (this.mState.State != (sbyte)StateOfGame.End && mState.time > 1.0) { var roundedTime = Mathf.RoundToInt((float)this.mState.time); if (roundedTime < 10) { this.SetTimerText("0" + roundedTime); } else { this.SetTimerText(roundedTime.ToString()); } } else { this.endScreenManager.Enable(); if (!block) { this.endScreenManager.SetScore((int)this.mState.p1_score, (int)this.mState.p2_score); block = true; } if (AgentTypeScript.Instance.turbo) { PlayAgain(); } } } }
public ManagedStateDisposable(ManagedState <T> stateMonitor, Action <(T Previous, T Current)> listener)