Пример #1
0
        /// <summary>
        /// Returns true if Duty instances are equal
        /// </summary>
        /// <param name="other">Instance of Duty to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Duty other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     DutyId == other.DutyId ||
                     DutyId != null &&
                     DutyId.Equals(other.DutyId)
                     ) &&
                 (
                     SlaveDutyId == other.SlaveDutyId ||
                     SlaveDutyId != null &&
                     SlaveDutyId.Equals(other.SlaveDutyId)
                 ) &&
                 (
                     BlockId == other.BlockId ||
                     BlockId != null &&
                     BlockId.Equals(other.BlockId)
                 ) &&
                 (
                     ClientDeptId == other.ClientDeptId ||
                     ClientDeptId != null &&
                     ClientDeptId.Equals(other.ClientDeptId)
                 ) &&
                 (
                     SubDiscipline == other.SubDiscipline ||
                     SubDiscipline != null &&
                     SubDiscipline.Equals(other.SubDiscipline)
                 ) &&
                 (
                     RequestGender == other.RequestGender ||

                     RequestGender.Equals(other.RequestGender)
                 ) &&
                 (
                     Grade == other.Grade ||
                     Grade != null &&
                     Grade.Equals(other.Grade)
                 ) &&
                 (
                     FallbackGrade == other.FallbackGrade ||
                     FallbackGrade != null &&
                     FallbackGrade.Equals(other.FallbackGrade)
                 ) &&
                 (
                     VacancyReason == other.VacancyReason ||
                     VacancyReason != null &&
                     VacancyReason.Equals(other.VacancyReason)
                 ) &&
                 (
                     Date == other.Date ||
                     Date != null &&
                     Date.Equals(other.Date)
                 ) &&
                 (
                     StartTime == other.StartTime ||
                     StartTime != null &&
                     StartTime.Equals(other.StartTime)
                 ) &&
                 (
                     EndTime == other.EndTime ||
                     EndTime != null &&
                     EndTime.Equals(other.EndTime)
                 ) &&
                 (
                     BreakDuration == other.BreakDuration ||

                     BreakDuration.Equals(other.BreakDuration)
                 ) &&
                 (
                     PoNumber == other.PoNumber ||

                     PoNumber.Equals(other.PoNumber)
                 ) &&
                 (
                     UniqueNumber == other.UniqueNumber ||

                     UniqueNumber.Equals(other.UniqueNumber)
                 ) &&
                 (
                     Agency == other.Agency ||
                     Agency != null &&
                     Agency.Equals(other.Agency)
                 ) &&
                 (
                     Skill == other.Skill ||
                     Skill != null &&
                     Skill.Equals(other.Skill)
                 ) &&
                 (
                     Specialty == other.Specialty ||
                     Specialty != null &&
                     Specialty.Equals(other.Specialty)
                 ) &&
                 (
                     FallbackSkill == other.FallbackSkill ||
                     FallbackSkill != null &&
                     FallbackSkill.Equals(other.FallbackSkill)
                 ) &&
                 (
                     FallbackSpeciality == other.FallbackSpeciality ||
                     FallbackSpeciality != null &&
                     FallbackSpeciality.Equals(other.FallbackSpeciality)
                 ) &&
                 (
                     Status == other.Status ||

                     Status.Equals(other.Status)
                 ) &&
                 (
                     Rates == other.Rates ||
                     Rates != null &&
                     other.Rates != null &&
                     Rates.SequenceEqual(other.Rates)
                 ) &&
                 (
                     TimeIntervalRates == other.TimeIntervalRates ||
                     TimeIntervalRates != null &&
                     other.TimeIntervalRates != null &&
                     TimeIntervalRates.SequenceEqual(other.TimeIntervalRates)
                 ) &&
                 (
                     Person == other.Person ||
                     Person != null &&
                     Person.Equals(other.Person)
                 ));
        }
Пример #2
0
 public bool Equals(BlockModifierKey other)
 {
     return(Block.Equals(other.Block) && AttachmentPoint.Equals(other.AttachmentPoint));
 }
Пример #3
0
        /// <summary>
        /// Reads blockchain information from a stream in the following order:
        ///  - number of blocks to read
        ///  - blocks with Hash256 representing the blockId first, then int
        ///         representing the parentAlias
        /// The blockHeight is calculated for each block based on the
        /// blockHeight of its parent, so it should not be stored.
        /// The corresponding Serialization method is <see cref="WriteTo"/>.
        /// </summary>
        /// <returns>A new list representing the blockchain.</returns>
        public static SimpleBlockchain ReadFrom(BinaryReader reader)
        {
            var committedBlocks   = new List <CommittedBlock>();
            var uncommittedBlocks = new List <UncommittedBlock>();
            var maxBlockHeight    = 0; // track the blockHeight so that it doesn't have to be recalculated afterward

            // Read blocks
            var committedBlockCount = reader.ReadInt32();

            for (var i = 0; i < committedBlockCount; i++)
            {
                var blockId     = new BlockId(reader.ReadHash256());
                var blockAlias  = new BlockAlias(reader.ReadUInt32());
                var parentAlias = new BlockAlias(reader.ReadUInt32());

                // Only the first block can have parentAlias 0.
                if (parentAlias == BlockAlias.GenesisParent && !blockId.Equals(BlockId.Genesis) ||
                    blockAlias.IsPrior(parentAlias))
                {
                    throw new FormatException(
                              $"Parent alias {parentAlias} is an invalid parent for block {blockAlias}.");
                }

                if (!TryFindCommitted(parentAlias, committedBlocks, out var parentBlock) &&
                    !blockId.Equals(BlockId.Genesis))
                {
                    throw new ArgumentNullException($"No parent {parentAlias} found.");
                }

                // The first block, which is the only one to have parent 0, has block height 0.
                var blockHeight = parentAlias == BlockAlias.GenesisParent
                    ? 0
                    : parentBlock.BlockHeight + 1;
                var newBlock = new CommittedBlock(blockHeight, blockId, blockAlias, parentAlias);

                if (blockHeight > maxBlockHeight)
                {
                    maxBlockHeight = blockHeight;
                }

                committedBlocks.Add(newBlock);
            }

            var numUncommmittedBlocks = reader.ReadInt32();

            for (var i = 0; i < numUncommmittedBlocks; i++)
            {
                var blockId     = new TempBlockId(reader.ReadHash128());
                var blockAlias  = new BlockAlias(reader.ReadUInt32());
                var parentAlias = new BlockAlias(reader.ReadUInt32());

                // Only the first block can have parentAlias 0.
                if ((uncommittedBlocks.Count != 0 || committedBlocks.Count != 0) &&
                    parentAlias == BlockAlias.GenesisParent || blockAlias.IsPrior(parentAlias))
                {
                    throw new FormatException(
                              $"Parent alias {parentAlias} is an invalid parent for block {blockAlias}.");
                }

                int blockHeight;
                if (TryFindCommitted(parentAlias, committedBlocks, out var parentBlock))
                {
                    blockHeight = parentBlock.BlockHeight + 1;
                }
                else
                {
                    if (uncommittedBlocks.Count == 0 && committedBlocks.Count == 0 &&
                        parentAlias == BlockAlias.GenesisParent) // we're adding the first block
                    {
                        blockHeight = 1;
                    }
                    else
                    {
                        if (!TryFindUncommitted(parentAlias, uncommittedBlocks, out var uParentBlock))
                        {
                            throw new ArgumentNullException($"No parent {parentAlias} found.");
                        }
                        blockHeight = uParentBlock.BlockHeight + 1;
                    }
                }

                var newBlock = new UncommittedBlock(blockHeight, blockId, blockAlias, parentAlias);

                if (blockHeight > maxBlockHeight)
                {
                    maxBlockHeight = blockHeight;
                }

                uncommittedBlocks.Add(newBlock);
            }

            return(new SimpleBlockchain(committedBlocks, uncommittedBlocks, maxBlockHeight));
        }