public IRpcMethodResult GetBlock(string blockHash, int format = 0) { try { var blockComponent = new BlockComponent(); var block = blockComponent.GetBlockMsgByHash(blockHash); if (block != null) { if (format == 0) { var bytes = block.Serialize(); var result = Base16.Encode(bytes); return(Ok(result)); } else { return(Ok(block)); } } else { return(Ok()); } } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
private static XDesign_Block XDesign_Block(BlockComponent blockComponent, int size) { if (blockComponent == null) { throw new ArgumentNullException(nameof(blockComponent)); } var idxLastSlash = blockComponent.Name.LastIndexOf('/'); var group = idxLastSlash != -1 ? blockComponent.Name.Substring(0, idxLastSlash) : "Default"; var id = blockComponent.Name.Replace(" ", ""); var result = new XDesign_Block() { id = id, blockCategory = blockComponent.Category, blockGroup = group, blockName = blockComponent.Name, fabricStyles = XDesign_FabricStyles(blockComponent.FabricStyles), preview = XDesign_BlockPreview(blockComponent, size) }; return(result); }
public static MDesign_Block MDesign_Block(BlockComponent blockComponent, string[] tags, int size) { if (blockComponent == null) { throw new ArgumentNullException(nameof(blockComponent)); } var idxLastSlash = blockComponent.Name.LastIndexOf('/'); var group = idxLastSlash != -1 ? blockComponent.Name.Substring(0, idxLastSlash) : "Default"; var id = blockComponent.Name.Replace(" ", "").Replace("/", ""); var result = new MDesign_Block() { Id = id, Category = blockComponent.Category, Group = group, BlockName = blockComponent.Name, FabricStyles = MDesign_FabricStyles(blockComponent.FabricStyles), Tags = tags, Preview = MDesign_BlockPreview(blockComponent, size) }; return(result); }
public TilemapReader(BlockComponent mapComponent) { this.mapComponent = mapComponent; _nodes = new TileNode[mapComponent.fullSize.x, mapComponent.fullSize.y]; ReadGrid(); }
public void InitMap() { List <Area> list = new List <Area>(); string content = FileTool.ReadStringByFile(Environment.CurrentDirectory + "/Map/mapData.txt"); string[] contentArray = content.Split('\n'); for (int i = 0; i < contentArray.Length; i++) { if (contentArray[i] != "") { list.Add(deserializer.Deserialize <Area>(contentArray[i])); } } for (int i = 0; i < list.Count; i++) { CollisionComponent cc = new CollisionComponent(); cc.area = list[i]; SyncComponent sc = new SyncComponent(); BlockComponent bc = new BlockComponent(); m_world.CreateEntity(cc, sc, bc); Debug.Log("Create map"); } }
public void TestSpecificAllocationBlocks() { using (var context = new TrialDataContext()) { foreach (var part in GetMultipleParticipantCategories(new int[] { 1, 20000 })) { if (part.TrialArm != RandomisationArm.NotSet) { var nextBlock = Engine.Get1stBlockWithSpaceForSpecificAllocation(part, out RandomisationStrata strata, context); if (nextBlock == null) { Console.WriteLine("no spare allocations found for male:{0}, wt:{1}, arm:{2}", part.IsMale, part.AdmissionWeight, part.TrialArm); continue; } int parts = context.Participants.Count(p => p.AllocationBlockId == nextBlock.Id && p.TrialArm == part.TrialArm); BlockComponent b = nextBlock.GetComponents(); int allocs = b.Ratios[part.TrialArm] * b.Repeats; string outcome = string.Format("first block (Id:{0}) with space for allocation has {1} of {2} allocations taken", nextBlock.Id, parts, allocs); Assert.IsTrue(allocs > parts, outcome); Console.WriteLine(outcome); } } } }
public static Entity NewBlock(Vector3 positionValues, Texture2D texture, string typeName) { Entity block = EntityFactory.NewEntity(typeName); TransformComponent transformComponent = new TransformComponent(block, new Vector3(x: positionValues.X, y: positionValues.Y, z: positionValues.Z)); ModelComponent modelComponent = new ModelComponent(block, AssetManager.Instance.GetContent <Model>("Models/block2")); modelComponent.World = Matrix.CreateWorld(transformComponent.Position, Vector3.Forward, Vector3.Up); TextureComponent textureComponent = new TextureComponent(block, texture); CollisionComponent collisionComponent = new CollisionComponent(block, new BoxVolume(EntityFactory.CreateBoundingBox(modelComponent.Model))); LightComponent lightComponent = new LightComponent(block, new Vector3(0, 7, -5), Color.White.ToVector4(), 10f, Color.Blue.ToVector4(), 0.2f, Color.White.ToVector4(), 1000f); EffectComponent effectComponent = new EffectComponent(block, AssetManager.Instance.GetContent <Effect>("Shading")); BlockComponent blockComponent = new BlockComponent(block); ComponentManager.Instance.AddComponentToEntity(block, transformComponent); ComponentManager.Instance.AddComponentToEntity(block, modelComponent); ComponentManager.Instance.AddComponentToEntity(block, textureComponent); ComponentManager.Instance.AddComponentToEntity(block, collisionComponent, typeof(CollisionComponent)); ComponentManager.Instance.AddComponentToEntity(block, blockComponent); ComponentManager.Instance.AddComponentToEntity(block, effectComponent); ComponentManager.Instance.AddComponentToEntity(block, lightComponent); TransformHelper.SetInitialModelPos(modelComponent, transformComponent); TransformHelper.SetBoundingBoxPos(collisionComponent, transformComponent); //EntityFactory.AddBoundingBoxChildren((BoxVolume)collisionComponent); return(block); }
private static MDesign_BlockPreview MDesign_BlockPreview(BlockComponent blockComponent, int size) { if (blockComponent == null) { throw new ArgumentNullException(nameof(blockComponent)); } var blockSize = new Dimension(12, DimensionUnits.Inch); var scale = new DimensionScale(blockSize.Value, blockSize.Unit, size, DimensionUnits.Pixel); var pageLayout = new PageLayoutNode(blockSize * scale, blockSize * scale); pageLayout.LayoutSites[0].Node = blockComponent.Expand(false); pageLayout.UpdateBounds(PathOrientation.CreateDefault(), scale); var result = new MDesign_BlockPreview() { Width = (int)(blockSize * scale).Value, Height = (int)(blockSize * scale).Value, Shapes = MDesign_Shapes(pageLayout) }; return(result); }
public IRpcMethodResult GetBaseTarget(long blockHeight) { try { var blockComponent = new BlockComponent(); BlockMsg lastBlock = null; BlockMsg prevStepBlock = null; if (blockHeight > 0) { lastBlock = blockComponent.GetBlockMsgByHeight(blockHeight - 1); prevStepBlock = blockComponent.GetBlockMsgByHeight(blockHeight - POC.DIFFIUCLTY_ADJUST_STEP); } long baseTarget; if (lastBlock != null) { baseTarget = POC.CalculateBaseTarget(blockHeight, lastBlock, prevStepBlock); } else { baseTarget = POC.CalculateBaseTarget(0, null, null); } return(Ok(baseTarget)); } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
// Use this for initialization void Start() { blockComponent = GetComponent <BlockComponent> (); Debug.Assert(blockComponent); billboard = GetComponentInChildren <Billboard> (); Debug.Assert(billboard != null); }
public IRpcMethodResult GetDifficulty() { try { var blockComponent = new BlockComponent(); var height = blockComponent.GetLatestHeight(); var newHeight = height + 1; var previousBlockMsg = blockComponent.GetBlockMsgByHeight(height); var prevStepBlockMsg = blockComponent.GetBlockMsgByHeight(newHeight - POC.DIFFIUCLTY_ADJUST_STEP - 1); var bits = POC.CalculateBaseTarget(height, previousBlockMsg, prevStepBlockMsg).ToString(); var result = new GetDifficultyOM() { height = newHeight, hashTarget = bits }; return(Ok(result)); } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
public IRpcMethodResult GetBlockHash(long blockHeight) { try { var blockComponent = new BlockComponent(); var block = blockComponent.GetBlockMsgByHeight(blockHeight); if (block != null) { return(Ok(block.Header.Hash)); } else { return(Ok()); } } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
public IRpcMethodResult GenerateNewBlock(string minerName, string address = null, int format = 0) { try { var block = new BlockComponent().CreateNewBlock(minerName, address); if (block != null) { if (format == 0) { var bytes = block.Serialize(); var result = Base16.Encode(bytes); return(Ok(result)); } else { return(Ok(block)); } } else { return(Ok()); } } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
public IRpcMethodResult GetTxOutSetInfo() { try { GetTxOutSetInfoOM result = new GetTxOutSetInfoOM(); var blockComponent = new BlockComponent(); var txComponent = new TransactionComponent(); var utxoComponent = new UtxoComponent(); result.height = blockComponent.GetLatestHeight(); result.bestblock = null; if (result.height >= 0) { var bestBlock = blockComponent.GetBlockMsgByHeight(result.height); result.bestblock = bestBlock != null ? bestBlock.Header.Hash : null; } result.transactions = utxoComponent.GetTransactionCounts(); result.txouts = utxoComponent.GetOutputCounts(); long confirmedBalance, unconfirmedBalance; utxoComponent.GetBalanceInDB(out confirmedBalance, out unconfirmedBalance); result.total_amount = confirmedBalance; return(Ok(result)); } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
private void UpdateActiveState(BlockComponent blockComponent) { if (blockComponent != null) { //Debug.Log(blockComponent.name); currentState = (blockComponent.isMoving) ? ActiveState.Idle : ActiveState.Action; } }
public void OnUpdate() { if (_mapGrid == null || OnDestroyCallback == null) { return; } Vector3 unitPosition = transform.position; //Update map information TileNode standTile = FindValidStandPosition(unitPosition); if (standTile.TilemapMember != null && standTile.GridIndex != _currentTile.GridIndex) { if (_currentTile.TilemapMember != null) { _mapGrid.EditUnitState(_currentTile.GridIndex.x, _currentTile.GridIndex.y, this, false); } _mapGrid.EditUnitState(standTile.GridIndex.x, standTile.GridIndex.y, this, true); } //Add self under mapObject BlockComponent blockComponent = _mapBlockManager.GetMapComponentByPos(unitPosition); if (blockComponent != null && currentBlockComp != blockComponent) { if (currentBlockComp == null || (!currentBlockComp.isMoving && !blockComponent.isMoving)) { currentBlockComp = blockComponent; this.transform.SetParent(currentBlockComp.unitHolder); } } UpdateActiveState(currentBlockComp); if (currentState == ActiveState.Action) { //Fallback function if (_strategy == null) { AgentMove(); } else { //_strategy shouldn't put any where but here, all units share the same strategy object _strategy.SetUp(this, _uniqueUnitID, _monsterStats, _mapGrid, _gameDamageManager); _currentStrategy = _strategy.Think(_currentTile, _currentStrategy); _strategy.Execute(_currentTile, _currentStrategy); } } _currentTile = standTile; }
public P2PJob() { this.p2pComponent = new P2PComponent(); this.txComponent = new TransactionComponent(); this.blockComponent = new BlockComponent(); blockSyncTimer = new System.Timers.Timer(10 * 1000); blockSyncTimer.AutoReset = true; blockSyncTimer.Elapsed += blockSyncTimer_Elapsed; }
public static BlockComponent CreateBlockComponent(XDesign_DesignBlock xDesignBlock) { var result = BlockComponent.Create( xDesignBlock.blockCategory ?? Constants.DefaultComponentCategory, xDesignBlock.blockName, CreateFabricStyleList(xDesignBlock.fabricStyles)); return(result); }
public IRpcMethodResult GetTxOut(string txid, int vount, bool unconfirmed = false) { try { GetTxOutOM result = null; var txComponent = new TransactionComponent(); var blockComponent = new BlockComponent(); string blockHash = null; TransactionMsg tx = txComponent.GetTransactionMsgFromDB(txid, out blockHash); if (tx == null && unconfirmed) { tx = txComponent.GetTransactionMsgFromPool(txid); } if (tx != null && tx.OutputCount > vount) { var output = tx.Outputs[vount]; long confirmations = 0; if (!string.IsNullOrWhiteSpace(blockHash)) { var block = blockComponent.GetBlockMsgByHash(blockHash); if (block != null) { var latestHeight = blockComponent.GetLatestHeight(); if (latestHeight > block.Header.Height) { confirmations = latestHeight - block.Header.Height; } } } result = new GetTxOutOM(); result.bestblock = blockHash; result.confirmations = confirmations; result.value = output.Amount; result.scriptPubKey = output.LockScript; result.version = tx.Version; result.coinbase = (tx.InputCount == 0 && tx.Inputs[0].OutputTransactionHash == Base16.Encode(HashHelper.EmptyHash())); } return(Ok(result)); } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
public static void Main(string[] args) { var hostBuilder = Host.CreateDefaultBuilder(args); _ = hostBuilder.ConfigureLogging(logging => { // Add logging support to Azure BLOB's and the servers file system. // This logging is only active when App Service Logs are enabled through the Azure portal. // _ = logging.AddAzureWebAppDiagnostics(); // Enable logging data to be transmitted to Application Insights. // //_ = logging.AddApplicationInsights(); }); _ = hostBuilder.ConfigureServices(services => { // Configure the logging associated with AddAzureWebAppDiagnostics above. // _ = services.Configure <AzureFileLoggerOptions>(options => { }); _ = services.Configure <AzureBlobLoggerOptions>(options => { }); }); _ = hostBuilder.ConfigureWebHostDefaults(builder => builder.UseStartup <Startup>()); var host = hostBuilder.Build(); using (var serviceScope = host.Services.CreateScope()) { var services = serviceScope.ServiceProvider; try { var quiltContextFactory = services.GetRequiredService <IQuiltContextFactory>(); var nodeFactory = new CompositeNodeFactory(); nodeFactory.Add(new DatabaseNodeFactory(quiltContextFactory)); nodeFactory.Add(new BuiltInQuiltLayoutNodeFactory()); BlockComponent.Configure(nodeFactory); LayoutComponent.Configure(nodeFactory); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Startup> >(); logger.LogError(ex, "An error occurred."); throw; } } GlobalFontSettings.FontResolver = new ReportFontResolver(); GlobalFontSettings.DefaultFontEncoding = PdfFontEncoding.WinAnsi; host.Run(); }
public P2PJob() { this.p2pComponent = new P2PComponent(); this.txComponent = new TransactionComponent(); this.blockComponent = new BlockComponent(); MiningPoolComponent.OnNewMiningPoolHandle = (msg) => receivedNewMiningPoolMessage(null, msg); blockSyncTimer = new System.Timers.Timer(10 * 1000); blockSyncTimer.AutoReset = true; blockSyncTimer.Elapsed += blockSyncTimer_Elapsed; }
public static void ConfigureFactories(IServiceProvider services) { var quiltContextFactory = services.GetRequiredService <IQuiltContextFactory>(); var nodeFactory = new CompositeNodeFactory(); nodeFactory.Add(new DatabaseNodeFactory(quiltContextFactory)); nodeFactory.Add(new BuiltInQuiltLayoutNodeFactory()); BlockComponent.Configure(nodeFactory); LayoutComponent.Configure(nodeFactory); }
public void Init(BlockComponent data) { this.data = data; sprite = GetComponent <SpriteRenderer>(); sprite.sprite = data.sprite; Restart(); Message.AddListener("RestartLevel", Restart); }
public static List <RandomisationArm> ToList(this BlockComponent block) { var returnVar = new List <RandomisationArm>(); foreach (var r in block.Ratios) { int count = r.Value * block.Repeats; for (int i = 0; i < count; i++) { returnVar.Add(r.Key); } } return(returnVar); }
protected void StatePatrol() { var hit = Physics2D.Raycast(transform.position, transform.up, 0.5f, _layers); if (hit.collider) { var exit = hit.collider.GetComponent <ExitComponent>(); if (exit) { _targetVector = -transform.up; _state = StateTurnAround; return; } var elevator = hit.collider.GetComponent <ElevatorComponent>(); if (elevator) { _targetVector = -transform.up; _state = StateTurnAround; return; } var tilemap = hit.collider.GetComponent <DiggableTilemapComponent>(); var block = hit.collider.GetComponent <BlockComponent>(); if (tilemap) { var point = hit.point + ((hit.point - (Vector2)transform.position).normalized * 0.1f); block = tilemap.Dig(Mathf.RoundToInt(point.x), Mathf.RoundToInt(point.y)); if (!block || block.Definition.Impassable) { _targetVector = -transform.up; _state = StateTurnAround; return; } } if (block) { _state = StateMine; _target = block; return; } return; } transform.position += transform.up * _moveSpeed * Time.fixedDeltaTime; }
private static XDesign_DesignBlock XDesign_DesignBlock(BlockComponent blockComponent) { if (blockComponent == null) { throw new ArgumentNullException(nameof(blockComponent)); } var result = new XDesign_DesignBlock() { blockName = blockComponent.Name, fabricStyles = XDesign_FabricStyles(blockComponent.FabricStyles) }; return(result); }
public IRpcMethodResult GetBlockDataList(int skipCount, int takeCount) { try { List <BlockInfo> result = new List <BlockInfo>(); var lastblock = BlockDac.Default.SelectLast(); if (lastblock == null) { return(Ok(result)); } BlockComponent component = new BlockComponent(); long startHeight = lastblock.Header.Height - skipCount; long height = startHeight; for (long count = 1; count <= takeCount; count++) { if (height < 0) { break; } var block = component.GetBlockInfo(height); if (block != null) { result.Add(block); } height--; } //for (int i = skipCount; i < takeCount; i++) //{ // var height = lastblock.Header.Height - i; // if (height < 0) // break; // var block = component.GetBlockInfo(height); // if (block != null) // result.Add(block); //} return(Ok(result)); } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
private void CallEveryoneReady() { if (_mapHolder == null) { return; } var tComponent = FindEntryComponent(_mapHolder); this.recordTime = 0; if (tComponent != null) { _entranceComponent = tComponent; } }
/// <summary> /// 获取区块的所有奖励,包含挖矿和手续费 /// </summary> /// <param name="blockHash"></param> /// <returns></returns> public IRpcMethodResult GetBlockReward(string blockHash) { try { BlockComponent block = new BlockComponent(); long reward = block.GetBlockReward(blockHash); return(Ok(reward)); } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
public IRpcMethodResult GetVerifiedHashes(List <string> hashes) { try { BlockComponent component = new BlockComponent(); List <Block> result = component.GetBlockEntityByHash(hashes); return(Ok(result)); } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }