コード例 #1
0
ファイル: TLDCOption.cs プロジェクト: TelegramOrg/Telegram-wp
        public bool AreEquals(TLDCOption dcOption)
        {
            if (dcOption == null)
            {
                return(false);
            }

            return(Id.Value == dcOption.Id.Value);
        }
コード例 #2
0
ファイル: TLVector.cs プロジェクト: yuukidesu9/telegram-wp
        public int IndexOf(TLDCOption dcOption)
        {
            for (var i = 0; i < Items.Count; i++)
            {
                if (Items[i] == dcOption)
                {
                    return(i);
                }
            }

            return(-1);
        }
コード例 #3
0
ファイル: TLConfig.cs プロジェクト: TelegramOrg/Telegram-wp
        public static TLConfig Merge(TLConfig oldConfig, TLConfig newConfig)
        {
            if (oldConfig == null)
            {
                return(newConfig);
            }

            if (newConfig == null)
            {
                return(oldConfig);
            }

            foreach (var dcOption in oldConfig.DCOptions)
            {
                if (dcOption.AuthKey != null)
                {
                    var option = dcOption;
                    foreach (var newDCOption in newConfig.DCOptions.Where(x => x.AreEquals(option)))
                    {
                        newDCOption.AuthKey          = dcOption.AuthKey;
                        newDCOption.Salt             = dcOption.Salt;
                        newDCOption.SessionId        = dcOption.SessionId;
                        newDCOption.ClientTicksDelta = dcOption.ClientTicksDelta;
                    }
                }
            }
            if (!string.IsNullOrEmpty(oldConfig.Country))
            {
                newConfig.Country = oldConfig.Country;
            }
            if (oldConfig.ActiveDCOptionIndex != default(int))
            {
                var oldActiveDCOption = oldConfig.DCOptions[oldConfig.ActiveDCOptionIndex];
                var dcId  = oldConfig.DCOptions[oldConfig.ActiveDCOptionIndex].Id.Value;
                var ipv6  = oldActiveDCOption.IPv6.Value;
                var media = oldActiveDCOption.Media.Value;

                TLDCOption newActiveDCOption      = null;
                int        newActiveDCOptionIndex = 0;
                for (var i = 0; i < newConfig.DCOptions.Count; i++)
                {
                    if (newConfig.DCOptions[i].Id.Value == dcId &&
                        newConfig.DCOptions[i].IPv6.Value == ipv6 &&
                        newConfig.DCOptions[i].Media.Value == media)
                    {
                        newActiveDCOption      = newConfig.DCOptions[i];
                        newActiveDCOptionIndex = i;
                        break;
                    }
                }

                if (newActiveDCOption == null)
                {
                    for (var i = 0; i < newConfig.DCOptions.Count; i++)
                    {
                        if (newConfig.DCOptions[i].Id.Value == dcId)
                        {
                            newActiveDCOption      = newConfig.DCOptions[i];
                            newActiveDCOptionIndex = i;
                            break;
                        }
                    }
                }

                newConfig.ActiveDCOptionIndex = newActiveDCOptionIndex;
            }
            if (oldConfig.LastUpdate != default(DateTime))
            {
                newConfig.LastUpdate = oldConfig.LastUpdate;
            }

            return(newConfig);
        }