예제 #1
0
        protected override AbstractSource DoCreateNewSource(string name, string url, Dictionary <string, string> metaData)
        {
            if (metaData.ContainsKey(Site))
            {
                if (metaData[Site].Equals(JapanType, StringComparison.OrdinalIgnoreCase))
                {
                    metaData[Site] = JapanType;
                }
                else if (metaData[Site].Equals(ChinaType, StringComparison.OrdinalIgnoreCase))
                {
                    metaData[Site] = ChinaType;
                }
                else
                {
                    ThrowBadSiteException();
                }
            }
            else
            {
                ThrowBadSiteException();
            }

            var source = new GenericSource(metaData[Site], PROVIDER);

            source.SetMetaData(metaData);

            return(source);
        }
예제 #2
0
        public void Shoud_Be_Able_To_Call_Filter_Methods_If_Resolver_Is_Set()
        {
            _testInstance.With(domain => domain.Comparison("TestName"));

            var queryable = new GenericSource[0].AsQueryable();

            Action domainAction = () => _testInstance.Domain();

            domainAction.ShouldNotThrow <MissingResolverException>();

            Action applyFilterAction = () => _testInstance.ApplyFilter(queryable);

            applyFilterAction.ShouldNotThrow <MissingResolverException>();

            Action setAvailableEntitiesAction = () => _testInstance.SetAvailableEntities(queryable).Wait();

            setAvailableEntitiesAction.ShouldNotThrow <MissingResolverException>();

            Action setSelectableEntitiesAction = () => _testInstance.SetSelectableEntities(queryable).Wait();

            setSelectableEntitiesAction.ShouldNotThrow <MissingResolverException>();

            Action needsToBeResolvedAction = () => _testInstance.NeedsToBeResolved = true;

            needsToBeResolvedAction.ShouldNotThrow <MissingResolverException>();
        }
예제 #3
0
        private AbstractSource ParseToSource(string data)
        {
            string[] fields = data.Split(FieldDelim);

            int idx = 0;

            int    id         = Int32.Parse(fields[idx++]);
            string providerId = fields[idx++];
            string catName    = fields[idx++];
            string url        = fields[idx++];
            string meta       = fields[idx++];


            Dictionary <string, string> metaDict = new Dictionary <string, string>();

            foreach (string kv in meta.Split(new char[] { MetaDelim }, StringSplitOptions.RemoveEmptyEntries))
            {
                int    split = kv.IndexOf('=');
                string key   = kv.Substring(0, split);
                string val   = kv.Substring(split + 1);

                metaDict.Add(key, val);
            }


            AbstractSource s = new GenericSource(catName, providerId);

            s.SetID(id);
            s.SetMetaData(metaDict);

            //Don't need, url

            return(s);
        }
예제 #4
0
        public async Task OnGetAsync()
        {
            string original = "0810";
            string modified = original.Insert(2, ":");


            var baseAddress = new Uri("https://api.jikan.moe/v3/");

            using (var httpClient = new HttpClient {
                BaseAddress = baseAddress
            })
            {
                using (var response = await httpClient.GetAsync("season/2020/winter"))
                {
                    string responseData = await response.Content.ReadAsStringAsync();

                    var animes = JsonSerializer.Deserialize <Result>(responseData, null);
                    try
                    {
                        var animesDto = _mapper.Map <List <AnimeDto> >(animes.Animes);
                    }
                    catch (Exception e)
                    {
                        throw;
                    }
                }

                // inheritance mapping

                List <Source> sources = new List <Source>()
                {
                    new Source()
                    {
                        Id = 1,
                    },
                    new SourceChild()
                    {
                        Id   = 2,
                        Name = "SourceChild",
                    }
                };

                List <Destination> destinations = _mapper.Map <List <Destination> >(sources);

                // generic mapping

                GenericSource <List <Source> > genericSource = new GenericSource <List <Source> >()
                {
                    Value = sources
                };

                GenericDestination <List <Destination> > genericDestination = _mapper.Map <GenericDestination <List <Destination> > >(genericSource);

                // enum mapping

                SourceEnum sourceEnum = SourceEnum.First;

                DestinationEnum destinationEnum = _mapper.Map <DestinationEnum>(sourceEnum);
            }
        }
예제 #5
0
        //Already converted
        private SourceAdapter(GenericSource src) : base(src)
        {
            //this.provider = provider;
            this.SetMetaData(src.GetMetaData());

            this.SetProviderID(src.ProviderID);
            this.SetSourceName(src.SourceName);
        }
예제 #6
0
 public GenericArgumentInfo(
     Type type,
     string name,
     int index,
     Variance variance,
     GenericSource genericSource,
     GenericArgumentRestriction[] restrictions)
 {
     Type          = type;
     Name          = name;
     Index         = index;
     Variance      = variance;
     GenericSource = genericSource;
     Restrictions  = restrictions;
 }
예제 #7
0
        /// <summary>
        /// Creates the source using the the GenericSource
        /// </summary>
        /// <param name="src">The Generic Source to get the parameters from</param>
        protected AbstractSource(GenericSource src)
        {
            //Support for AbstractSource2
            if (src == null)
            {
                return;
            }

            if (src.ID.HasValue)
            {
                this.SetID(src.ID.Value);
            }

            this.SetProviderID(src.ProviderID);
            this.SetSourceName(src.SourceName);
            this.SetMetaData(src.GetMetaData());
        }
예제 #8
0
        public override AbstractSource CastSource(GenericSource src)
        {
            var newFormat = base.CastSource(src);

            //Add the new format that are missing
            var providerMD = this.GetMetaFields();
            Dictionary <string, MetaDataObject> sourceMD = newFormat.GetMetaData();

            foreach (var md in providerMD)
            {
                if (!newFormat.GetMetaData().ContainsKey(md.ID))
                {
                    sourceMD.Add(md.ID, md);
                }
            }


            return(newFormat);
        }
예제 #9
0
        protected override List <GenericSource> LoadSources()
        {
            string command = "select ID, ProviderID, Name, MetaData from " + SourcesTable;

            var results = sqlWrapper.ExecuteSelect(command);

            List <GenericSource> sources = new List <GenericSource>();

            foreach (DataRow row in results.Rows)
            {
                GenericSource source = new GenericSource(row["Name"].ToString(), row["ProviderID"].ToString(), false); //TODO: new function
                source.SetID(Int32.Parse(row["ID"].ToString()));
                source.SetMetaData(DeserializeMeta(row["MetaData"].ToString()));

                sourceLookup.Add(source.ID.Value, source);

                sources.Add(source);
            }

            return(sources);
        }
        public IActionResult Post21()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap(typeof(GenericSource <>), typeof(GenericDestination <>));
            });
            var mapper = config.CreateMapper();

            var s1 = new GenericSource <int> {
                Value = 1
            };
            var res1 = mapper.Map <GenericDestination <int> >(s1);

            var s2 = new GenericSource <Source> {
                Value = new Source {
                    Value = 2
                }
            };
            var res2 = mapper.Map <GenericDestination <Source> >(s2);

            return(Ok());
        }
예제 #11
0
        public static SourceAdapter CreateSourceAdapter(V1.AbstractSource src, V1.AbstractProvider provider)
        {
            string strDisabled = src.GetMetaDataValue(AbstractSource.DISABLED);
            bool   disabled    = strDisabled == null ? false : Convert.ToBoolean(strDisabled);

            GenericSource gs = new GenericSource(src.SourceName, src.ProviderID, disabled);

            //Update Meta
            Dictionary <string, MetaDataObject> newMeta = new Dictionary <string, MetaDataObject>();

            List <string> providerMeta = provider.GetMetaFields();

            {
                foreach (string name in providerMeta)
                {
                    var mdo = new MetaDataObject(name, name);
                    if (src.GetMetaData().ContainsKey(name))
                    {
                        mdo.SetValue(src.GetMetaDataValue(name));
                    }

                    newMeta.Add(mdo.ID, mdo);
                }
            }

            gs.SetMetaData(newMeta);

            if (src.ID.HasValue)
            {
                gs.SetID(src.ID.Value);
            }

            var sa = new SourceAdapter(gs);


            return(sa);
        }
예제 #12
0
        public void Should_Throw_Exception_If_No_Resolver_Was_Specified()
        {
            var queryable = new GenericSource[0].AsQueryable();

            Action domainAction = () => _testInstance.Domain();

            domainAction.ShouldThrow <MissingResolverException>();

            Action applyFilterAction = () => _testInstance.ApplyFilter(queryable);

            applyFilterAction.ShouldThrow <MissingResolverException>();

            Action setAvailableEntitiesAction = () => _testInstance.SetAvailableEntities(queryable).Wait();

            setAvailableEntitiesAction.ShouldThrow <MissingResolverException>();

            Action setSelectableEntitiesAction = () => _testInstance.SetSelectableEntities(queryable).Wait();

            setSelectableEntitiesAction.ShouldThrow <MissingResolverException>();

            Action needsToBeResolvedAction = () => _testInstance.NeedsToBeResolved = true;

            needsToBeResolvedAction.ShouldThrow <MissingResolverException>();
        }
예제 #13
0
        public override AbstractSource CastSource(GenericSource src)
        {
            AbstractSource s = new GoodAnimeSource(src);

            return(s);
        }
예제 #14
0
 public static GenericArgumentInfo Create(Type type, string name, Variance variance, GenericSource genericSource)
 {
     return(new GenericArgumentInfo(type, name, 0, variance, genericSource, GenericArgumentRestriction.EmptyArray));
 }
예제 #15
0
 public override AbstractSource CastSource(GenericSource src)
 {
     return(SmackSource.CreateFrom(src));
 }
예제 #16
0
 public GoodAnimeSource(GenericSource src) : base(src)
 {
 }
예제 #17
0
        protected ARoom(ASystem system, RoomConfig config)
            : base(system)
        {
            try
            {
                _config = config;
                Debug.WriteInfo("Loading Room Config", "Room {0} \"{1}\"", config.Id, config.Name);

                Name = string.IsNullOrEmpty(config.Name) ? string.Format("Room {0}", Id) : config.Name;

                DivisibleRoomType = config.DivisibleRoomType;

                SystemSwitcher = system.Switcher;

                if (system.Dsp != null)
                {
                    system.Dsp.HasIntitialized += DspOnHasIntitialized;
                }

                if (SystemSwitcher != null)
                {
                    SystemSwitcher.InputStatusChanged += SwitcherOnInputStatusChanged;
                }

                try
                {
                    if (config.Displays == null)
                    {
                        config.Displays = new List <DisplayConfig>();
                    }
                    foreach (var displayConfig in config.Displays
                             .Where(d => d.Enabled)
                             .OrderBy(d => d.Id))
                    {
                        Debug.WriteInfo("Loading Display Config", "{0} {1}", displayConfig.DisplayType,
                                        displayConfig.DeviceAddressString);

                        switch (displayConfig.DisplayType)
                        {
                        case DisplayType.Samsung:
                            if (SystemSwitcher != null && displayConfig.DeviceConnectionType == DeviceConnectionType.Serial)
                            {
                                var comports =
                                    SystemSwitcher.GetEndpointForOutput(displayConfig.SwitcherOutputIndex) as
                                    IComPorts;
                                new ADisplay(this,
                                             new SamsungDisplay(displayConfig.Name, 1,
                                                                new SamsungDisplayComPortHandler(comports.ComPorts[1])), displayConfig);
                            }
                            else
                            {
                                new ADisplay(this,
                                             new SamsungDisplay(displayConfig.Name, 1,
                                                                new SamsungDisplaySocket(displayConfig.DeviceAddressString)), displayConfig);
                            }
                            break;

                        case DisplayType.CrestronConnected:
                            var proj = new ADisplay(this,
                                                    new CrestronConnectedDisplay(displayConfig.DeviceAddressNumber, system.ControlSystem,
                                                                                 displayConfig.Name), displayConfig);
                            if (displayConfig.UsesRelaysForScreenControl && SystemSwitcher != null)
                            {
                                var relayEndpoint =
                                    SystemSwitcher.GetEndpointForOutput(displayConfig.SwitcherOutputIndex) as
                                    IRelayPorts;
                                if (relayEndpoint == null)
                                {
                                    CloudLog.Error("Could not get relays for projector");
                                    break;
                                }
                                var relays = new UpDownRelays(relayEndpoint.RelayPorts[2],
                                                              relayEndpoint.RelayPorts[1], UpDownRelayModeType.Momentary);
                                relays.Register();
                                proj.SetScreenController(relays);
                            }
                            break;

                        default:
                            new ADisplay(this, null, displayConfig);
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    CloudLog.Error("Error setting up displays in Room {0}, {1}", Id, e.Message);
                }

                if (config.Sources != null)
                {
                    foreach (var sourceConfig in config.Sources
                             .Where(s => s.Enabled)
                             .OrderBy(s => s.Id))
                    {
                        try
                        {
                            ASource source;
                            switch (sourceConfig.SourceType)
                            {
                            case SourceType.PC:
                                source = new PCSource(this, sourceConfig);
                                break;

                            case SourceType.IPTV:
                                source = new TVSource(this, sourceConfig);
                                break;

                            default:
                                source = new GenericSource(this, sourceConfig);
                                break;
                            }

                            if (!String.IsNullOrEmpty(sourceConfig.GroupName))
                            {
                                source.AddToGroup(sourceConfig.GroupName);
                            }
                        }
                        catch (Exception e)
                        {
                            CloudLog.Error("Error setting up source \"{0}\" in Room {1}, {2}", sourceConfig.Name, Id,
                                           e.Message);
                        }
                    }
                }

                foreach (var source in Sources.Cast <ASource>())
                {
                    if (source.Type == SourceType.Laptop)
                    {
                        source.VideoStatusChangeDetected += LaptopSourceOnVideoDetected;
                    }
                }
            }
            catch (Exception e)
            {
                CloudLog.Exception(e);
            }
        }
예제 #18
0
 public static GenericArgumentInfo Create(Type type, string name, int index, Variance variance, GenericSource genericSource, GenericArgumentRestriction[] restrictions)
 {
     return(new GenericArgumentInfo(type, name, index, variance, genericSource, restrictions));
 }
예제 #19
0
 public virtual AbstractSource CastSource(GenericSource src)
 {
     return(src);
 }