Beispiel #1
0
        OracleServer SetupOracleServer(ErrorResultTO errors)
        {
            var server = new OracleServer();

            try
            {
                var connected = server.Connect(Source.ConnectionString, CommandType.StoredProcedure, ProcedureName);
                if (!connected)
                {
                    Dev2Logger.Error(string.Format(ErrorResource.FailedToConnectWithConnectionString,
                                                   Source.ConnectionString), GlobalConstants.WarewolfError);
                }
                return(server);
            }
            catch (OracleException oex)
            {
                var errorMessages = new StringBuilder();
                errorMessages.Append(oex.Message);
                errors.AddError(errorMessages.ToString());
                Dev2Logger.Error(errorMessages.ToString(), GlobalConstants.WarewolfError);
            }
            catch (Exception ex)
            {
                errors.AddError($"{ex.Message}{Environment.NewLine}{ex.StackTrace}");
                Dev2Logger.Error(ex, GlobalConstants.WarewolfError);
            }
            return(server);
        }
Beispiel #2
0
        public void OracleTest()
        {
            BaseKeyPair kp            = BaseKeyPair.Generate();
            Account     oracleAccount = fluentClient.ConstructAccount(kp);
            Account     account       = fluentClient.ConstructAccount(baseKeyPair);
            ulong       money         = (ulong)1m.ToAettos(Unit.AE);
            bool        result        = account.SendAmount(oracleAccount.KeyPair.PublicKey, money).WaitForFinish(TimeSpan.FromSeconds(30));

            Assert.IsTrue(result);
            oracleAccount.Refresh();
            Assert.AreEqual(oracleAccount.Balance, money);

            OracleServer <CityQuery, TemperatureResponse> query = oracleAccount.RegisterOracle <CityQuery, TemperatureResponse>().WaitForFinish(TimeSpan.FromSeconds(30));
            CityTemperatureService svc = new CityTemperatureService();

            svc.Server = query;
            Task.Factory.StartNew(svc.Start);
            OracleClient <CityQuery, TemperatureResponse> reg = account.GetOracle <CityQuery, TemperatureResponse>(query.OracleId);
            TemperatureResponse resp = reg.Ask(new CityQuery {
                City = "montevideo"
            }).WaitForFinish(TimeSpan.FromSeconds(300));

            Assert.AreEqual(resp.TemperatureCelsius, 24);
            resp = reg.Ask(new CityQuery {
                City = "sofia"
            }).WaitForFinish(TimeSpan.FromSeconds(30));
            Assert.AreEqual(resp.TemperatureCelsius, 25);
            resp = reg.Ask(new CityQuery {
                City = "hell"
            }).WaitForFinish(TimeSpan.FromSeconds(30));
            Assert.AreEqual(resp.TemperatureCelsius, 2000);
            svc.Stop();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            int          selector     = 2;
            SqlServer    sqlServer    = new SqlServer();
            OracleServer oracleServer = new OracleServer();

            sqlServer.Add(selector);
            oracleServer.Delete();

            Console.ReadLine();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            // Test Code.
            var svr = new OracleServer("ktarbet", File.ReadAllLines(@"C:\temp\karl.txt")[0], "uchdb2.uc.usbr.gov", "uchdb2.uc.usbr.gov", "MST", "1521");

            Hdb.Instance = new Hdb(svr);

            SqlViewEditor.Server = Hdb.Instance.Server;
            var f = new FormMetaData();

            Application.Run(f);
        }
Beispiel #5
0
        public async Task <(object result, bool done)> CheckForFinishAsync(object input, CancellationToken token = default(CancellationToken))
        {
            OracleServer <T, S> c      = (OracleServer <T, S>)input;
            RegisteredOracle    oracle = await c.Account.Client.GetRegisteredOracleAsync(c.OracleId, token).ConfigureAwait(false);

            c.AbiVersion     = oracle.AbiVersion;
            c.QueryFee       = oracle.QueryFee;
            c.QueryFormat    = oracle.QueryFormat;
            c.ResponseFormat = oracle.ResponseFormat;
            c.Ttl            = oracle.Ttl;
            return(c, true);
        }
        private static void PushCode(string[] temp, OracleServer _lstserver, int lastIndex, int i)
        {
            StringBuilder sb = new StringBuilder(500);

            for (int _i = lastIndex; _i < i - 3; _i++)
            {
                string line = temp[_i];
                if (!line.Trim().StartsWith("#"))
                {
                    sb.AppendLine(line);
                }
            }
            _lstserver.Value = sb.ToString();
        }
Beispiel #7
0
        private void addHDB_Click(object sender, EventArgs e)
        {
            var server = OracleServer.ConnectToOracle();

            if (server != null)
            {
                Hdb.Instance = new Hdb(server);
                var dlg = new HdbPoet.FormAddSeries();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    HdbPoet.Properties.Settings.Default.Save();
                    ImportFromHdb.Import(dlg.DataSet, DB, CurrentFolder);
                    DatabaseChanged();
                }
            }
        }
        // ReSharper disable InconsistentNaming
        public void OracleServer_FetchDataTable_AddParams_VerifyAllAdded()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var factory     = new Mock <IDbFactory>();
            var mockCommand = new Mock <IDbCommand>();



            mockCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");
            var added = new SqlCommand().Parameters;

            mockCommand.Setup(a => a.Parameters).Returns(added);
            var helpTextCommand = new Mock <IDbCommand>();

            helpTextCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            DataTable dt = new DataTable();

            dt.Columns.Add("database_name");
            dt.Rows.Add(new object[] { "Bob" });
            dt.Rows.Add(new object[] { "Dave" });
            factory.Setup(a => a.GetSchema(It.IsAny <IDbConnection>(), "Databases")).Returns(dt);
            var conn = new Mock <IDbConnection>();

            conn.Setup(a => a.State).Returns(ConnectionState.Open);
            var sqlServer = new OracleServer(factory.Object);

            try
            {
                PrivateObject pvt = new PrivateObject(sqlServer);
                pvt.SetField("_connection", conn.Object);
                pvt.SetField("_command", mockCommand.Object);
                //------------Execute Test---------------------------
                IDbDataParameter[] param = new IDbDataParameter[] { new SqlParameter("a", "a"), new SqlParameter("b", "b") };

                SqlServer.AddParameters(mockCommand.Object, param);
                Assert.AreEqual(2, added.Count);


                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
        // ReSharper disable InconsistentNaming
        public void OracleServer_FetchDataTable_CommandIsNull_ThrowsArgumentNullException()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var sqlServer = new OracleServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.FetchDataTable(null);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Beispiel #10
0
        public void OracleServer_CreateCommand_ConnectionNotInitialized_ThrowsConnectFirstException()

        {
            //------------Setup for test--------------------------
            var sqlServer = new OracleServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.CreateCommand();

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Beispiel #11
0
        public void OracleServer_Connect_ConnectionStringIsNull_ThrowsArgumentNullException()

        {
            //------------Setup for test--------------------------
            var sqlServer = new OracleServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.Connect(null, CommandType.Text, null);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
        // ReSharper disable InconsistentNaming
        public void OracleServer_FetchDatabases_ConnectionNotInitialized_ThrowsConnectFirstException()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var sqlServer = new OracleServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.FetchDatabases();

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
        // ReSharper disable InconsistentNaming
        public void OracleServer_Connect_ConnectionStringIsInvalid_ThrowsArgumentException()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var sqlServer = new OracleServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.Connect("xxx", CommandType.Text, null);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Beispiel #14
0
        private void AddHDBModel_Click(object sender, EventArgs e)
        {
#if  !PISCES_OPEN
            var server = OracleServer.ConnectToOracle();

            if (server == null)
            {
                return;
            }
            Hdb.Instance = new Hdb(server);

            SelectHdbModel dlg = new SelectHdbModel();

            if (dlg.ShowDialog() == DialogResult.OK && dlg.ModelID > 0)
            {
                // create tree for this model.
                var folder = DB.AddFolder(CurrentFolder, dlg.ModelName + " " + dlg.ModelTable);
                var tbl    = HdbModelTreeBuilder.PiscesSeriesCatalog(dlg.ModelID, dlg.ModelTable, dlg.OldestModelRunDate, DB.NextSDI(), folder.ID);

                if (tbl.Rows.Count == 0)
                {
                    MessageBox.Show("No model runs found for model_id " + dlg.ModelID + " after " + dlg.OldestModelRunDate.ToString());
                    return;
                }
                DB.Server.SaveTable(tbl);

                // create scenario list.
                var scenarioTable = DB.GetScenarios();
                var ref_model_run = Hdb.Instance.ref_model_run(dlg.ModelID, dlg.OldestModelRunDate);
                foreach (DataRow item in ref_model_run.Rows)
                {
                    string date           = Convert.ToDateTime(item["run_date"]).ToShortDateString();
                    string model_run_name = item["model_run_name"].ToString();
                    string id             = item["model_run_id"].ToString();
                    string path           = HdbModelSeries.BuildScenairoPath(model_run_name, id, date);
                    string name           = HdbModelSeries.BuildScenairoName(model_run_name, id, date);
                    scenarioTable.AddScenarioRow(name, true, path, 0);
                }

                DB.Server.SaveTable(scenarioTable);
                DatabaseChanged();
            }
#endif
        }
        // ReSharper disable InconsistentNaming
        public void OracleServer_CreateCommand_CreateCommand()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var factory     = new Mock <IDbFactory>();
            var mockCommand = new Mock <IDbCommand>();

            mockCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");
            var added = new SqlCommand().Parameters;

            mockCommand.Setup(a => a.Parameters).Returns(added);
            var helpTextCommand = new Mock <IDbCommand>();

            helpTextCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            DataTable dt = new DataTable();

            dt.Columns.Add("database_name");
            dt.Rows.Add(new object[] { "Bob" });
            dt.Rows.Add(new object[] { "Dave" });
            factory.Setup(a => a.GetSchema(It.IsAny <IDbConnection>(), "Databases")).Returns(dt);
            var conn = new Mock <IDbConnection>();

            conn.Setup(a => a.State).Returns(ConnectionState.Open);
            conn.Setup(a => a.ConnectionString).Returns("bob");
            conn.Setup(a => a.CreateCommand()).Returns(mockCommand.Object);
            factory.Setup(a => a.CreateConnection(It.IsAny <string>())).Returns(conn.Object);
            var sqlServer = new OracleServer(factory.Object);

            try
            {
                PrivateObject pvt = new PrivateObject(sqlServer);
                pvt.SetField("_connection", conn.Object);
                //------------Execute Test---------------------------
                sqlServer.CreateCommand();
                conn.Verify(a => a.CreateCommand());
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
        // ReSharper disable InconsistentNaming
        public void OracleServer_FetchStoredProcedures_FunctionProcessorIsNull_ThrowsArgumentNullException()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var sqlServer = new OracleServer();

            try
            {
                //------------Execute Test---------------------------
                Func <IDbCommand, List <IDbDataParameter>, string, string, bool> procProcessor = (command, list, arg3, a) => false;

                sqlServer.FetchStoredProcedures(procProcessor, null);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Beispiel #17
0
        public void OracleServer_FetchDataTable_ConnectionsString()

        {
            //------------Setup for test--------------------------
            var factory     = new Mock <IDbFactory>();
            var mockCommand = new Mock <IDbCommand>();

            mockCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");
            var added = new SqlCommand().Parameters;

            mockCommand.Setup(a => a.Parameters).Returns(added);
            var helpTextCommand = new Mock <IDbCommand>();

            helpTextCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            var dt = new DataTable();

            dt.Columns.Add("database_name");
            dt.Rows.Add(new object[] { "Bob" });
            dt.Rows.Add(new object[] { "Dave" });
            factory.Setup(a => a.GetSchema(It.IsAny <IDbConnection>(), "Databases")).Returns(dt);
            var conn = new Mock <IDbConnection>();

            conn.Setup(a => a.State).Returns(ConnectionState.Open);
            conn.Setup(a => a.ConnectionString).Returns("bob");
            var sqlServer = new OracleServer(factory.Object);

            try
            {
                var pvt = new Warewolf.Testing.PrivateObject(sqlServer);
                pvt.SetField("_connection", conn.Object);
                pvt.SetField("_command", mockCommand.Object);
                //------------Execute Test---------------------------

                Assert.AreEqual("bob", sqlServer.ConnectionString);
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Beispiel #18
0
 public static InProgress <bool> Extend <T, S>(this OracleServer <T, S> oracleQuery, ulong fee = Constants.BaseConstants.FEE, ulong extendTtl = Constants.BaseConstants.ORACLE_RESPONSE_TTL_VALUE) => oracleQuery.ExtendAsync(fee, extendTtl).RunAndUnwrap();
Beispiel #19
0
 public static List <OracleQuestion <T, S> > Query <T, S>(this OracleServer <T, S> oracleQuery, ushort?limit, string lastQueryId = null) => oracleQuery.QueryAsync(limit, lastQueryId).RunAndUnwrap();
        private static List <OracleServer> LoadServersFromTextFile(string FP)
        {
            List <OracleServer> _lst = new List <OracleServer>();
            string inputString;


            StreamReader streamReader = File.OpenText(FP.Trim()); // FP is the filepath of TNS file

            inputString = streamReader.ReadToEnd();
            string[]     temp       = inputString.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            OracleServer _lstserver = null;
            int          lastIndex  = 0;

            for (int i = 0; i < temp.Length; i++)
            {
                OracleServer _server = null;
                if (temp[i].Trim(' ', '(').Contains("DESCRIPTION"))
                {
                    string DS = temp[i - 1].Trim('=', ' ');
                    if (DS != "(LOAD_BALANCE = OFF)" && DS != ")")
                    {
                        if (_lstserver != null)
                        {
                            PushCode(temp, _lstserver, lastIndex, i);
                        }

                        _server = new OracleServer()
                        {
                            Name = DS, index = i - 1
                        };
                        _lst.Add(_server);
                        lastIndex  = i - 1;
                        _lstserver = _server;
                    }
                }
            }

            if (_lstserver != null)
            {
                PushCode(temp, _lstserver, lastIndex, temp.Length);
            }

            streamReader.Close();

            foreach (OracleServer item in _lst)
            {
                string u = item.Value;

                var c = u.IndexOf('=');
                if (c != -1)
                {
                    u = u.Substring(c + 1).Trim();
                }

                u = u.Replace(Environment.NewLine, " ");


                while (item.Value != u)
                {
                    item.Value = u;
                    u          = u.Replace("  ", " ");
                    u          = u.Replace(") )", "))");
                    u          = u.Replace("( (", "((");
                }
            }

            return(_lst);
        }