Exemplo n.º 1
0
 public ProcessWindow(OrganizeOrder order, HashSet <string> sources, DirectoryInfo destination, List <FileInformation> files, bool overwrite, bool move)
 {
     _order        = order;
     _sources      = sources;
     _destination  = destination;
     _files        = files;
     _overwrite    = overwrite;
     _cancellation = new CancellationTokenSource();
     _move         = move;
     InitializeComponent();
 }
Exemplo n.º 2
0
        private void ValidateOrderInput()
        {
            var text      = OrderTextBox.Text;
            var variables = Regex.Matches(text, "<.+?>");

            if (variables.Count < 1)
            {
                NotifyOrderValidatation("Order Expression Must Contain One Field Value.", true);
                return;
            }
            var containsFile = false;
            var fileIndex    = 0;
            var order        = new OrganizeOrder();

            foreach (Match match in variables)
            {
                containsFile = Regex.IsMatch(match.Value, "<file.+?>", RegexOptions.IgnoreCase);
                if (!containsFile)
                {
                    if (match.Value.Replace(">", "").Replace("<", "").ToLower() == "file")
                    {
                        containsFile = true;
                        fileIndex    = variables.OfType <Match>().ToList().IndexOf(match);
                        break;
                    }
                }


                if (containsFile)
                {
                    var content = match.Value.Remove(0, Regex.Match(match.Value, "<file", RegexOptions.IgnoreCase).Length).Replace(">", "");
                    if (content.Length > 0)
                    {
                        var matches = Regex.Matches(text, "\\[.+?\\]");
                        if (matches.Count > 0)
                        {
                            var fileName = new FileNameTemplate();
                            foreach (var contentm in from Match tem in matches select tem.Value.Replace("]", "").Replace("[", ""))
                            {
                                if (contentm.StartsWith("\"") && contentm.EndsWith("\""))
                                {
                                    fileName.AddLiterel(contentm.Replace("\"", ""));
                                    continue;
                                }
                                switch (contentm)
                                {
                                case "artist":
                                    fileName.AddElement(FileNameItem.Artist);
                                    continue;

                                case "album":
                                    fileName.AddElement(FileNameItem.Album);
                                    continue;

                                case "track":
                                    fileName.AddElement(FileNameItem.Trak);
                                    continue;

                                case "title":
                                    fileName.AddElement(FileNameItem.Title);
                                    continue;

                                case "count":
                                    fileName.AddElement(FileNameItem.Count);
                                    continue;
                                }
                            }
                            order.FileNameTemplate = fileName;
                        }
                    }
                    fileIndex = variables.OfType <Match>().ToList().IndexOf(match);
                    break;
                }
            }
            if (!containsFile)
            {
                NotifyOrderValidatation("Order Expression Must Contain File Field Value.", true);
                return;
            }

            for (var i = 0; i < variables.Count; i++)
            {
                var match = variables[i];
                var value = fileIndex == i ? "file" : match.Value.Substring(1, match.Value.Length - 2).ToLower();
                switch (value)
                {
                case "file":
                    if (i < variables.Count - 1)
                    {
                        NotifyOrderValidatation("File Must be the last Field", true);
                        OrderTextBox.Select(match.Index, match.Length);
                        return;
                    }
                    order.AddElement(OrderElement.File);
                    continue;

                case "album":
                    if (!order.AddElement(OrderElement.Album))
                    {
                        OrderTextBox.Text = text.Remove(match.Index, match.Length);
                    }
                    continue;

                case "artist":
                    if (!order.AddElement(OrderElement.Artist))
                    {
                        OrderTextBox.Text = text.Remove(match.Index, match.Length);
                    }
                    continue;

                case "genre":
                    if (!order.AddElement(OrderElement.Genre))
                    {
                        OrderTextBox.Text = text.Remove(match.Index, match.Length);
                    }
                    continue;

                case "year":
                    if (!order.AddElement(OrderElement.Year))
                    {
                        OrderTextBox.Text = text.Remove(match.Index, match.Length);
                    }
                    continue;
                }
            }
            var count = variables.Cast <Match>().Sum(v => v.Length);

            //var orderString = order.ToOrderString();
            if (count < OrderTextBox.Text.Length)
            {
                NotifyOrderValidatation("Text Contains Unwanted Characters ", true);
                return;
            }
            NotifyOrderValidatation(order.IsEmpty()?"   ":order.ToString(), false);
            _order = order;
        }