Ejemplo n.º 1
0
        public bool SetBookingRequestComplete(BookingResponse bookingResponse, IQueueConfig queueConfig)
        {
            try
            {
                try
                {
                    string fileName = bookingResponse.ReservationId + ".txt";

                    if (File.Exists(Path.Combine(queueConfig.PendingBookingQueuePath, fileName)))
                    {
                        string queuePathToMove = string.Empty;
                        switch (bookingResponse.BookingStatus)
                        {
                            case BookingStatus.Confirmed:
                                queuePathToMove = queueConfig.ConfirmedBookingQueuePath;
                                break;
                            case BookingStatus.Rejected:
                                queuePathToMove = queueConfig.RejectedNotificationQueuePath;
                                break;
                            case BookingStatus.Booked:
                                queuePathToMove = queueConfig.PendingBookingQueuePath;
                                break;
                            default:
                                queuePathToMove = queueConfig.ErrorQueuePath;
                                break;
                        }

                        // move file to error queue
                        File.Move(Path.Combine(queueConfig.PendingBookingQueuePath, fileName), Path.Combine(queuePathToMove, fileName));

                        return true;
                    }

                }
                catch
                {

                }

            }
            catch
            {
                // todo logging

            }

            return false;
        }
Ejemplo n.º 2
0
        public Entities.BookingRequest GetPendingBookingRequest(IQueueConfig queueConfig)
        {
            while (true)
            {
                try
                {
                    var files = Directory.GetFiles(queueConfig.PendingBookingQueuePath, "*.txt", SearchOption.TopDirectoryOnly);
                    if (files.Count() > 0)
                    {
                        try
                        {
                            XmlSerializer serializer = new XmlSerializer(typeof(BookingRequest));
                            var bookingRequest = (BookingRequest)serializer.Deserialize(File.OpenRead(Path.Combine(queueConfig.PendingBookingQueuePath, files[0])));
                            if (bookingRequest == null)
                            {
                                throw new Exception("Unable to deserialize booking request");
                            }

                            return bookingRequest;

                        }
                        catch
                        {
                            // move file to error queue
                            File.Move(Path.Combine(queueConfig.PendingBookingQueuePath, files[0]), Path.Combine(queueConfig.ErrorQueuePath, files[0]));
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                catch
                {
                    // todo logging

                }
            }

            return null;
        }
Ejemplo n.º 3
0
 private static void Init(IQueueConfig queueConfig, IMessageChannel messageChannel)
 {
     messageChannel.Init(ConfigurationManager.AppSettings.Get("HostName"), queueConfig);
 }
Ejemplo n.º 4
0
        //--- 1
        public QueueWriter(IQueueConfig queueConfig)
        {
            #region AzureServiceBusAMQP CreateConnection
            /// <summary>
            /// Attempt to connect with a valid connection string
            /// </summary>

            /// <param name="UserName">AppSettings.Get("mq.user")</param>
            /// <param name="Password">AppSettings.Get("mq.pass")</param>
            /// <param name="RequestedHeartbeat">30</param>
            /// <param name="Handle<BrokerUnreachableException>()"></param>
            /// <param name="Retry(tries)">5</param>
            /// <returns></returns>

            try
            {
                connectionString = queueConfig.PrimaryConnectionString;
                password         = queueConfig.Password;
                userName         = queueConfig.UserName;



                queueName    = queueConfig.QueueName;
                queueNameNew = queueConfig.QueueNameNew;
                queueNameDel = queueConfig.QueueNameDel;


                Uri uri = ServiceBusEnvironment.CreateServiceUri("sb", userName, string.Empty);

                // Create management credentials
                //---TokenProvider credentials = TokenProvider.CreateSharedAccessSignatureTokenProvider(sasKeyName, sasKeyValue);
                //---Microsoft.ServiceBus.TokenProvider tokenProvider = Microsoft.ServiceBus.TokenProvider.CreateSharedAccessSignatureTokenProvider(nameKey, password);
                Microsoft.ServiceBus.TokenProvider credentials   = Microsoft.ServiceBus.TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", password);
                Microsoft.ServiceBus.TokenProvider tokenProvider = Microsoft.ServiceBus.TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", password);
                NamespaceManager namespaceManager = new NamespaceManager(uri, tokenProvider);

                // Create if not exists new one
                if (namespaceManager.QueueExists(queueName))
                {
                    queueClient = new Microsoft.Azure.ServiceBus.QueueClient(connectionString, queueName, Microsoft.Azure.ServiceBus.ReceiveMode.PeekLock);
                    Debug.WriteLine($"{DateTime.Now.TimeOfDay} : Queue opened successfully.", queueConfig.QueueName);

                    //IQueueClient queueClient = new Microsoft.Azure.ServiceBus.QueueClient(connectionString, queueConfig.QueueName, Microsoft.Azure.ServiceBus.ReceiveMode.PeekLock);
                    //Debug.WriteLine(" Queue opened successfully.", queueConfig.QueueName);
                }
                else
                {
                    //namespaceManager.CreateQueue(queueNameNew);
                    // Configure queue settings.

                    var queueDescription = new QueueDescription(queueNameNew);
                    queueDescription.MaxSizeInMegabytes = 1024;
                    // Setting message TTL to 7 days where as default TTL is 14 days.
                    queueDescription.DefaultMessageTimeToLive = TimeSpan.FromDays(7);
                    //--- https://stackoverflow.com/questions/44720880/cant-create-queue
                    namespaceManager.CreateQueue(new QueueDescription(queueNameNew)
                    {
                        DefaultMessageTimeToLive = TimeSpan.FromDays(7),
                        LockDuration             = TimeSpan.FromSeconds(30),
                        EnablePartitioning       = true,
                        AutoDeleteOnIdle         = TimeSpan.FromDays(1),
                        MaxSizeInMegabytes       = 1024
                    });

                    Debug.WriteLine($"{DateTime.Now.TimeOfDay} : Queue Created successfully. ", queueNameNew);
                }

                //--- ReceiveMessagesAsync().GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                logger.Error($"Tries happened {maxTrials} times. Throwing the exception.{ex}");
                throw;
            }
            #endregion
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 根据配置文件创佳妮队列
 /// </summary>
 /// <param name="config">配置文件</param>
 /// <returns>通信队列</returns>
 public abstract ICommunicationQueue CreateQueue(IQueueConfig config);
Ejemplo n.º 6
0
 /// <summary>
 /// 设置配置信息的路由信息
 /// </summary>
 /// <param name="queueConfig">队列配置信息</param>
 /// <param name="routeingString">路由字符串</param>
 public abstract void SetRouteingString(ref IQueueConfig queueConfig, string routeingString);
Ejemplo n.º 7
0
 /// <summary>
 /// 从队列配置中读取路由字符串信息
 /// </summary>
 /// <param name="queueConfig">队列配置文件</param>
 /// <returns>路由字符串信息</returns>
 public abstract string GetRouteingString(IQueueConfig queueConfig);
Ejemplo n.º 8
0
 //--- 1
 public QueueReader(IQueueConfig queueConfig, ILog logger) /*: base(queueConfig, logger)*/
 {
 }