Exemplo n.º 1
0
        private void WriteConfig(String filename)
        {
            TextWriter        outfile = null;
            EncryptionWrapper enc     = null;

            try
            {
                enc = new EncryptionWrapper();
                enc.InitializeCipher(key, IV);
                outfile = new StreamWriter(filename);
                outfile.WriteLine("essServer|{0}", essServer);
                outfile.WriteLine("apsServer|{0}", this.apsProviderURL.Substring(apsProviderURL.IndexOf("//") + 2, apsProviderURL.LastIndexOf(":") - apsProviderURL.IndexOf("//") - 2));
                outfile.WriteLine("essUser|{0}", essUser);
                outfile.WriteLine("essPW|{0}", System.Convert.ToBase64String(enc.Encrypt(System.Text.Encoding.ASCII.GetBytes(essPW))));
                outfile.WriteLine("essApp|{0}", essApp);
                outfile.WriteLine("essDB|{0}", essDB);
                outfile.WriteLine("query|{0}", scintQry.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error saving config file: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (outfile != null)
                {
                    outfile.Flush();
                    outfile.Close();
                }
                enc = null;
            }
            return;
        }
Exemplo n.º 2
0
        private void LoadConfig(String filename)
        {
            StreamReader      cfg = null;
            EncryptionWrapper dec = null;

            try
            {
                dec = new EncryptionWrapper();
                dec.InitializeCipher(key, IV);
                cfg = new StreamReader(filename);
                String   line   = null;
                String[] values = null;
                while ((line = cfg.ReadLine()) != null)
                {
                    values = line.Split('|');
                    switch (values[0])
                    {
                    case "essServer":
                        this.essServer = values[1];
                        break;

                    case "apsServer":
                        this.apsProviderURL = "http://" + values[1] + ":13080/aps/JAPI";
                        break;

                    case "essUser":
                        this.essUser = values[1];
                        break;

                    case "essPW":
                        this.essPW = System.Text.Encoding.ASCII.GetString(dec.Decrypt(System.Convert.FromBase64String(values[1])));
                        break;

                    case "essApp":
                        this.essApp = values[1];
                        break;

                    case "essDB":
                        this.essDB = values[1];
                        break;

                    case "query":
                        this.m_qry = values[1] + cfg.ReadToEnd();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error loading config file: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (cfg != null)
                {
                    cfg.Close();
                }
                dec = null;
            }
            try
            {
                if (ess == null || !ess.isSignedOn())
                {
                    ess = IEssbase.Home.create(JAPI_VERSION);
                }
                if (svr == null || !svr.isConnected())
                {
                    svr = ess.signOn(essUser, essPW, false, null, apsProviderURL, essServer);
                }
                if (cv != null)
                {
                    cv.close();
                }
                cv            = svr.getApplication(essApp).getCube(essDB).openCubeView("JDH_CubeView");
                frmState      = ConnectionState.Connected;
                scintQry.Text = m_qry;
                UpdateFormState();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error connecting with configuration provided: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return;
        }