コード例 #1
0
ファイル: NetId.cs プロジェクト: paulpach/MLAPI
        /// <summary>
        /// Checks if two NetId's are equal
        /// </summary>
        /// <param name="obj">NetId to compare to</param>
        /// <returns>Wheter or not the two NetIds are equal</returns>
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            NetId key = (NetId)obj;

            return((HostId == key.HostId) && (ConnectionId == key.ConnectionId));
        }
コード例 #2
0
            private static void StructureDestroyed(NetId netId)
            {
                var structure = NetIdRegistry.Get <StructureDrop>(netId);

                if (structure == null)
                {
                    return;
                }

                OnStructureDestroying?.Invoke(structure);
            }
コード例 #3
0
            private static void BarricadeDestroyed(NetId netId)
            {
                var barricade = NetIdRegistry.Get <BarricadeDrop>(netId);

                if (barricade == null)
                {
                    return;
                }

                OnBarricadeDestroying?.Invoke(barricade);
            }
コード例 #4
0
        internal void WriteToStream(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream);

            writer.Write(Timestamp.ToFileTimeUtc());
            writer.Write(Tag ?? String.Empty);
            writer.Write(Uuid.ToString());
            writer.Write(NetId.ToString());
            writer.Write(Network ?? String.Empty);
            writer.Write(Color.ToString());
            writer.Write(Convert.ToBase64String(Frame.ToArray()));
        }
コード例 #5
0
        // don't work with CFLIST atm
        private static byte[] CalculateKey(SessionKeyType type, AppNonce appNonce, NetId netId, DevNonce devNonce, AppKey appKey)
        {
            using var aes = Aes.Create("AesManaged");
            var rawAppKey = new byte[AppKey.Size];

            _       = appKey.Write(rawAppKey);
            aes.Key = rawAppKey;
#pragma warning disable CA5358 // Review cipher mode usage with cryptography experts
            // Cipher is part of the LoRaWAN specification
            aes.Mode = CipherMode.ECB;
#pragma warning restore CA5358 // Review cipher mode usage with cryptography experts
            aes.Padding = PaddingMode.None;

            var buffer = new byte[1 + AppNonce.Size + NetId.Size + DevNonce.Size + 7];
            var pt     = buffer.AsSpan();
            Debug.Assert(pt.Length == 16);
            pt[0] = unchecked ((byte)type);
            pt    = pt[1..];
コード例 #6
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (UserId != 0)
            {
                hash ^= UserId.GetHashCode();
            }
            if (NetId != 0)
            {
                hash ^= NetId.GetHashCode();
            }
            if (Seat != 0)
            {
                hash ^= Seat.GetHashCode();
            }
            if (Team != 0)
            {
                hash ^= Team.GetHashCode();
            }
            hash ^= combatInitHeroes_.GetHashCode();
            return(hash);
        }
コード例 #7
0
 public static AppSessionKey CalculateAppSessionKey(AppNonce appNonce, NetId netId, DevNonce devNonce, AppKey appKey) =>
 AppSessionKey.Read(CalculateKey(SessionKeyType.Application, appNonce, netId, devNonce, appKey));
コード例 #8
0
 public static NetworkSessionKey CalculateNetworkSessionKey(AppNonce appNonce, NetId netId, DevNonce devNonce, AppKey appKey) =>
 NetworkSessionKey.Read(CalculateKey(SessionKeyType.Network, appNonce, netId, devNonce, appKey));
コード例 #9
0
        public static bool TryRead <T>(this TwinCollection twinCollection, string property, ILogger?logger, [NotNullWhen(true)] out T?value)
        {
            _ = twinCollection ?? throw new ArgumentNullException(nameof(twinCollection));

            value = default;

            if (!twinCollection.Contains(property))
            {
                return(false);
            }

            // cast to object to avoid dynamic code to be generated
            var some = (object)twinCollection[property];

            // quick path for values that can be directly converted
            if (some is Newtonsoft.Json.Linq.JValue someJValue)
            {
                if (someJValue.Value is T someT)
                {
                    value = someT;
                    return(true);
                }
            }

            try
            {
                var t      = typeof(T);
                var tPrime = Nullable.GetUnderlyingType(t) ?? t;

                // For 100% case coverage we should handle the case where type T is nullable and the token is null.
                // Since this is not possible in IoT hub, we do not handle the null cases exhaustively.

                if (tPrime == StationEuiType)
                {
                    value = (T)(object)StationEui.Parse(some.ToString());
                }
                else if (tPrime == DevNonceType)
                {
                    value = (T)(object)new DevNonce(Convert.ToUInt16(some, CultureInfo.InvariantCulture));
                }
                else if (tPrime == DevAddrType)
                {
                    value = (T)(object)DevAddr.Parse(some.ToString());
                }
                else if (tPrime == AppSessionKeyType)
                {
                    value = (T)(object)AppSessionKey.Parse(some.ToString());
                }
                else if (tPrime == AppKeyType)
                {
                    value = (T)(object)AppKey.Parse(some.ToString());
                }
                else if (tPrime == NetworkSessionKeyType)
                {
                    value = (T)(object)NetworkSessionKey.Parse(some.ToString());
                }
                else if (tPrime == JoinEuiType)
                {
                    value = (T)(object)JoinEui.Parse(some.ToString());
                }
                else if (tPrime == NetIdType)
                {
                    value = (T)(object)NetId.Parse(some.ToString());
                }
                else
                {
                    value = (T)Convert.ChangeType(some, t, CultureInfo.InvariantCulture);
                }
                if (t.IsEnum && !t.IsEnumDefined(value))
                {
                    LogParsingError(logger, property, some);
                    return(false);
                }
            }
            catch (Exception ex) when(ex is ArgumentException
                                      or InvalidCastException
                                      or FormatException
                                      or OverflowException
                                      or Newtonsoft.Json.JsonSerializationException)
            {
                LogParsingError(logger, property, some, ex);
                return(false);
            }
            return(true);
        }
コード例 #10
0
 protected virtual void Start()
 {
     NetId.GotNewComponent(this);
 }
コード例 #11
0
 public IFuture <TR> RemoteCall <TR, T0, T1>(NetId agentId, string methodName, T0 t0, T1 t1)
 {
     throw new NotImplementedException();
 }