public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            Aggregator.Subscribe(this);

            if (state.TryGet("json", out PassportElement element))
            {
                state.Remove("json");

                var personal = element.GetPersonalDocument();
                if (personal == null)
                {
                    return;
                }

                DocumentType = element;
                Files.ReplaceWith(personal.Files);
                Translation.ReplaceWith(personal.Translation);
            }

            if (state.TryGet("password", out string password))
            {
                state.Remove("password");

                _password = password;
            }
        }
Exemple #2
0
        public static MessageBody For(
            string httpVersion, IDictionary<string, IEnumerable<string>> headers, Action continuation)
        {
            // see also http://tools.ietf.org/html/rfc2616#section-4.4

            var keepAlive = httpVersion != "HTTP/1.0";

            string connection;
            if (headers.TryGet("Connection", out connection))
            {
                keepAlive = connection.Equals("keep-alive", StringComparison.OrdinalIgnoreCase);
            }

            string transferEncoding;
            if (headers.TryGet("Transfer-Encoding", out transferEncoding))
            {
                return new ForChunkedEncoding(keepAlive, continuation);
            }

            string contentLength;
            if (headers.TryGet("Content-Length", out contentLength))
            {
                return new ForContentLength(keepAlive, int.Parse(contentLength), continuation);
            }

            if (keepAlive)
            {
                return new ForContentLength(true, 0, continuation);
            }

            return new ForRemainingData(continuation);
        }
        public static MessageBody For(
            string httpVersion, IDictionary <string, string[]> headers, Action continuation)
        {
            // see also http://tools.ietf.org/html/rfc2616#section-4.4

            var keepAlive = httpVersion != "HTTP/1.0";

            string connection;

            if (headers.TryGet("Connection", out connection))
            {
                keepAlive = connection.Equals("keep-alive", StringComparison.OrdinalIgnoreCase);
            }

            string transferEncoding;

            if (headers.TryGet("Transfer-Encoding", out transferEncoding))
            {
                return(new ForChunkedEncoding(keepAlive, continuation));
            }

            string contentLength;

            if (headers.TryGet("Content-Length", out contentLength))
            {
                return(new ForContentLength(keepAlive, int.Parse(contentLength), continuation));
            }

            if (keepAlive)
            {
                return(new ForContentLength(true, 0, continuation));
            }

            return(new ForRemainingData(continuation));
        }
        public ErrorViewModel(ErrorContext errorContext, IDictionary<string, object> routeValues, WikiDownConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            this.ClientMessage = (errorContext != null) ? errorContext.ClientData : null;

            var exception = (errorContext != null) ? errorContext.Exception : null;
            if (exception != null)
            {
                this.ExceptionContent = exception.ToString();
                this.ExceptionMessage = exception.Message;
                this.ExceptionTypeName = exception.GetType().Name;
            }

            if (routeValues != null)
            {
                this.ActionName = routeValues.TryGet("action") as string;
                this.ControllerName = routeValues.TryGet("controller") as string;
            }

            this.config = config;
        }
Exemple #5
0
 public Event(String type, IDictionary<String, Object> eventInitDict = null)
     : this()
 {
     var bubbles = eventInitDict.TryGet<Boolean>("bubbles") ?? false;
     var cancelable = eventInitDict.TryGet<Boolean>("cancelable") ?? false;
     Init(type, bubbles, cancelable);
 }
Exemple #6
0
            private void OnEnter()
            {
                var stateType = State.GetType();
                var configs   = _stateConfigCache.TryGet(stateType, TryGetMode.GetOrCreate, CacheStateConfiguration);

                configs.Iterate(s => s.Enter(Context, State));
            }
Exemple #7
0
 public KeyboardEvent(String type, IDictionary <String, Object> eventInitDict = null)
     : base(type, eventInitDict)
 {
     Key        = (eventInitDict.TryGet("key") ?? String.Empty).ToString();
     Location   = (KeyboardLocation)(eventInitDict.TryGet <Int32>("location") ?? 0);
     IsRepeated = eventInitDict.TryGet <Boolean>("repeat") ?? false;
     _modifiers = (eventInitDict.TryGet("code") ?? String.Empty).ToString();
 }
Exemple #8
0
        public void TryGet_KeyNotFound_ReturnFalse()
        {
            //Act
            var result = _dictionary.TryGet("-1", out _);

            //Assert
            result.Should().BeFalse();
        }
Exemple #9
0
        public Event(String type, IDictionary <String, Object> eventInitDict = null)
            : this()
        {
            var bubbles    = eventInitDict.TryGet <Boolean>("bubbles") ?? false;
            var cancelable = eventInitDict.TryGet <Boolean>("cancelable") ?? false;

            Init(type, bubbles, cancelable);
        }
Exemple #10
0
 public WheelEvent(String type, IDictionary<String, Object> eventInitDict = null)
     : base(type, eventInitDict)
 {
     DeltaX = eventInitDict.TryGet<Double>("deltaX") ?? 0.0;
     DeltaY = eventInitDict.TryGet<Double>("deltaY") ?? 0.0;
     DeltaZ = eventInitDict.TryGet<Double>("deltaZ") ?? 0.0;
     DeltaMode = (WheelMode)(eventInitDict.TryGet<Int32>("deltaMode") ?? 0);
 }
Exemple #11
0
 public WheelEvent(String type, IDictionary <String, Object> eventInitDict = null)
     : base(type, eventInitDict)
 {
     DeltaX    = eventInitDict.TryGet <Double>("deltaX") ?? 0.0;
     DeltaY    = eventInitDict.TryGet <Double>("deltaY") ?? 0.0;
     DeltaZ    = eventInitDict.TryGet <Double>("deltaZ") ?? 0.0;
     DeltaMode = (WheelMode)(eventInitDict.TryGet <Int32>("deltaMode") ?? 0);
 }
Exemple #12
0
 public KeyboardEvent(String type, IDictionary<String, Object> eventInitDict = null)
     : base(type, eventInitDict)
 {
     Key = (eventInitDict.TryGet("key") ?? String.Empty).ToString();
     Location = (KeyboardLocation)(eventInitDict.TryGet<Int32>("location") ?? 0);
     IsRepeated = eventInitDict.TryGet<Boolean>("repeat") ?? false;
     _modifiers = (eventInitDict.TryGet("code") ?? String.Empty).ToString();
 }
Exemple #13
0
 public MessageEvent(String type, IDictionary <String, Object> eventInitDict = null)
     : base(type, eventInitDict)
 {
     Data        = eventInitDict.TryGet("data");
     Origin      = (eventInitDict.TryGet("origin") ?? String.Empty).ToString();
     LastEventId = (eventInitDict.TryGet("lastEventId") ?? String.Empty).ToString();
     Source      = eventInitDict.TryGet("source") as IWindow;
     Ports       = eventInitDict.TryGet("ports") as IMessagePort[] ?? new IMessagePort[0];
 }
Exemple #14
0
        public static Result <Argon2Kdf, InvalidDataException> Deserialize(IDictionary <string, object> properties)
        {
            var ret = new Argon2Kdf();

            if (!properties.TryGet <string>("kdf", out var kdf))
            {
                return(new InvalidDataException("The kdf dictionary does not have the required 'kdf' field."));
            }

            if (kdf != KdfName)
            {
                return(new InvalidDataException($"The kdf needs to be '{KdfName}' (was '{kdf}')."));
            }

            if (!properties.TryGet <int>("version", out var version))
            {
                return(new InvalidDataException("The kdf dictionary does not have the required 'version' field."));
            }

            if (version != Version)
            {
                return(new InvalidDataException(
                           $"Only version 0x{Version:X4} is supported at the moment (was 0x{version:X4})"));
            }

            if (!properties.TryGet <int>("opslimit", out var opslimit))
            {
                return(new InvalidDataException("The kdf dictionary does not have the required 'opslimit' field."));
            }

            ret.OpsLimit = opslimit;

            if (!properties.TryGet <int>("memlimit", out var memlimit))
            {
                return(new InvalidDataException("The kdf dictionary does not have the required 'memlimit' field."));
            }

            ret.MemLimit = memlimit;

            if (!properties.TryGet <string>("salt", out var salt))
            {
                return(new InvalidDataException("The kdf dictionary does not have the required 'salt' field."));
            }

            var fb64 = salt.FromBase64();

            if (!fb64)
            {
                return(new InvalidDataException("The salt is not a valid base64 string."));
            }

            ret.Salt = fb64.Value;

            return(ret);
        }
Exemple #15
0
 public MouseEvent(String type, IDictionary <String, Object> eventInitDict = null)
     : base(type, eventInitDict)
 {
     ScreenX        = eventInitDict.TryGet <Int32>("screenX") ?? 0;
     ScreenY        = eventInitDict.TryGet <Int32>("screenY") ?? 0;
     ClientX        = eventInitDict.TryGet <Int32>("clientX") ?? 0;
     ClientY        = eventInitDict.TryGet <Int32>("clientY") ?? 0;
     IsCtrlPressed  = eventInitDict.TryGet <Boolean>("ctrlKey") ?? false;
     IsMetaPressed  = eventInitDict.TryGet <Boolean>("metaKey") ?? false;
     IsShiftPressed = eventInitDict.TryGet <Boolean>("shiftKey") ?? false;
     IsAltPressed   = eventInitDict.TryGet <Boolean>("altKey") ?? false;
     Button         = (MouseButton)(eventInitDict.TryGet <Int32>("button") ?? 0);
     Target         = eventInitDict.TryGet("relatedTarget") as IEventTarget;
 }
        public CecilCommandInputDescriptor(PropertyDefinition property, IDictionary<string, object> inputAttrib)
        {
            IsValueRequired = property.PropertyType.FullName != typeof(bool).FullName;

            _propertyName = property.Name;
            inputAttrib.TryGet("Name", name => Name = (string)name);
            inputAttrib.TryGet("Description", description => Description = (string)description);
            inputAttrib.TryGet("IsValueRequired", _ => IsValueRequired = (bool)_);
            inputAttrib.TryGet("IsRequired", _ => IsRequired = (bool)_);
            inputAttrib.TryGet("Position", position => Position = (int)position);

            Name = Name ?? property.Name;
            Type = property.PropertyType.Name;
        }
Exemple #17
0
        public string GetDvbcChannelName(decimal freqInMhz)
        {
            // in case the parameter is in Hz or kHz, correct it to MHz to avoid overflow errors. 2 GHz is the largest plausible frequency
            if (freqInMhz > 2000)
            {
                freqInMhz /= 1000;
            }
            if (freqInMhz > 2000)
            {
                freqInMhz /= 1000;
            }

            return(dvbcChannels.TryGet((int)(freqInMhz * 1000)) ?? dvbcChannels.TryGet((int)((freqInMhz - 1) * 1000)) ?? "");
        }
Exemple #18
0
 public MouseEvent(String type, IDictionary<String, Object> eventInitDict = null)
     : base(type, eventInitDict)
 {
     ScreenX = eventInitDict.TryGet<Int32>("screenX") ?? 0;
     ScreenY = eventInitDict.TryGet<Int32>("screenY") ?? 0;
     ClientX = eventInitDict.TryGet<Int32>("clientX") ?? 0;
     ClientY = eventInitDict.TryGet<Int32>("clientY") ?? 0;
     IsCtrlPressed = eventInitDict.TryGet<Boolean>("ctrlKey") ?? false;
     IsMetaPressed = eventInitDict.TryGet<Boolean>("metaKey") ?? false;
     IsShiftPressed = eventInitDict.TryGet<Boolean>("shiftKey") ?? false;
     IsAltPressed = eventInitDict.TryGet<Boolean>("altKey") ?? false;
     Button = (MouseButton)(eventInitDict.TryGet<Int32>("button") ?? 0);
     Target = eventInitDict.TryGet("relatedTarget") as IEventTarget;
 }
        public CecilCommandInputDescriptor(PropertyDefinition property, IDictionary <string, object> inputAttrib)
        {
            IsValueRequired = property.PropertyType.FullName != typeof(bool).FullName;

            _propertyName = property.Name;
            inputAttrib.TryGet("Name", name => Name = (string)name);
            inputAttrib.TryGet("Description", description => Description = (string)description);
            inputAttrib.TryGet("IsValueRequired", _ => IsValueRequired   = (bool)_);
            inputAttrib.TryGet("IsRequired", _ => IsRequired             = (bool)_);
            inputAttrib.TryGet("Position", position => Position          = (int)position);

            Name = Name ?? property.Name;
            Type = property.PropertyType.Name;
        }
Exemple #20
0
        public Settings(IDictionary <string, string> settings)
        {
            this.Errors = new List <string>();

            this.Path = settings.TryGet("path") ?? string.Empty;
            if (string.IsNullOrEmpty(this.Path) || !Directory.Exists(this.Path))
            {
                this.Errors.Add(string.Format("Directory {0} doesn't exists", this.Path));
            }

            this.ConnectionString = settings.TryGet("ConnectionString") ?? string.Empty;
            this.UserVariables    = settings
                                    .Where(p => p.Key.StartsWith("$"))
                                    .ToDictionary(p => p.Key.Substring(1), p => p.Value);
        }
    public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
    {
        if (dictionary == null)
        {
            throw new ArgumentNullException("dictionary");
        }
        if (type != typeof(Money))
        {
            return(null);
        }
        var amount   = Convert.ToDecimal(dictionary.TryGet("Amount"));
        var currency = (string)dictionary.TryGet("Currency");

        return(new Money(currency, amount));
    }
Exemple #22
0
        public Settings(IDictionary<string, string> settings)
        {
            this.Errors = new List<string>();

            this.Path = settings.TryGet("path") ?? string.Empty;
            if (string.IsNullOrEmpty(this.Path) || !Directory.Exists(this.Path))
            {
                this.Errors.Add(string.Format("Directory {0} doesn't exists", this.Path));
            }

            this.ConnectionString = settings.TryGet("ConnectionString") ?? string.Empty;
            this.UserVariables = settings
                .Where(p => p.Key.StartsWith("$"))
                .ToDictionary(p => p.Key.Substring(1), p => p.Value);
        }
 private Maybe <Type> TryGetType(string name)
 {
     lock (sync)
     {
         return(specialTypes.TryGet(name));
     }
 }
 private Maybe <Tuple <string, Type> > TryGetName(string forType)
 {
     lock (sync)
     {
         return(renames.TryGet(forType));
     }
 }
Exemple #25
0
        public DigitalChannel(int slot, SignalSource signalSource, DataMapping data,
                              IDictionary <int, decimal> transpFreq, FavoritesIndexMode sortedFavorites, IDictionary <int, string> providerNames) :
            base(data, sortedFavorites)
        {
            this.InitCommonData(slot, (SignalSource)((int)signalSource & ~(int)(SignalSource.TvAndRadio)), data);

            if (!this.InUse || this.OldProgramNr == 0)
            {
                return;
            }

            this.InitDvbData(data, providerNames);

            int     transp = data.GetByte(_ChannelOrTransponder);
            decimal freq   = transpFreq.TryGet(transp);

            if (freq == 0)
            {
                if ((this.SignalSource & SignalSource.Antenna) != 0)
                {
                    freq = transp * 8 + 306;
                }
                else if ((this.SignalSource & SignalSource.Cable) != 0)
                {
                    freq = transp * 8 + 106;
                }
            }

            this.ChannelOrTransponder = transp.ToString();
            this.FreqInMhz            = freq;
        }
        public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var chatId = (long)parameter;

            if (state.TryGet("selectedIndex", out int selectedIndex))
            {
                SelectedIndex = selectedIndex;
            }

            //Peer = (TLInputPeerBase)parameter;
            //With = Peer is TLInputPeerUser ? (ITLDialogWith)CacheService.GetUser(Peer.ToPeer().Id) : CacheService.GetChat(Peer.ToPeer().Id);

            Chat = ProtoService.GetChat(chatId);

            Media = new MediaCollection(ProtoService, chatId, new SearchMessagesFilterPhotoAndVideo());
            Files = new MediaCollection(ProtoService, chatId, new SearchMessagesFilterDocument());
            Links = new MediaCollection(ProtoService, chatId, new SearchMessagesFilterUrl());
            Music = new MediaCollection(ProtoService, chatId, new SearchMessagesFilterAudio());
            Voice = new MediaCollection(ProtoService, chatId, new SearchMessagesFilterVoiceNote());

            RaisePropertyChanged(() => Media);
            RaisePropertyChanged(() => Files);
            RaisePropertyChanged(() => Links);
            RaisePropertyChanged(() => Music);
            RaisePropertyChanged(() => Voice);

            return(Task.CompletedTask);
        }
            public IStateConfigurator <TActualState> In <TActualState>()
                where TActualState : TState
            {
                var stateType = typeof(TActualState);
                var stateData = _states.TryGet(stateType, TryGetMode.GetOrCreate, t => new StateConfiguration(t));

                return(new StateConfigurator <TActualState>(this, stateData));
            }
Exemple #28
0
        public void TryGet_SourceIsNull_ThrowArgumentNullException()
        {
            //Act
            Action action = () => _dictionaryNull.TryGet("1", out _);

            //Assert
            action.Should().ThrowExactly <ArgumentNullException>();
        }
Exemple #29
0
        private static SimpleFieldDescription ToFieldDescription(TypeName declaringType, Type fieldType, string name,
                                                                 IDictionary <Type, ITypeDescription> knownTypes, IndexStateLookup indexLookUp)
        {
            var type = knownTypes.TryGet(fieldType)
                       .GetValue(() => Create(fieldType, knownTypes, new ITypeDescription[0], indexLookUp));

            return(SimpleFieldDescription.Create(name, type, indexLookUp(declaringType, name, type.TypeName)));
        }
        public void TryGetIDictionaryValueWithNullInstanceShouldThrow()
        {
            IDictionary <string, SomeDemoObject> dict = null;

            Action act = () => dict.TryGet("somekey");

            act.ShouldThrowExactly <ArgumentNullException>("Implementation should handle the extension used on null instance.");
        }
Exemple #31
0
 private static void EnsureWritten <TKey, TValue>(IDictionary <TKey, TValue> dictionary, IReadOnlyList <KeyValuePair <TKey, TValue> > values)
 {
     foreach (var pair in values)
     {
         dictionary.TryGet(pair.Key, out var actualValue)
         .Should().BeTrue();
         actualValue.Should().Be(pair.Value);
     }
 }
 public RedisLiveConnection(IDictionary<string, string> settings)
 {
     if (!settings.TryGet("host", out _Host))
     {
         throw new Exception("Redis host is required");
     }
     _Port = settings.Get("port", 6379);
     _Timeout = settings.Get("timeout", 2000);
 }
Exemple #33
0
 public RedisLiveConnection(IDictionary <string, string> settings)
 {
     if (!settings.TryGet("host", out _Host))
     {
         throw new Exception("Redis host is required");
     }
     _Port    = settings.Get("port", 6379);
     _Timeout = settings.Get("timeout", 2000);
 }
        public CecilCommandDescriptor(TypeDefinition typeDef, IDictionary<string, object> commandAttribute, IEnumerable<CecilCommandInputDescriptor> inputs)
        {
            Visible = true;
            IsDefault = false;
            commandAttribute.TryGet("Noun", noun => Noun = (string)noun);
            commandAttribute.TryGet("Verb", verb => Verb = (string)verb);
            commandAttribute.TryGet("Visible", visible => Visible = (bool)visible);
            commandAttribute.TryGet("IsDefault", isDefault => IsDefault = (bool)isDefault);
            var tokenPrefix = Verb + "-" + Noun;
            commandAttribute.TryGet("Description", _ => Description = (string)_);
            Description = Description ?? CommandDocumentation.GetCommandDescription(typeDef.Module.Assembly, tokenPrefix);
            Inputs = inputs.ToDictionary(x => x.Name,
                                         x =>
                                         {
                                             x.Description = x.Description ?? CommandDocumentation.GetCommandDescription(typeDef.Module.Assembly, tokenPrefix + "-" + x.Name);
                                             return (ICommandInputDescriptor)x;
                                         }, StringComparer.OrdinalIgnoreCase);

            Factory = () => (ICommand)Activator.CreateInstanceFrom(typeDef.Module.FullyQualifiedName, typeDef.FullName).Unwrap();
        }
        public CecilCommandDescriptor(TypeDefinition typeDef, IDictionary <string, object> commandAttribute, IEnumerable <CecilCommandInputDescriptor> inputs)
        {
            Visible   = true;
            IsDefault = false;
            commandAttribute.TryGet("Noun", noun => Noun                = (string)noun);
            commandAttribute.TryGet("Verb", verb => Verb                = (string)verb);
            commandAttribute.TryGet("Visible", visible => Visible       = (bool)visible);
            commandAttribute.TryGet("IsDefault", isDefault => IsDefault = (bool)isDefault);
            var tokenPrefix = Verb + "-" + Noun;

            commandAttribute.TryGet("Description", _ => Description = (string)_);
            Description = Description ?? CommandDocumentation.GetCommandDescription(typeDef.Module.Assembly, tokenPrefix);
            Inputs      = inputs.ToDictionary(x => x.Name,
                                              x =>
            {
                x.Description = x.Description ?? CommandDocumentation.GetCommandDescription(typeDef.Module.Assembly, tokenPrefix + "-" + x.Name);
                return((ICommandInputDescriptor)x);
            }, StringComparer.OrdinalIgnoreCase);

            Factory = () => (ICommand)Activator.CreateInstanceFrom(typeDef.Module.FullyQualifiedName, typeDef.FullName).Unwrap();
        }
Exemple #36
0
        static void OutputKanji(Kanji kanji)
        {
            Writer.WriteLine($"{kanji.Character} {kanji.SingleMeaning} (UCS {kanji.UCSCode}, Freq {kanji.Frequency?.ToString() ?? "unknown"}) Radical #{kanji.RadicalNumber} (Approx: {RadicalAsKanji(kanji)?.Character})");
            Writer.WriteLine($"{string.Join(", ", kanji.Kunyomi.Union(kanji.Onyomi))}");
            Writer.WriteLine($"{string.Join(", ", kanji.Meanings)}");
            {
                var radicalKanji = _radicalAsKanjiLookup.TryGet(kanji.RadicalNumber);
                var components   = new List <char>();
                components.Add(radicalKanji.Character);
                components.AddRange(kanji.Components);
                Writer.WriteLine("Components:");
                Writer.WriteLine(string.Join(Environment.NewLine, components.Select(c => {
                    var s = "    " + c.ToString();
                    var k = _kanjiLookup.TryGet(c);
                    if (k != null)
                    {
                        s += " ";
                        if (!string.IsNullOrEmpty(k.Heisig6Keyword))
                        {
                            s += $"[{k.Heisig6Keyword}] ";
                        }
                        s += string.Join(", ", k.Meanings);
                    }
                    return(s);
                })));
            }
            if (kanji.Heisig6Elements != null && kanji.Heisig6Elements.Any())
            {
                Writer.WriteLine("Heisig components: " + string.Join(", ", kanji.Heisig6Elements));
            }
            void PrintAssociations(string prefix, IList <Kanji> kanjis)
            {
                const int maxToPrint = 10;
                var       numMore    = kanjis.Count() - maxToPrint;
                var       hasMore    = numMore > 0;
                var       toPrint    = kanjis.Take(maxToPrint)
                                       .Select(x => x.Character + " " + x.SingleMeaning);
                var kstring = string.Join(" ", toPrint);

                if (hasMore)
                {
                    kstring += $" . . . ({numMore} more)";
                }
                Writer.WriteLine($"{prefix}: " + kstring);
            }

            if (_radicalNumberLookup.TryGetValue(kanji.RadicalNumber, out var kanjiSameRadical))
            {
                PrintAssociations("Same radical", kanjiSameRadical);
            }
            PrintAssociations("Same component", kanji.RelatedKanjiByComponent.Select(c => _kanjiLookup.TryGet(c)).ToList());
        }
        private TypeBuilder BuildNamespaceContext(string lastNameSpace,
                                                  string forNamespace, string ns)
        {
            var parentNS = nameSpaceHolder.TryGet(lastNameSpace).GetValue(rootType);

            var currentType = BuildNSContextType(forNamespace);

            var property = CodeGenerationUtils.DefineProperty(parentNS, ns, currentType.Item1);

            property.SetGetMethod(CreateNewInstanceGetter(parentNS, property, currentType.Item2, QueryPropertyAccessRights(parentNS)));

            nameSpaceHolder[forNamespace] = currentType.Item1;
            return(currentType.Item1);
        }
Exemple #38
0
        public DigitalChannel(int slot, SignalSource signalSource, DataMapping data, DataRoot dataRoot,
                              IDictionary <int, decimal> transpFreq, FavoritesIndexMode sortedFavorites, IDictionary <int, string> providerNames) :
            base(data, sortedFavorites)
        {
            // ToDo - ShiT
            this.InitCommonData(slot, signalSource & ~SignalSource.TVAndRadioAndData, data);

            if (!this.InUse)
            {
                return;
            }

            // "InUse" and "IsDeleted" are not always guessed correctly. If PrNr=0, the channel contains garbage
            if (this.OldProgramNr == 0)
            {
                this.InUse = false;
                return;
            }

            this.InitDvbData(data, providerNames);

            decimal freq   = 0;
            int     transp = data.GetByte(_ChannelOrTransponder);

            if (dataRoot.Transponder.TryGetValue(transp, out var tp))
            {
                this.Polarity = tp.Polarity;
            }
            freq = transpFreq.TryGet(transp);
            if (freq == 0 && tp != null)
            {
                freq = tp.FrequencyInMhz;
            }
            if (freq == 0)
            {
                if ((this.SignalSource & SignalSource.Antenna) != 0)
                {
                    freq = transp * 8 + 306;
                }
                else if ((this.SignalSource & SignalSource.Cable) != 0)
                {
                    freq = transp * 8 + 106;
                }
            }

            this.ChannelOrTransponder = transp.ToString();
            this.FreqInMhz            = freq;
        }
    public static void AddToDictionary <K, V>(this IDictionary <K, IList <V> > dict, K key, V value)
    {
        var existingList = dict.TryGet(key);

        if (existingList.WasFound)
        {
            existingList.Value.Add(value);
        }
        else
        {
            dict.Add(key, new List <V>()
            {
                value
            });
        }
    }
Exemple #40
0
        private static Task <IReadOnlyList <KeyValuePair <TKey, TValue> > > GetValuesAsync <TKey, TValue>(IDictionary <TKey, TValue> dictionary, IEnumerable <TKey> keys)
        {
            return(Task.Factory.StartNew(() =>
            {
                var values = new List <KeyValuePair <TKey, TValue> >();
                foreach (var key in keys)
                {
                    if (dictionary.TryGet(key, out var value))
                    {
                        values.Add(new KeyValuePair <TKey, TValue>(key, value));
                    }
                }

                return (IReadOnlyList <KeyValuePair <TKey, TValue> >)values;
            }));
        }
    public DigitalChannel(int slot, SignalSource signalSource, DataMapping data,
      IDictionary<int, decimal> transpFreq, FavoritesIndexMode sortedFavorites, IDictionary<int, string> providerNames) :
      base(data, sortedFavorites)
    {
      this.InitCommonData(slot, (SignalSource)((int)signalSource & ~(int)(SignalSource.TvAndRadio)), data);

      if (!this.InUse || this.OldProgramNr == 0)
        return;

      this.InitDvbData(data, providerNames);

      int transp = data.GetByte(_ChannelOrTransponder);
      decimal freq = transpFreq.TryGet(transp);
      if (freq == 0)
        freq = LookupData.Instance.GetDvbtFrequeny(transp); // transp*8 + 106); // (106 = DVB-C; DVB-T=306?)

      this.ChannelOrTransponder = transp.ToString();
      this.FreqInMhz = freq;
    }
Exemple #42
0
 private ITypeDescription GetOrCreateTypeByName(TypeName name,
     Func<TypeName, Maybe<IReflectClass>> classLookup,
     IDictionary<string, ITypeDescription> knownTypes)
 {
     var type = knownTypes.TryGet(name.FullName);
     if(type.HasValue)
     {
         return type.Value;
     }
     var systemType = typeResolver(name);
     return systemType.Convert(KnownType.Create)
         .GetValue(()=>classLookup(name)
             .Convert(n=>CreateType(name, n, classLookup, knownTypes))
             .GetValue(()=>MockTypeFor(name,knownTypes)));
 }
Exemple #43
0
 private static Type GetOrCreateType(IDictionary<ITypeDescription, Type> typeBuildMap,
     ModuleBuilder modBuilder, ITypeDescription typeInfo)
 {
     return typeBuildMap.TryGet(typeInfo)
         .GetValue(() => CreateType(typeBuildMap, modBuilder, typeInfo));
 }
 public HashChangedEvent(String type, IDictionary<String, Object> eventInitDict = null)
     : base(type, eventInitDict)
 {
     PreviousUrl = (eventInitDict.TryGet("oldURL") ?? String.Empty).ToString();
     CurrentUrl = (eventInitDict.TryGet("newURL") ?? String.Empty).ToString();
 }
 public CecilUICommandDescriptor(TypeDefinition typeDef, IDictionary<string, object> commandAttribute, IDictionary<string, object> uiAttribute, IEnumerable<CecilCommandInputDescriptor> inputs)
     : base(typeDef, commandAttribute,inputs)
 {
     uiAttribute.TryGet("Label", label => Label = (string)label);
     uiAttribute.TryGet("Context", context => Context = (UICommandContext)context);
 }
 public PageTransitionEvent(String type, IDictionary<String, Object> eventInitDict = null)
     : base(type, eventInitDict)
 {
     IsPersisted = eventInitDict.TryGet<Boolean>("persisted") ?? false;
 }
Exemple #47
0
 public UiEvent(String type, IDictionary<String, Object> eventInitDict = null)
     : base(type, eventInitDict)
 {
     View = eventInitDict.TryGet("view") as IWindow;
     Detail = eventInitDict.TryGet<Int32>("detail") ?? 0;
 }
 protected void InitDvbData(DataMapping data, IDictionary<int, string> providerNames)
 {
   this.ShortName = data.GetString(_ShortName, data.Settings.GetInt("lenShortName"));
   this.ServiceId = data.GetWord(_ServiceId);
   //this.PcrPid = data.GetWord(_PcrPid);
   this.VideoPid = data.GetWord(_VideoPid);
   this.AudioPid = data.GetWord(_AudioPid);
   this.OriginalNetworkId = data.GetWord(_OriginalNetworkId);
   this.TransportStreamId = data.GetWord(_TransportStreamId);
   this.ServiceType = data.GetByte(_ServiceType);
   this.SymbolRate = data.GetWord(_SymbolRate);
   if (data.Settings.GetInt(_ServiceProviderId, -1) != -1)
   {
     int source = -1;
     if ((this.SignalSource & SignalSource.MaskProvider) == SignalSource.Freesat)
       source = 4;
     else if ((this.SignalSource & SignalSource.MaskProvider) == SignalSource.TivuSat)
       source = 6;
     else if ((this.SignalSource & SignalSource.Antenna) != 0)
       source = 0;
     else if ((this.SignalSource & SignalSource.Cable) != 0)
       source = 1;
     else if ((this.SignalSource & SignalSource.Sat) != 0)
       source = 3;
     int providerId = data.GetWord(_ServiceProviderId);
     this.Provider = providerNames.TryGet((source << 16) + providerId);
   }
   this.SignalSource |= LookupData.Instance.IsRadioOrTv(this.ServiceType);
 }
Exemple #49
0
 public FocusEvent(String type, IDictionary<String, Object> eventInitDict = null)
     : base(type, eventInitDict)
 {
     Target = eventInitDict.TryGet("target") as IEventTarget;
 }
        public void Connect(INode target, IDictionary<String, Object> options)
        {
            if (options == null)
                throw new ArgumentNullException("options");

            var init = new MutationObserverInit
            {
                AttributeFilters = options.TryGet("attributeFilter") as IEnumerable<String>,
                IsObservingAttributes = options.TryGet<Boolean>("attributes"),
                IsObservingChildNodes = options.TryGet<Boolean>("childList") ?? false,
                IsObservingCharacterData = options.TryGet<Boolean>("characterData"),
                IsObservingSubtree = options.TryGet<Boolean>("subtree") ?? false,
                IsExaminingOldAttributeValue = options.TryGet<Boolean>("attributeOldValue"),
                IsExaminingOldCharacterData = options.TryGet<Boolean>("characterDataOldValue")
            };

            Connect(target, init);
        }
 public CompositionEvent(String type, IDictionary<String, Object> eventInitDict = null)
     : base(type, eventInitDict)
 {
     Data = (eventInitDict.TryGet("data") ?? String.Empty).ToString();
 }
Exemple #52
0
 private ITypeDescription GetOrCreateType(IReflectClass typeToFind, Func<TypeName, Maybe<IReflectClass>> classLookup,
     IDictionary<string, ITypeDescription> knownTypes)
 {
     return knownTypes.TryGet(NameOf(typeToFind).FullName)
         .GetValue(() => CreateType(typeToFind, classLookup, knownTypes));
 }
Exemple #53
0
 private static SimpleFieldDescription ToFieldDescription(TypeName declaringType,Type fieldType,string name,
     IDictionary<Type, ITypeDescription> knownTypes, IndexStateLookup indexLookUp)
 {
     var type = knownTypes.TryGet(fieldType)
         .GetValue(() => Create(fieldType, knownTypes,new ITypeDescription[0],indexLookUp));
     return SimpleFieldDescription.Create(name, type, indexLookUp(declaringType, name, type.TypeName));
 }
Exemple #54
0
 protected void ReadDvbData(SQLiteDataReader r, IDictionary<string, int> field, DataRoot dataRoot, 
   IDictionary<string, bool> encryptionInfo)
 {
   string longName, shortName;
   this.GetChannelNames(r.GetString(field["channel_label"]), out longName, out shortName);
   this.Name = longName;
   this.ShortName = shortName;
   this.RecordOrder = r.GetInt32(field["channel_order"]);
   this.FreqInMhz = (decimal)r.GetInt32(field["frequency"]) / 1000;
   int serviceType = r.GetInt32(field["dvb_service_type"]);
   this.ServiceType = serviceType;
   this.OriginalNetworkId = r.GetInt32(field["onid"]);
   this.TransportStreamId = r.GetInt32(field["tsid"]);
   this.ServiceId = r.GetInt32(field["sid"]);
   int bits = r.GetInt32(field["list_bits"]);
   this.Favorites = this.ParseFavorites(bits);
   if ((this.SignalSource & SignalSource.Sat) != 0)
   {
     int satId = r.GetInt32(field["sat_id"]);
     var sat = dataRoot.Satellites.TryGet(satId);
     if (sat != null)
     {
       this.Satellite = sat.Name;
       this.SatPosition = sat.OrbitalPosition;
       int tpId = satId * 1000000 + (int)this.FreqInMhz;
       var tp = dataRoot.Transponder.TryGet(tpId);
       if (tp != null)
       {
         this.SymbolRate = tp.SymbolRate;
       }
     }
   }
   this.Encrypted = encryptionInfo.TryGet(this.Uid);      
 }