Exemplo n.º 1
0
 /// <summary>
 /// Sets the configuration.
 /// </summary>
 /// <param name="config">The configuration.</param>
 public void SetConfiguration(RenameConfig config)
 {
     if (config == null)
     {
         this.Formula = this.SearchText = this.ReplaceText = string.Empty;
     }
     else
     {
         this.Formula     = config.Formula;
         this.SearchText  = config.SearchText;
         this.ReplaceText = config.ReplaceText;
     }
 }
Exemplo n.º 2
0
        bool TryConfig(RenameConfig config)
        {
            System.Diagnostics.Debug.WriteLine("-->TryFormula");
            string tmp;

            this.LastViewUpdate = DateTime.Now;
            this.Status.Clear();
            if (config.IsTransform)
            {
                bool needFormula = !string.IsNullOrWhiteSpace(config.Formula);
                bool needReplace = !string.IsNullOrEmpty(config.SearchText);
                try {
                    Func <MediaFile, string> worker = null;
                    if (needFormula)
                    {
                        worker = this.Processor.GetEvaluator(config.Formula);
                    }
                    foreach (var itm in this.Items)
                    {
                        tmp = null;
                        if (needFormula)
                        {
                            tmp = worker(itm.Key);
                        }
                        if (needReplace)
                        {
                            tmp = (tmp ?? itm.Key.Title).Replace(config.SearchText, config.ReplaceText);
                        }
                        itm.Value = (tmp ?? string.Empty).Trim();
                    }
                    return(true);
                }
                catch (ArgumentException x) {
                    this.Status.SetError(string.Format("Bad pattern: {0}", x.Message));
                }
                catch (Exception x) {
                    this.Status.SetError(string.Format("Failed to apply pattern. {0}: {1}", x.GetType().Name, x.Message));
                }
            }
            else
            {
                foreach (var itm in this.Items)
                {
                    itm.Value = null;
                }
            }
            return(false);
        }