Beispiel #1
0
        void OnOverwriteFile(OverwriteFileEventArgs args)
        {
            if (OverwriteFile == null)
            {
                return;
            }

            OverwriteFile(this, args);
        }
        public void WriteDefaultConfigFile(string name, FeatureTarget target, string path, IDefaultContainer[] defaults)
        {
            AssertStorage();

            DefaultConfigFile dcf;

            if (!storage.ContainsKey(name) || (dcf = storage [name]) == null)
            {
                throw new ApplicationException(
                          String.Format("Definition of the '{0}' default config file not found.", name));
            }

            if (target != FeatureTarget.Any && dcf.Target != target)
            {
                throw new ApplicationException(
                          String.Format("Config file '{0}' can be generated only for the '{1}' target",
                                        name, target));
            }

            string targetFile = Path.Combine(path, dcf.FileName);

            if (File.Exists(targetFile))
            {
                OverwriteFileEventArgs args = new OverwriteFileEventArgs(
                    dcf.FileName,
                    path,
                    target,
                    true
                    );

                OnOverwriteFile(args);
                if (!args.Overwrite)
                {
                    return;
                }
            }

            try
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(
                          String.Format("Could not create directory '{0}'", path),
                          ex);
            }

            XmlDocument doc = new XmlDocument();

            PopulateDocument(name, target, doc, dcf, defaults);
            Helpers.SaveXml(doc, targetFile);
        }
Beispiel #3
0
        static void OnOverwriteFile(object sender, OverwriteFileEventArgs e)
        {
            Console.Write("Do you want to overwrite existing file '{0}'? [{1}] ",
                          e.Name, e.Overwrite ? "Y/n" : "y/N");
            ConsoleKeyInfo cki = Console.ReadKey(false);

            switch (cki.Key)
            {
            case ConsoleKey.N:
                e.Overwrite = false;
                break;

            case ConsoleKey.Y:
                e.Overwrite = true;
                break;
            }
            Console.WriteLine();
        }
Beispiel #4
0
		static void OnOverwriteFile (object sender, OverwriteFileEventArgs e)
		{
			Console.Write ("Do you want to overwrite existing file '{0}'? [{1}] ",
				       e.Name, e.Overwrite ? "Y/n" : "y/N");
			ConsoleKeyInfo cki = Console.ReadKey (false);
			switch (cki.Key) {
				case ConsoleKey.N:
					e.Overwrite = false;
					break;

				case ConsoleKey.Y:
					e.Overwrite = true;
					break;
			}
			Console.WriteLine ();
		}
		void OnOverwriteFile (OverwriteFileEventArgs args)
		{
			if (OverwriteFile == null)
				return;

			OverwriteFile (this, args);
		}
		public void WriteDefaultConfigFile (string name, FeatureTarget target, string path, IDefaultContainer[] defaults)
		{
			AssertStorage ();

			DefaultConfigFile dcf;
			if (!storage.ContainsKey (name) || (dcf = storage [name]) == null)
				throw new ApplicationException (
					String.Format ("Definition of the '{0}' default config file not found.", name));

			if (target != FeatureTarget.Any && dcf.Target != target)
				throw new ApplicationException (
					String.Format ("Config file '{0}' can be generated only for the '{1}' target",
						       name, target));

			string targetFile = Path.Combine (path, dcf.FileName);
			if (File.Exists (targetFile)) {
				OverwriteFileEventArgs args = new OverwriteFileEventArgs (
					dcf.FileName,
					path,
					target,
					true
				);

				OnOverwriteFile (args);
				if (!args.Overwrite)
					return;
			}

			try {
				if (!Directory.Exists (path))
					Directory.CreateDirectory (path);
			} catch (Exception ex) {
				throw new ApplicationException (
					String.Format ("Could not create directory '{0}'", path),
					ex);
			}

			XmlDocument doc = new XmlDocument ();
			PopulateDocument (name, target, doc, dcf, defaults);
			Helpers.SaveXml (doc, targetFile);
		}