예제 #1
0
파일: Program.cs 프로젝트: lnaie/SiteMonitR
        public static void DeleteSite(

            // the incoming queue
            [QueueInput(SiteMonitRConfiguration.QUEUE_NAME_DELETE_SITE)] string url,

            // the site list table from which data should be deleted
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITES)]
            IDictionary <Tuple <string, string>, SiteRecord> siteRecords,

            // the site log table from which data should be deleted
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITE_LOGS)]
            IDictionary <Tuple <string, string>, SiteResult> siteResults
            )
        {
            var cleansedUrl = SiteMonitRConfiguration.CleanUrlForRowKey(url);

            var key = new Tuple <string, string>(
                SiteMonitRConfiguration.GetPartitionKey(), cleansedUrl);

            // delete the site record
            if (siteRecords.ContainsKey(key))
            {
                siteRecords.Remove(key);
            }

            // delete all the site's logs
            foreach (var siteResult in siteResults)
            {
                if (siteResult.Key.Item1 == cleansedUrl)
                {
                    siteResults.Remove(siteResult.Key);
                }
            }
        }
예제 #2
0
        public static void AddSite(

            // the incoming queue
            [QueueTrigger(SiteMonitRConfiguration.QUEUE_NAME_NEW_SITE)] string url,

            // the list of all sites
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITES)]
            IQueryable <SiteRecord> listOfSiteRecords,

            // the table into which sites should be saved
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITES)]
            CloudTable table
            )
        {
            var cleansedUrl = SiteMonitRConfiguration.CleanUrlForRowKey(url);
            var siteRecord  = new SiteRecord();

            siteRecord.RowKey       = SiteMonitRConfiguration.GetPartitionKey();
            siteRecord.PartitionKey = cleansedUrl;
            siteRecord.Uri          = url;
            if (!listOfSiteRecords.ToList().Any(entity => entity.PartitionKey == siteRecord.PartitionKey))
            {
                table.Execute(TableOperation.InsertOrReplace(siteRecord));
            }
        }
예제 #3
0
        public static void CheckSitesFunction(

            // the table containing the list of sites
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITES)]
            IDictionary <Tuple <string, string>, SiteRecord> siteRecords,

            // the queue that will receive site results
            [QueueOutput(SiteMonitRConfiguration.QUEUE_NAME_INCOMING_SITE_LOG)]
            out IEnumerable <SiteResult> siteResults
            )
        {
            // create a new list of the result classes
            var resultList = new List <SiteResult>();

            foreach (var nv in siteRecords)
            {
                // create a new result for this site
                var siteResult = new SiteResult
                {
                    Uri    = nv.Value.Uri,
                    Status = SiteMonitRConfiguration.DASHBOARD_SITE_CHECKING
                };

                // update the UX to let the user know we're checking the site
                SiteMonitRConfiguration.UpdateDashboard(siteResult);

                // check the site
                var request = (HttpWebRequest)HttpWebRequest.Create(siteResult.Uri);

                try
                {
                    // the site is up
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    siteResult.Status = SiteMonitRConfiguration.DASHBOARD_SITE_UP;
                }
                catch (Exception)
                {
                    // the site is down
                    siteResult.Status = SiteMonitRConfiguration.DASHBOARD_SITE_DOWN;
                }

                // add the result to the list
                resultList.Add(siteResult);

                // update the UX to let the user know we're done checking this site
                SiteMonitRConfiguration.UpdateDashboard(siteResult);
            }

            // set the output value, sending the messages into the queue individually
            siteResults = resultList;
        }
예제 #4
0
        public static void CheckSitesFunction(

            // the table containing the list of sites
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITES)]
            IQueryable <SiteRecord> siteRecords,

            // update the site results table
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITES)]
            CloudTable recordTable,

            // the queue that will receive site results
            [Queue(SiteMonitRConfiguration.QUEUE_NAME_INCOMING_SITE_LOG)]
            ICollection <SiteResult> siteResults
            )
        {
            foreach (var nv in siteRecords)
            {
                // create a new result for this site
                var siteResult = new SiteResult
                {
                    Uri    = nv.Uri,
                    Status = SiteMonitRConfiguration.DASHBOARD_SITE_CHECKING
                };

                // update the UX to let the user know we're checking the site
                SiteMonitRConfiguration.UpdateDashboard(siteResult);

                // check the site
                var request = (HttpWebRequest)HttpWebRequest.Create(siteResult.Uri);

                try
                {
                    // the site is up
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    siteResult.Status = SiteMonitRConfiguration.DASHBOARD_SITE_UP;
                }
                catch (Exception)
                {
                    // the site is down
                    siteResult.Status = SiteMonitRConfiguration.DASHBOARD_SITE_DOWN;
                }

                // add the result to the list
                // send the messages into the queue individually once this function completes
                siteResults.Add(siteResult);

                // update the UX to let the user know we're done checking this site
                SiteMonitRConfiguration.UpdateDashboard(siteResult);
            }
        }
예제 #5
0
        public static void SaveSiteLogEntry(

            // the incoming queue
            [QueueTrigger(SiteMonitRConfiguration.QUEUE_NAME_INCOMING_SITE_LOG)]
            SiteResult siteResult,

            // the site log table, into which data will be saved
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITE_LOGS)]
            CloudTable resultTable
            )
        {
            siteResult.RowKey       = SiteMonitRConfiguration.CleanUrlForRowKey(siteResult.Uri);
            siteResult.PartitionKey = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
            resultTable.Execute(TableOperation.InsertOrReplace(siteResult));
        }
예제 #6
0
        public SiteLogTableEntity GetLatestLogForSite(string uri)
        {
            var partitionKey = SiteMonitRConfiguration.CleanUrlForRowKey(uri);

            var query = new TableQuery <SiteLogTableEntity>().Where(
                TableQuery.GenerateFilterCondition("Uri", QueryComparisons.Equal, uri)
                );

            var tbl = GetSiteLogTable();

            var ret = tbl.ExecuteQuery <SiteLogTableEntity>(query)
                      .OrderByDescending(x => x.Timestamp)
                      .FirstOrDefault();

            return(ret);
        }
예제 #7
0
파일: Program.cs 프로젝트: lnaie/SiteMonitR
        public static void SaveSiteLogEntry(

            // the incoming queue
            [QueueInput(SiteMonitRConfiguration.QUEUE_NAME_INCOMING_SITE_LOG)]
            SiteResult siteResult,

            // the site log table, into which data will be saved
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITE_LOGS)]
            IDictionary <Tuple <string, string>, SiteResult> siteResults
            )
        {
            var tuple = new Tuple <string, string>(
                SiteMonitRConfiguration.CleanUrlForRowKey(siteResult.Uri),
                Path.GetFileNameWithoutExtension(Path.GetRandomFileName())
                );

            siteResults.Add(new KeyValuePair <Tuple <string, string>, SiteResult>(
                                tuple, siteResult));
        }
예제 #8
0
파일: Program.cs 프로젝트: lnaie/SiteMonitR
        public static void AddSite(

            // the incoming queue
            [QueueInput(SiteMonitRConfiguration.QUEUE_NAME_NEW_SITE)] string url,

            // the table into which sites should be saved
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITES)]
            IDictionary <Tuple <string, string>, SiteRecord> siteRecords
            )
        {
            var cleansedUrl = SiteMonitRConfiguration.CleanUrlForRowKey(url);

            var key = new Tuple <string, string>(
                SiteMonitRConfiguration.GetPartitionKey(), cleansedUrl);

            if (!siteRecords.ContainsKey(key))
            {
                siteRecords.Add(key, new SiteRecord {
                    Uri = url
                });
            }
        }
예제 #9
0
        public static void DeleteSite(

            // the incoming queue
            [QueueTrigger(SiteMonitRConfiguration.QUEUE_NAME_DELETE_SITE)] string url,

            // the list of all sites
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITES)]
            IQueryable <SiteRecord> listofSiteRecords,

            // the list of all site logs
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITE_LOGS)]
            IQueryable <SiteResult> listofSiteResults,

            // the site list table from which data should be deleted
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITES)]
            CloudTable recordTable,

            // the site log table from which data should be deleted
            [Table(SiteMonitRConfiguration.TABLE_NAME_SITE_LOGS)]
            CloudTable resultTable
            )
        {
            var cleansedUrl = SiteMonitRConfiguration.CleanUrlForRowKey(url);

            if (listofSiteRecords.ToList().Any(entity => entity.PartitionKey == cleansedUrl))
            {
                var siteRecord = listofSiteRecords.ToList().Where(entity => entity.RowKey == cleansedUrl).FirstOrDefault();
                recordTable.Execute(TableOperation.Delete(siteRecord));
            }
            // delete all the site's logs
            foreach (var siteResult in listofSiteResults)
            {
                if (siteResult.PartitionKey == cleansedUrl)
                {
                    resultTable.Execute(TableOperation.Delete(siteResult));
                }
            }
        }
예제 #10
0
 public SiteRecordTableEntity()
 {
     this.PartitionKey = SiteMonitRConfiguration.GetPartitionKey();
 }