public void SynchronizeAnimationsSecToPri()
        {
            var pri = AnimationDirectoryPRI as AnimationDirectory;
            var sec = AnimationDirectorySEC as AnimationDirectory;

            if (pri != null && sec != null &&
                pri != sec &&
                pri.IsInitialized &&
                sec.IsInitialized)
            {
                ThreadPool.QueueUserWorkItem(o =>
                {
                    lock (_lockSynchronizeAnimationsSecToPri)
                    {
                        if (!_isSynchronizedAnimationsSecToPri)
                        {
                            try
                            {
                                Debug.WriteLine(this, "SynchronizeAnimationsSecToPri started");
                                Logger.Debug("SynchronizeAnimationsSecToPri started");
                                var priAnimations = pri.GetFiles().ToList();
                                foreach (AnimatedMedia priAnimation in priAnimations)
                                {
                                    if (priAnimation.MediaStatus == TMediaStatus.Available)
                                    {
                                        AnimatedMedia sECAnimation = (AnimatedMedia)((AnimationDirectory)sec).FindMediaByMediaGuid(priAnimation.MediaGuid);
                                        if (sECAnimation == null)
                                        {
                                            sECAnimation = (AnimatedMedia)((MediaDirectory)sec).FindMediaFirst(m => m.Folder == priAnimation.Folder && m.FileName == priAnimation.FileName && !priAnimations.Any(a => a.MediaGuid == m.MediaGuid));
                                            if (sECAnimation != null)
                                            {
                                                sECAnimation.CloneMediaProperties(priAnimation);
                                                sECAnimation.MediaGuid = priAnimation.MediaGuid;
                                                sECAnimation.Save();
                                                Debug.WriteLine(sECAnimation, "Updated");
                                            }
                                            else
                                            {
                                                var secFileName = Path.Combine(sec.Folder, priAnimation.Folder, priAnimation.FileName);
                                                if (File.Exists(secFileName))
                                                {
                                                    sec.CloneMedia(priAnimation, priAnimation.MediaGuid);
                                                }
                                            }
                                        }
                                    }
                                }
                                _isSynchronizedAnimationsSecToPri = true;
                                Logger.Debug("SynchronizeAnimationsSecToPri finished");
                            }
                            catch (Exception e)
                            {
                                Logger.Error(e, "SynchronizeAnimationsSecToPri exception");
                            }
                        }
                    }
                });
            }
        }
        public IAnimatedMedia CloneMedia(IAnimatedMedia source, Guid newMediaGuid)
        {
            var result = new AnimatedMedia(this, newMediaGuid, 0);

            result.Folder   = source.Folder;
            result.FileName = source.FileName;
            result.CloneMediaProperties(source);
            result.MediaStatus = source.MediaStatus;
            result.LastUpdated = DateTime.UtcNow;
            result.Save();
            return(result);
        }
        protected override IMedia AddFile(string fullPath, DateTime lastWriteTime = default(DateTime), Guid guid = default(Guid))
        {
            AnimatedMedia newMedia = _files.Values.FirstOrDefault(m => fullPath.Equals(m.FullPath, StringComparison.CurrentCultureIgnoreCase)) as AnimatedMedia;

            if (newMedia == null && AcceptFile(fullPath))
            {
                newMedia             = (AnimatedMedia)CreateMedia(fullPath, guid);
                newMedia.MediaName   = FileUtils.GetFileNameWithoutExtension(fullPath, TMediaType.Animation).ToUpper();
                newMedia.LastUpdated = lastWriteTime == default(DateTime) ? File.GetLastWriteTimeUtc(fullPath) : lastWriteTime;
                newMedia.MediaStatus = TMediaStatus.Available;
                newMedia.Save();
            }
            return(newMedia);
        }
Beispiel #4
0
 public void SynchronizeAnimationsPropertiesSecToPri()
 {
     if (AnimationDirectoryPRI is AnimationDirectory pri &&
         AnimationDirectorySEC is AnimationDirectory sec &&
         pri != sec &&
         pri.IsInitialized &&
         sec.IsInitialized)
     {
         try
         {
             Debug.WriteLine(this, "SynchronizeAnimationsSecToPri started");
             Logger.Debug("SynchronizeAnimationsSecToPri started");
             var priAnimations = pri.GetAllFiles();
             foreach (var priAnimation in priAnimations)
             {
                 if (priAnimation.MediaStatus != TMediaStatus.Available)
                 {
                     continue;
                 }
                 AnimatedMedia sEcAnimation = null;
                 if (sec.FindMediaByMediaGuid(priAnimation.MediaGuid) is AnimatedMedia animatedMedia)
                 {
                     if (animatedMedia.FileExists())
                     {
                         continue;
                     }
                     else
                     {
                         sEcAnimation = animatedMedia;
                     }
                 }
                 if (sEcAnimation == null)
                 {
                     sEcAnimation = (AnimatedMedia)sec.FindMediaFirst(m =>
                                                                      m.Folder == priAnimation.Folder && m.FileName == priAnimation.FileName &&
                                                                      priAnimations.All(a => a.MediaGuid != m.MediaGuid));
                 }
                 if (sEcAnimation != null)
                 {
                     sEcAnimation.CloneMediaProperties(priAnimation);
                     sec.UpdateMediaGuid(sEcAnimation, priAnimation.MediaGuid);
                     sEcAnimation.Save();
                     Logger.Trace("Animation {0} updated", sec);
                 }
                 else
                 {
                     var secFileName = Path.Combine(sec.Folder, priAnimation.Folder, priAnimation.FileName);
                     if (File.Exists(secFileName))
                     {
                         sec.CloneMedia((IAnimatedMedia)priAnimation, priAnimation.MediaGuid);
                     }
                 }
             }
             Logger.Debug("SynchronizeAnimationsSecToPri finished");
         }
         catch (Exception e)
         {
             Logger.Error(e, "SynchronizeAnimationsSecToPri exception");
         }
     }
 }