private static int ComputeActorIdSize(ActorId actorId) { int size = sizeof(byte); // Null indicator prefix if (actorId == null) { return(size); } size += sizeof(byte); // ActorIdKind switch (actorId.Kind) { case ActorIdKind.Long: size += sizeof(long); break; case ActorIdKind.Guid: size += 16; // Guid is stored as 128 bit value. break; case ActorIdKind.String: size += DataEncoding.GetByteCount(actorId.GetStringId()); size += sizeof(int); // String Id byte array lenth. break; default: ReleaseAssert.Failfast("The ActorIdKind value {0} is invalid", actorId.Kind); size = -1; // unreachable break; } return(size); }
public static void Write(this BinaryWriter writer, ActorId actorId) { if (actorId == null) { writer.WriteNullPrefixByte(); return; } writer.WriteNotNullPrefixByte(); writer.Write((byte)actorId.Kind); switch (actorId.Kind) { case ActorIdKind.Long: writer.Write(actorId.GetLongId()); break; case ActorIdKind.Guid: writer.Write(actorId.GetGuidId()); break; case ActorIdKind.String: writer.Write(actorId.GetStringId()); break; default: ReleaseAssert.Failfast("The ActorIdKind value {0} is invalid", actorId.Kind); break; } }
public RequiredPaymentsService(ActorService actorService, ActorId actorId, IPaymentLogger paymentLogger, IApprenticeshipKeyService apprenticeshipKeyService, Func <IPaymentHistoryRepository> paymentHistoryRepositoryFactory, IApprenticeshipContractType2EarningsEventProcessor contractType2EarningsEventProcessor, IApprenticeshipAct1RedundancyEarningsEventProcessor act1RedundancyEarningsEventProcessor, IFunctionalSkillEarningsEventProcessor functionalSkillEarningsEventProcessor, IPayableEarningEventProcessor payableEarningEventProcessor, IRefundRemovedLearningAimProcessor refundRemovedLearningAimProcessor, ITelemetry telemetry) : base(actorService, actorId) { this.paymentLogger = paymentLogger; this.paymentHistoryRepositoryFactory = paymentHistoryRepositoryFactory; this.contractType2EarningsEventProcessor = contractType2EarningsEventProcessor; this.act1RedundancyEarningsEventProcessor = act1RedundancyEarningsEventProcessor; this.functionalSkillEarningsEventProcessor = functionalSkillEarningsEventProcessor; this.payableEarningEventProcessor = payableEarningEventProcessor; this.refundRemovedLearningAimProcessor = refundRemovedLearningAimProcessor; this.telemetry = telemetry; apprenticeshipKeyString = actorId.GetStringId(); apprenticeshipKey = apprenticeshipKeyService.ParseApprenticeshipKey(apprenticeshipKeyString); logSafeApprenticeshipKeyString = CreateLogSafeApprenticeshipKeyString(apprenticeshipKey); }
/// <summary> /// Parses an <see cref="ActorId" /> created by <see cref="Create(string, string)" /> into the (repository, branch) /// pair that created it. /// </summary> public static (string repository, string branch) Parse(ActorId id) { string str = id.GetStringId(); if (string.IsNullOrEmpty(str)) { throw new ArgumentException("Actor id must be a string kind", nameof(id)); } int colonIndex = str.IndexOf(":", StringComparison.Ordinal); if (colonIndex == -1) { throw new ArgumentException("Actor id not in correct format", nameof(id)); } string repository = Decode(str.Substring(0, colonIndex)); string branch = Decode(str.Substring(colonIndex + 1)); return(repository, branch); }
public ScaleSetIdentityActor(ActorService actorService, ActorId actorId, IIndex <DeploymentEnvironment, IAzure> azureFactory, IBigBrother bigBrother) : base(actorService, actorId) { _azureFactory = azureFactory; _bigBrother = bigBrother; if (actorId.Kind != ActorIdKind.String) { throw new ArgumentException($"The ScaleSetIdentity actor expects string id but got {actorId}"); } var id = actorId.GetStringId(); if (!id.StartsWith(ActorIdPrefix)) { throw new ArgumentException( $"The ScaleSetIdentity actor id must starts with '{ActorIdPrefix}' followed by a virtual machine scale set id."); } _scaleSetId = id.Substring(ActorIdPrefix.Length); }
public TransactionId(ActorId actorId) { switch (actorId.Kind) { case ActorIdKind.Long: this.kind = ActorIdKind.Long; this.longId = actorId.GetLongId(); break; case ActorIdKind.Guid: this.kind = ActorIdKind.Long; this.guidId = actorId.GetGuidId(); break; case ActorIdKind.String: this.kind = ActorIdKind.Long; this.stringId = actorId.GetStringId(); break; default: throw new InvalidOperationException($"he ActorIdKind value {(object)this.kind} is invalid"); } }
internal static string GetStorageKey(this ActorId actorId) { switch (actorId.Kind) { case ActorIdKind.Long: return(string.Format(CultureInfo.InvariantCulture, "{0}_{1}", actorId.Kind.ToString(), actorId.GetLongId())); case ActorIdKind.Guid: return(string.Format(CultureInfo.InvariantCulture, "{0}_{1}", actorId.Kind.ToString(), actorId.GetGuidId())); case ActorIdKind.String: return(string.Format(CultureInfo.InvariantCulture, "{0}_{1}", actorId.Kind.ToString(), actorId.GetStringId())); default: return(null); } }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="actorService"></param> /// <param name="actorId"></param> /// <param name="logger"></param> public StateActor(ActorService actorService, ActorId actorId, ILogger logger) : base(actorService, actorId) { this.state = new StateObject(actorId.GetStringId(), new StateObjectActorDataStore(this), logger); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="actorService"></param> /// <param name="actorId"></param> public StateActor(ActorService actorService, ActorId actorId) : base(actorService, actorId) { this.state = new StateObject(actorId.GetStringId(), new StateActorDataStore(this)); }