/// <summary> /// This TBS returns a random handle value in the desired handle range (ugh). /// </summary> /// <param name="owner"></param> /// <param name="tpmHandle"></param> /// <returns></returns> private uint GetFreeHandle(Tbs.TbsContext owner, TpmHandle tpmHandle) { Tbs.SlotType neededType = Tbs.SlotTypeFromHandle(tpmHandle); if (neededType == Tbs.SlotType.NoSlot) { return(tpmHandle.handle); } int numTries = 0; while (true) { Ht handleType = tpmHandle.GetType(); var randomPos = (uint)Globs.GetRandomInt((int)TpmHandle.GetRangeLength(tpmHandle.GetType())); uint candidateHandle = ((uint)handleType << 24) + randomPos; if (!OwnerHandleInUse(owner, candidateHandle)) { return(candidateHandle); } numTries++; if (numTries >= 1000) { break; } } throw new Exception("Too many TBS contexts"); }
/// <summary> /// /// </summary> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <returns></returns> public PagerData GetPagerData(int pageSize, int pageIndex) { SqlPager queryEr = new SqlPager(); queryEr.FirstResult = pageSize * pageIndex; queryEr.MaxResults = pageSize; DataTable dt = GetData(queryEr); ExecSqlQuery countQuery = new ExecSqlQuery(); if (SimpleCount) { countQuery.Sql = @"select count(1) as total " + FromSqlPart + " " + WhereAndOtherExpress; } else { countQuery.Sql = @"select count(1) as total " + string.Format(" from ({0}) t22 ", @"select 1 as id23 " + FromSqlPart + " " + WhereAndOtherExpress); } countQuery.ParamerList.AddRange(queryEr.ParamerList); IList listCountData = Ht.ExecuteFind(countQuery); int total = dt.Rows.Count; if (listCountData != null && listCountData.Count > 0) { int.TryParse(Convert.ToString((listCountData[0] as Hashtable)["total"]), out total); } PagerData returnData = new PagerData { Data = dt, Total = total }; return(returnData); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (Water != null) { hashCode = hashCode * 59 + Water.GetHashCode(); } if (Lt != null) { hashCode = hashCode * 59 + Lt.GetHashCode(); } if (Wind != null) { hashCode = hashCode * 59 + Wind.GetHashCode(); } if (Freeze != null) { hashCode = hashCode * 59 + Freeze.GetHashCode(); } if (Ht != null) { hashCode = hashCode * 59 + Ht.GetHashCode(); } if (Burn != null) { hashCode = hashCode * 59 + Burn.GetHashCode(); } return(hashCode); } }
private void HT_Click(object sender, RoutedEventArgs e) { txbtext.Items.Clear(); txbtext.Items.Add("STT \t\t Ban Kinh \t\t Chu Vi \t\t Dien Tich"); txbtext.Items.Add("***********************************************************************************"); List <HinhTron> ht = new List <HinhTron>(); int dem = 1; for (int i = 0; i < Int32.Parse(txbso.Text); i++) { ht.Add(new HinhTron((double)rand.Next(2, 15))); } foreach (HinhTron Ht in ht) { Ht.ChuVi(); Ht.DienTich(); txbtext.Items.Add(dem.ToString() + "\t\t " + Ht.BanKinh + "\t\t\t " + Ht.chuvi.ToString() + "\t\t" + Ht.dientich.ToString()); dem += 1; } }
public ActionResult DeleteConfirmed(int id) { Ht ht = db.Ht.Find(id); db.Ht.Remove(ht); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Get the length (number of handles) in the range dedicated to the handles /// of the given type. /// </summary> /// <param name="rangeType"></param> /// <returns></returns> public static uint GetRangeLength(Ht rangeType) { if (rangeType == Ht.NvIndex) { return(0x00FFFFFF); } return(1U << 24); }
public ActionResult Edit([Bind(Include = "ID,Name,Type,Area,Eat,Graft,DateNewGraft")] Ht ht) { if (ModelState.IsValid) { db.Entry(ht).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ht)); }
/// <summary> /// 把sql和条件装载到queryEr,然后执行queryEr上的方法获得数据 /// </summary> /// <param name="queryEr"></param> /// <returns></returns> public DataTable GetData(ExecSqlQuery queryEr) { //下面查询是导案板中的一条记录*一个卡主一条记录 queryEr.Sql = FieldsSqlPart + " " + FromSqlPart + " " + WhereAndOtherExpress + " " + OrderSqlPart; queryEr.ParamerList.AddRange(this.ParamerList); IList listData = Ht.ExecuteFind(queryEr); DataTable dt = HashTableListToDataTable.ToDataTable(listData); return(dt); }
public ActionResult Create([Bind(Include = "ID,Name,Type,Area,Eat,Graft,DateNewGraft")] Ht ht) { if (ModelState.IsValid) { db.Ht.Add(ht); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ht)); }
private static string g(int num) { if ((num >= -20319) && (num <= -10247)) { while (!Ht.ContainsKey(num)) { num--; } return(Ht[num].ToString()); } return(""); }
// GET: Hts/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Ht ht = db.Ht.Find(id); if (ht == null) { return(HttpNotFound()); } return(View(ht)); }
/// <summary> /// Returns true if DisasterInfo instances are equal /// </summary> /// <param name="other">Instance of DisasterInfo to be compared</param> /// <returns>Boolean</returns> public bool Equals(DisasterInfo other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Date == other.Date || Date != null && Date.Equals(other.Date) ) && ( Water == other.Water || Water != null && Water.Equals(other.Water) ) && ( Lt == other.Lt || Lt != null && Lt.Equals(other.Lt) ) && ( Wind == other.Wind || Wind != null && Wind.Equals(other.Wind) ) && ( Freeze == other.Freeze || Freeze != null && Freeze.Equals(other.Freeze) ) && ( Ht == other.Ht || Ht != null && Ht.Equals(other.Ht) ) && ( Burn == other.Burn || Burn != null && Burn.Equals(other.Burn) )); }
private TpmHandle[] GetLoadedEntities(Tpm2 tpm, Ht rangeToQuery) { const uint maxHandles = UInt32.MaxValue; ICapabilitiesUnion h; byte moreData = tpm.GetCapability(Cap.Handles, ((uint)rangeToQuery) << 24, maxHandles, out h); if (moreData != 0) { throw new NotImplementedException("Too much data returned"); } if (h.GetType() != typeof(HandleArray)) { throw new Exception("Incorrect type"); } var handles = (HandleArray)h; return(handles.handle); }
public static TpmHandle[] GetLoadedEntities(Tpm2 tpm, Ht rangeToQuery) { uint maxHandles = UInt32.MaxValue; ICapabilitiesUnion h = null; byte moreData = tpm.GetCapability(Cap.Handles, ((uint)rangeToQuery) << 24, maxHandles, out h); if (moreData != 0) { throw new NotImplementedException( "GetLoadedEntities: Too much data returned"); } if (h.GetType() != typeof(HandleArray)) { throw new Exception( "GetLoadedEntities: Incorrect capability type requested"); } return((h as HandleArray).handle); }
/// <summary> /// Returns true if DisasterGuidelines instances are equal /// </summary> /// <param name="other">Instance of DisasterGuidelines to be compared</param> /// <returns>Boolean</returns> public bool Equals(DisasterGuidelines other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Water == other.Water || Water != null && Water.SequenceEqual(other.Water) ) && ( Lt == other.Lt || Lt != null && Lt.SequenceEqual(other.Lt) ) && ( Wind == other.Wind || Wind != null && Wind.SequenceEqual(other.Wind) ) && ( Freeze == other.Freeze || Freeze != null && Freeze.SequenceEqual(other.Freeze) ) && ( Ht == other.Ht || Ht != null && Ht.SequenceEqual(other.Ht) ) && ( Burn == other.Burn || Burn != null && Burn.SequenceEqual(other.Burn) )); }
/// <summary> /// Returns the cached name of an entity referenced by this handle. If the /// name is not cached yet, retrieves it from the TPM (for a transient or /// persistent object, or NV index) or computes it (for session, PCR or /// permanent handles). /// </summary> public byte[] GetName(Tpm2 tpm) { Ht ht = GetType(); if (_Name == null) { if (ht == Ht.NvIndex) { tpm.NvReadPublic(this, out _Name); return(_Name); } if (ht == Ht.Transient || ht == Ht.Persistent) { byte[] qName; tpm.ReadPublic(this, out _Name, out qName); return(_Name); } } return(GetName()); }
/// <summary> /// Get the TPM name of the associated entity. /// /// If the entity is a transient object, persistent object or NV index, the /// name must have been previously set explicitly by the caller (by means of /// SetName() or GetName(Tpm2 tpm) methods) or implicitly by the framework /// (when an object is created by means of CreatePrimary, CreateLoaded or /// Create command). /// /// Otherwise the name is a 4-byte TPM representation of the handle value. /// </summary> public byte[] GetName() { Ht ht = GetType(); switch (ht) { case Ht.Transient: case Ht.Persistent: case Ht.NvIndex: return(_Name); case Ht.Pcr: case Ht.HmacSession: case Ht.PolicySession: case Ht.Permanent: return(Marshaller.GetTpmRepresentation(handle)); default: return(null); } }
public static Matrix[] KalmanFilter(Matrix y, Matrix Z, Matrix d, Matrix T, Matrix c, Matrix a0, Matrix P0, Matrix H, Matrix Q, int timeVar) { /* * function [a_smooth,P_smooth,P2_smooth] = Kalman_Smoothing(y,Z,d,T,c,a0,P0,H,Q,timevar) * % Kalman smoothing * % code is a Matlab translation of Thierry Roncalli's. * * nobs = size(y,1); * n = size(y,2); * at = a0; * Pt = P0; * * * if timevar == 1 * m=size(Z,2)/n; * g=size(Q,2)/m; * else * m=size(Z,2); * g=size(Q,2); * end * * a_cond = zeros(nobs,m); * a = zeros(nobs,m); * P_cond = zeros(nobs,m*m); * P = zeros(nobs,m*m); * a_smooth = zeros(nobs,m); * P_smooth = zeros(nobs,m*m); * * if timevar ~= 1 % then matrices are time invariant * Zt=Z; * dt=d; * Ht=H; * Tt=T; * ct=c; * %Rt=R; * Qt=Q; * end * * for i=1:nobs * * yt=y(i,:)'; % y(t) * * if timevar == 1 * Zt=reshape(Z(i,:),n,m); % Z(t) * dt=d(i,:)'; % d(t) * Ht=reshape(H(i,:),n,n); % H(t) * Tt=reshape(T(i,:),m,m); % T(t) * ct=c(i,:)'; % c(t) * Rt=reshape(R(i,:),m,g); % R(t) * Qt=reshape(Q(i,:),g,g); % Q(t) * end; * * % Prediction Equations * * at_1 = Tt*at + ct ; % a(t|t-1) formula(3.2.2a) * Pt_1 = Tt*Pt*Tt' + Qt;%Rt*Qt*Rt' ; % P(t|t-1) formula(3.2.2b) * * % Innovations * * yt_1 = Zt*at_1 + dt ; % y(t|t-1) formula(3.2.18) * vt = yt-yt_1 ; % v(t) formula(3.2.19) * * % Updating Equations * * Ft = Zt*Pt_1*Zt' + Ht ; % F(t) formula(3.2.3c) * inv_Ft = Ft\eye(size(Ft,1)); % Inversion de Ft * * at = at_1 + Pt_1*Zt'*inv_Ft*vt ; % a(t) formula(3.2.3a) * Pt = Pt_1 - Pt_1*Zt'*inv_Ft*Zt*Pt_1 ; % P(t) formula(3.2.3b) * * % Save results * * a(i,:)=at'; * a_cond(i,:)=at_1'; * P(i,:)=vecr(Pt)'; * P_cond(i,:)=vecr(Pt_1)'; * * end; * * % Smoothing Equations * * a_smooth(nobs,:)=at'; * P_smooth(nobs,:)=vecr(Pt)'; * * for i=(nobs-1):-1:1; * * if timevar == 1; * Tt=reshape(T(i+1,:),m,m); % T(t+1) * end; * * Pt=reshape(P(i,:),m,m); % P(t) * Pt_1=reshape(P_cond(i+1,:),m,m); % P(t+1|t) * Pt_1_T=reshape(P_smooth(i+1,:),m,m); % P(t+1|T) * at=a(i,:)'; % a(t) * at_1=a_cond(i+1,:)'; % a(t+1|t) * at_1_T=a_smooth(i+1,:)'; % a(t+1|T) * * inv_Pt_1 = Pt_1\eye(size(Pt_1,1)); % Inversion de Ft * * P_star = Pt*Tt'*inv_Pt_1; * * as = at + P_star*(at_1_T-at_1) ; % a(t|T) formula(3.6.16a) * Ps = Pt + P_star*(Pt_1_T-Pt_1)*P_star' ; % P(t|T) formula(3.6.16b) * * %Added equation P(t|t-1)' * P2_smooth(i,:)=vecr((Pt_1_T*P_star')'); * a_smooth(i,:)=as'; * P_smooth(i,:)=vecr(Ps)'; * * end */ int nobs = y.R; int n = y.C; int m = 0; int g = 0; Matrix at = a0; Matrix Pt = P0; Matrix logl = new Matrix(nobs, 1); if (timeVar == 1) { m = Z.C / n; g = Q.C / n; } else { m = Z.C; g = Q.C; } Matrix y_cond = new Matrix(nobs, n); Matrix v = new Matrix(nobs, n); Matrix a_cond = new Matrix(nobs, m); Matrix a = new Matrix(nobs, m); Matrix P_cond = new Matrix(nobs, m * m); Matrix P = new Matrix(nobs, m * m); Matrix F = new Matrix(nobs, n * n); Matrix Zt = new Matrix(); Matrix dt = new Matrix(); Matrix Ht = new Matrix(); Matrix Tt = new Matrix(); Matrix ct = new Matrix(); Matrix Qt = new Matrix(); if (timeVar != 1) { Zt = Z; dt = d; Ht = H; Tt = T; ct = c; Qt = Q; } for (int i = 0; i < nobs; i++) { Matrix yt = y[i, Range.All]; yt = yt.Transpose(); if (timeVar == 1) { Zt = Z[i, Range.All]; Zt = Zt.Reshape(n, m); dt = d[i, Range.All]; dt = dt.Transpose(); Ht = H[i, Range.All]; Ht = Ht.Reshape(n, n); Tt = T[i, Range.All]; Tt = Tt.Reshape(m, m); ct = c[i, Range.All]; ct = ct.Transpose(); Qt = Q[i, Range.All]; Qt = Qt.Reshape(g, g); } //% Prediction Equations Matrix at_1 = Tt * at + ct; Matrix Pt_1 = Tt * Pt * Tt.Transpose() + Qt; //% Innovations Matrix yt_1 = Zt * at_1 + dt; Matrix vt = yt - yt_1; //% Updating Equation Matrix Ft = Zt * Pt_1 * Zt.Transpose() + Ht; Matrix inv_Ft = Ft.Inverse(); at = at_1 + Pt_1 * Zt.Transpose() * inv_Ft * vt; Pt = Pt_1 - Pt_1 * Zt.Transpose() * inv_Ft * Zt * Pt_1; //% Save results y_cond[i, Range.All] = yt_1.Transpose(); v[i, Range.All] = vt.Transpose(); a[i, Range.All] = at.Transpose(); a_cond[i, Range.All] = at_1.Transpose(); P[i, Range.All] = Vecr(Pt).Transpose(); P_cond[i, Range.All] = Vecr(Pt_1).Transpose(); F[i, Range.All] = Vecr(Ft).Transpose(); double dFt = Ft.Determinant(); if (dFt <= 0) { dFt = 1e-10; } // The matrix here is 1x1. logl[i, 0] = (double)(-(n / 2) * Math.Log(2 * Math.PI) - 0.5 * Math.Log(dFt) - 0.5 * vt.Transpose() * inv_Ft * vt); } return(new Matrix[] { y_cond, v, a, a_cond, P, P_cond, F, logl }); }
/// <summary> /// Create a handle of the given type with the given numerical value. /// </summary> /// <param name="reservedHandle"></param> public TpmHandle (Ht handleType, uint offset) { new TpmHandle(((uint)handleType << 24) + offset); }
/// <summary> /// Get uint value representing the first handle in the range dedicated to /// the handles of the given type. /// </summary> /// <param name="rangeType"></param> /// <returns></returns> public static uint GetFirst(Ht rangeType) { return (uint)rangeType >> 24; }
internal bool IsSession() { Ht range = GetType(); return(range == Ht.HmacSession || range == Ht.PolicySession || handle == (uint)TpmRh.TpmRsPw); }
/// <summary> /// Get the length (number of handles) in the range dedicated to the handles /// of the given type. /// </summary> /// <param name="rangeType"></param> /// <returns></returns> public static uint GetRangeLength(Ht rangeType) { if (rangeType == Ht.NvIndex) { return 0x00FFFFFF; } return 1U << 24; }
/// <summary> /// Get uint value representing the first handle in the range dedicated to /// the handles of the given type. /// </summary> /// <param name="rangeType"></param> /// <returns></returns> public static uint GetFirst(Ht rangeType) { return((uint)rangeType >> 24); }
/// <summary> /// Create a handle of the given type with the given numerical value. /// </summary> /// <param name="reservedHandle"></param> public TpmHandle(Ht handleType, uint offset) { new TpmHandle(((uint)handleType << 24) + offset); }
private TpmHandle[] GetLoadedEntities(Tpm2 tpm, Ht rangeToQuery) { const uint maxHandles = UInt32.MaxValue; ICapabilitiesUnion h; byte moreData = tpm.GetCapability(Cap.Handles, ((uint)rangeToQuery) << 24, maxHandles, out h); if (moreData != 0) { throw new NotImplementedException("Too much data returned"); } if (h.GetType() != typeof (HandleArray)) { throw new Exception("Incorrect type"); } var handles = (HandleArray)h; return handles.handle; }