示例#1
0
        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);
        }
示例#2
0
        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));
            }
        }
示例#3
0
            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));
                }
            }
示例#4
0
        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();
            }
        }