Пример #1
0
        /// <summary>Runs the local disk space healthcheck.</summary>
        public override void RunHealthcheck()
        {
            var dateTime = DateTime.UtcNow;

            this.SaveRemoteCheckStarted(dateTime);

            var message = new OutGoingMessage
            {
                Parameters = new System.Collections.Generic.Dictionary <string, string>
                {
                    { "DriveName", this._driveName },
                    { "ErrorPercentageThreshold", this._errorPercentageThreshold.ToString() },
                    { "WarningPercentageThreshold", this._warningPercentageThreshold.ToString() }
                },
                TargetInstance = this.TargetInstance,
                ComponentId    = this.InnerItem.ID.Guid,
                EventRaised    = dateTime
            };

            if (Settings.GetSetting("Healthcheck.Remote.Mode").Equals("eventqueue", StringComparison.OrdinalIgnoreCase))
            {
                EventQueueSender.Send(Constants.TemplateNames.RemoteDiskSpaceCheckTemplateName, message);
            }
            else
            {
                MessageBusSender.Send(Constants.TemplateNames.RemoteDiskSpaceCheckTemplateName, message);
            }
        }
        /// <summary>
        /// Runs the healthcheck.
        /// </summary>
        public override void RunHealthcheck()
        {
            var dateTime = DateTime.UtcNow;

            this.SaveRemoteCheckStarted(dateTime);

            var parameters = string.Join("&", Array.ConvertAll(this.Parameters.AllKeys, key => string.Format("{0}={1}", key, this.Parameters[key])));

            var message = new OutGoingMessage
            {
                Parameters = new System.Collections.Generic.Dictionary <string, string>
                {
                    { "Type", this.Type },
                    { "Parameters", this.InnerItem["Parameters"] }
                },
                TargetInstance = this.TargetInstance,
                ComponentId    = this.InnerItem.ID.Guid,
                EventRaised    = dateTime
            };

            if (Settings.GetSetting("Healthcheck.Remote.Mode").Equals("eventqueue", StringComparison.OrdinalIgnoreCase))
            {
                EventQueueSender.Send(Constants.TemplateNames.RemoteCustomHealthcheckTemplateName, message);
            }
            else
            {
                MessageBusSender.Send(Constants.TemplateNames.RemoteCustomHealthcheckTemplateName, message);
            }
        }
        /// <summary>
        /// Runs the healthcheck.
        /// </summary>
        public override void RunHealthcheck()
        {
            var dateTime = DateTime.UtcNow;

            this.SaveRemoteCheckStarted(dateTime);

            var message = new OutGoingMessage
            {
                Parameters = new System.Collections.Generic.Dictionary <string, string>
                {
                    { "XConnectApiConnectionStringKey", this.XConnectApiConnectionStringKey },
                    { "XConnectApiCertificateConnectionStringKey", this.XConnectApiCertificateConnectionStringKey },
                    { "Warn Before", this.WarnBefore.ToString() }
                },
                TargetInstance = this.TargetInstance,
                ComponentId    = this.InnerItem.ID.Guid,
                EventRaised    = dateTime
            };

            if (Settings.GetSetting("Healthcheck.Remote.Mode").Equals("eventqueue", StringComparison.OrdinalIgnoreCase))
            {
                EventQueueSender.Send(Constants.TemplateNames.RemoteXConnectApiCheckTemplateName, message);
            }
            else
            {
                MessageBusSender.Send(Constants.TemplateNames.RemoteXConnectApiCheckTemplateName, message);
            }
        }
        /// <summary>
        /// Runs the healthcheck.
        /// </summary>
        public override void RunHealthcheck()
        {
            var dateTime = DateTime.UtcNow;

            this.SaveRemoteCheckStarted(dateTime);

            if (this.LastCheckTime == DateTime.MinValue)
            {
                this.LastCheckTime = DateTime.Now.AddDays(-this.NumberOfDaysToCheck);
            }
            var message = new OutGoingMessage
            {
                Parameters = new System.Collections.Generic.Dictionary <string, string>
                {
                    { "FileNameFormat", this.FileNameFormat },
                    { "ItemCreationDate", this.ItemCreationDate.ToString("yyyyMMddTHHmmss") },
                    { "NumberOfDaysToCheck", this.NumberOfDaysToCheck.ToString() },
                    { "LastCheckTime", this.LastCheckTime.ToString("yyyyMMddTHHmmss") }
                },
                TargetInstance = this.TargetInstance,
                ComponentId    = this.InnerItem.ID.Guid,
                EventRaised    = dateTime
            };

            if (Settings.GetSetting("Healthcheck.Remote.Mode").Equals("eventqueue", StringComparison.OrdinalIgnoreCase))
            {
                EventQueueSender.Send(Constants.TemplateNames.RemoteLogFileCheckTemplateName, message);
            }
            else
            {
                MessageBusSender.Send(Constants.TemplateNames.RemoteLogFileCheckTemplateName, message);
            }
        }
Пример #5
0
        public static void Send(string type, OutGoingMessage message)
        {
            var remoteEvent = new HealthcheckStartedRemoteEvent(type, "healthcheck:started:remote", message);
            var database    = Sitecore.Configuration.Factory.GetDatabase("web");
            var eventQueue  = database.RemoteEvents.EventQueue;

            eventQueue.QueueEvent <HealthcheckStartedRemoteEvent>(remoteEvent, true, false);
        }
        public static void Send(string type, OutGoingMessage message)
        {
            var busMessage = new Microsoft.Azure.ServiceBus.Message
            {
                ContentType = "application/json",
                Label       = type,
                Body        = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message))
            };

            var messageSender = new MessageSender(SharedConfig.ConnectionStringOrKey, SharedConfig.TopicName);

            messageSender.SendAsync(busMessage).ConfigureAwait(false).GetAwaiter().GetResult();
        }
        /// <summary>
        /// Runs the healthcheck.
        /// </summary>
        public override void RunHealthcheck()
        {
            var dateTime = DateTime.UtcNow;

            this.SaveRemoteCheckStarted(dateTime);

            var message = new OutGoingMessage
            {
                Parameters = new System.Collections.Generic.Dictionary <string, string>
                {
                    { "Url", this.Url },
                    { "RequestHeaders", this.InnerItem    ["Request Headers"] },

                    { "Method", this.Method },
                    { "PostBody", this.PostBody },
                    { "ExpectedResponseCode", this.ExpectedResponseCode.ToString() },

                    { "ExpectedResponseBody", this.ExpectedResponseBody },
                    { "usingBasicAuthentication", this.usingBasicAuthentication.ToString() },
                    { "usingJwtAuthentication", this.usingJwtAuthentication.ToString() },
                    { "usingCertificateAuthentication", this.usingCertificateAuthentication.ToString() },
                    { "Username", this.Username },

                    { "Password", this.Password },
                    { "JwtToken", this.JwtToken },
                    { "GenerateTokenUrl", this.GenerateTokenUrl },
                    { "generateTokenEndpointMetho", this.GenerateTokenEndpointMethod },
                    { "storeName", this.StoreName },

                    { "location", this.Location },
                    { "findByTypeName", this.FindByType },
                    { "value", this.Value }
                },
                TargetInstance = this.TargetInstance,
                ComponentId    = this.InnerItem.ID.Guid,
                EventRaised    = dateTime
            };

            if (Settings.GetSetting("Healthcheck.Remote.Mode").Equals("eventqueue", StringComparison.OrdinalIgnoreCase))
            {
                EventQueueSender.Send(Constants.TemplateNames.RemoteApiHealthcheckTemplateName, message);
            }
            else
            {
                MessageBusSender.Send(Constants.TemplateNames.RemoteApiHealthcheckTemplateName, message);
            }
        }
 public HealthcheckStartedRemoteEvent(string type, string eventName, OutGoingMessage componentData)
 {
     this.Type          = type;
     this.EventName     = eventName;
     this.ComponentData = componentData;
 }
Пример #9
0
    /// <summary>
    /// Storing the message replied to the user
    /// </summary>
    /// <param name="RwSentMsg">The Raw message sent to user</param>
    /// <param name="MessageKey"> The key of the message; similar to the incoming message key</param>
    /// <param name="IsScheduled">boolen comfirming if the message has been scheduled or not</param>
    /// <param name="labAcronym">The lab being scheduled for</param>
    /// <param name="GivenStartTimeDB">The given startTime if lab was scheduled</param>
    /// <param name="GivenEndTimeDB">The given Endtime of the given lab</param>
    /// <param name="codeERR">The error incase of not succesfully sent</param>
    public static void storeOutgoing(string RwSentMsg, string MessageKey,
        bool IsScheduled, string labAcronym,
        DateTime GivenStartTimeDB, DateTime GivenEndTimeDB, string codeERR)
    {
        DataClassesDataContext db = new DataClassesDataContext();
            OutGoingMessage OutGo = new OutGoingMessage();

            OutGo.RwSentMsg = RwSentMsg;
            OutGo.MessageKey = MessageKey;
            OutGo.TimeAndDateSent = DateTime.UtcNow;
            OutGo.IsScheduled = IsScheduled;
            OutGo.GivenStartTime = GivenStartTimeDB;
            OutGo.GivenEndTime = GivenEndTimeDB;
            OutGo.LabConfigurationID = isLabnamePresent(labAcronym);
            OutGo.codeError = codeERR;

            db.OutGoingMessages.InsertOnSubmit(OutGo);
            db.SubmitChanges();
    }
Пример #10
0
 public static HealthcheckResult RunHealthcheck(OutGoingMessage message)
 {
     return(RunHealthcheck(message.Parameters["Url"], Sitecore.StringUtil.GetNameValues(message.Parameters["RequestHeaders"]), message.Parameters["Method"], message.Parameters["PostBody"], int.Parse(message.Parameters["ExpectedResponseCode"]), message.Parameters["ExpectedResponseBody"], bool.Parse(message.Parameters["usingBasicAuthentication"]), bool.Parse(message.Parameters["usingJwtAuthentication"]), bool.Parse(message.Parameters["usingCertificateAuthentication"]), message.Parameters["Username"], message.Parameters["Password"], message.Parameters["JwtToken"], message.Parameters["GenerateTokenUrl"], message.Parameters["generateTokenEndpointMetho"], message.Parameters["storeName"], message.Parameters["location"], message.Parameters["findByTypeName"], message.Parameters["value"]));
 }
Пример #11
0
        private void Monitor()
        {
            CancellationToken cancellation = cts.Token;
            TimeSpan          interval     = TimeSpan.Zero;

            while (!cancellation.WaitHandle.WaitOne(interval))
            {
                using (var db = new  KeysEntities())
                {
                    try
                    {
                        var tps = db.TenantProperty.Where(x => x.Id == 1582 /*&& (x.IsActive ?? false) && x.Property.IsActive*/);
                        foreach (var tp in tps)
                        {
                            var paymentDue = TenantService.GetNextPaymentDate(tp.PaymentStartDate, tp.PaymentDueDate, tp.PaymentFrequencyId);
                            if (paymentDue.HasValue)
                            {
                                var today   = DateTime.UtcNow.ToLocalTime();
                                var dayDiff = paymentDue.Value - today;
                                var payFreq = tp.PaymentFrequencyId == 1 ? 7 : tp.PaymentFrequencyId == 2 ? 14 : 30;
                                if (dayDiff.TotalDays >= 0 /*&& dayDiff.TotalDays < 2*/)
                                {
                                    var    lastQueueDate = tp.LastQueuedPaymentRemind;
                                    double days          = 0;
                                    if (lastQueueDate.HasValue)
                                    {
                                        days = Math.Abs((paymentDue.Value - lastQueueDate.Value).TotalDays);
                                    }
                                    if (lastQueueDate == null || days >= payFreq)
                                    {
                                        var addr         = tp.Property.Address.ToAddressString();
                                        var newQueueItem = new OutGoingMessage
                                        {
                                            PersonId       = tp.TenantId,
                                            MessageTypeId  = 1,
                                            DeliveryTypeId = 1,
                                            TargetAddress  = tp.Tenant.Person.Login.Email,
                                            Subject        = addr,
                                            Message        = paymentDue.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                            DateCreated    = DateTime.UtcNow,
                                            IsProcessed    = false,
                                            IsActive       = true,
                                        };
                                        db.OutGoingMessage.Add(newQueueItem);
                                        var owners = tp.Property.OwnerProperty.Select(x => x.Person).Select(x => new { Id = x.Id, Email = x.Login.UserName });;
                                        foreach (var o in owners)
                                        {
                                            var tenantName = tp.Tenant.Person.FirstName;
                                            var dateStr    = paymentDue.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
                                            newQueueItem = new OutGoingMessage
                                            {
                                                PersonId       = o.Id,
                                                MessageTypeId  = 2,
                                                DeliveryTypeId = 1,
                                                TargetAddress  = o.Email,
                                                Subject        = addr,
                                                Message        = tenantName + " " + dateStr,
                                                DateCreated    = DateTime.UtcNow,
                                                IsProcessed    = false,
                                                IsActive       = true,
                                            };
                                            db.OutGoingMessage.Add(newQueueItem);
                                        }
                                        tp.LastQueuedPaymentRemind = DateTime.UtcNow;
                                        var newPaymentTracking = new RentalPaymentTracking
                                        {
                                            TenantPropertyId = tp.Id,
                                            DueDate          = paymentDue.Value,
                                            PaymentComplete  = false
                                        };
                                        db.RentalPaymentTracking.Add(newPaymentTracking);
                                    }
                                }
                            }
                        }
                        db.SaveChanges();
                        if (cancellation.IsCancellationRequested)
                        {
                            break;
                        }
                        interval = new TimeSpan(0, 0, 10);
                    }
                    catch (Exception ex)
                    {
                        // Log the exception.
                        interval = new TimeSpan(0, 0, 5);
                    }
                }
            }
        }
	private void detach_OutGoingMessages(OutGoingMessage entity)
	{
		this.SendPropertyChanging();
		entity.LabConfiguration = null;
	}
 partial void DeleteOutGoingMessage(OutGoingMessage instance);
 partial void UpdateOutGoingMessage(OutGoingMessage instance);
 partial void InsertOutGoingMessage(OutGoingMessage instance);