Ejemplo n.º 1
0
        /// <summary>
        ///     load yaml files without doing anything special
        /// </summary>
        private void RawYamlLoad()
        {
            var typesToLoad = (
                from assembly in AppDomain.CurrentDomain.GetAssemblies()
                from type in assembly.GetTypes()
                let fileAnnotation = type.GetCustomAttribute <LoadFromProjectFileAttribute>()
                                     where fileAnnotation != null
                                     select(
                    Type: type,
                    PathInProj: fileAnnotation.ProjectRelativePath,
                    fileAnnotation.Required,
                    fileAnnotation.IsList
                    )
                ).ToList();

            foreach (var tuple in typesToLoad)
            {
                string absPath = Helper.ProjectToNormalPath(tuple.PathInProj, this._folder);
                Logger.Debug("PARSER: Parsing file {f}", absPath);

                if (!File.Exists(absPath))
                {
                    if (tuple.Required)
                    {
                        throw new LoadException(
                                  $"The required project file '{tuple.PathInProj}' is missing!\n" +
                                  $"Expected it at '{absPath}'"
                                  );
                    }

                    Logger.Warning(
                        "File {f} does not exist, but is not required",
                        tuple.PathInProj);
                    continue;
                }

                var elementOrList =
                    Deserializer.DeserializeSafely(tuple.Type, absPath, tuple.IsList);
                switch (elementOrList)
                {
                case null when tuple.Required:
                    throw new LoadException($"A required file is empty: {absPath}");

                case null:
                    continue;

                case BasicElement elem:
                    this.AddToList(elem, absPath);
                    continue;

                case IList list:
                    foreach (var elem in list)
                    {
                        this.AddToList((BasicElement)elem, absPath);
                    }

                    continue;
                }
            }
        }