Пример #1
0
        public bool WorkerShouldRun()
        {
            WorkerCommandEntity wce = (WorkerCommandEntity)statsTable.Execute(
                TableOperation.Retrieve <WorkerCommandEntity>(command.PartitionKey, command.RowKey)).Result;

            return(wce.ShouldRun);
        }
Пример #2
0
        public void ClearTables()
        {
            urlTable.DeleteIfExists();

            urlTotalCount = new TotalEntity("urlsIndexed", 0);
            statsTable.Execute(TableOperation.InsertOrReplace(urlTotalCount));

            allUrlsCrawled = new TotalEntity("allUrls", 0);
            statsTable.Execute(TableOperation.InsertOrReplace(allUrlsCrawled));

            command = new WorkerCommandEntity(false);
            statsTable.Execute(TableOperation.InsertOrReplace(command));

            recentUrls = new RecentUrlEntity();
            statsTable.Execute(TableOperation.InsertOrReplace(recentUrls));

            TableQuery query = new TableQuery().Where(
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, ErrorEntity.ERROR_PARTITION));

            foreach (var row in statsTable.ExecuteQuery(query))
            {
                statsTable.Execute(TableOperation.Delete(row));
            }
        }
Пример #3
0
        private void InitEntities()
        {
            // all of the following create a new local entity, try to get the remote one
            // only assigning to the new one if the remote doesn't exist
            // Tried making a generic function for this, doesn't work well
            TotalEntity newUrlTotal    = new TotalEntity("urlsIndexed", 0);
            TotalEntity remoteUrlTotal = (TotalEntity)statsTable.Execute(TableOperation
                                                                         .Retrieve <TotalEntity>(newUrlTotal.PartitionKey, newUrlTotal.RowKey)).Result;

            if (remoteUrlTotal != null)
            {
                urlTotalCount = remoteUrlTotal;
            }
            else
            {
                urlTotalCount = newUrlTotal;
                statsTable.Execute(TableOperation.InsertOrReplace(urlTotalCount));
            }

            TotalEntity newAllUrl    = new TotalEntity("allUrls", 0);
            TotalEntity remoteAllUrl = (TotalEntity)statsTable.Execute(TableOperation
                                                                       .Retrieve <TotalEntity>(newAllUrl.PartitionKey, newAllUrl.RowKey)).Result;

            if (remoteAllUrl != null)
            {
                allUrlsCrawled = remoteAllUrl;
            }
            else
            {
                allUrlsCrawled = newAllUrl;
                statsTable.Execute(TableOperation.InsertOrReplace(allUrlsCrawled));
            }

            WorkerCommandEntity newCommand    = new WorkerCommandEntity(false);
            WorkerCommandEntity remoteCommand = (WorkerCommandEntity)statsTable.Execute(TableOperation
                                                                                        .Retrieve <WorkerCommandEntity>(newCommand.PartitionKey, newCommand.RowKey)).Result;

            if (remoteCommand != null)
            {
                command = remoteCommand;
            }
            else
            {
                command = newCommand;
                statsTable.Execute(TableOperation.InsertOrReplace(command));
            }

            RecentUrlEntity newRecents    = new RecentUrlEntity();
            RecentUrlEntity remoteRecents = (RecentUrlEntity)statsTable.Execute(TableOperation
                                                                                .Retrieve <RecentUrlEntity>(newRecents.PartitionKey, newRecents.RowKey)).Result;

            if (remoteRecents != null)
            {
                recentUrls = remoteRecents;
            }
            else
            {
                recentUrls = newRecents;
                statsTable.Execute(TableOperation.InsertOrReplace(recentUrls));
            }
        }