Exemplo n.º 1
0
        public SyncViewModel(ConnectionInfo server = new ConnectionInfo())
        {
            Title = "Синхронизация";

            LocalConnectionString = Nhib.ConnectionString;
            LocalProviderName     = LocalConnectionString.Contains(".sdf") ? Constants.SqlCeProvider : Constants.SqlServerProvider;

            Remote = new DataConnectionViewModel(server);

            Poster.MessagePosted += syncer_MessagePosted;
            Syncer.SyncEnded     += syncer_SyncEnded;
        }
Exemplo n.º 2
0
        public string MSSQLRunQuery(string query)
        {
            DataConnectionViewModel ConResult = new DataConnectionViewModel();

            ConResult.Calls = calls;
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            //string ConnStr = Helpers.GetMSSQLConnectionString();

            Console.WriteLine("ConnectionString=" + ConnStr);

            //using (SqlConnection con = new SqlConnection(ConnStr)) {
            //    con.Open();
            if (con == null)
            {
                con = new SqlConnection(ConnStr);
                con.Open();
            }

            Console.WriteLine("connection open");

            try {
                var cmd    = new SqlCommand(query, con);
                var result = cmd.ExecuteScalar();
                ConResult.IPAddress = result.ToString();
                stopwatch.Stop();
                ConResult.ElapsedTime      = stopwatch.Elapsed.ToString();
                ConResult.ElapsedTimeMilli = stopwatch.Elapsed.Milliseconds.ToString();

                Console.WriteLine("Connection Succeeded! Time=" + ConResult.ElapsedTime);

                string output = JsonConvert.SerializeObject(ConResult);
                Console.WriteLine("ConResult=" + output);
                calls++;
                return(output);
            }
            catch (System.Data.Common.DbException ex) {
                Console.WriteLine("Connection failed, message=" + ex.Message);
                return("Something went wrong: " + ex.Message);
            }
            //}
        }
Exemplo n.º 3
0
        /// <summary>
        /// A Lambda function to respond to HTTP Get methods from API Gateway
        /// </summary>
        /// <param name="request"></param>
        /// <returns>The list of blogs</returns>
        public APIGatewayProxyResponse Get(APIGatewayProxyRequest request, ILambdaContext context)
        {
            Console.WriteLine("Get Request");
            Console.WriteLine("Request=" + JsonConvert.SerializeObject(request));
            string qsp          = "";
            string bodyResponse = "";
            DataConnectionViewModel TestOutput = new DataConnectionViewModel();
            Stopwatch LambdaStopwatch          = new Stopwatch();

            if (request.QueryStringParameters != null && request.QueryStringParameters.ContainsKey(qsk))
            {
                qsp = request.QueryStringParameters[qsk];
            }

            Console.WriteLine("qsp=" + qsp);

            if (qsp == "webapi")
            {
                TestOutput   = PoolManagerMSSQLQuery().Result;
                bodyResponse = JsonConvert.SerializeObject(TestOutput);
            }
            else
            {
                LambdaStopwatch.Start();
                TestOutput = DirectMSSQLQuery();
                LambdaStopwatch.Stop();

                TestOutput.LamElapsedTime      = LambdaStopwatch.Elapsed.ToString();
                TestOutput.LamElapsedTimeMilli = (Convert.ToDecimal(LambdaStopwatch.Elapsed.Ticks) / 10000).ToString();
                bodyResponse = JsonConvert.SerializeObject(TestOutput);
            }

            var response = new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Body       = bodyResponse,
                Headers    = new Dictionary <string, string> {
                    { "Content-Type", "application/json" }
                }
            };

            return(response);
        }
Exemplo n.º 4
0
        public DataConnectionViewModel DirectMSSQLQuery()
        {
            byte[] decodedBytes = Convert.FromBase64String(encodedQuery);
            string query        = System.Text.Encoding.UTF8.GetString(decodedBytes);
            DataConnectionViewModel ConResult = new DataConnectionViewModel();
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            string ConnStr = Helpers.GetMSSQLConnectionString();

            Console.WriteLine("ConnectionString=" + ConnStr);

            using (SqlConnection con = new SqlConnection(ConnStr)) {
                con.Open();

                Console.WriteLine("connection open");

                try {
                    var cmd    = new SqlCommand(query, con);
                    var result = cmd.ExecuteScalar();
                    ConResult.IPAddress = result.ToString();
                    stopwatch.Stop();
                    ConResult.ElapsedTime      = stopwatch.Elapsed.ToString();
                    ConResult.ElapsedTimeMilli = stopwatch.Elapsed.Milliseconds.ToString();

                    Console.WriteLine("Connection Succeeded! Time=" + ConResult.ElapsedTime);

                    string output = JsonConvert.SerializeObject(ConResult);
                    Console.WriteLine("ConResult=" + output);
                    calls++;
                    ConResult.Calls    = calls;
                    ConResult.CallType = "Direct";
                    return(ConResult);
                }
                catch (System.Data.Common.DbException ex) {
                    Console.WriteLine("Connection failed, message=" + ex.Message);
                    return(ConResult);
                }
            }
        }
Exemplo n.º 5
0
        static async Task <DataConnectionViewModel> PoolManagerMSSQLQuery()
        {
            Console.WriteLine("Load Environment Variables");
            string baseUrl = Environment.GetEnvironmentVariable("baseUrl");

            DataConnectionViewModel ConResult = new DataConnectionViewModel();

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            using (HttpClient client = new HttpClient()) {
                Console.WriteLine("calling url: " + baseUrl + encodedQuery);

                using (HttpResponseMessage res = await client.GetAsync(baseUrl + encodedQuery)) {
                    using (HttpContent content = res.Content) {
                        string data = await content.ReadAsStringAsync();

                        stopwatch.Stop();

                        if (data != null)
                        {
                            Console.WriteLine("Call Suceeded:" + data);
                            ConResult = JsonConvert.DeserializeObject <DataConnectionViewModel>(data);
                            ConResult.LamElapsedTime      = stopwatch.Elapsed.ToString();
                            ConResult.LamElapsedTimeMilli = (Convert.ToDecimal(stopwatch.Elapsed.Ticks) / 10000).ToString();
                            calls++;
                            ConResult.Calls    = calls;
                            ConResult.CallType = "Pool";
                        }
                        else
                        {
                            Console.WriteLine("No data returned");
                        }
                    }
                }
            }
            Console.WriteLine("Return Results");
            return(ConResult);
        }
Exemplo n.º 6
0
        public VocabularySyncViewModel(ConnectionInfo server = new ConnectionInfo())
        {
            Contract.Requires(Constants.IsClient);

            Title = "Словари";

            LocalConnectionString = Nhib.ConnectionString;
            LocalProviderName     = LocalConnectionString.Contains(".sdf") ? Constants.SqlCeProvider : Constants.SqlServerProvider;

            Remote = new DataConnectionViewModel(server);
            Remote.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "ConnectionString" || e.PropertyName == "ProviderName")
                {
                    TryGetAvailableVocs();
                }
            };
            Poster.MessagePosted += syncer_MessagePosted;
            Syncer.SyncEnded     += syncer_SyncEnded;

            TryGetAvailableVocs();
        }
Exemplo n.º 7
0
        static async Task <decimal> runTest(int CurCount, string runType)
        {
            //string baseUrl = Environment.GetEnvironmentVariable("baseUrl");
            string baseUrl = "https://6l5g0zi2xi.execute-api.us-east-1.amazonaws.com/Prod";

            if (runType == "Pool")
            {
                baseUrl += "?pool=webapi";
            }
            decimal returnValue = 0;

            using (HttpClient client = new HttpClient()) {
                //Setting up the response...

                using (HttpResponseMessage res = await client.GetAsync(baseUrl)) {
                    using (HttpContent content = res.Content) {
                        string data = await content.ReadAsStringAsync();

                        if (data != null)
                        {
                            DataConnectionViewModel DC = JsonConvert.DeserializeObject <DataConnectionViewModel>(data);
                            string singleRun           = $"{DateTime.Now.Month}/{DateTime.Now.Day} {DateTime.Now.Hour}.{DateTime.Now.Minute}.{DateTime.Now.Second}.{DateTime.Now.Millisecond}, {DC.LamCalls}, {DC.LamElapsedTime}, {DC.LamElapsedTimeMilli}, {DC.ElapsedTime}, {DC.ElapsedTimeMilli}, {DC.IPAddress}";
                            Console.WriteLine($" {CurCount + 1}...{singleRun}");
                            logResults += singleRun + "\n";
                            returnValue = Convert.ToDecimal(DC.LamElapsedTimeMilli);
                            //runValues.Add(returnValue);
                        }
                        else
                        {
                            Console.WriteLine("No data returned");
                        }
                    }
                }
            }
            return(returnValue);
        }