view Postarc/Postarc/Settings.cs @ 0:1aca3d413885 tip

Initial import of Postarc
author Christian Lins <christian.lins@intevation.de>
date Fri, 05 Oct 2012 23:55:06 +0200
parents
children
line wrap: on
line source
/*
 * Postarc
 *
 * Author:
 * Christian Lins <christian.lins@intevation.de>
 *
 * Copyright:
 * Copyright (C) 2012 Intevation GmbH <http://www.intevation.de/>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.Reflection;

namespace Postarc
{
    public class Settings
    {
		public class Binder : SerializationBinder
		{
			public override Type BindToType(string assemblyName, string typeName)
			{
				Type type = null;
				string shortAssem = assemblyName.Split(',')[0];
				Assembly[] assemblies =
					AppDomain.CurrentDomain.GetAssemblies();

				foreach (Assembly assem in assemblies)
				{
					if (shortAssem == assem.FullName.Split(',')[0])
					{
						type = assem.GetType(typeName);
						break;
					}

				}
				return type;
			}

		}

		public static List<PostGISConnection> LoadSavedProfiles()
		{
			List<PostGISConnection> profiles = new List<PostGISConnection>();
			string path = Application.UserAppDataPath + "\\postarc\\";

			string[] files = Directory.GetFiles(path, "*.connprof");
			foreach(string file in files)
			{
				FileStream fs = new FileStream(file, FileMode.Open);
				BinaryFormatter formatter = new BinaryFormatter();
				formatter.Binder = new Settings.Binder();
				PostGISConnection conn = (PostGISConnection)formatter.Deserialize(fs);
				fs.Close();
				profiles.Add(conn);
			}

			return profiles;
		}
    }
}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)