Example #1
0
        void PullPlaylists(Item root)
        {
            var playLists = YoutubeProcessor.GetAllPlaylists();
            var topics = root.Subtree().OfType<LectureWrap>().ToList();

            var playListHandler = new Matching.MatchItemHandler<YoutubePlaylist>(
                z => z.PlaylistTitle,
                z => z.PlaylistTitle,
                z => { }
                );

            var topicHandler = new Matching.MatchItemHandler<LectureWrap>(
                z => z.Caption,
                z => z.Caption,
                z => { }
                );

            var updaters = new Matching.MatchUpdater<LectureWrap,YoutubePlaylist>(
                (wrap,list)=>wrap.Store<YoutubePlaylist>(list),
                (list, wrap)=>{},
                wrap=>wrap.Store<YoutubePlaylist>(null),
                list=>{}
                );

            Matching.MatchingAlgorithm.RunWeakAlgorithm(
                topics,
                playLists,
                new Matching.MatchHandlers<LectureWrap, YoutubePlaylist>(topicHandler, playListHandler),
                updaters);
        }
Example #2
0
        void PullClips(Item root)
        {
            var clips = GetYoutubeClips();
            if (clips == null) return;

            var lectures = root.Subtree().OfType<VideoWrap>();

            var clipHandler = new Matching.MatchItemHandler<YoutubeClip>(z => z.GetProperName(), z => z.Name, z => Process.Start(z.VideoURLFull));
            var lectureHandler = new Matching.MatchItemHandler<VideoWrap>(z => z.Caption, z => z.Caption, z => { });
            var updaters = new Matching.MatchUpdater<VideoWrap, YoutubeClip>(
                (wrap, clip) => wrap.Store<YoutubeClip>(clip),
                (clip, wrap) => { clip.UpdateGuid(wrap.Guid); YoutubeProcessor.UpdateVideo(clip); },
                wrap => wrap.Store<YoutubeClip>(null),
                clip => { clip.UpdateGuid(null); YoutubeProcessor.UpdateVideo(clip); }
                );

            var handlers = new Matching.MatchHandlers<VideoWrap, YoutubeClip>(lectureHandler, clipHandler);

            var keys = new Matching.MatchKeySet<VideoWrap, YoutubeClip, Guid?, string>(
                wrap => wrap.Guid,
                wrap => { var c = wrap.Get<YoutubeClip>(); if (c != null) return c.Id; return null; },
                clip => clip.GetGuid(),
                clip => clip.Id,
                guid => !guid.HasValue,
                id => id == null
                );
            var allData = new Matching.MatchHandlersAndKeys<VideoWrap, YoutubeClip, Guid?, string>(handlers, keys, updaters);

            Matching.MatchingAlgorithm.RunStrongAlgorithm(lectures, clips, allData);
        }