void PopulateMediaMediaProps(ActionStatusVModel avm, IList <MediaFile> source, MediaFile toSetCurrent)
        {
            string        tfn = null;
            MediaFile     mf;
            StringBuilder err = new StringBuilder();

            for (int i = 0; i < source.Count; i++)
            {
                mf  = source[i];
                tfn = "n/a";
                try {
                    mf.GetMetadata();
                    avm.SetSuccess(i + 1, mf.Title);
                }
                catch (Exception x) {
                    string em = x.ToShortMsg(mf.FullName);
                    avm.SetError(i + 1, em);
                    this.Parent.Status.SetError(em);
                    //this.Log.LogTechError(em, x);
                    err.AppendLine(em);
                }
                //System.Threading.Thread.Sleep(500);
            }
            if (avm.ErrorCount > 0)
            {
                this.Parent.Status.SetError(string.Format("Completed with {1} error(s): {0}\r\n{2}. Click Save to finalize.", avm.Title, avm.ErrorCount, err));
            }
            else
            {
                this.Parent.Status.SetPositive(string.Format("Completed: {0}.\r\nClick Save to finalize.", avm.Title));
            }
            this.RunOnUIThread(() => this.Parent.CurrentMedia = toSetCurrent);
        }
        ///<summary>Execute Slide show Command</summary>
        void DoSlideShowCmd(object prm = null)
        {
            List <MediaFile> src = new List <MediaFile>(from mf in this.GetSelectedMedia()
                                                        where mf.MediaType == MediaTypes.Image
                                                        orderby mf.OrderWeight, mf.Title
                                                        select mf); // Get the work set

            if (src.Count > 0)
            {
                CancellationTokenSource cncToken = new CancellationTokenSource();
                ActionStatusVModel      avm      = new ActionStatusVModel(string.Format("Slide Show for {0} files", src.Count))
                {
                    MaxIndex      = src.Count,
                    MinIndex      = 1,
                    CurrentIndex  = 0,
                    ExitHitAction = (a) => cncToken.Cancel()
                };
                var ssw = new SlideShowWorker()
                {
                    Items = src, ItemDurationMs = 5000, SleepStepMS = 200, StopSignal = cncToken.Token
                };
                ssw.Show = (mf) => {
                    this.Parent.RunOnUIThread(() => this.Parent.CurrentMedia = mf);
                    avm.SetSuccess(0, mf.Title);
                };
                this.CurrentActions.Insert(0, avm);
                Task.Factory.StartNew(ssw.DoShow).ContinueWith((t) => {
                    this.RunOnUIThread(() => {
                        this.Parent.Status.SetPositive("Slide Show canceled");
                        this.CurrentActions.Remove(avm);
                    });
                });
            }
        }
        void MoveMediaToFolder(ActionStatusVModel avm, IList <MediaFile> source, string targetFolder)
        {
            string              tfn = null, tnm;
            MediaFile           mf;
            StringBuilder       err     = new StringBuilder();
            int                 cx      = 0;
            Func <string, bool> onError = (em) => {
                avm.SetError(cx + 1, em);
                this.Parent.Status.SetError(em);
                err.AppendLine(em);
                return(true);
            };

            for (int i = 0; i < source.Count; i++)
            {
                mf  = source[i];
                tfn = "n/a";
                cx  = i;
                try {
                    tnm = mf.GetFullPath();
                    tfn = Path.Combine(this._lastSelectedFolder, Path.GetFileName(tnm));
                    File.Move(tnm, tfn);
                    mf.FullName = tfn; // If other files fail project still shoud be OK
                    MoveAllExtensions(tnm, tfn, onError);
                    avm.SetSuccess(i + 1, mf.Title);
                }
                catch (Exception x) {
                    string em = string.Format("Failed to move file \"{0}\" to \"{1}\". {2}: {3}", mf.FullName, tfn, x.GetType().Name, x.Message);
                    onError(em);
                    //avm.SetError(i + 1, em);
                    //this.Parent.Status.SetError(em);
                    //err.AppendLine(em);
                }
                //System.Threading.Thread.Sleep(500);
            }
            if (avm.ErrorCount > 0)
            {
                this.Parent.Status.SetError(string.Format("Completed with {1} error(s): {0}\r\n{2}", avm.Title, avm.ErrorCount, err));
            }
            else
            {
                this.Parent.Status.SetPositive(string.Format("Completed: {0}", avm.Title));
            }
        }
 void DoCopyMediaToFolder(object prm)
 {
     if (this.UIHelper.SelectFolder("Select target folder to copy media files", ref this._lastSelectedFolder))
     {
         List <MediaFile> src = new List <MediaFile>(this.GetSelectedMedia()); // Get the work set
         if (!this.UIHelper.GetUserConfirmation(string.Format("You are going to copy {0} files to {1}\r\n\r\n\t\tContinue?", src.Count, this._lastSelectedFolder)))
         {
             return;
         }
         ClearCompleted();
         ActionStatusVModel avm = new ActionStatusVModel(string.Format("Copy {0} files to {1}", src.Count, this._lastSelectedFolder))
         {
             MaxIndex     = src.Count,
             MinIndex     = 1,
             CurrentIndex = 0
         };
         this.CurrentActions.Insert(0, avm);
         Task.Factory.StartNew(() => this.CopyMediaToFolder(avm, src, this._lastSelectedFolder));
     }
 }
            public void Execute(object prm = null)
            {
                List <MediaFile> src = new List <MediaFile>(Parent.GetSelectedMedia()); // Get the work set

                if (!Parent.UIHelper.GetUserConfirmation(string.Format("You are going to execute external command {1} for {0} files\r\nCommand description:\r\n{2}\r\n\r\n\t\tContinue?",
                                                                       src.Count, this.XCmd.Title, this.XCmd.Description)))
                {
                    return;
                }
                Parent.ClearCompleted();
                ActionStatusVModel avm = new ActionStatusVModel(string.Format("{1} for {0} files", src.Count, this.XCmd.Title))
                {
                    MaxIndex     = src.Count,
                    MinIndex     = 1,
                    CurrentIndex = 0
                };

                Parent.CurrentActions.Insert(0, avm);
                Task.Factory.StartNew(() => this.Execute(avm, src));
            }
        ///<summary>Execute Populate media properties Command</summary>
        void DoPopulateMediaPropsCmd(object prm = null)
        {
            List <MediaFile> src = new List <MediaFile>(this.GetSelectedMedia()); // Get the work set

            if (!this.UIHelper.GetUserConfirmation(
                    string.Format("You are going to load each of {0} files in order to populate media properties.\r\nIt can take some time.\r\n\r\n\t\tContinue?", src.Count)))
            {
                return;
            }
            ClearCompleted();
            ActionStatusVModel avm = new ActionStatusVModel(string.Format("Populating media properties for {0} files", src.Count))
            {
                MaxIndex     = src.Count,
                MinIndex     = 1,
                CurrentIndex = 0
            };

            this.CurrentActions.Insert(0, avm);
            var curr = this.Parent.CurrentMedia;

            this.Parent.CurrentMedia = null;
            Task.Factory.StartNew(() => this.PopulateMediaMediaProps(avm, src, curr));
        }
 void DoMoveMediaToFolder(object prm)
 {
     if (this.UIHelper.SelectFolder("Select target folder to move media files", ref this._lastSelectedFolder))
     {
         List <MediaFile> src = new List <MediaFile>(this.GetSelectedMedia()); // Get the work set
         if (!this.UIHelper.GetUserConfirmation(string.Format("You are going to move {0} files to {1}\r\n\r\nProject will be updated to point to the new location and saved.\r\n\r\n\t\tContinue?", src.Count, this._lastSelectedFolder)))
         {
             return;
         }
         ClearCompleted();
         ActionStatusVModel avm = new ActionStatusVModel(string.Format("Move {0} files to {1}", src.Count, this._lastSelectedFolder))
         {
             MaxIndex     = src.Count,
             MinIndex     = 1,
             CurrentIndex = 0
         };
         this.CurrentActions.Insert(0, avm);
         var curr = this.Parent.CurrentMedia;
         this.Parent.CurrentMedia = null;
         this.MoveMediaToFolder(avm, src, this._lastSelectedFolder);
         this.Parent.CurrentMedia = curr;
         this.Parent.SaveCmd.ExecuteIfCan();
     }
 }
            void Execute(ActionStatusVModel avm, IList <MediaFile> source)
            {
                string        tfn = null;
                MediaFile     mf;
                StringBuilder err = new StringBuilder();

                for (int i = 0; i < source.Count; i++)
                {
                    mf = source[i];
                    if (!XCmd.CanExecute(mf))
                    {
                        continue;
                    }
                    tfn = "n/a";
                    try {
                        XCmd.Execute(mf, this.GetPrmVal);
                        avm.SetSuccess(i + 1, mf.Title);
                    }
                    catch (Exception x) {
                        string em = string.Format("Failed to process file \"{0}\" to \"{1}\". {2}: {3}", mf.FullName, tfn, x.GetType().Name, x.Message);
                        avm.SetError(i + 1, em);
                        this.Parent.Status.SetError(em);
                        //this.Log.LogTechError(em, x);
                        err.AppendLine(em);
                    }
                    //System.Threading.Thread.Sleep(500);
                }
                if (avm.ErrorCount > 0)
                {
                    this.Parent.Status.SetError(string.Format("Completed with {1} error(s): {0}\r\n{2}", avm.Title, avm.ErrorCount, err));
                }
                else
                {
                    this.Parent.Status.SetPositive(string.Format("Completed: {0}", avm.Title));
                }
            }
        void DoRenameMedia(object prm)
        {
            MediaRenameVModel vm = new MediaRenameVModel();

            vm.AddMediaFiles(this.GetSelectedMedia());
            vm.Processor.AddDefinition(new TTSubName());
            vm.Processor.AddDefinition(new TTCounter());
            vm.Processor.AddDefinition(new TTConst());
            vm.Processor.AddDefinition(new TTMarker());
            foreach (var rd in this.Project.RatingDefinitions)
            {
                vm.Processor.AddDefinition(new TTRating(rd));
            }
            foreach (var cd in this.Project.CategoryDefinitions)
            {
                vm.Processor.AddDefinition(new TTCategory(cd));
            }
            vm.SetConfiguration(_lastRenameConfig);
            Views.MeidaRenameView vw = new Views.MeidaRenameView();
            vw.Owner    = this.UIHelper.GetMainWindow();
            vw.FontSize = vw.Owner.FontSize;
            vw.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            vw.SetViewModel(vm);
            vw.ShowDialog();
            if (vm.IsConfirmed)
            {
                this._lastRenameConfig = vm.GetConfiguration();
                // Do actual rename
                if (!this.UIHelper.GetUserConfirmation(string.Format("You are going to rename {0} files using pattern\r\n\r\n\t{1}\r\n\r\nProject will be updated to point to the new files and saved.\r\n\r\n\t\tContinue?",
                                                                     vm.Items.Count, vm.Formula)))
                {
                    return;
                }
                ClearCompleted();
                ActionStatusVModel avm = new ActionStatusVModel(string.Format("Reanme {0} files according to pattern {1}", vm.Items.Count, vm.Formula))
                {
                    MaxIndex     = vm.Items.Count,
                    MinIndex     = 1,
                    CurrentIndex = 0
                };
                string        tfn = null, tnm = "n/a";
                MediaFile     mf;
                StringBuilder err = new StringBuilder();

                this.CurrentActions.Insert(0, avm);
                var curr = this.Parent.CurrentMedia;
                this.Parent.CurrentMedia = null;

                int cx = 0;
                Func <string, bool> onError = (em) => {
                    avm.SetError(cx + 1, em);
                    this.Parent.Status.SetError(em);
                    err.AppendLine(em);
                    return(true);
                };


                for (int i = 0; i < vm.Items.Count; i++)
                {
                    cx = i;
                    mf = vm.Items[i].Key;
                    try {
                        tnm = mf.GetFullPath();
                        tfn = Path.Combine(Path.GetDirectoryName(tnm), vm.Items[i].Value);
                        tfn = tfn + Path.GetExtension(tnm);
                        File.Move(tnm, tfn);
                        mf.FullName = tfn; // If other files fail project still shoud be OK
                        mf.Title    = vm.Items[i].Value;
                        MoveAllExtensions(tnm, tfn, onError);
                        avm.SetSuccess(i + 1, mf.Title);
                    }
                    catch (Exception x) {
                        string em = string.Format("Failed to rename file \"{0}\" to \"{1}\". {2}: {3}", tnm, vm.Items[i].Value, x.GetType().Name, x.Message);
                        onError(em);
                        //avm.SetError(i + 1, em);
                        //this.Parent.Status.SetError(em);
                        ////this.Log.LogTechError(em, x);
                        //err.AppendLine(em);
                    }
                }
                if (avm.ErrorCount > 0)
                {
                    this.Parent.Status.SetError(string.Format("Completed with {1} error(s): {0}\r\n{2}", avm.Title, avm.ErrorCount, err));
                }
                else
                {
                    this.Parent.Status.SetPositive(string.Format("Completed: {0}", avm.Title));
                }
                this.Parent.CurrentMedia = curr;
                this.Parent.SaveCmd.ExecuteIfCan();
            }
        }