Пример #1
0
        public static async Task<ServiceTable> GetServiceTableAsync(string ConnString, int ServiceTableID, TaskLoggingHelper Log)
        {
            ServiceTable result = new ServiceTable();

            SqlConnection conn = new SqlConnection(ConnString);
            conn.Open();

            SqlCommand cmd = new SqlCommand("select ServiceTableID, DescServiceTable, Value, CreationDate, StringField1, StringField2 " +
                    "from ServiceTable where ServiceTableID = @ServiceTableID", conn);

            using (conn)
            {
                SqlParameter p1 = cmd.Parameters.Add("@ServiceTableID", SqlDbType.Int);
                p1.Value = ServiceTableID;

                SqlDataReader rd = await cmd.ExecuteReaderAsync();
                rd.Read();
                using (rd)
                {
                    result.ServiceTableID = rd.GetInt32(0);
                    result.DescServiceTable = rd.GetString(1);
                    result.Value = (float)rd.GetDouble(2);
                    result.CreationDate = rd.GetDateTime(3);
                    result.StringField1 = rd.GetString(4);
                    result.StringField2 = rd.GetString(5);
                }
            }

            if (Log != null)
                Log.LogMessage("Getting ServiceTableID: " + ServiceTableID.ToString());

            return result;
        }
        public override bool Execute()
        {
            Binding binding;

            if (this.EndpointType == "http")
            {
                binding = new BasicHttpBinding();
                ((BasicHttpBinding)binding).MessageEncoding = WSMessageEncoding.Text;
                ((BasicHttpBinding)binding).TextEncoding = Encoding.UTF8;
                ((BasicHttpBinding)binding).TransferMode = TransferMode.Buffered;
                ((BasicHttpBinding)binding).Security.Mode = BasicHttpSecurityMode.None;
            }
            else if (this.EndpointType == "nettcp")
            {
                binding = new NetTcpBinding();
                ((NetTcpBinding)binding).MaxReceivedMessageSize = 1024 * 1024;
                ((NetTcpBinding)binding).Security.Mode = SecurityMode.None;
                ((NetTcpBinding)binding).CloseTimeout = new TimeSpan(0, 1, 0);
                ((NetTcpBinding)binding).OpenTimeout = new TimeSpan(0, 1, 10);
                ((NetTcpBinding)binding).ReceiveTimeout = new TimeSpan(0, 1, 10);
                ((NetTcpBinding)binding).SendTimeout = new TimeSpan(0, 1, 10);
            }
            else
                throw new ArgumentException("Invalid value for EndpointType. Expected: http, nettcp");
            EndpointAddress address = new EndpointAddress(new Uri(WebServiceUri));

            IntegrationTestsService.IntegrationTestsServiceClient client = new IntegrationTestsService.IntegrationTestsServiceClient(binding, address);

            Log.LogMessage("Doing " + TotalRequests.ToString() + " calls");

            Stopwatch watch = new Stopwatch();
            watch.Start();

            for (int i = 1; i <= TotalRequests; i++)
            {
                ServiceTable t = null;
                bool tryAgain = true;
                while (tryAgain)
                {
                    try
                    {
                        t = client.GetServiceTable(i);
                        tryAgain = false;
                    }
                    catch (EndpointNotFoundException)
                    {
                        Thread.Sleep(100);
                        t = client.GetServiceTable(i);
                        tryAgain = true;
                    }
                }

                ServiceTable t2 = new ServiceTable();
                t2.ServiceTableID = t.ServiceTableID;
                t2.DescServiceTable = t.DescServiceTable;
                t2.Value = t.Value;
                t2.CreationDate = t.CreationDate;
                t2.StringField1 = t.StringField1;
                t2.StringField2 = t.StringField2;

                DAO.ProcessServiceTable(ConnString, t2);
            }

            watch.Stop();
            Log.LogMessage("Total processing time: " + watch.Elapsed.TotalSeconds.ToString("0.00") + " seconds");

            return true;
        }
        public override bool Execute()
        {
            Binding binding;

            if (this.EndpointType == "http")
            {
                binding = new BasicHttpBinding();
                ((BasicHttpBinding)binding).MaxReceivedMessageSize = 2048 * 1024;
            }
            else if (this.EndpointType == "nettcp")
            {
                binding = new NetTcpBinding();
                ((NetTcpBinding)binding).MaxReceivedMessageSize = 1024 * 1024;
                ((NetTcpBinding)binding).Security.Mode = SecurityMode.None;
                ((NetTcpBinding)binding).CloseTimeout = new TimeSpan(0, 0, 10);
                ((NetTcpBinding)binding).OpenTimeout = new TimeSpan(0, 0, 10);
                ((NetTcpBinding)binding).ReceiveTimeout = new TimeSpan(0, 0, 10);
                ((NetTcpBinding)binding).SendTimeout = new TimeSpan(0, 0, 10);
            }
            else
                throw new ArgumentException("Invalid value for EndpointType. Expected: http, nettcp");
            EndpointAddress address = new EndpointAddress(new Uri(WebServiceUri));

            IntegrationTestsService.IntegrationTestsServiceClient client = new IntegrationTestsService.IntegrationTestsServiceClient(binding, address);

            Log.LogMessage("Doing " + TotalBatches.ToString() + " batch calls with " + BatchSize.ToString() + " itens each");

            Stopwatch watch = new Stopwatch();
            watch.Start();

            int count = 1;
            for (int i = 0; i < TotalBatches; i++)
            {
                ServiceTable[] stArray = client.GetServiceTables(count, count + (BatchSize - 1));

                foreach (ServiceTable t in stArray)
                {

                    ServiceTable t2 = new ServiceTable();
                    t2.ServiceTableID = t.ServiceTableID;
                    t2.DescServiceTable = t.DescServiceTable;
                    t2.Value = t.Value;
                    t2.CreationDate = t.CreationDate;
                    t2.StringField1 = t.StringField1;
                    t2.StringField2 = t.StringField2;

                    DAO.ProcessServiceTable(ConnString, t2);
                }
                count += BatchSize;
            }

            watch.Stop();
            Log.LogMessage("Total processing time: " + watch.Elapsed.TotalSeconds.ToString("0.00") + " seconds");

            return true;
        }
Пример #4
0
		public static void ProcessServiceTable(string ConnString, ServiceTable table)
		{
			SqlConnection conn = new SqlConnection(ConnString);
			conn.Open();

			SqlCommand cmd = new SqlCommand("insert into ClientTable (ClientTableID, DescClientTable, Value, CreationDate, StringField1, StringField2)" +
					"values (@ClientTableID, @DescClientTable, @Value, @CreationDate, @StringField1, @StringField2)", conn);
            cmd.CommandTimeout = 0;

			using (conn)
			{

				SqlParameter p1 = cmd.Parameters.Add("@ClientTableID", SqlDbType.Int);
				SqlParameter p2 = cmd.Parameters.Add("@DescClientTable", SqlDbType.VarChar, 200);
				SqlParameter p3 = cmd.Parameters.Add("@Value", SqlDbType.Float);
				SqlParameter p4 = cmd.Parameters.Add("@CreationDate", SqlDbType.DateTime);
				SqlParameter p5 = cmd.Parameters.Add("@StringField1", SqlDbType.VarChar, 200);
				SqlParameter p6 = cmd.Parameters.Add("@StringField2", SqlDbType.VarChar, 200);

				p1.Value = table.ServiceTableID;
				p2.Value = table.DescServiceTable;
				p3.Value = table.Value;
				p4.Value = table.CreationDate;
				p5.Value = table.StringField1;
				p6.Value = table.StringField2;

				cmd.ExecuteNonQuery();
			}
		}
Пример #5
0
		public static void ClearClientTable(string ConnString)
		{
			ServiceTable result = new ServiceTable();

			SqlConnection conn = new SqlConnection(ConnString);		
			conn.Open();

			SqlCommand cmd = new SqlCommand("delete from ClientTable", conn);
			cmd.CommandTimeout = 180;

			using (conn)
				cmd.ExecuteNonQuery();
		}
Пример #6
0
        public static void ImportarStream(string connString, Stream stream, TaskLoggingHelper log)
        {
            XmlTextReader rd = new XmlTextReader(stream);

            CultureInfo c = new CultureInfo("pt-BR");
            c.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy hh:mm:ss";

            bool first = true;

            using (rd)
            {
                rd.Read();
                rd.Read();
                rd.ReadStartElement("table");
                while (rd.Name == "record")
                {
                    rd.ReadStartElement("record");
                    ServiceTable st = new ServiceTable();
                    st.ServiceTableID = Convert.ToInt32(rd.ReadElementContentAsString("ServiceTableID", ""));
                    if (first)
                    {
                        if (log != null)
                            log.LogMessage("Importing ID " + st.ServiceTableID.ToString());
                        first = false;
                    }
                    st.DescServiceTable = rd.ReadElementContentAsString("DescServiceTable", "");
                    st.Value = Convert.ToSingle(rd.ReadElementContentAsString("Value", ""));
                    st.CreationDate = Convert.ToDateTime(rd.ReadElementContentAsString("CreationDate", ""), c.DateTimeFormat);
                    st.StringField1 = rd.ReadElementContentAsString("StringField1", "");
                    st.StringField2 = rd.ReadElementContentAsString("StringField2", "");
                    rd.ReadEndElement();

                    /*if (Log != null)
                        Log.LogMessage("ServiceTableID: " + st.ServiceTableID.ToString());*/

                    DAO.ProcessServiceTable(connString, st);
                }
                rd.ReadEndElement();
            }
        }
        private void ThreadJob(IntegrationTestsService.IntegrationTestsServiceClient client, ConcurrentQueue<ManualResetEvent> waitObjectQueue, int start, int end)
        {
            ManualResetEvent e = new ManualResetEvent(false);
            waitObjectQueue.Enqueue(e);

            ServiceTable[] stArray = client.GetServiceTables(start, end);
            foreach (ServiceTable t in stArray)
            {

                ServiceTable t2 = new ServiceTable();
                t2.ServiceTableID = t.ServiceTableID;
                t2.DescServiceTable = t.DescServiceTable;
                t2.Value = t.Value;
                t2.CreationDate = t.CreationDate;
                t2.StringField1 = t.StringField1;
                t2.StringField2 = t.StringField2;

                DAO.ProcessServiceTable(ConnString, t2);
            }
            e.Set();
        }
        public override bool Execute()
        {
            Binding binding;

            if (this.EndpointType == "http")
            {
                /*binding = new BasicHttpBinding();
                ((BasicHttpBinding)binding).MaxReceivedMessageSize = 2048 * 1024;*/
                binding = new CustomBinding();
                ((CustomBinding)binding).Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8));
                ((CustomBinding)binding).SendTimeout = new TimeSpan(0, 50, 0);
                ((CustomBinding)binding).ReceiveTimeout = new TimeSpan(0, 50, 0);
                ((CustomBinding)binding).OpenTimeout = new TimeSpan(0, 50, 0);
                ((CustomBinding)binding).CloseTimeout = new TimeSpan(0, 50, 0);
                HttpTransportBindingElement element = new HttpTransportBindingElement();
                element.MaxReceivedMessageSize = 2048 * 1024;
                element.KeepAliveEnabled = false;
                element.RequestInitializationTimeout = new TimeSpan(1, 0, 0);
                ((CustomBinding)binding).Elements.Add(element);
            }
            else if (this.EndpointType == "nettcp")
            {
                binding = new NetTcpBinding();
                ((NetTcpBinding)binding).MaxReceivedMessageSize = 1024 * 1024;
                ((NetTcpBinding)binding).Security.Mode = SecurityMode.None;
                ((NetTcpBinding)binding).CloseTimeout = new TimeSpan(0, 50, 10);
                ((NetTcpBinding)binding).OpenTimeout = new TimeSpan(0, 50, 10);
                ((NetTcpBinding)binding).ReceiveTimeout = new TimeSpan(0, 50, 10);
                ((NetTcpBinding)binding).SendTimeout = new TimeSpan(0, 50, 10);
            }
            else
                throw new ArgumentException("Invalid value for EndpointType. Expected: http, nettcp");
            EndpointAddress address = new EndpointAddress(new Uri(WebServiceUri));

            IntegrationTestsService.IntegrationTestsServiceClient client = new IntegrationTestsService.IntegrationTestsServiceClient(binding, address);

            Log.LogMessage("Doing " + TotalBatches.ToString() + " batch calls with " + BatchSize.ToString() + " itens each");

            Stopwatch watch = new Stopwatch();
            watch.Start();

            int count = 1;
            Queue<Task<ServiceTable[]>> tasks = new Queue<Task<ServiceTable[]>>();
            for (int i = 0; i < TotalBatches; i++)
            {
                if (UseSynchronousServer)
                    tasks.Enqueue(client.GetServiceTablesAsync(count, count + (BatchSize - 1)));
                else
                    tasks.Enqueue(client.GetServiceTablesAsynchronousAsync(count, count + (BatchSize - 1)));
                count += BatchSize;

            }

            Queue<Task> queue2 = new Queue<Task>();

            while (tasks.Count > 0)
            {
                Task<ServiceTable[]> task = tasks.Dequeue();

                task.Wait();
                ServiceTable[] stArray = task.Result;

                foreach (ServiceTable t in stArray)
                {

                    ServiceTable t2 = new ServiceTable();
                    t2.ServiceTableID = t.ServiceTableID;
                    t2.DescServiceTable = t.DescServiceTable;
                    t2.Value = t.Value;
                    t2.CreationDate = t.CreationDate;
                    t2.StringField1 = t.StringField1;
                    t2.StringField2 = t.StringField2;

                    queue2.Enqueue(DAO.ProcessServiceTableAsync(ConnString, t2));
                }
            }

            while (queue2.Count > 0)
                queue2.Dequeue().Wait();

            watch.Stop();
            Log.LogMessage("Total processing time: " + watch.Elapsed.TotalSeconds.ToString("0.00") + " seconds");

            return true;
        }