Пример #1
0
        /// <summary>
        /// Loads landscape from a file.
        /// </summary>
        /// <param name="file"> the file to be read.</param>
        /// <returns></returns>
        public async Task Load(StorageFile file)
        {
            if (file != null)
            {
                string xml = await FileIO.ReadTextAsync(file);

                //loading
                try {
                    LandscapeBuilder lb = new LandscapeBuilder {
                        XML = xml
                    };
                    BuilderModels.Clear();
                    foreach (string key in lb.Builders.Keys)
                    {
                        BuilderModel model = new BuilderModel(lb.Builders[key])
                        {
                            ID = key
                        };
                        BuilderModels.Add(model);
                    }
                    await Output.SetAsync("File was loaded sucessfully.");
                } catch (Exception) {
                    await Output.SetAsync("Unable to deserialize the file.");
                } finally { }
            }
            else
            {
                //cancelled
            }
        }
Пример #2
0
        /// <summary>
        /// Adds a BuilderModel based on parameters.
        /// </summary>
        /// <param name="builderIndex"> Indesx of the selected type in PossibleBuilders.</param>
        /// <param name="typeParameterIndex">Indesx of the selected type in PossibleTypeParameters.</param>
        public void Add(int builderIndex, int typeParameterIndex)
        {
            Type builderType  = PossibleBuilders[builderIndex];
            Type specificType = builderType;

            if (builderType.IsGenericType)
            {
                specificType = builderType.MakeGenericType(new Type[] { PossibleTypeParameters[typeParameterIndex] });
            }
            BuilderModels.Add(new BuilderModel((IAlgorithmBuilder)Activator.CreateInstance(specificType)));
        }