~ubuntu-branches/ubuntu/quantal/openerp6.1/quantal

« back to all changes in this revision

Viewing changes to openerp/addons/plugin_outlook/static/openerp-outlook-plugin/OpenERPOutlookPlugin/ConfigManager.cs

  • Committer: Package Import Robot
  • Author(s): Yolanda Robla
  • Date: 2012-09-20 15:29:00 UTC
  • Revision ID: package-import@ubuntu.com-20120920152900-woyy3yww8z6acmsk
Tags: upstream-6.1-1+dfsg
ImportĀ upstreamĀ versionĀ 6.1-1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    OpenERP, Open Source Business Applications
 
3
    Copyright (c) 2011 OpenERP S.A. <http://openerp.com>
 
4
 
 
5
    This program is free software: you can redistribute it and/or modify
 
6
    it under the terms of the GNU Affero General Public License as
 
7
    published by the Free Software Foundation, either version 3 of the
 
8
    License, or (at your option) any later version.
 
9
 
 
10
    This program is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU Affero General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Affero General Public License
 
16
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
 
 
19
 
 
20
using System;
 
21
using System.Collections;
 
22
using System.Drawing;
 
23
using System.Drawing.Imaging;
 
24
using System.IO;
 
25
using System.Windows.Forms;
 
26
using System.Text.RegularExpressions;
 
27
using OpenERPClient;
 
28
 
 
29
namespace OpenERPOutlookPlugin
 
30
{
 
31
    public class ConfigManager
 
32
    {
 
33
        string openerp_config_file = "openerp_config.ini";
 
34
 
 
35
        public void SaveConfigurationSetting()
 
36
        {
 
37
            string filepath = Tools.GetAppFolderPath();
 
38
            OpenERPOutlookPlugin openerp_outlook = Cache.OpenERPOutlookPlugin;
 
39
            OpenERPConnect openerp_connect = openerp_outlook.Connection;
 
40
            filepath = Path.Combine(filepath, openerp_config_file);
 
41
            string[] datas = { "url=" + openerp_connect.URL, "userid=" + openerp_connect.UserId, "dbname=" + openerp_connect.DBName,"rempwd="+openerp_connect.rempwd,"pswrd=" + openerp_connect.pswrd };
 
42
            StreamWriter userfile = new StreamWriter(filepath, false);
 
43
 
 
44
            foreach (string data in datas)
 
45
            {
 
46
                userfile.WriteLine(data);
 
47
            }
 
48
            userfile.Close();
 
49
 
 
50
        }
 
51
        public void LoadConfigurationSetting()
 
52
        {
 
53
 
 
54
            string filePath = Tools.GetAppFolderPath();
 
55
            filePath = Path.Combine(filePath, this.openerp_config_file);
 
56
            OpenERPConnect openerp_connect=null;
 
57
            OpenERPOutlookPlugin openerp_outlook=null;
 
58
            openerp_outlook = Cache.OpenERPOutlookPlugin;
 
59
            if (openerp_outlook == null)
 
60
            {
 
61
 
 
62
                openerp_outlook = new OpenERPOutlookPlugin(openerp_connect);
 
63
            }
 
64
                openerp_connect = openerp_outlook.Connection;
 
65
                if (openerp_connect == null)
 
66
            {
 
67
               openerp_connect = new OpenERPConnect();
 
68
            }
 
69
            
 
70
            if (File.Exists(filePath))
 
71
            {
 
72
 
 
73
                string line;
 
74
 
 
75
                using (StreamReader file = new StreamReader(filePath))
 
76
                {
 
77
                    while ((line = file.ReadLine()) != null)
 
78
                    {
 
79
                        char[] delimiters = new char[] { '=' };
 
80
                        string[] parts = line.Split(delimiters, 2);
 
81
 
 
82
                        for (int i = 0; i < parts.Length; i += 2)
 
83
                        {
 
84
                            if (parts[i] == "url")
 
85
                                openerp_connect.URL = parts[i + 1].Trim();
 
86
                            else if (parts[i] == "userid")
 
87
                                openerp_connect.UserId = parts[i + 1].Trim();
 
88
                            else if (parts[i] == "dbname")
 
89
                                openerp_connect.DBName = parts[i + 1].Trim();                          
 
90
                            else if (parts[i] == "pswrd")
 
91
                                openerp_connect.pswrd = parts[i + 1].Trim();
 
92
                            else if (parts[i] == "rempwd")
 
93
                            {
 
94
                                openerp_connect.rempwd = false;
 
95
                                if (parts[i + 1].Trim().ToLower() == "true")
 
96
                                    openerp_connect.rempwd = true;
 
97
                            }
 
98
 
 
99
                        }
 
100
                    }
 
101
                    file.Close();
 
102
                }
 
103
            }
 
104
            openerp_outlook.Connection = openerp_connect;
 
105
            Cache.OpenERPOutlookPlugin = openerp_outlook;
 
106
        }        
 
107
 
 
108
    }
 
109
}