Пример #1
0
        public void Save(Item root)
        {
            Model.YoutubeClipData = DataBinding <VideoItem> .GetLayer <YoutubeClip>(root);

            Model.YoutubePlaylistData = DataBinding <LectureItem> .GetLayer <YoutubePlaylist>(root);
        }
Пример #2
0
        public void Load(Item root)
        {
            DataBinding <VideoItem> .PullFromLayer(root, Model.YoutubeClipData);

            DataBinding <LectureItem> .PullFromLayer(root, Model.YoutubePlaylistData);
        }
Пример #3
0
        public void Push(Item root)
        {
            AllExternalDataItems = initialDataItems.ToList();
            MatchedExternalDataItems.Clear();
            UnmatchedExternalDataItems = initialDataItems.ToList();
            AllTreeItems.AddRange(root.Subtree().OfType <TItem>());
            MatchedTreeItems.Clear();
            UnmatchedTreeItems = AllTreeItems.ToList();
            match  = new Dictionary <TItem, TData>();
            matrix = new double[AllTreeItems.Count, AllExternalDataItems.Count];

            for (int i = 0; i < AllTreeItems.Count; i++)
            {
                for (int j = 0; j < AllExternalDataItems.Count; j++)
                {
                    matrix[i, j] = distance(AllTreeItems[i], AllExternalDataItems[j]);
                }
            }

            for (int i = 0; i < AllTreeItems.Count; i++)
            {
                var storedData = AllTreeItems[i].Get <TData>();
                if (storedData != null)
                {
                    var foundData = UnmatchedExternalDataItems.Where(z => Equals(z, storedData)).FirstOrDefault();
                    if (foundData != null)
                    {
                        MakeMatch(i, AllExternalDataItems.IndexOf(foundData));
                    }
                }
            }



            while (true)
            {
                int    bestX = -1;
                int    bestY = -1;
                double best  = 0;
                for (int i = 0; i < AllTreeItems.Count; i++)
                {
                    for (int j = 0; j < AllExternalDataItems.Count; j++)
                    {
                        if (bestX < 0 || matrix[i, j] > best)
                        {
                            bestX = i;
                            bestY = j;
                            best  = matrix[i, j];
                        }
                    }
                }
                if (best > 0)
                {
                    MakeMatch(bestX, bestY);
                }
                else
                {
                    break;
                }
            }

            DataBinding <TItem> .Pull(root, z => match.ContainsKey(z)?match[z] : default(TData));
        }