Exemplo n.º 1
0
        public Snowflake(
            int machineId            = 0,
            DateTime?timestampOffset = null,
            IClock clock             = null,
            bool ignoreWarning       = false)
        {
            IgnoreWarning = ignoreWarning;
            LastSequence  = 0;
            MachineIdMask =
                Convert.ToInt64(
                    new string('0', MachineIdOffset) +
                    new string('1', MachineIdLength) +
                    new string('0', 64 - MachineIdOffset - MachineIdLength),
                    2);
            var idWithOnlyUnmaskedMachineId = ((long)machineId) << (64 - MachineIdOffset - MachineIdLength);

            IdWithOnlyMachineId = idWithOnlyUnmaskedMachineId & MachineIdMask;
            if (IdWithOnlyMachineId != idWithOnlyUnmaskedMachineId)
            {
                throw new ArgumentException($"Machine ID should not be longer than {MachineIdLength} bits.");
            }

            TimestampMask = Convert.ToInt64(
                new string('0', 1) +
                new string('1', MachineIdOffset - 1) +
                new string('0', MachineIdLength) +
                new string('0', 64 - MachineIdOffset - MachineIdLength),
                2);
            RandomNumberMask =
                Convert.ToInt64(
                    new string('0', MachineIdOffset) +
                    new string('0', MachineIdLength) +
                    new string('1', 64 - MachineIdOffset - MachineIdLength),
                    2);

            TimestampOffset           = timestampOffset ?? DateTime.Parse("2014-01-10 08:00:00Z");
            LastTimestamp             = TimestampOffset;
            TimestampWarningThreshold = TimestampOffset
                                        .AddMilliseconds(Precision * Math.Pow(2, MachineIdOffset - 1))
                                        .AddYears(-10);
            Clock = clock ?? new SystemClock();
            var random = new byte[2];

            using (var randomNumberGenerator = RandomNumberGenerator.Create())
            {
                randomNumberGenerator.GetBytes(random);
            }

            SequenceEncryptionKey = BitConverter.ToInt16(random, 0) & RandomNumberMask;
        }
Exemplo n.º 2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (CameraNames.Length != 0)
            {
                hash ^= CameraNames.GetHashCode();
            }
            if (InputCameraChannelNames.Length != 0)
            {
                hash ^= InputCameraChannelNames.GetHashCode();
            }
            if (TimestampOffset != 0D)
            {
                hash ^= TimestampOffset.GetHashCode();
            }
            if (CameraObstaclePerceptionConfDir.Length != 0)
            {
                hash ^= CameraObstaclePerceptionConfDir.GetHashCode();
            }
            if (CameraObstaclePerceptionConfFile.Length != 0)
            {
                hash ^= CameraObstaclePerceptionConfFile.GetHashCode();
            }
            if (FrameCapacity != 0)
            {
                hash ^= FrameCapacity.GetHashCode();
            }
            if (ImageChannelNum != 0)
            {
                hash ^= ImageChannelNum.GetHashCode();
            }
            if (EnableUndistortion != false)
            {
                hash ^= EnableUndistortion.GetHashCode();
            }
            if (EnableVisualization != false)
            {
                hash ^= EnableVisualization.GetHashCode();
            }
            if (OutputObstaclesChannelName.Length != 0)
            {
                hash ^= OutputObstaclesChannelName.GetHashCode();
            }
            if (CameraPerceptionVizMessageChannelName.Length != 0)
            {
                hash ^= CameraPerceptionVizMessageChannelName.GetHashCode();
            }
            if (PrefusedChannelName.Length != 0)
            {
                hash ^= PrefusedChannelName.GetHashCode();
            }
            if (DefaultCameraPitch != 0D)
            {
                hash ^= DefaultCameraPitch.GetHashCode();
            }
            if (DefaultCameraHeight != 0D)
            {
                hash ^= DefaultCameraHeight.GetHashCode();
            }
            if (LaneCalibrationWorkingSensorName.Length != 0)
            {
                hash ^= LaneCalibrationWorkingSensorName.GetHashCode();
            }
            if (CalibratorMethod.Length != 0)
            {
                hash ^= CalibratorMethod.GetHashCode();
            }
            if (CalibServiceName.Length != 0)
            {
                hash ^= CalibServiceName.GetHashCode();
            }
            if (RunCalibService != false)
            {
                hash ^= RunCalibService.GetHashCode();
            }
            if (OutputCameraDebugMsg != false)
            {
                hash ^= OutputCameraDebugMsg.GetHashCode();
            }
            if (CameraDebugChannelName.Length != 0)
            {
                hash ^= CameraDebugChannelName.GetHashCode();
            }
            if (TsDiff != 0D)
            {
                hash ^= TsDiff.GetHashCode();
            }
            if (OutputFinalObstacles != false)
            {
                hash ^= OutputFinalObstacles.GetHashCode();
            }
            return(hash);
        }