public async Task <EventPosition> GetPartitionPosition(string partitionId) { if (partitionId == null) { throw new ArgumentNullException(nameof(partitionId)); } if (_blobStorage == null) { return(EventPosition.FromStart()); } string state; try { state = await _blobStorage.ReadTextAsync(GetBlobName(partitionId)); } catch (StorageException ex) when(ex.ErrorCode == ErrorCode.NotFound) { state = null; } if (state == null) { return(EventPosition.FromStart()); } StateToken token = state.AsJsonObject <StateToken>(); return(token.SequenceNumber == null?EventPosition.FromStart() : EventPosition.FromSequenceNumber(token.SequenceNumber.Value)); }
public async Task <string> GetPartitionOffset(string partitionId) { if (partitionId == null) { throw new ArgumentNullException(nameof(partitionId)); } if (_blobStorage == null) { return(PartitionReceiver.StartOfStream); } string state; try { state = await _blobStorage.ReadTextAsync(GetBlobName(partitionId)); } catch (StorageException ex) when(ex.ErrorCode == ErrorCode.NotFound) { state = null; } if (state == null) { return(PartitionReceiver.StartOfStream); } StateToken token = state.AsJsonObject <StateToken>(); return(token.Offset); }
public async Task SetPartitionStateAsync(string partitionId, string offset, string sequenceNumber) { if (partitionId == null) { throw new ArgumentNullException(nameof(partitionId)); } if (_blobStorage == null) { return; } if (offset == null) { await _blobStorage.DeleteAsync(GetBlobName(partitionId)); } else { var state = new StateToken { PartitionId = partitionId, SequenceNumber = sequenceNumber, Offset = offset, CreatedAt = DateTime.UtcNow }; await _blobStorage.WriteTextAsync(GetBlobName(partitionId), state.ToJsonString()); } }
// Set label to current state when arrived public void SetCurrentStateLabel(StateToken token) { if (currentStateText) { currentStateText.text = token.ToString(); } }
private void OnStateMachineChanged(StateMachine machine, StateChangedEventArgs e) { StateToken newStateToken = e.NewState.Token; if (newStateToken == SkillStateToken.Release) { //进度条隐藏 ShowProgressBar(false); } }
void IStateModifier.ModifyWith(object targ, StateToken token) { var cam = ComponentUtil.GetComponentFromSource <Camera>(targ); if (cam == null) { return; } token.CopyTo(cam); }
/// <summary> /// Starts a state, and returns a token that can be used to stop it again. /// </summary> /// <param name="stateData">Custom state data. This is useful in cases /// where all the active states needs to be examined. For example, this data /// can be used to identify states externally.</param> /// <returns>A token that wraps the custom state data and can be used to stop /// the state started with this method.</returns> public IStateToken <TStateData> StartState(TStateData stateData) { var token = new StateToken(stateData); if (!IsActive) { if (OnStateActive != null) { OnStateActive(); } } activeTokens.Add(token); return(token); }
/// <summary> /// The Listen callback /// </summary> /// /// <param name="Ar">The IAsyncResult</param> /// /// <exception cref="CryptoSocketException">Thrown if the Tcp listen operation has failed</exception> private void ListenCallback(IAsyncResult Ar) { // retrieve the state object and the client socket from the asynchronous state object StateToken state = (StateToken)Ar.AsyncState; Socket srv = state.Client; try { // get the socket for the accepted client connection and put it into the ReadEventArg object user token Socket cltSocket = srv.EndAccept(Ar); // store the socket SocketAsyncEventArgs readEventArgs = new SocketAsyncEventArgs(); readEventArgs.UserToken = cltSocket; if (Connected != null) { Connected(this, readEventArgs); } // create the state object state = new StateToken(m_lsnSocket); // accept the incoming clients m_lsnSocket.BeginAccept(new AsyncCallback(ListenCallback), state); } catch (ObjectDisposedException) { // disconnected if (DisConnected != null) { DisConnected(this, SocketError.ConnectionAborted); } } catch (SocketException se) { throw new CryptoSocketException("TcpSocket:ListenCallback", "The Tcp listener has failed!", se); } catch (Exception) { if (m_isListening) { throw; } } }
static List <BlockState> GetBlockData(Stream InputStream) { /* * This whole section is just a tangled mess to parse the blockstate JSON files. * * Rather than even try to parse the JSON myself with string operators (cancer), * I decided to use an external function library. */ List <BlockState> BlockStates = new List <BlockState>(); //Generate the lists List <ModelReference> ModelList = new List <ModelReference>(); //before using them Dictionary <string, string> ModelDictionary = new Dictionary <string, string>(); using (StreamReader sr = new StreamReader(InputStream)) { JObject JsonOutput = JObject.Parse(sr.ReadToEnd()); foreach (KeyValuePair <string, JToken> Token in JsonOutput) { if (Token.Key == "variants") { BlockStates = new List <BlockState>(); foreach (JToken Variants in Token.Value) { foreach (JToken StateToken in Variants.Values <JToken>()) { ModelList = new List <ModelReference>(); ModelDictionary = new Dictionary <string, string>(); foreach (JToken ModelToken in StateToken.Children()) { ModelDictionary.Add(ModelToken.ToObject <JProperty>().Name, ModelToken.ToObject <string>()); } ModelList.Add(new ModelReference(ModelDictionary)); BlockStates.Add(new BlockState(Variants.ToObject <JProperty>().Name, ModelList)); } } //PackBlocks.Add(new Block(Entry.Name.Split('.')[0], BlockStates)); } else { throw new TrashMonkeyException("Model is multipart!"); } } } return(BlockStates); }
/// <summary> /// Start Non-Blocking listen on a port for an incoming connection /// </summary> /// /// <param name="Address">The IP address assigned to this server</param> /// <param name="Port">The Port number assigned to this server</param> /// <param name="MaxConnections">The maximum number of simultaneous connections allowed (default is 10)</param> /// <param name="Timeout">The wait timeout period</param> /// /// <exception cref="CryptoSocketException">Thrown if the Tcp listen operation has failed</exception> public void ListenAsync(IPAddress Address, int Port, int MaxConnections = 10, int Timeout = Timeout.Infinite) { try { IPEndPoint ipEP = new IPEndPoint(Address, Port); m_lsnSocket = new Socket(ipEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (ipEP.AddressFamily == AddressFamily.InterNetworkV6) { m_lsnSocket.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, false); m_lsnSocket.Bind(ipEP); } else { // associate the socket with the local endpoint m_lsnSocket.Bind(ipEP); } m_isListening = true; m_lsnSocket.Listen(MaxConnections); // create the state object StateToken state = new StateToken(m_lsnSocket); // accept the incoming clients m_lsnSocket.BeginAccept(new AsyncCallback(ListenCallback), state); // blocks the current thread to receive incoming messages m_opDone.WaitOne(Timeout); } catch (SocketException se) { throw new CryptoSocketException("TcpSocket:ListenAsync", "The Tcp listener has failed!", se); } catch (Exception) { throw; } }
protected ColorGeneratorFSMStateBase(StateToken token) : base(token) { }
static void GetBlockStates(string PathInput) { List <Block> Blocks = new List <Block>(); using (ZipArchive MinecraftJar = ZipFile.OpenRead(PathInput)) { IEnumerable <ZipArchiveEntry> BlockStateEntries = MinecraftJar.Entries.Where(Entry => (Entry.Name.EndsWith(".json")) && (Entry.FullName.EndsWith(@"minecraft/blockstates/" + Entry.Name))); foreach (ZipArchiveEntry Entry in BlockStateEntries) { /* * This whole section is just a tangled mess to parse the blockstate JSON files. * * Rather than even try to parse the JSON myself with string operators (cancer), * I decided to use an external function library. */ List <BlockState> BlockStates = new List <BlockState>(); //Generate the lists List <ModelReference> ModelList = new List <ModelReference>(); //before using them Dictionary <string, string> ModelDictionary = new Dictionary <string, string>(); using (StreamReader sr = new StreamReader(Entry.Open())) { try { JObject JsonOutput = JObject.Parse(sr.ReadToEnd()); foreach (KeyValuePair <string, JToken> Token in JsonOutput) { if (Token.Key == "variants") { BlockStates = new List <BlockState>(); foreach (JToken Variants in Token.Value) { foreach (JToken StateToken in Variants.Values <JToken>()) { ModelList = new List <ModelReference>(); ModelDictionary = new Dictionary <string, string>(); foreach (JToken ModelToken in StateToken.Children()) { ModelDictionary.Add(ModelToken.ToObject <JProperty>().Name, ModelToken.ToObject <string>()); } ModelList.Add(new ModelReference(ModelDictionary)); BlockStates.Add(new BlockState(Variants.ToObject <JProperty>().Name, ModelList)); } } Blocks.Add(new Block(Entry.Name.Split('.')[0], BlockStates)); } } } catch { /* * For some reason Mojang has a crappy blockstate for acacia_wall_sign. * It has a random 'n' after all the data, which gives my code AIDS * unless I put it all in a try/catch. :P */ } } } ResourcePack[] ResourcePacks = null; foreach (ResourcePack Pack in ResourcePacks) { switch (Pack.Type) { case ResourcePack.PackType.Mod: case ResourcePack.PackType.Jar: case ResourcePack.PackType.Zip: break; case ResourcePack.PackType.Folder: break; default: break; } } List <ZipArchiveEntry> BlockModelEntries = new List <ZipArchiveEntry>(); foreach (Block block in Blocks) { BlockModelEntries.Add(MinecraftJar.GetEntry("assets/minecraft/models/" + block.BlockStates[0].Models[0].ModelData["model"] + ".json")); } BlockModelEntries = BlockModelEntries.Distinct().ToList(); List <BlockModel> BlockModels = new List <BlockModel>(); foreach (ZipArchiveEntry Entry in BlockModelEntries) { } Console.Write(""); //IEnumerable<ZipArchiveEntry> BlockModelEntries = MinecraftJar.Entries.Where(Entry => (Entry.Name.EndsWith(".json")) && (Entry.FullName.EndsWith(@"minecraft/models/block/" + Entry.Name))); //foreach (ZipArchiveEntry Entry in BlockModelEntries) //{ //} } }
public TestAutoStateBase(StateToken stateToken) : base(stateToken) { }
protected ShopStateBase(StateToken token) : base(token) { }
public StateExitEventArgs(StateToken to) : this(to, null) { }
void IStateModifier.LerpTo(StateToken token, float t) { _cameraSettings.LerpTo(token, t); }
public BaseSample01State(StateToken token) : base(token) { }
protected SkillStateBase(StateToken token) : base(token) { }
protected RandomColorizeStateBase(StateToken token) : base(token) { }
public StateEnterEventArgs(StateToken from) : this(from, null) { }
protected AActionState(StateToken token) : base(token) { }
public StateExitEventArgs(StateToken to, object data) : base(data) { To = to; }
public void LerpToTarget(object targ, float t, float lerpT) { if (_dur == 0f) { t = 1f; } else { t = t / _dur; } if (_updateTranslation > TranslationOptions.None || _updateRotation >= RotationOptions.Heading) { var trans = GameObjectUtil.GetTransformFromSource(targ); if (trans != null) { if (_updateRotation == RotationOptions.Heading) { var wp = _path.Path.GetWaypointAt(t); this.SetPosition(trans, wp.Position, float.NaN); this.SetRotation(trans, Quaternion.LookRotation(wp.Heading), lerpT); } else if (_updateTranslation > TranslationOptions.None) { this.SetPosition(trans, _path.Path.GetPositionAt(t), lerpT); } } } bool useModifiers = (_modifierTable != null && _modifierTable.Count > 0); if (useModifiers || _updateRotation == RotationOptions.Rotation || _updateRotation == RotationOptions.LocalRotation) { var data = _path.Path.GetRelativePositionData(t); var cnt = _path.Path.Count; int i = data.Index; int j = (_path.Path.IsClosed) ? (i + 1) % cnt : i + 1; if (_updateRotation == RotationOptions.Rotation || _updateRotation == RotationOptions.LocalRotation) { var trans = GameObjectUtil.GetTransformFromSource(targ); if (trans != null) { var a = (i >= 0 && i < cnt) ? ComponentUtil.GetComponentFromSource <Transform>(_path.Path.ControlPoint(i)) : null; var b = (j >= 0 && j < cnt) ? ComponentUtil.GetComponentFromSource <Transform>(_path.Path.ControlPoint(j)) : null; if (a != null) { bool useRelative = _path.TransformRelativeTo != null; var r = (useRelative) ? a.GetRelativeRotation(_path.TransformRelativeTo) : a.rotation; if (b != null) { var rb = (useRelative) ? b.GetRelativeRotation(_path.TransformRelativeTo) : b.rotation; r = Quaternion.LerpUnclamped(r, rb, data.TPrime); } this.SetRotation(trans, r, lerpT); } } } if (useModifiers) { var e = _modifierTable.GetEnumerator(); while (e.MoveNext()) { var len = e.Current.Value.Length; var ma = (i >= 0 && i < len) ? e.Current.Value[i] : null; var mb = (j >= 0 && j < len) ? e.Current.Value[j] : null; if (float.IsNaN(lerpT)) { if (ma != null) { if (mb != null) { using (var state = StateToken.GetToken()) { ma.CopyTo(state); mb.LerpTo(state, data.TPrime); ma.ModifyWith(targ, state); } } else { ma.Modify(targ); } } else if (mb != null) { mb.Modify(targ); } } else { using (var curState = StateToken.GetToken()) using (var state = StateToken.GetToken()) { IStateModifier m = null; if (ma != null) { m = ma; if (mb != null) { ma.CopyTo(state); mb.LerpTo(state, data.TPrime); } else { ma.CopyTo(state); } } else if (mb != null) { m = mb; mb.CopyTo(state); } if (m != null) { state.CopyTo(curState); curState.SyncFrom(targ); curState.LerpTo(state, lerpT); m.ModifyWith(state, curState); } } } } } } }
void IStateModifier.CopyTo(StateToken token) { _cameraSettings.CopyTo(token); }
protected FlyerStateBase(StateToken token) : base(token) { }
protected BitcraftTestStateBase(StateToken token) : base(token) { }
public StateEnterEventArgs(StateToken from, object data) : base(data) { From = from; }