Ejemplo n.º 1
0
        /// <summary>
        /// Normalisiert den Dateinamen und benennt die Datei ggf. um. (Bedingung: endet mit .pdf)
        /// </summary>
        public string NormalizeFile(string path)
        {
            string filename = path.Split('\\').Last();
            string newName  = filename.Substring(0, filename.Length - 4);

            if (namePattern.IsNormalizedInstrument(newName))
            {
                return(path);
            }

            newName = namePattern.NormalizeInstrument(newName);

            if (newName == "") // -> Pattern unbekannt
            {
                WorkList.GetInstance().LoTasks.Add(new Task()
                {
                    Type = TaskType.FileNamePattern,
                    Path = path
                });

                return(path);
            }
            else
            {
                string newPath = path.Substring(0, path.Length - filename.Length) + newName + ".pdf";

                File.Move(
                    Path.Combine(config.StoragePath, path),
                    Path.Combine(config.StoragePath, newPath)
                    ); // todo: Exceptionhandling fehlt: Was passiert, wenn neuer Pfad schon vorhanden?

                return(newPath);
            }
        }