Exemplo n.º 1
0
        public virtual CollectionDiffWithValue <PVForAlbum, PVForAlbum> SyncPVs(IEnumerable <PVContract> newPVs)
        {
            ParamIs.NotNull(() => newPVs);

            var diff    = CollectionHelper.Diff(PVs, newPVs, (n1, n2) => n1.Id == n2.Id);
            var created = new List <PVForAlbum>();
            var edited  = new List <PVForAlbum>();

            foreach (var n in diff.Removed)
            {
                PVs.Remove(n);
            }

            foreach (var newEntry in diff.Added)
            {
                var l = CreatePV(newEntry);
                created.Add(l);
            }

            foreach (var linkEntry in diff.Unchanged)
            {
                var entry    = linkEntry;
                var newEntry = newPVs.First(e => e.Id == entry.Id);

                if (!entry.ContentEquals(newEntry))
                {
                    linkEntry.CopyMetaFrom(newEntry);
                    edited.Add(linkEntry);
                }
            }

            return(new CollectionDiffWithValue <PVForAlbum, PVForAlbum>(created, diff.Removed, diff.Unchanged, edited));
        }
Exemplo n.º 2
0
        public virtual PVForAlbum CreatePV(PVContract contract)
        {
            ParamIs.NotNull(() => contract);

            var pv = new PVForAlbum(this, contract);

            PVs.Add(pv);

            return(pv);
        }
Exemplo n.º 3
0
        public virtual PVForSong CreatePV(PVContract contract)
        {
            ParamIs.NotNull(() => contract);

            var pv = new PVForSong(this, contract);

            PVs.Add(pv);

            UpdateNicoId();
            UpdatePVServices();

            return(pv);
        }
Exemplo n.º 4
0
        public virtual void UpdatePVServices()
        {
            var services = PVServices.Nothing;

            foreach (var service in EnumVal <PVService> .Values)
            {
                if (PVs.Any(p => p.Service == service))
                {
                    services |= (PVServices)service;
                }
            }

            PVServices = services;
        }
Exemplo n.º 5
0
        public virtual PVForSong CreatePV(PVContract contract)
        {
            ParamIs.NotNull(() => contract);

            var pv = new PVForSong(this, contract);

            PVs.Add(pv);

            UpdateNicoId();
            UpdatePVServices();

            if (LengthSeconds <= 0)
            {
                LengthSeconds = GetLengthFromPV();
            }

            return(pv);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds new PVs and removes deleted PVs.
        /// </summary>
        /// <param name="newPVs">Updated list of PVs. Cannot be null.</param>
        /// <returns>PVs list diff. Cannot be null.</returns>
        public virtual CollectionDiffWithValue <PVForSong, PVForSong> SyncPVs(IList <PVContract> newPVs)
        {
            var result = PVs.Sync(newPVs, CreatePV);

            if (result.Changed || string.IsNullOrEmpty(ThumbUrl))
            {
                UpdateThumbUrl();
            }

            if (result.Changed && !PublishDate.DateTime.HasValue)
            {
                UpdatePublishDateFromPVs();
            }

            new LocalFileManager().SyncLocalFilePVs(result, Id);

            return(result);
        }
Exemplo n.º 7
0
        public virtual void UpdatePublishDateFromPVs()
        {
            if (!PVs.Any())
            {
                return;
            }

            // Sanity check
            var minDateLimit = new DateTime(2000, 1, 1);

            // Original PVs that have a publish date
            var pvsWithDate = PVs.Where(p => p.PVType == PVType.Original && p.PublishDate.HasValue && p.PublishDate > minDateLimit).ToArray();

            // Lowest published (original) PV
            var minPvDate = pvsWithDate.Any() ? pvsWithDate.Min(p => p.PublishDate) : null;

            var minAlbumDate = FirstAlbumDate;

            var minDate = minAlbumDate.HasValue && minAlbumDate > minDateLimit && minAlbumDate < minPvDate ? minAlbumDate : minPvDate;

            PublishDate = minDate;
        }
Exemplo n.º 8
0
        public virtual void UpdateNicoId()
        {
            var originalPv = PVs.FirstOrDefault(p => p.Service == PVService.NicoNicoDouga && p.PVType == PVType.Original);

            NicoId = (originalPv != null ? originalPv.PVId : null);
        }
Exemplo n.º 9
0
 public virtual CollectionDiffWithValue <PVForSong, PVForSong> SyncPVs(IList <PVContract> newPVs)
 {
     return(PVs.Sync(newPVs, CreatePV));
 }
Exemplo n.º 10
0
        public virtual bool HasPV(PVService service, string pvId)
        {
            ParamIs.NotNullOrEmpty(() => pvId);

            return(PVs.Any(p => p.Service == service && p.PVId == pvId));
        }
Exemplo n.º 11
0
        public virtual int GetLengthFromPV()
        {
            var pv = PVs.FirstOrDefault(p => p.Length > 0);

            return(pv != null ? pv.Length : 0);
        }
Exemplo n.º 12
0
 public void SortPoolsViews()
 {
     PVs = PVs.OrderBy(pv => pv.Index).ToList();
 }
Exemplo n.º 13
0
        private void InitializePoolsCommands()
        {
            AddPool = new RelayCommand(obj =>
            {
                Selection.Add(false);
                PoolsSets.Add(new PoolSet {
                    Name = "New pool"
                });
                _model.cmd_SavePools(PoolsSets.ToList());
            });
            DeletePools = new RelayCommand(obj =>
            {
                for (int i = Selection.Count - 1; i > -1; i--)
                {
                    if (Selection[i])
                    {
                        Selection.RemoveAt(i);
                        PoolsSets[i].Wach = false;
                        PoolsSets.RemoveAt(i);

                        var x = PVMs.Where(pvm => pvm.Index == i).ToList();
                        if (x.Count > 0)
                        {
                            PVs  = PVs.Where(pv => pv.Index != i).ToList();
                            PVMs = PVMs.Where(pvm => pvm.Index != i).ToList();
                        }
                    }
                }
                _model.cmd_SavePools(PoolsSets.ToList());
            });
            UpPools = new RelayCommand(obj =>
            {
                for (int i = 1; i < Selection.Count; i++)
                {
                    if (Selection[i] && !Selection[i - 1])
                    {
                        Selection[i - 1] = true;
                        Selection[i]     = false;

                        PVMs.Where(p => p.Index == i).First().Index     = i - 1;
                        PVMs.Where(p => p.Index == i - 1).First().Index = i;

                        var ps = PoolsSets[i];
                        PoolsSets.Insert(i - 1, ps);
                        PoolsSets.RemoveAt(i);

                        SortPoolsViews();
                    }
                }
            });
            DownPools = new RelayCommand(obj =>
            {
                for (int i = Selection.Count - 2; i > -1; i--)
                {
                    if (Selection[i] && !Selection[i + 1])
                    {
                        Selection[i + 1] = true;
                        Selection[i]     = false;

                        PVMs.Where(p => p.Index == i).First().Index     = i + 1;
                        PVMs.Where(p => p.Index == i + 1).First().Index = i;

                        var ps = PoolsSets[i];
                        PoolsSets.RemoveAt(i);
                        PoolsSets.Insert(i + 1, ps);

                        SortPoolsViews();
                    }
                }
            });
        }