private string fromString(string line)
 {
     if (checkPreproccess(line))
     {
         return(string.Empty);
     }
     return(Insertion.Replace(line, (Match m) =>
     {
         string value = m.Value.Substring(1, m.Value.Length - 2);
         if (value.Contains(":"))
         {
             string[] splits = value.Split(":");
             if (splits.Length <= 1)
             {
                 throw new IllegalPipeException();
             }
             string result = Values.ContainsKey(splits[0]) ? (string)Values[splits[0]] : splits[0];
             System.Diagnostics.Debug.WriteLineIf(Values.ContainsKey(result), Values.Where(kv => kv.Key == result).Select(kv => kv.Value).FirstOrDefault());
             foreach (string pipeId in splits.Skip(1))
             {
                 string[] pipeAndArg = pipeId.Split(',');
                 if (!Pipes.ContainsKey(pipeAndArg[0]))
                 {
                     throw new IllegalPipeException(pipeAndArg[0]);
                 }
                 result = Pipes[pipeAndArg[0]](result, pipeAndArg.Skip(1).ToArray());
             }
             System.Diagnostics.Debug.WriteLine(result);
             return result;
         }
         else
         {
             if (Values.ContainsKey(value))
             {
                 if (Values[value] is DateTime dt)
                 {
                     if (Values.ContainsKey("dateTimeFormat"))
                     {
                         return dt.ToString((string)Values["dateTimeFormat"]);
                     }
                     return dt.ToShortDateString();
                 }
                 return Values[value].ToString();
             }
             return value;
         }
     }));
 }
Ejemplo n.º 2
0
        private async Task <FormatedDirectory> ReplaceNamesAsync(FormatedDirectory root, CancellationToken token = default)
        {
#if DEBUG
            System.Diagnostics.Debug.WriteLine($"sub dir count:{root.Folders.Count()}");
#endif
            if (Insertion.IsMatch(root.Name))
            {
                string[] splits = root.Name.Substring(1).Split(':');
                if (Values.ContainsKey(splits[0]))
                {
                    string output = splits[0];
                    foreach (string pipeName in splits.Skip(1))
                    {
                        token.ThrowIfCancellationRequested();
                        string[] pipeSplit = pipeName.Split(',');

                        if (Pipes.ContainsKey(pipeSplit[0]))
                        {
                            if (pipeSplit.Length == 1)
                            {
                                output = Pipes[pipeSplit[0]](output);
                            }
                            else
                            {
                                output = Pipes[pipeSplit[0]](output, pipeSplit.Skip(1));
                            }
                        }
                    }
                }
                else
                {
                    root.Name = splits[0];
                }
            }
            for (int dirPos = 0; dirPos < root.Folders.Length; dirPos++)
            {
                token.ThrowIfCancellationRequested();
                root.Folders[dirPos] = await ReplaceNamesAsync(root.Folders[dirPos], token);
            }
            List <FormatedFile> files = await root.GetFiles(token);

            for (int filePos = 0; filePos < files.Count; filePos++)
            {
                if (Insertion.IsMatch(files[filePos].Name))
                {
                    string name = files[filePos].Name;
                    if (name.Count(c => c == ',') == 0)
                    {
                        if (Values.ContainsKey(name))
                        {
                            files[filePos].Name = Values[name].ToString();
                        }
                    }
                    else
                    {
                        string[] splits   = name.Substring(1, name.Length - 2).Split(',');
                        string   output   = files[filePos].Name;
                        string   pipeName = splits[0];
                        if (Pipes.ContainsKey(pipeName))
                        {
                            output = Pipes[pipeName](output, splits.Skip(1));
                        }
                        files[filePos].Name = output;
                    }
                }
            }
            return(root);
        }