comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:1aca3d413885
1 /*
2 * Postarc
3 *
4 * Author:
5 * Christian Lins <christian.lins@intevation.de>
6 *
7 * Copyright:
8 * Copyright (C) 2012 Intevation GmbH <http://www.intevation.de/>
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 using System;
25 using System.Collections.Generic;
26 using System.Linq;
27 using System.Text;
28 using System.Windows.Forms;
29 using System.IO;
30 using System.Runtime.Serialization.Formatters.Binary;
31 using System.Runtime.Serialization;
32 using System.Reflection;
33
34 namespace Postarc
35 {
36 public class Settings
37 {
38 public class Binder : SerializationBinder
39 {
40 public override Type BindToType(string assemblyName, string typeName)
41 {
42 Type type = null;
43 string shortAssem = assemblyName.Split(',')[0];
44 Assembly[] assemblies =
45 AppDomain.CurrentDomain.GetAssemblies();
46
47 foreach (Assembly assem in assemblies)
48 {
49 if (shortAssem == assem.FullName.Split(',')[0])
50 {
51 type = assem.GetType(typeName);
52 break;
53 }
54
55 }
56 return type;
57 }
58
59 }
60
61 public static List<PostGISConnection> LoadSavedProfiles()
62 {
63 List<PostGISConnection> profiles = new List<PostGISConnection>();
64 string path = Application.UserAppDataPath + "\\postarc\\";
65
66 string[] files = Directory.GetFiles(path, "*.connprof");
67 foreach(string file in files)
68 {
69 FileStream fs = new FileStream(file, FileMode.Open);
70 BinaryFormatter formatter = new BinaryFormatter();
71 formatter.Binder = new Settings.Binder();
72 PostGISConnection conn = (PostGISConnection)formatter.Deserialize(fs);
73 fs.Close();
74 profiles.Add(conn);
75 }
76
77 return profiles;
78 }
79 }
80 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)