Beispiel #1
0
        void PullPlaylists(Item root)
        {
            var playLists = YoutubeApisProcessor.Current.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);
        }
Beispiel #2
0
 public void Push(MatchUpdater <TInternal, TExternal> updater)
 {
     foreach (var e in UnmatchedInternals)
     {
         if (e.Status != MatchStatus.Pending)
         {
             updater.ClearInternal(e.OriginalItem);
         }
     }
     foreach (var e in UnmatchedExternals)
     {
         if (e.Status != MatchStatus.Pending)
         {
             updater.ClearExternal(e.OriginalItem);
         }
     }
     foreach (var pair in Matched)
     {
         if (pair.Internal.Status != MatchStatus.OldMatch)
         {
             updater.InternalTakesExternal(pair.Internal.OriginalItem, pair.External.OriginalItem);
         }
         if (pair.External.Status != MatchStatus.OldMatch)
         {
             updater.ExternalTakesInternal(pair.External.OriginalItem, pair.Internal.OriginalItem);
         }
     }
 }
Beispiel #3
0
 public MatchHandlersAndKeys(
     MatchHandlers <TInternal, TExternal> handlers,
     MatchKeySet <TInternal, TExternal, TInternalKey, TExternalKey> keySet,
     MatchUpdater <TInternal, TExternal> updaters)
 {
     Handlers = handlers;
     KeySet   = keySet;
     Updaters = updaters;
 }
Beispiel #4
0
        public static void RunWeakAlgorithm <TInternal, TExternal>(
            IEnumerable <TInternal> internals,
            IEnumerable <TExternal> externals,
            MatchHandlers <TInternal, TExternal> handlers,
            MatchUpdater <TInternal, TExternal> updates)
        {
            var pendingData     = new MatchingPendingData <TInternal, TExternal>(internals, externals);
            var nameMatch       = new NameMatch <TInternal, TExternal>(pendingData, handlers);
            var nameMatchResult = nameMatch.Run();
            var model           = new ManualMatchViewModel <TInternal, TExternal>(handlers);

            model.Pull(nameMatchResult);
            model.Pull(nameMatchResult.GetPendingData());
            model.Push(updates);
        }
Beispiel #5
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); YoutubeApisProcessor.Current.UpdateVideo(clip); },
                wrap => wrap.Store <YoutubeClip>(null),
                clip => { clip.UpdateGuid(null); YoutubeApisProcessor.Current.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);
        }