Пример #1
0
 public void DisplayBlockInfo(Block bl)
 {
     BlockInfo = bl;
     if (BlockInfo.Active == clsConst.NOT_ACTIVE)
     {
         return;
     }
     lbDeviceTitle.Update();
 }
Пример #2
0
        private static async Task <bool> IndexBlock(Model.BCExplorerContext context, string blockHash)
        {
            _logger.LogInformation($"Processing block at height {_currentBlockHeight}: {blockHash}");

            BlockResult blockResult = await _client.GetBlockAsync(blockHash);

            if (blockResult == null)
            {
                _logger.LogWarning($"Warning - could not retrieve block at height {_currentBlockHeight}: {blockHash}");
                return(false);
            }

            var block = new Model.Block
            {
                Id        = _currentBlockNumber,
                Height    = _currentBlockHeight,
                BlockHash = blockHash,
                BlockData = blockResult.OriginalJson
            };

            context.Blocks.Add(block);

            if (_currentBlockHeight == 0)
            {
                // for the transaction in the genesis block, we can't pull transaction data, so this is all we know
                var genesisBlockTransaction = new Model.Transaction {
                    Block = block, Id = blockResult.Transactions[0]
                };
                context.Transactions.Add(genesisBlockTransaction);
                _currentBlockHeight++;
                _currentBlockNumber++;
                context.SaveChanges();
                return(true);
            }

            List <BCExplorer.Network.Models.Transaction> blockTransactions = new List <BCExplorer.Network.Models.Transaction>();

            foreach (var txid in blockResult.Transactions)
            {
                var transaction = await _transactionProvider.GetTransaction(txid);

                transaction.Block = new BCExplorer.Network.Models.Block {
                    Height = _currentBlockHeight
                };
                blockTransactions.Add(transaction);
            }

            foreach (var blockTx in blockTransactions)
            {
                ProcessTransaction(blockTx, context);
            }

            context.SaveChanges();
            _currentBlockHeight++;
            _currentBlockNumber++;
            return(true);
        }
Пример #3
0
 public string GetAllBlocks(int index)
 {
     Model.Block block = null;
     if (index < blockMiner.Blockchain.Count)
     {
         block = blockMiner.Blockchain[index];
     }
     return(JsonSerializer.Serialize(block));
 }
Пример #4
0
		/// <summary>
		/// Creates a report for the given block, fills all process reports
		/// </summary>
		/// <param name="block"></param>
		public BlockReportVm(BlockVm vm)
		{
			_parent = vm;
			UOW = new Dal.SoheilEdmContext();
			TaskDataService = new DataServices.TaskDataService(UOW);
			ProcessReportDataService = new DataServices.ProcessReportDataService(UOW);
			entity = new DataServices.BlockDataService(UOW).GetSingle(vm.Id);

			ReloadReports();
		}
Пример #5
0
        private void StageInitialize(int width, int height, int length)
        {
            Width        = width;
            Height       = height;
            BlocksLength = length;
            BlocksWidth  = Width / BlocksLength;
            BlocksHeight = Height / BlocksLength;
            Blocks       = new Model.Block[BlocksHeight, BlocksWidth];
            Stage        = new View.Block[BlocksHeight, BlocksWidth];

            for (int y = 0; y < BlocksHeight; y++)
            {
                for (int x = 0; x < BlocksWidth; x++)
                {
                    Blocks[y, x] = new Block();
                    Stage[y, x]  = new View.Block(BlocksLength - 2);

                    Rectangle rectangle = new Rectangle
                    {
                        Margin = new Thickness(1)
                    };
                    Binding brushBinding = new Binding("Brush")
                    {
                        Source = Stage[y, x]
                    };
                    rectangle.SetBinding(Rectangle.FillProperty, brushBinding);
                    Binding lengthBinding = new Binding("Length")
                    {
                        Source = Stage[y, x]
                    };
                    rectangle.SetBinding(Rectangle.HeightProperty, lengthBinding);
                    rectangle.SetBinding(Rectangle.WidthProperty, lengthBinding);

                    StageView.Add(rectangle);
                }
            }
        }
        protected BlockViewModel(SequencerViewModel sequencer, Model.Block model, string typeLabel)
        {
            this.sequencer  = sequencer;
            this.model      = model;
            this._typeLabel = typeLabel;

            ForwardPropertyEvents(nameof(model.StartTime), model, nameof(StartTime), nameof(EndTime), nameof(EndTimeOccupied), nameof(DisplayOffset));
            ForwardPropertyEvents(nameof(model.Duration), model, nameof(Duration), nameof(EndTime), nameof(EndTimeOccupied), nameof(DisplayWidth));

            ForwardPropertyEvents(nameof(model.SegmentContext), model, nameof(SegmentContext), nameof(IsSegmentActive));
            // track affiliation
            ForwardCollectionEvents(model.Tracks, nameof(DisplayTopOffset), nameof(DisplayHeight), nameof(DisplayClip));
            // tracks in general
            // moved to OnTracksCollectionChanged(), called by the sequencer, because when this view model is constructed, the "Tracks" collection may still be under construction
            //CollectionChangedEventManager.AddHandler(sequencer.Tracks, (sender, e) => { Notify(nameof(DisplayTopOffset)); Notify(nameof(DisplayHeight)); Notify(nameof(DisplayClip)); });

            // subscribe to sequencer
            ForwardPropertyEvents(nameof(sequencer.ActiveMusicSegment), sequencer, nameof(IsSegmentActive));
            ForwardPropertyEvents(nameof(sequencer.TimePixelScale), sequencer, nameof(DisplayOffset), nameof(DisplayWidth));
            ForwardCollectionEvents(sequencer.SelectedBlocks, (sender, e) =>
            {
                if ((e.Action == NotifyCollectionChangedAction.Add && e.NewItems.Contains(this)) ||
                    (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems.Contains(this)) ||
                    e.Action == NotifyCollectionChangedAction.Replace ||
                    e.Action == NotifyCollectionChangedAction.Reset)
                {
                    Notify(nameof(IsSelected));
                }
            });

            // subscribe to track height changes
            if (globalParams != null)
            {
                ForwardPropertyEvents(nameof(globalParams.TrackDisplayHeight), globalParams, NotifyTrackRelatedProperties);
            }
        }
        public static BlockViewModel FromModel(SequencerViewModel sequencer, Model.Block model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            BlockViewModel vm;

            if (!s_viewModelCache.TryGetValue(model, out vm))
            {
                if (model is Model.ColorBlock)
                {
                    vm = new ColorBlockViewModel(sequencer, (Model.ColorBlock)model);
                }
                else if (model is Model.RampBlock)
                {
                    vm = new RampBlockViewModel(sequencer, (Model.RampBlock)model);
                }
                else if (model is Model.LoopBlock)
                {
                    vm = new LoopBlockViewModel(sequencer, (Model.LoopBlock)model);
                }
                //else if (model is Model.GroupBlock)
                //    vm = new GroupBlockViewModel(sequencer, (Model.GroupBlock)model);

                else
                {
                    throw new NotImplementedException("unknown block type: " + model.GetType().Name);
                }

                s_viewModelCache[model] = vm;
            }

            return(vm);
        }
Пример #8
0
		void initializeCommands()
		{
			ChangeStationCommand = new Commands.Command(o =>
			{
				if (Model != null)
					try { _blockDataService.DeleteModelRecursive(Model); }
					catch { }
				ActivityList.Clear();

				StateStation = SelectedStateStation;
				Model = new Model.Block
				{
					Code = StateStation.Code,
					StateStation = StateStation.Model,
					StartDateTime = DateTime.Now.Date.AddHours(DateTime.Now.Hour),
					EndDateTime = DateTime.Now.Date.AddHours(DateTime.Now.Hour),
					DurationSeconds = 0,
					ModifiedBy = LoginInfo.Id,
				};

				initTask();
			});
			DontChangeStationCommand = new Commands.Command(o =>
			{
				SelectedStateStation = StateStation;
				Model.StateStation = StateStation.Model;
			});
			DeleteBlockFromList = new Commands.Command(vm =>
			{
				var planEditor = vm as PlanEditorVm;
				if (planEditor != null) planEditor.RemoveBlock(this);
			});
			SelectTodayCommand = new Commands.Command(o => StartDateForAll = DateTime.Now.Date);
			SelectTomorrowCommand = new Commands.Command(o => StartDateForAll += TimeSpan.FromDays(1));
			SelectThisHourCommand = new Commands.Command(o =>
			{
				SelectTodayCommand.Execute(o);
				StartTime = TimeSpan.FromHours(DateTime.Now.Hour);
			});
			AddOneHourCommand = new Commands.Command(o =>
			{
				StartTime = StartTime.Add(TimeSpan.FromHours(1));
				if (StartTime.CompareTo(TimeSpan.FromDays(1)) >= 1)
				{
					StartTime = StartTime.Add(TimeSpan.FromHours(-24));
					StartDate = StartDate.AddDays(1);
				}
			});
			SubtractOneHourCommand = new Commands.Command(o =>
			{
				if (StartTime.CompareTo(TimeSpan.FromHours(1)) < 1)
				{
					StartTime = StartTime.Add(TimeSpan.FromHours(23));
					StartDate = StartDate.AddDays(-1);
				}
				else
					StartTime = StartTime.Add(TimeSpan.FromHours(-1));
			});
			SetStartForAllCommand = new Commands.Command(o =>
			{
				var start = StartDateForAll.Add(StartTimeForAll);
				var end = DateTime.MinValue;
				foreach (var act in ActivityList)
				{
					foreach (var process in act.ProcessList)
					{
						if (!process.HasReport)
							process.Timing.StartDateTime = start;
						if (process.Timing.EndDateTime > end)
							end = process.Timing.EndDateTime;
					}
				}
				StartDate = start.Date;
				StartTime = start.TimeOfDay;
				EndDate = end.Date;
				EndTime = end.TimeOfDay;
				Duration = end - start;
			});
			SetOffsetForAllCommand = new Commands.Command(o =>
			{
				var start = DateTime.MaxValue;
				var end = DateTime.MinValue;
				var offset = o == null ? StartOffsetForAll : -StartOffsetForAll;
				foreach (var act in ActivityList)
				{
					foreach (var process in act.ProcessList)
					{
						if (!process.HasReport)
							process.Timing.StartDateTime += offset;
						if (process.Timing.StartDateTime < start)
							start = process.Timing.StartDateTime; 
						if (process.Timing.EndDateTime > end)
							end = process.Timing.EndDateTime;
					}
				}
				StartDate = start.Date;
				StartTime = start.TimeOfDay;
				EndDate = end.Date;
				EndTime = end.TimeOfDay;
				Duration = end - start;
			});
		}