| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555 |
- using MassTransit;
- using MassTransit.Util;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Threading.Tasks;
- namespace Message.MessageTypes
- {
- public class RabbitMq
- {
- private readonly IRequestClient<ISimpleRequest, ISimpleResponse> _requestClient;
- public RabbitMq(IRequestClient<ISimpleRequest, ISimpleResponse> requestClient)
- {
- _requestClient = requestClient;
- }
- //CommonRepository oCommonRepository = new CommonRepository();
- //public bool SendMq(string Tranid, string UserId, string AppType, string StageType, string Enviroment)
- //{
- // //oCommonRepository.WriteLog("SendMq:", "Main App");
- // string ServiceAddress = "";
- // string RabbitMQHost = "";
- // string userName = "";
- // string password = "";
- // using (IDbConnection dbConnection = ConnectionBase.Connection)
- // {
- // dbConnection.Open();
- // DynamicParameters param = new DynamicParameters();
- // param.Add("p_tranid", dbType: DbType.Int32, value: Tranid, direction: ParameterDirection.Input);
- // param.Add("p_userid", dbType: DbType.Int32, value: UserId, direction: ParameterDirection.Input);
- // param.Add("p_status", dbType: DbType.String, value: "P", direction: ParameterDirection.Input);
- // param.Add("p_option", dbType: DbType.String, value: AppType, direction: ParameterDirection.Input);
- // var Checkinapp = dbConnection.Query<string>("public.spusrlottranupdatev1", param, commandType: CommandType.StoredProcedure).ToList();
- // if (Checkinapp != null)
- // {
- // // var i_Checkinapp = JsonConvert.DeserializeObject<object>(Checkinapp[0].ToString());
- // // checkinprocess obj = JsonConvert.DeserializeObject<checkinprocess>(Checkinapp[0].ToString());
- // var next_ordernodata10 = JsonConvert.DeserializeObject<object>(Checkinapp[0].ToString());
- // JArray dtparallelnextstage10 = JArray.Parse(next_ordernodata10.ToString());
- // checkinprocess obj = JsonConvert.DeserializeObject<checkinprocess>(dtparallelnextstage10[0].ToString());
- // if (obj.ipaddress != null)
- // {
- // ServiceAddress = obj.ipaddress + "" + "/" + obj.root_path;
- // RabbitMQHost = obj.ipaddress;
- // userName = obj.username;
- // password = obj.password;
- // StageType = obj.stagetype;
- // }
- // if (StageType != "server")
- // return false;
- // }
- // }
- // var datetime = DateTime.Now.ToString();
- // var message = new PublishMessage(datetime, Tranid, UserId, AppType, StageType, Startup.Configuration.GetValue<string>("AppSettings:envirnmentname"), null, "");
- // var task = Publish(message);
- // if (task.Result != true)
- // {
- // return false;
- // }
- // return true;
- //}
- //public bool SendMq_WorkArea(string Tranid, string UserId, string AppType, string StageType, string Enviroment, string cflag, string extravalues, string Batch="", string PublicationType="", string comments="", string PublicationID = "" )
- //{
- // string RabbitMQHost = "";
- // oCommonRepository.WriteLog("RabbitMq", "SendMq_WorkArea");
- // using (IDbConnection dbConnection = ConnectionBase.Connection)
- // {
- // dbConnection.Open();
- // DynamicParameters param = new DynamicParameters();
- // param.Add("p_tranid", dbType: DbType.Int32, value: Convert.ToInt32(Tranid), direction: ParameterDirection.Input);
- // param.Add("p_userid", dbType: DbType.Int32, value: Convert.ToInt32(UserId), direction: ParameterDirection.Input);
- // param.Add("p_status", dbType: DbType.String, value: "P", direction: ParameterDirection.Input);
- // param.Add("p_option", dbType: DbType.String, value: AppType, direction: ParameterDirection.Input);
- // var Checkinapp = dbConnection.Query<string>("public.spusrlottranupdatev1", param, commandType: CommandType.StoredProcedure).ToList();
- // if (Checkinapp != null)
- // {
- // oCommonRepository.WriteLog("SendMq_WorkArea", Checkinapp[0].ToString());
- // var next_ordernodata10 = JsonConvert.DeserializeObject<object>(Checkinapp[0].ToString());
- // JArray dtparallelnextstage10 = JArray.Parse(next_ordernodata10.ToString());
- // checkinprocess obj = JsonConvert.DeserializeObject<checkinprocess>(dtparallelnextstage10[0]["json_build_object"].ToString());
- // RabbitMQHost = Startup.Configuration.GetValue<string>("AppSettings:chechoutqueue_path");
- // oCommonRepository.WriteLog("SendMq_WorkArea:RabbitMQHost", RabbitMQHost);
- // if (obj.stagetype != null)
- // {
- // StageType = obj.stagetype;
- // }
- // }
- // }
- // oCommonRepository.WriteLog("SendMq_WorkArea:Tranid" + Tranid, AppType);
- // var datetime = DateTime.Now.ToString();
- // var message = new PublishMessage(datetime, Tranid, UserId, AppType, StageType, Startup.Configuration.GetValue<string>("AppSettings:envirnmentname"), extravalues, cflag, Batch, PublicationType, comments, PublicationID);
- // var task = Publish(message);
- // if (task.Result != true)
- // {
- // return false;
- // }
- // return true;
- //}
- public bool SendMq_StageComplete(string Tranid, string UserId, string AppType, string StageType, string Enviroment, string cflag, string extravalues)
- {
- //string exchangeName = Startup.Configuration.GetValue<string>("AppSettings:chechoutqueue_exchange");
- Enviroment = ConfigurationManager.AppSettings["Environment"];
- var datetime = DateTime.Now.ToString();
- var message = new PublishMessage("", Tranid, UserId, AppType, StageType, Enviroment,null, cflag);
- var task = Publish(message);
- if (task.Result != true)
- {
- return false;
- }
- return true;
- }
- public async Task<bool> Publish(PublishMessage message)
- {
- //string ServiceAddress = Startup.Configuration.GetValue<string>("AppSettings:chechoutqueue_path") + "" + "/" + Startup.Configuration.GetValue<string>("AppSettings:chechoutqueue");
- //string QueueName = Startup.Configuration.GetValue<string>("AppSettings:chechoutqueue");
- //string RabbitMQHost = Startup.Configuration.GetValue<string>("AppSettings:chechoutqueue_path");
- string ServiceAddress = ConfigurationManager.AppSettings["chechoutqueue_path"] + "" + "/" + ConfigurationManager.AppSettings["chechoutqueue"];
- string QueueName = ConfigurationManager.AppSettings["chechoutqueue"];
- string RabbitMQHost = ConfigurationManager.AppSettings["chechoutqueue_path"];
- string userName = "admin"; //obj.username;
- string password = "admin"; //obj.password;
- var _busControl = Bus.Factory.CreateUsingRabbitMq(x =>
- {
- var host = x.Host(new Uri(RabbitMQHost), h =>
- {
- h.Username(userName);
- h.Password(password);
- });
- });
- try
- {
- //TaskUtil.Await(() => _busControl.StartAsync());
- Uri ServiceAddress_uri = new Uri(ServiceAddress);
- var endPoint = await _busControl.GetSendEndpoint(ServiceAddress_uri);
- await endPoint.Send(message);
- //await _busControl.Publish(message);
- }
- catch (Exception ex)
- {
- //oCommonRepository.ErrorLog(ex);
- // Console.WriteLine($"Error publishing message: {ex.Message}");
- return false;
- }
- finally
- {
- _busControl.Stop();
- }
- return true;
- }
- //public async Task<bool> Publish_MailQueue(PublishMessage message)
- //{
- // string ServiceAddress = Startup.Configuration.GetValue<string>("AppSettings:mailqueue_path") + "" + "/" + Startup.Configuration.GetValue<string>("AppSettings:mailqueue");
- // string RabbitMQHost = Startup.Configuration.GetValue<string>("AppSettings:mailqueue_path");
- // string userName = "admin"; //obj.username;
- // string password = "admin"; //obj.password;
- // var _busControl = Bus.Factory.CreateUsingRabbitMq(x =>
- // {
- // var host = x.Host(new Uri(RabbitMQHost), h =>
- // {
- // h.Username(userName);
- // h.Password(password);
- // });
- // });
- // try
- // {
- // TaskUtil.Await(() => _busControl.StartAsync());
- // Uri ServiceAddress_uri = new Uri(ServiceAddress);
- // var endPoint = await _busControl.GetSendEndpoint(ServiceAddress_uri);
- // await endPoint.Send(message);
- // // _busControl.Publish(message);
- // }
- // catch (Exception ex)
- // {
- // oCommonRepository.ErrorLog(ex);
- // return false;
- // }
- // finally
- // {
- // _busControl.Stop();
- // }
- // return true;
- //}
- //public bool SendMq_Stage_Call_Web(string Tranid, string UserId, string AppType, string StageType, string Enviroment, string cflag, object extravalues = null)
- //{
- // var datetime = DateTime.Now.ToString();
- // var message = new PublishMessage(datetime, Tranid, UserId, AppType, StageType, Startup.Configuration.GetValue<string>("AppSettings:envirnmentname"), extravalues, cflag);
- // var task = Publish(message);
- // if (task.Result != true)
- // {
- // return false;
- // }
- // return true;
- //}
- //public bool SendMqMail(string Tranid, string JobWorkflowid, string flag, string curtranid, string userid)
- //{
- // oCommonRepository.WriteLog("SendMqMail started:", "RabbitMq");
- // DynamicParams dynamicparams = new DynamicParams()
- // {
- // jobworkflowid = JobWorkflowid,
- // nexttranid = curtranid
- // };
- // List<DynamicParams> dynamicparams_ = new List<DynamicParams>();
- // dynamicparams_.Add(dynamicparams);
- // var datetime = DateTime.Now.ToString();
- // var message = new PublishMessage(DateTime.Now.ToString(), Tranid, userid, "", "", Startup.Configuration.GetValue<string>("AppSettings:envirnmentname"), dynamicparams, flag);
- // oCommonRepository.WriteLog("JobWorkflowid:" + JobWorkflowid, "RabbitMq-SendMqMail");
- // oCommonRepository.WriteLog("curtranid:" + curtranid, "RabbitMq-SendMqMail");
- // var task = Publish_MailQueue(message);
- // if (task.Result != true)
- // {
- // return false;
- // }
- // return true;
- //}
- //public bool SendMqTest(string Tranid, string JobWorkflowid, string flag, string curtranid, string userid)
- //{
- // DynamicParams dynamicparams = new DynamicParams()
- // {
- // jobworkflowid = JobWorkflowid,
- // nexttranid = curtranid
- // };
- // List<DynamicParams> dynamicparams_ = new List<DynamicParams>();
- // dynamicparams_.Add(dynamicparams);
- // var message = new PublishMessage(DateTime.Now.ToString(), "123", userid, "", "", Startup.Configuration.GetValue<string>("AppSettings:envirnmentname"), dynamicparams, flag);
- // oCommonRepository.WriteLog("JobWorkflowid:" + JobWorkflowid, "RabbitMq-SendMqMail");
- // oCommonRepository.WriteLog("curtranid:" + curtranid, "RabbitMq-SendMqMail");
- // var task = Publish_MailQueue(message);
- // if (task.Result != true)
- // {
- // return false;
- // }
- // return true;
- //}
- public IRequestClient<ISimpleRequest, ISimpleResponse> CreateRequestClient(IBusControl busControl, string ServiceAddress)
- {
- var serviceAddress = new Uri(ServiceAddress);
- IRequestClient<ISimpleRequest, ISimpleResponse> client =
- busControl.CreateRequestClient<ISimpleRequest, ISimpleResponse>(serviceAddress, TimeSpan.FromSeconds(30));
- return client;
- }
- public IBusControl CreateBus(string RabbitMQHost, string userName, string password)
- {
- var currentBus = Bus.Factory.CreateUsingRabbitMq(x =>
- {
- var Host = x.Host(new Uri(RabbitMQHost), h =>
- {
- h.Username(userName);
- h.Password(password);
- });
- });
- return currentBus;
- }
- static void ConfigureLogger()
- {
- // const string logConfig = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
- //<log4net>
- // <root>
- // <level value=""INFO"" />
- // <appender-ref ref=""console"" />
- // </root>
- // <appender name=""console"" type=""log4net.Appender.ColoredConsoleAppender"">
- // <layout type=""log4net.Layout.PatternLayout"">
- // <conversionPattern value=""%m%n"" />
- // </layout>
- // </appender>
- //</log4net>";
- // using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(logConfig)))
- // {
- // XmlConfigurator.Configure(stream);
- // }
- }
- }
- //public class PublishMessage
- //{
- // public PublishMessage(string customerId, string Tranid, string UserId, string AppType, string StageType, string Enviroment, object DynamicList, string Flag)
- // {
- // _customerId = customerId;
- // _TransId = Tranid;
- // _UserId = UserId;
- // _AppType = AppType;
- // _StageType = StageType;
- // _Enviroment = Enviroment;
- // _timestamp = DateTime.UtcNow;
- // _DynamicList = DynamicList;
- // _Flag = Flag;
- // }
- // public string _customerId { get; set; }
- // public string _TransId { get; set; }
- // public string _UserId { get; set; }
- // public string _AppType { get; set; }
- // public string _StageType { get; set; }
- // public string _Enviroment { get; set; }
- // public DateTime _timestamp { get; set; }
- // public object _DynamicList { get; set; }
- // public string _Flag { get; set; }
- //}
- class SimpleRequest : ISimpleRequest
- {
- readonly string _customerId;
- readonly string _TransId;
- readonly string _UserId;
- readonly string _AppType;
- readonly string _StageType;
- readonly string _Enviroment;
- readonly DateTime _timestamp;
- readonly object _DynamicList;
- readonly string _Flag;
- public SimpleRequest(string customerId, string Tranid, string UserId, string AppType, string StageType, string Enviroment, object DynamicList, string Flag)
- {
- _customerId = customerId;
- _TransId = Tranid;
- _UserId = UserId;
- _AppType = AppType;
- _StageType = StageType;
- _Enviroment = Enviroment;
- _timestamp = DateTime.UtcNow;
- _DynamicList = DynamicList;
- _Flag = Flag;
- }
- public DateTime Timestamp
- {
- get { return _timestamp; }
- }
- public string TransId
- {
- get { return _TransId; }
- }
- public string CustomerId
- {
- get { return _customerId; }
- }
- public string UserId
- {
- get { return _UserId; }
- }
- public string AppType
- {
- get { return _AppType; }
- }
- public string StageType
- {
- get { return _StageType; }
- }
- public string Enviroment
- {
- get { return _Enviroment; }
- }
- public object DynamicList
- {
- get { return _DynamicList; }
- }
- public string Flag
- {
- get { return _Flag; }
- }
- string ISimpleRequest.TransId
- {
- get
- {
- throw new NotImplementedException();
- }
- set
- {
- throw new NotImplementedException();
- }
- }
- string ISimpleRequest.UserId
- {
- get
- {
- throw new NotImplementedException();
- }
- set
- {
- throw new NotImplementedException();
- }
- }
- string ISimpleRequest.AppType
- {
- get
- {
- throw new NotImplementedException();
- }
- set
- {
- throw new NotImplementedException();
- }
- }
- string ISimpleRequest.StageType
- {
- get
- {
- throw new NotImplementedException();
- }
- set
- {
- throw new NotImplementedException();
- }
- }
- string ISimpleRequest.Enviroment
- {
- get
- {
- throw new NotImplementedException();
- }
- set
- {
- throw new NotImplementedException();
- }
- }
- object ISimpleRequest.DynamicList
- {
- get
- {
- throw new NotImplementedException();
- }
- set
- {
- throw new NotImplementedException();
- }
- }
- string ISimpleRequest.Flag
- {
- get
- {
- throw new NotImplementedException();
- }
- set
- {
- throw new NotImplementedException();
- }
- }
- }
- public class checkinprocess
- {
- public Int32? jobworkflowid { get; set; }
- public Int32? isexe { get; set; }
- public Int32? isservice { get; set; }
- public Int32? applicationserverid { get; set; }
- public string paramss { get; set; }
- public string ipaddress { get; set; }
- public string appname { get; set; }
- public string stagetype { get; set; }
- public string file_movement { get; set; }
- public string root_path { get; set; }
- public Int32? stageorder { get; set; }
- public string checkout_app { get; set; }
- public Int32? appid { get; set; }
- public string username { get; set; }
- public string password { get; set; }
- }
- public interface ISimpleRequest
- {
- DateTime Timestamp { get; }
- string CustomerId { get; }
- string TransId { get; set; }
- string UserId { get; set; }
- string AppType { get; set; }
- string StageType { get; set; }
- string Enviroment { get; set; }
- object DynamicList { get; set; }
- string Flag { get; set; }
- }
- public interface ISimpleResponse
- {
- string CusomerName { get; }
- }
- public class DynamicParams
- {
- public string jobworkflowid { get; set; }
- public string nexttranid { get; set; }
- public string extravalues { get; set; }
- }
- }
|