Exemplo n.º 1
0
        private bool StoreLogsInFileAndSendEmail()
        {
            bool IsDone = false;

            try
            {
                SystemDetails s1 = GetSystemDetails();
                LastRecordedTime = s1.PreciseTimeStamp;
                string systemLog = SerializeJSONData(s1);
                IsDone = HostFileUtility.Instance.WriteLog(systemLog);

                if (Internet.IsConnectionActive())
                {
                    //Consume RabbitMQ messages here somewhere.
                    SendEmail(s1);
                }
                else
                {
                    //Call RabbitMQ as message broker.
                    using (MsgBroker.RabbitMQ Rpc = new MsgBroker.RabbitMQ())
                    {
                        Rpc.MessageBrokerPublish(systemLog);
                    }
                }

                IncrementCount();
            }
            catch (Exception e)
            {
                throw e;
            }

            return(IsDone);
        }
Exemplo n.º 2
0
        private string GetBody(SystemDetails s1)
        {
            string body = string.Empty;

            if (SystemContinuosOnCount == 0)
            {
                body += "Your system has just boot up. Would you mind take a look at this.<br>";
            }
            else
            {
                body += string.Format("Your system is online since {0}+ hours. <br>", SystemContinuosOnCount);
            }

            body += "Here are system details : <br><br>";
            body += "<table width='100%' cellspacing='2' cellpadding='0' border='0' align='center' bgcolor='#ff6600'>";
            body += "<tr bgcolor='#ffffff'>";
            body += "<td width='50%' height='40' bgcolor='#ffdb99'>System Property</td>";
            body += "<td width='50%' bgcolor='#ffdb99'>Value</td>";
            body += "</tr>";
            body += "<tr bgcolor='#ffffff'>";
            body += "<td width= '50%' height='40'>Precise DateTime</td>";
            body += string.Format("<td width='50%'>{0}</td>", s1.PreciseTimeStamp);
            body += "</tr>";
            body += "<tr bgcolor='#ffffff'>";
            body += "<td width='50%' height='40'>UTC DateTime</td>";
            body += string.Format("<td width='50%'>{0}</td>", s1.UTCTimeStamp);
            body += "</tr>";
            body += "<tr bgcolor='#ffffff'>";
            body += "<td width='50%' height='40'>MachineName</td>";
            body += string.Format("<td width='50%'>{0}</td>", s1.MachineName);
            body += "</tr>";
            body += "<tr bgcolor='#ffffff'>";
            body += "<td width='50%' height='40'>Is64Bit OS</td>";
            body += string.Format("<td width='50%'>{0}</td>", s1.Is64BitOperatingSystem);
            body += "</tr>";
            body += "<tr bgcolor='#ffffff'>";
            body += "<td width='50%' height='40'>OSVersion</td>";
            body += string.Format("<td width='50%'>{0}</td>", s1.OSVersion);
            body += "</tr>";
            body += "<tr bgcolor='#ffffff'>";
            body += "<td width='50%' height='40'>ProcessorCount</td>";
            body += string.Format("<td width='50%'>{0}</td>", s1.PreciseTimeStamp);
            body += "</tr>";
            body += "<tr bgcolor='#ffffff'>";
            body += "<td width='50%' height='40'>Hours Running</td>";
            body += string.Format("<td width='50%'>{0}</td>", s1.OnCount);
            body += "</tr>";
            body += "<tr bgcolor='#ffffff'>";
            body += "<td width='50%' height='40'>Running Processes</td>";
            body += string.Format("<td width='50%'>{0}</td>", ProcessesRunningAttachInEmail());
            body += "</tr>";
            body += "</table>";


            return(body);
        }
Exemplo n.º 3
0
        private string SerializeJSONData(SystemDetails e)
        {
            Newtonsoft.Json.JsonSerializerSettings jss = new Newtonsoft.Json.JsonSerializerSettings();

            Newtonsoft.Json.Serialization.DefaultContractResolver dcr = new Newtonsoft.Json.Serialization.DefaultContractResolver();
            dcr.DefaultMembersSearchFlags |= System.Reflection.BindingFlags.NonPublic;
            jss.ContractResolver           = dcr;

            var response = Newtonsoft.Json.JsonConvert.SerializeObject(e, jss);

            return(response);
        }
Exemplo n.º 4
0
        private SystemDetails GetSystemDetails()
        {
            SystemDetails s = new SystemDetails()
            {
                LogId                  = Guid.NewGuid(),
                PreciseTimeStamp       = DateTime.Now,
                UTCTimeStamp           = DateTime.UtcNow,
                MachineName            = System.Environment.MachineName,
                OSVersion              = System.Environment.OSVersion.ToString(),
                Is64BitOperatingSystem = System.Environment.Is64BitOperatingSystem,
                ProcessorCount         = System.Environment.ProcessorCount,
                OnCount                = SystemContinuosOnCount,
                ProcessesRunning       = ProcessesRunningForLogs()
            };

            return(s);
        }
Exemplo n.º 5
0
        private bool SendEmail(SystemDetails s1)
        {
            //prepare to send an email with login creds
            string Secrets = ReadServerSecrets();

            if (string.IsNullOrWhiteSpace(Secrets))
            {
                return(false);
            }

            var Keys = DeserializeJSONData <Secrets>(Secrets);

            string Subject = GetSubjectLine();
            string Body    = GetBody(s1);

            Mail m = new Mail();

            m.Send("smtp.gmail.com", Keys.HostLiveSecrets.Gmail.username, Keys.HostLiveSecrets.Gmail.password, Keys.HostLiveSecrets.Gmail.username, Subject, Body);

            return(true);
        }