// Abort the specified transaction public void Abort(TP.Transaction context) { if (abortFailure) { // Sleep forever if simulate failure flag is set Thread.Sleep(System.Threading.Timeout.Infinite); } // abort transaction this.dataStore.Abort(context); }
/// <summary> // Call from WC in response to a client's abort /// </summary> /// <param name="context"></param> public void Abort(TP.Transaction context) { WaitTillReady(); lock (_resourceManagersEnlistedInTransactions) { if (_resourceManagersEnlistedInTransactions.ContainsKey(context)) { var list = _resourceManagersEnlistedInTransactions[context].ResourceManagers; foreach (RM r in list) { r.Abort(context); } _resourceManagersEnlistedInTransactions.Remove(context); } } Console.WriteLine(string.Format("TM: Transaction {0} aborted", context.Id)); }
private static void RunWritePerformanceSingleThread <TP>() where TP : ProtocolWrapper, new() { using (ProtocolWrapper protocol = new TP()) { protocol.Open("localhost"); const string dropKeyspace = "drop keyspace Tests"; const string truncateTable = "truncate Tests.stresstest"; const string truncateEvents = "truncate system_traces.events"; const string truncateSessions = "truncate system_traces.sessions"; const string createKeyspace = "create keyspace Tests with replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}"; const string createTable = "create table Tests.stresstest (strid varchar,intid int, primary key (strid))"; const string insertPerf = "insert into Tests.stresstest (intid, strid) values (?, ?)"; try { protocol.Query(dropKeyspace); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { } protocol.Query(createKeyspace); protocol.Query(createTable); protocol.Query(truncateTable); protocol.Query(truncateSessions); protocol.Query(truncateEvents); protocol.Prepare(insertPerf); PerformanceInstrumentation.Initialize(); long totalTime = ExecuteStressTest(protocol); // ExportTracingInfo(protocol, totalTime); protocol.Query(dropKeyspace); } }
internal static Nullable <K> ParseNullable <K>(string a, TP <K> tp) where K : struct { K retval = default(K); return(retval); }
private MicroLayout GetCameraImage(int Index) { Bitmap Bmp; ImageConstant v; DateTime TP; string Id; lock (images) { Bmp = images [Index]; TP = imageTP [Index]; } if (Bmp == null) { return(new MicroLayout(new Rows( new Row(1, HorizontalAlignment.Center, VerticalAlignment.Center, new Label("N/A"))))); } else { Id = typeof(CamStorage).FullName + ".Cam." + TP.Year.ToString("D4") + TP.Month.ToString("D2") + TP.Day.ToString("D2") + TP.Hour.ToString("D2") + TP.Minute.ToString("D2") + TP.Second.ToString("D2"); v = new ImageConstant(Id, Bmp); v.ScaleToFit = true; return(new MicroLayout(new Rows( new Row(1, HorizontalAlignment.Center, VerticalAlignment.Center, new Label(TP.ToShortDateString() + ", " + TP.ToLongTimeString())), new Row(4, HorizontalAlignment.Center, VerticalAlignment.Center, v)))); } }
public void Constructor2_TyPeTest() { TP tp = new TP(typeof(string)); Assert.AreNotEqual(null, tp); }
public bool Reserve(TP.Transaction context, TP.Customer c, TP.RID resource) { return true; }
public int Query(TP.Transaction context, TP.RID resource) { return 1; }
public void Enlist(TP.Transaction context) { }
public TP.XaResponse Abort(TP.Transaction context) { return this.AbortResponse; }
/// <summary> /// Prints the item report /// </summary> /// <returns>The item report</returns> public override string ItemReport() { string report = ItemReaderText + "\n" + "Hex: " + HexString + "\n\n"; report += "Type: " + Enum.GetName(typeof(ItemType), Type) + "\n"; if (RequirementLevel != 0) { report += "Requirement: Level " + RequirementLevel + " \n"; } if (Type == ItemType.Frame) { report += "Slots: " + Slots.ToString() + "\n"; } report += "Base DFP: " + DFP.ToString() + "\n"; report += "Base EVP: " + EVP.ToString() + "\n"; report += "DFP Roll: " + VariableDFP.ToString() + "/" + (MaxDFP - DFP).ToString() + "\n"; report += "EVP Roll: " + VariableEVP.ToString() + "/" + (MaxEVP - EVP).ToString() + "\n"; report += "\n"; if (HP != 0) { report += "HP: " + HP.ToString() + "\n"; } if (TP != 0) { report += "TP: " + TP.ToString() + "\n"; } if (ATP != 0) { report += "ATP: " + ATP.ToString() + "\n"; } if (MST != 0) { report += "MST: " + MST.ToString() + "\n"; } if (ATA != 0) { report += "ATA: " + ATA.ToString() + "\n"; } if (LCK != 0) { report += "LCK: " + LCK.ToString() + "\n"; } if (EFR != 0) { report += "EFR: " + EFR.ToString() + "\n"; } if (EIC != 0) { report += "EIC: " + EIC.ToString() + "\n"; } if (ETH != 0) { report += "ETH: " + ETH.ToString() + "\n"; } if (ELT != 0) { report += "ELT: " + ELT.ToString() + "\n"; } if (EDK != 0) { report += "EDK: " + EDK.ToString() + "\n"; } report += "\n"; report += "HUmar: " + (((EquipMask & HUmarMask) > 0) ? "x" : "") + "\n"; report += "HUnewearl: " + (((EquipMask & HUnewearlMask) > 0) ? "x" : "") + "\n"; report += "HUcast: " + (((EquipMask & HUcastMask) > 0) ? "x" : "") + "\n"; report += "HUcaseal: " + (((EquipMask & HUcasealMask) > 0) ? "x" : "") + "\n"; report += "RAmar: " + (((EquipMask & RAmarMask) > 0) ? "x" : "") + "\n"; report += "RAmarl: " + (((EquipMask & RAmarlMask) > 0) ? "x" : "") + "\n"; report += "RAcast: " + (((EquipMask & RAcastMask) > 0) ? "x" : "") + "\n"; report += "RAcaseal: " + (((EquipMask & RAcasealMask) > 0) ? "x" : "") + "\n"; report += "FOmar: " + (((EquipMask & FOmarMask) > 0) ? "x" : "") + "\n"; report += "FOmarl: " + (((EquipMask & FOmarlMask) > 0) ? "x" : "") + "\n"; report += "FOnewm: " + (((EquipMask & FOnewmMask) > 0) ? "x" : "") + "\n"; report += "FOnewearl: " + (((EquipMask & FOnewearlMask) > 0) ? "x" : "") + "\n"; return(report); }
/// <summary> /// Prints the item report /// </summary> /// <returns>The item report</returns> public override string ItemReport() { string report = ItemReaderText + "\n" + "Hex: " + HexString + "\n\n"; report += "Type: " + Enum.GetName(typeof(ItemType), Type) + "\n"; report += "Weapon Type: " + Enum.GetName(typeof(WeaponType), WeaponType) + "\n"; if (RequirementATP != 0) { report += "Requirement: " + RequirementATP + " ATP\n"; } else if (RequirementATA != 0) { report += "Requirement: " + RequirementATA + " ATA\n"; } else if (RequirementMST != 0) { report += "Requirement: " + RequirementMST + " MST\n"; } report += "Grind: " + Grind.ToString() + "/" + MaxGrind.ToString() + "\n"; report += "Special: " + Enum.GetName(typeof(SpecialType), Special) + "\n"; report += "ATP: " + MinATP.ToString() + "-" + MaxATP.ToString() + "\n"; report += "ATA: " + ATA.ToString() + "\n"; if (HP != 0) { report += "HP: " + HP.ToString() + "\n"; } if (TP != 0) { report += "TP: " + TP.ToString() + "\n"; } if (DFP != 0) { report += "DFP: " + DFP.ToString() + "\n"; } if (MST != 0) { report += "MST: " + MST.ToString() + "\n"; } if (EVP != 0) { report += "EVP: " + EVP.ToString() + "\n"; } if (LCK != 0) { report += "LCK: " + LCK.ToString() + "\n"; } if (EFR != 0) { report += "EFR: " + EFR.ToString() + "\n"; } if (EIC != 0) { report += "EIC: " + EIC.ToString() + "\n"; } if (ETH != 0) { report += "ETH: " + ETH.ToString() + "\n"; } if (ELT != 0) { report += "ELT: " + ELT.ToString() + "\n"; } if (EDK != 0) { report += "EDK: " + EDK.ToString() + "\n"; } report += "\n"; report += "Native: " + NativePercentage.ToString() + "%\n"; report += "A. Beast: " + ABeastPercentage.ToString() + "%\n"; report += "Machine: " + MachinePercentage.ToString() + "%\n"; report += "Dark: " + DarkPercentage.ToString() + "%\n"; report += "Hit: " + HitPercentage.ToString() + "%\n"; report += "\n"; report += "HUmar: " + (((EquipMask & HUmarMask) > 0) ? "x" : "") + "\n"; report += "HUnewearl: " + (((EquipMask & HUnewearlMask) > 0) ? "x" : "") + "\n"; report += "HUcast: " + (((EquipMask & HUcastMask) > 0) ? "x" : "") + "\n"; report += "HUcaseal: " + (((EquipMask & HUcasealMask) > 0) ? "x" : "") + "\n"; report += "RAmar: " + (((EquipMask & RAmarMask) > 0) ? "x" : "") + "\n"; report += "RAmarl: " + (((EquipMask & RAmarlMask) > 0) ? "x" : "") + "\n"; report += "RAcast: " + (((EquipMask & RAcastMask) > 0) ? "x" : "") + "\n"; report += "RAcaseal: " + (((EquipMask & RAcasealMask) > 0) ? "x" : "") + "\n"; report += "FOmar: " + (((EquipMask & FOmarMask) > 0) ? "x" : "") + "\n"; report += "FOmarl: " + (((EquipMask & FOmarlMask) > 0) ? "x" : "") + "\n"; report += "FOnewm: " + (((EquipMask & FOnewmMask) > 0) ? "x" : "") + "\n"; report += "FOnewearl: " + (((EquipMask & FOnewearlMask) > 0) ? "x" : "") + "\n"; return(report); }
/// <summary> /// Make upper bound inference from U to V. /// V# 4.0 spec: §7.5.2.10 Upper-bound inferences /// </summary> void MakeUpperBoundInference(IType U, IType V) { // If V is one of the unfixed Xi then U is added to the set of bounds for Xi. TP tp = GetTPForType(V); if (tp != null && tp.IsFixed == false) { tp.UpperBounds.Add(U); return; } // Handle array types: ArrayType arrU = U as ArrayType; ArrayType arrV = V as ArrayType; ParameterizedTypeSpec pU = U as ParameterizedTypeSpec; if (arrV != null && arrU != null && arrU.Dimensions == arrV.Dimensions) { MakeUpperBoundInference(arrU.ElementType, arrV.ElementType); return; } else if (arrV != null && IsGenericInterfaceImplementedByArray(pU) && arrV.Dimensions == 1) { MakeUpperBoundInference(pU.GetTypeArgument(0), arrV.ElementType); return; } // Handle parameterized types: if (pU != null) { ParameterizedTypeSpec uniqueBaseType = null; foreach (IType baseV in V.GetAllBaseTypes()) { ParameterizedTypeSpec pV = baseV as ParameterizedTypeSpec; if (pV != null && object.Equals(pU.GetDefinition(), pV.GetDefinition()) && pU.TypeParameterCount == pV.TypeParameterCount) { if (uniqueBaseType == null) { uniqueBaseType = pV; } else { return; // cannot make an inference because it's not unique } } } if (uniqueBaseType != null) { for (int i = 0; i < uniqueBaseType.TypeParameterCount; i++) { IType Ui = pU.GetTypeArgument(i); IType Vi = uniqueBaseType.GetTypeArgument(i); if (Ui.IsReferenceType == true) { // look for variance ITypeParameter Xi = pU.GetDefinition().TypeParameters[i]; MakeExactInference(Ui, Vi); } else { // not known to be a reference type MakeExactInference(Ui, Vi); } } } } }
/// <summary> /// Register and initialize a specified module. /// </summary> /// <param name="item"></param> /// <returns></returns> public static bool Register(string AuthContext, string item) { bool __ = false; try { OperatorAuthentication.AuthedAction(AuthContext, () => { try { var asm = Assembly.LoadFrom(item); FileInfo fi = new(item); var TPS = asm.GetTypes(); foreach (var TP in TPS) { if (typeof(IManageCommand).IsAssignableFrom(TP)) { var MC = (IManageCommand)Activator.CreateInstance(TP); Trace.WriteLine(Language.Query("LWMS.Commands.Found", "Found Manage Command:{0},{1}", MC.CommandName, TP.ToString())); ManageCommands.Add(MC.CommandName, MappedType.CreateFrom(MC)); var alias = MC.Alias; foreach (var MCA in alias) { ManageCommandAliases.Add(MCA, MappedType.CreateFrom(MC)); } } } __ = true; } catch (Exception) { Trace.Write(Language.Query("LWMS.Commands.Error.LoadModule", "Cannot load management module: {0}", item)); } }, false, true, PermissionID.RegisterCmdModule, PermissionID.CmdModuleAll); } catch (Exception) { Trace.Write(Language.Query("LWMS.Commands.Error.LoadModule", "Cannot load management module: {0}", item)); } return(__); }
private static void Encode(object Object, int?Indent, StringBuilder Json) { if (Object is null) { Json.Append("null"); } else { Type T = Object.GetType(); TypeInfo TI = T.GetTypeInfo(); if (TI.IsValueType) { if (Object is bool b) { Json.Append(CommonTypes.Encode(b)); } else if (Object is char ch) { Json.Append('"'); Json.Append(Encode(new string(ch, 1))); Json.Append('"'); } else if (Object is double dbl) { Json.Append(CommonTypes.Encode(dbl)); } else if (Object is float fl) { Json.Append(CommonTypes.Encode(fl)); } else if (Object is decimal dec) { Json.Append(CommonTypes.Encode(dec)); } else if (TI.IsEnum) { Json.Append('"'); Json.Append(Encode(Object.ToString())); Json.Append('"'); } else if (Object is DateTime TP) { Json.Append(((int)((TP.ToUniversalTime() - UnixEpoch).TotalSeconds)).ToString()); } else { Json.Append(Object.ToString()); } } else if (Object is string s) { Json.Append('"'); Json.Append(Encode(s)); Json.Append('"'); } else if (Object is IEnumerable <KeyValuePair <string, object> > Obj) { Encode(Obj, Indent, Json, null); } else if (Object is IEnumerable E) { IEnumerator e = E.GetEnumerator(); bool First = true; Json.Append('['); if (Indent.HasValue) { Indent = Indent + 1; } while (e.MoveNext()) { if (First) { First = false; } else { Json.Append(','); } if (Indent.HasValue) { Json.AppendLine(); Json.Append(new string('\t', Indent.Value)); } Encode(e.Current, Indent, Json); } if (!First && Indent.HasValue) { Json.AppendLine(); Indent = Indent - 1; Json.Append(new string('\t', Indent.Value)); } Json.Append(']'); } else { throw new ArgumentException("Unsupported type: " + T.FullName, nameof(Object)); } } }
bool Fix(TP tp) { Log.WriteLine(" Trying to fix " + tp); Debug.Assert(!tp.IsFixed); Log.Indent(); var types = CreateNestedInstance().FindTypesInBounds(tp.LowerBounds.ToArray(), tp.UpperBounds.ToArray()); Log.Unindent(); if (algorithm == TypeInferenceAlgorithm.ImprovedReturnAllResults) { tp.FixedTo = IntersectionType.Create(types); Log.WriteLine(" T was fixed " + (types.Count >= 1 ? "successfully" : "(with errors)") + " to " + tp.FixedTo); return types.Count >= 1; } else { tp.FixedTo = GetFirstTypePreferNonInterfaces(types); Log.WriteLine(" T was fixed " + (types.Count == 1 ? "successfully" : "(with errors)") + " to " + tp.FixedTo); return types.Count == 1; } }
public static CoordF CartesianRot(TP rv) => delegate(float c, float s, ParametricInfo bpi, out Vector2 nrv) { var v2 = rv(bpi); nrv.x = c * v2.x - s * v2.y; nrv.y = s * v2.x + c * v2.y; };
public TP.XaResponse Commit(TP.Transaction context) { return this.CommitResponse; }
public static CoordF CartesianNRot(TP tpnrv) => delegate(float c, float s, ParametricInfo bpi, out Vector2 nrv) { nrv = tpnrv(bpi); };
public string[] ListResources(TP.Transaction context, TP.RID.Type type) { return new string[] { "item1", "item2" }; }
public static CoordF Cartesian(TP rv, TP tpnrv) => delegate(float c, float s, ParametricInfo bpi, out Vector2 nrv) { nrv = tpnrv(bpi); var v2 = rv(bpi); nrv.x += c * v2.x - s * v2.y; nrv.y += s * v2.x + c * v2.y; };
public string QueryReserved(TP.Transaction context, TP.Customer customer) { return string.Empty; }
bool DependsOn(TP Xi, TP Xj) { return(GetDependencies(Xi).Contains(Xj)); }
/// <summary> /// Prints the item report /// </summary> /// <returns>The item report</returns> public override string ItemReport() { string report = ItemReaderText + "\n" + "Hex: " + HexString + "\n\n"; report += "Type: " + Enum.GetName(typeof(ItemType), Type) + "\n"; report += "\n"; if (HP != 0) { report += "HP: " + HP.ToString() + "\n"; } if (TP != 0) { report += "TP: " + TP.ToString() + "\n"; } if (ATP != 0) { report += "ATP: " + ATP.ToString() + "\n"; } if (DFP != 0) { report += "DFP: " + DFP.ToString() + "\n"; } if (MST != 0) { report += "MST: " + MST.ToString() + "\n"; } if (ATA != 0) { report += "ATA: " + ATA.ToString() + "\n"; } if (EVP != 0) { report += "EVP: " + EVP.ToString() + "\n"; } if (LCK != 0) { report += "LCK: " + LCK.ToString() + "\n"; } if (EFR != 0) { report += "EFR: " + EFR.ToString() + "\n"; } if (EIC != 0) { report += "EIC: " + EIC.ToString() + "\n"; } if (ETH != 0) { report += "ETH: " + ETH.ToString() + "\n"; } if (ELT != 0) { report += "ELT: " + ELT.ToString() + "\n"; } if (EDK != 0) { report += "EDK: " + EDK.ToString() + "\n"; } report += "\n"; report += "HUmar: " + (((EquipMask & HUmarMask) > 0) ? "x" : "") + "\n"; report += "HUnewearl: " + (((EquipMask & HUnewearlMask) > 0) ? "x" : "") + "\n"; report += "HUcast: " + (((EquipMask & HUcastMask) > 0) ? "x" : "") + "\n"; report += "HUcaseal: " + (((EquipMask & HUcasealMask) > 0) ? "x" : "") + "\n"; report += "RAmar: " + (((EquipMask & RAmarMask) > 0) ? "x" : "") + "\n"; report += "RAmarl: " + (((EquipMask & RAmarlMask) > 0) ? "x" : "") + "\n"; report += "RAcast: " + (((EquipMask & RAcastMask) > 0) ? "x" : "") + "\n"; report += "RAcaseal: " + (((EquipMask & RAcasealMask) > 0) ? "x" : "") + "\n"; report += "FOmar: " + (((EquipMask & FOmarMask) > 0) ? "x" : "") + "\n"; report += "FOmarl: " + (((EquipMask & FOmarlMask) > 0) ? "x" : "") + "\n"; report += "FOnewm: " + (((EquipMask & FOnewmMask) > 0) ? "x" : "") + "\n"; report += "FOnewearl: " + (((EquipMask & FOnewearlMask) > 0) ? "x" : "") + "\n"; return(report); }
/// <summary> /// Make lower bound inference from U for V. /// </summary> void MakeLowerBoundInference(IReturnType U, IReturnType V) { Log(" MakeLowerBoundInference from " + U + " for " + V); if (U == null || V == null) { return; } // If V is one of the unfixed Xi then U is added to the set of bounds for Xi. TP tp = GetTPForType(V); if (tp != null && tp.Fixed == false) { Log(" Add bound '" + U.DotNetName + "' to " + tp); tp.Bounds.Add(U); return; } // Otherwise if U is an array type Ue[…] and V is either an array type Ve[…]of the // same rank, or if U is a onedimensional array type Ue[]and V is one of // IEnumerable<Ve>, ICollection<Ve> or IList<Ve> then ArrayReturnType arrU = U.CastToArrayReturnType(); ArrayReturnType arrV = V.CastToArrayReturnType(); ConstructedReturnType CV = V.CastToConstructedReturnType(); if (arrU != null && (arrV != null && arrU.ArrayDimensions == arrV.ArrayDimensions || (arrU.ArrayDimensions == 1 && IsIEnumerableCollectionOrList(CV)))) { IReturnType Ue = arrU.ArrayElementType; IReturnType Ve = arrV != null ? arrV.ArrayElementType : CV.TypeArguments[0]; // If Ue is known to be a reference type then a lowerbound inference from Ue to Ve is made if (IsReferenceType(Ue) ?? false) { MakeLowerBoundInference(Ue, Ve); } else { // Otherwise an exact inference from Ue to Ve is made MakeExactInference(Ue, Ve); } return; } // Otherwise if V is a constructed type C<V1…Vk> and there is a unique set of // types U1…Uk such that a standard implicit conversion exists from U to C<U1…Uk> // then an exact inference is made from each Ui for the corresponding Vi. if (CV != null) { foreach (IReturnType U2 in MemberLookupHelper.GetTypeInheritanceTree(U)) { ConstructedReturnType CU2 = U2.CastToConstructedReturnType(); if (CU2 != null && object.Equals(CU2.UnboundType, CV.UnboundType) && CU2.TypeArgumentCount == CV.TypeArgumentCount && CU2.TypeArguments.Count == CU2.TypeArgumentCount && // unfortunately these might not be the same... CV.TypeArguments.Count == CV.TypeArgumentCount) { for (int i = 0; i < CU2.TypeArgumentCount; i++) { MakeExactInference(CU2.TypeArguments[i], CV.TypeArguments[i]); } return; } } } }
public bool DownGradedLockRequest(TP.Transaction context, LockMode request) { System.Collections.Hashtable transactionList = this.transactions[(int)LockMode.Write]; if (request == LockMode.Read && (transactionList != null && transactionList[context] != null)) return true; return false; }
/* Add a lock of type _request_ for transaction _context_ */ public void Register(TP.Transaction context, LockMode request) { // First get the hash table for this lock mode on this resource entry, if it exists System.Collections.Hashtable transactionList = this.transactions[(int)request]; // If there is no hash table for this lock mode, create one if (transactionList == null) { transactionList = new System.Collections.Hashtable(); this.transactions[(int)request] = transactionList; } // Add the transaction to the list for _request_ lock mode transactionList[context] = context; // Update the strongest lock mode, if necessary if (request > locked) locked = request; // If we set locked mode to Update lock mode, we do not reset // the event because we still want to track the read locks. if (request != LockMode.Update) this.UnlockEvent.Reset(); }
/// <summary> /// Creates a new JWT token. /// </summary> /// <param name="Claims">Claims to include in token. /// /// For a list of public claim names, see: /// https://www.iana.org/assignments/jwt/jwt.xhtml</param> /// <returns>JWT token.</returns> public string Create(params KeyValuePair <string, object>[] Claims) { StringBuilder Json = new StringBuilder("{"); bool First = true; foreach (KeyValuePair <string, object> Claim in Claims) { if (First) { First = false; } else { Json.Append(','); } Json.Append('"'); Json.Append(JSON.Encode(Claim.Key)); Json.Append("\":"); if (Claim.Value == null) { Json.Append("null"); } else if (Claim.Value is string s) { Json.Append('"'); Json.Append(JSON.Encode(s)); Json.Append('"'); } else if (Claim.Value is bool b) { if (b) { Json.Append("true"); } else { Json.Append("false"); } } else if (Claim.Value is DateTime TP) { Json.Append(((int)((TP.ToUniversalTime() - JwtToken.epoch).TotalSeconds)).ToString()); } else if (Claim.Value is int i) { Json.Append(i.ToString()); } else if (Claim.Value is long l) { Json.Append(l.ToString()); } else if (Claim.Value is short sh) { Json.Append(sh.ToString()); } else if (Claim.Value is byte bt) { Json.Append(bt.ToString()); } else { Json.Append('"'); Json.Append(JSON.Encode(Claim.Value.ToString())); Json.Append('"'); } } Json.Append('}'); string PayloadStr = Json.ToString(); byte[] PayloadBin = Encoding.UTF8.GetBytes(PayloadStr); string Payload = JwtToken.Base64UrlEncode(PayloadBin); byte[] Signature; string Token = this.header + "." + Payload; lock (this.hmacSHA256) { Signature = this.hmacSHA256.ComputeHash(Encoding.ASCII.GetBytes(Token)); } Token += "." + JwtToken.Base64UrlEncode(Signature); return(Token); }
/// <summary> /* Release a lock of mode _request_ for transaction _context_ Return if context does not hold a lock for this resource */ /// </summary> public void Unregister(TP.Transaction context, LockMode request) { // First get the hash table for this lock mode System.Collections.Hashtable transactionList = this.transactions[(int)request]; if (transactionList == null || transactionList[context] == null) { // This transaction wasn't registered, return immediately return; } transactionList.Remove(context); for (LockMode l = locked; l > LockMode.Null; locked = --l) { // recalculate the strongest lock mode System.Collections.Hashtable nextTransactionList = this.transactions[(int)l]; if (nextTransactionList == null) continue; if (nextTransactionList.Count > 0) break; } // common case plus special case where we want to convert a read lock to write lock if (request > locked || (this.locked == LockMode.Update && this.transactions[(int)LockMode.Read].Count == 0)) // if anyone was waiting for this lock, they should recheck this.UnlockEvent.Set(); }
private static void Encode(object Object, int?Indent, StringBuilder Json) { if (Object is null) { Json.Append("null"); } else { Type T = Object.GetType(); TypeInfo TI = T.GetTypeInfo(); if (TI.IsValueType) { if (Object is bool b) { Json.Append(CommonTypes.Encode(b)); } else if (Object is char ch) { Json.Append('"'); Json.Append(Encode(new string(ch, 1))); Json.Append('"'); } else if (Object is double dbl) { Json.Append(CommonTypes.Encode(dbl)); } else if (Object is float fl) { Json.Append(CommonTypes.Encode(fl)); } else if (Object is decimal dec) { Json.Append(CommonTypes.Encode(dec)); } else if (TI.IsEnum) { Json.Append('"'); Json.Append(Encode(Object.ToString())); Json.Append('"'); } else if (Object is DateTime TP) { Json.Append(((int)((TP.ToUniversalTime() - UnixEpoch).TotalSeconds)).ToString()); } else { Json.Append(Object.ToString()); } } else if (Object is string s) { Json.Append('"'); Json.Append(Encode(s)); Json.Append('"'); } else if (Object is IEnumerable <KeyValuePair <string, object> > Obj) { Encode(Obj, Indent, Json, null); } else if (Object is IEnumerable <KeyValuePair <string, IElement> > Obj2) { Encode(Obj2, Indent, Json); } else if (Object is IEnumerable E) { IEnumerator e = E.GetEnumerator(); bool First = true; Json.Append('['); if (Indent.HasValue) { Indent++; } while (e.MoveNext()) { if (First) { First = false; } else { Json.Append(','); } if (Indent.HasValue) { Json.AppendLine(); Json.Append(new string('\t', Indent.Value)); } Encode(e.Current, Indent, Json); } if (!First && Indent.HasValue) { Json.AppendLine(); Indent--; Json.Append(new string('\t', Indent.Value)); } Json.Append(']'); } else if (Object is ObjectMatrix M && !(M.ColumnNames is null)) { bool First = true; Json.Append('['); if (Indent.HasValue) { Indent++; } foreach (IElement Element in M.VectorElements) { if (First) { First = false; Encode(M.ColumnNames, Indent, Json); } Json.Append(','); if (Indent.HasValue) { Json.AppendLine(); Json.Append(new string('\t', Indent.Value)); } Encode(Element.AssociatedObjectValue, Indent, Json); } if (!First && Indent.HasValue) { Json.AppendLine(); Indent--; Json.Append(new string('\t', Indent.Value)); } Json.Append(']'); }
// Get a read lock for the resource public void LockForRead(TP.Transaction context, TP.Lockable resource) { Lock(context, resource, MyLM.LockMode.Read); }
bool DependsOn(TP x, TP y) { if (dependencyMatrix == null) CalculateDependencyMatrix(); // x depends on y return dependencyMatrix[x.TypeParameter.Index, y.TypeParameter.Index]; }
// Get a write lock for the resource public void LockForWrite(TP.Transaction context, TP.Lockable resource) { Lock(context, resource, MyLM.LockMode.Write); }
public void UnReserve(TP.Transaction context, TP.Customer c) { }
// Unlock all resources for the passed in transaction public void UnlockAll(TP.Transaction context) { // Loop over the resources lock (this.ResourceTable) { // Get resource enumerator System.Collections.IDictionaryEnumerator resenum = ResourceTable.GetEnumerator(); // Loop over resources while (resenum.MoveNext()) { ResourceEntry lockTarget = (ResourceEntry)resenum.Value; lock (lockTarget) { // Unregister all unlock modes for current resource for (int lockMode = (int)LockMode.Read; lockMode < (int)LockMode._Length; lockMode++) { lockTarget.Unregister(context, (LockMode)lockMode); } } } } System.Console.WriteLine("----Unlocked all for Tx: {0}--------", context.Id); }
public bool Add(TP.Transaction context, TP.RID resource, int count, int price) { return true; }
bool DependsDirectlyOn(TP Xi, TP Xj) { if (Xj.Fixed) return false; for (int k = 0; k < arguments.Count; k++) { if (InputTypes(arguments[k], parameterTypes[k]).Any(t => Xj.OccursIn(t)) && OutputTypes(arguments[k], parameterTypes[k]).Any(t => Xi.OccursIn(t))) { return true; } } return false; }
public bool Delete(TP.Transaction context, TP.RID resource) { return true; }
void AddDependencies(HashSet<TP> hash, TP Xi) { foreach (TP Xj in typeParameters) { if (DependsDirectlyOn(Xi, Xj)) { if (hash.Add(Xj)) AddDependencies(hash, Xj); } } }
public TP.Customer[] ListCustomers(TP.Transaction context) { return null; }
HashSet<TP> GetDependencies(TP X) { HashSet<TP> hash = new HashSet<TP>(); AddDependencies(hash, X); return hash; }
public TP.XaResponse Prepare(TP.Transaction context) { return this.PrepareResponse; }
bool DependsOn(TP Xi, TP Xj) { return GetDependencies(Xi).Contains(Xj); }
public int QueryPrice(TP.Transaction context, TP.RID resource) { return 2; }
bool Fix(TP X) { Log("Trying to fix " + X); Log(" bounds = ", X.Bounds); List<IReturnType> candidates = new List<IReturnType>(X.Bounds); foreach (IReturnType U in X.Bounds) { candidates.RemoveAll((IReturnType candidate) => !MemberLookupHelper.ConversionExists(U, candidate)); } Log(" candidates after removal round = ", candidates); if (candidates.Count == 0) return false; var results = candidates.Where( c1 => candidates.All(c2 => MemberLookupHelper.ConversionExists(c1, c2)) ).ToList(); Log(" possible solutions (should be exactly one) = ", candidates); if (results.Count == 1) { X.FixedTo = results[0]; return true; } else { return false; } }
public int QueryReservedPrice(TP.Transaction context, TP.Customer customer) { return 3; }
/// <summary> /// Gets label values for a series vector. /// </summary> /// <param name="Min">Smallest value.</param> /// <param name="Max">Largest value.</param> /// <param name="ApproxNrLabels">Number of labels.</param> /// <param name="LabelType">Type of labels produced.</param> /// <returns>Vector of labels.</returns> public static DateTime[] GetLabels(DateTime Min, DateTime Max, int ApproxNrLabels, out LabelType LabelType) { List <DateTime> Labels = new List <DateTime>(); TimeSpan Span = Max - Min; TimeSpan StepSize = Span == TimeSpan.Zero ? new TimeSpan(0, 0, 1) : new TimeSpan((Span.Ticks + (ApproxNrLabels >> 1)) / ApproxNrLabels); int i, c; for (i = 0, c = timeStepSizes.Length - 2; i < c; i++) { if (StepSize >= timeStepSizes[i] && StepSize < timeStepSizes[i + 1]) { break; } } int Nr1 = (int)Math.Round(Span.TotalSeconds / timeStepSizes[i].TotalSeconds); int Diff1 = Math.Abs(ApproxNrLabels - Nr1); int Nr2 = (int)Math.Round(Span.TotalSeconds / timeStepSizes[i + 1].TotalSeconds); int Diff2 = Math.Abs(ApproxNrLabels - Nr1); if (Diff1 < Diff2) { StepSize = timeStepSizes[i]; } else { StepSize = timeStepSizes[i + 1]; } if (StepSize.TotalDays >= 1) { DateTime TP; TP = Min.Date; if (Min.TimeOfDay != TimeSpan.Zero) { TP = TP.AddDays(1); } Nr1 = (int)Math.Floor((Max - TP).TotalDays); Diff1 = Math.Abs(ApproxNrLabels - Nr1); Nr2 = (int)Math.Floor((Max - TP).TotalDays / 2); Diff2 = Math.Abs(ApproxNrLabels - Nr2); if (Diff1 <= Diff2) { LabelType = LabelType.DateTimeDate; while (TP <= Max) { Labels.Add(TP); TP = TP.AddDays(1); } } else { Nr1 = Nr2; Diff1 = Diff2; Nr2 = (int)Math.Floor((Max - TP).TotalDays / 7); Diff2 = Math.Abs(ApproxNrLabels - Nr2); if (Diff1 <= Diff2) { LabelType = LabelType.DateTimeDate; // Step every 2 days. while (TP <= Max) { Labels.Add(TP); TP = TP.AddDays(2); } } else { Nr1 = Nr2; Diff1 = Diff2; Nr2 = (int)Math.Floor((Max - TP).TotalDays / 30); Diff2 = Math.Abs(ApproxNrLabels - Nr2); if (Diff1 <= Diff2) { LabelType = LabelType.DateTimeWeek; i = (int)TP.DayOfWeek; if (i == 0) { TP = TP.AddDays(1); } else if (i != 1) { TP = TP.AddDays(8 - i); } while (TP <= Max) { Labels.Add(TP); TP = TP.AddDays(7); } } else { Nr1 = Nr2; Diff1 = Diff2; Nr2 = (int)Math.Floor((Max - TP).TotalDays / 180); Diff2 = Math.Abs(ApproxNrLabels - Nr2); if (Diff1 <= Diff2) { LabelType = LabelType.DateTimeMonth; if (TP.Day != 1) { TP = TP.AddDays(-TP.Day + 1).AddMonths(1); } while (TP <= Max) { Labels.Add(TP); TP = TP.AddMonths(1); } } else { Nr1 = Nr2; Diff1 = Diff2; Nr2 = (int)Math.Floor((Max - TP).TotalDays / 700); Diff2 = Math.Abs(ApproxNrLabels - Nr2); if (Diff1 <= Diff2) { LabelType = LabelType.DateTimeQuarter; if (TP.Day != 1) { TP = TP.AddDays(-TP.Day + 1).AddMonths(1); } i = (TP.Month - 1) % 3; if (i != 0) { TP = TP.AddMonths(3 - i); } while (TP <= Max) { Labels.Add(TP); TP = TP.AddMonths(3); } } else { LabelType = LabelType.DateTimeYear; i = (int)Math.Floor(GetStepSize((Min - referenceTimestamp).TotalDays / 365.25, (Max - referenceTimestamp).TotalDays / 365.25, ApproxNrLabels)); if (i == 0) { i++; } if (TP.Day > 1) { TP = TP.AddDays(-TP.Day + 1).AddMonths(1); } if (TP.Month > 1) { TP = TP.AddMonths(13 - TP.Month); } c = TP.Year % i; if (c > 0) { TP = TP.AddYears(i - c); } while (TP <= Max) { Labels.Add(TP); TP = TP.AddYears(i); } } } } } } } else { long Ticks = Min.Ticks; long MaxTicks = Max.Ticks; long Step = StepSize.Ticks; long Residue = Ticks % Step; if (Residue > 0) { Ticks += Step - Residue; } while (Ticks <= MaxTicks) { Labels.Add(new DateTime(Ticks)); Ticks += Step; } if (StepSize.TotalMinutes >= 1) { LabelType = LabelType.DateTimeShortTime; } else { LabelType = LabelType.DateTimeLongTime; } } return(Labels.ToArray()); }
public static void DoSomething() { Console.WriteLine(typeof(TK).Name); TP.DoSomething(); }
bool Fix(TP tp) { Log.WriteLine(" Trying to fix " + tp); Debug.Assert(!tp.IsFixed); if (tp.ExactBound != null) { // the exact bound will always be the result tp.FixedTo = tp.ExactBound; // check validity if (tp.MultipleDifferentExactBounds) return false; return tp.LowerBounds.All(b => conversions.ImplicitConversion(b, tp.FixedTo).IsValid) && tp.UpperBounds.All(b => conversions.ImplicitConversion(tp.FixedTo, b).IsValid); } Log.Indent(); var types = CreateNestedInstance().FindTypesInBounds(tp.LowerBounds.ToArray(), tp.UpperBounds.ToArray()); Log.Unindent(); if (algorithm == TypeInferenceAlgorithm.ImprovedReturnAllResults) { tp.FixedTo = IntersectionType.Create(types); Log.WriteLine(" T was fixed " + (types.Count >= 1 ? "successfully" : "(with errors)") + " to " + tp.FixedTo); return types.Count >= 1; } else { tp.FixedTo = GetFirstTypePreferNonInterfaces(types); Log.WriteLine(" T was fixed " + (types.Count == 1 ? "successfully" : "(with errors)") + " to " + tp.FixedTo); return types.Count == 1; } }
/// <summary> /// Make upper bound inference from U to V. /// C# 4.0 spec: §7.5.2.10 Upper-bound inferences /// </summary> void MakeUpperBoundInference(IType U, IType V) { Log.WriteLine(" MakeUpperBoundInference from " + U + " to " + V); // If V is one of the unfixed Xi then U is added to the set of bounds for Xi. TP tp = GetTPForType(V); if (tp != null && tp.IsFixed == false) { Log.WriteLine(" Add upper bound '" + U + "' to " + tp); tp.UpperBounds.Add(U); return; } // Handle array types: ArrayType arrU = U as ArrayType; ArrayType arrV = V as ArrayType; ParameterizedType pU = U as ParameterizedType; if (arrV != null && arrU != null && arrU.Dimensions == arrV.Dimensions) { MakeUpperBoundInference(arrU.ElementType, arrV.ElementType); return; } else if (arrV != null && IsGenericInterfaceImplementedByArray(pU) && arrV.Dimensions == 1) { MakeUpperBoundInference(pU.GetTypeArgument(0), arrV.ElementType); return; } // Handle parameterized types: if (pU != null) { ParameterizedType uniqueBaseType = null; foreach (IType baseV in V.GetAllBaseTypes()) { ParameterizedType pV = baseV as ParameterizedType; if (pV != null && object.Equals(pU.GetDefinition(), pV.GetDefinition()) && pU.TypeParameterCount == pV.TypeParameterCount) { if (uniqueBaseType == null) { uniqueBaseType = pV; } else { return; // cannot make an inference because it's not unique } } } Log.Indent(); if (uniqueBaseType != null) { for (int i = 0; i < uniqueBaseType.TypeParameterCount; i++) { IType Ui = pU.GetTypeArgument(i); IType Vi = uniqueBaseType.GetTypeArgument(i); if (Ui.IsReferenceType == true) { // look for variance ITypeParameter Xi = pU.GetDefinition().TypeParameters[i]; switch (Xi.Variance) { case VarianceModifier.Covariant: MakeUpperBoundInference(Ui, Vi); break; case VarianceModifier.Contravariant: MakeLowerBoundInference(Ui, Vi); break; default: // invariant MakeExactInference(Ui, Vi); break; } } else { // not known to be a reference type MakeExactInference(Ui, Vi); } } } Log.Unindent(); } }
public void constructor_TyPeTest() { TP tp = new TP(); Assert.AreNotEqual(null, tp); }