//Task to Q
        internal static string CollectionsTaskToMessage(CollectionsTask task)
        {
            string message = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}",
                                           task.Id,
                                           task.State,
                                           task.Created,
                                           task.Project,
                                           task.Source,

                                           task.Command,
                                           task.Target,
                                           task.Parameters,

                                           task.Issued,

                                           task.Collected,
                                           task.Station,
                                           task.Collector,

                                           task.ResultHash,
                                           task.BlobName,
                                           task.Processed);

            return(message);
        }
        public static void Display()
        {
            CloudQueue queue        = AzureClientService.GetCloudQueue(QueueTypeEnum.ProcessingTwitter);
            int        messageCount = queue.RetrieveApproximateMessageCount();

            for (int i = 0; i < messageCount; i++)
            {
                CloudQueueMessage message = queue.GetMessage();
                CollectionsTask   task    = CollectionsTaskHelper.MessageToCollectionsTask(message.AsString);
                Console.WriteLine(string.Format("ID={0}, Command{1}, Target={2}",
                                                task.Id, task.Command, task.Target));

                //GetBlob
                CloudBlob blob       = AzureClientService.GetBlobReference(task.Project, task.BlobName);
                string    resultsXml = blob.DownloadText();

                Console.WriteLine(string.Format("BLOB: {0}, {1}, {2}, {3}, {4},{5}",
                                                blob.Attributes.Metadata["Id"].ToString(),
                                                blob.Attributes.Metadata["Project"].ToString(),
                                                blob.Attributes.Metadata["State"].ToString(),
                                                blob.Attributes.Metadata["Collected"].ToString(),
                                                blob.Name,
                                                blob.Attributes.Properties.ContentMD5.ToString()));
                Console.WriteLine(string.Format("BLOB XML: {0}", resultsXml));
            }
        }
        //Q to Task
        internal static CollectionsTask MessageToCollectionsTask(string message)
        {
            CollectionsTask task = new CollectionsTask();

            string[] fields = message.Split('\t');

            task.Id      = fields[0];
            task.State   = fields[1];
            task.Created = fields[2];
            task.Project = fields[3];
            task.Source  = fields[4];

            task.Command    = fields[5];
            task.Target     = fields[6];
            task.Parameters = fields[7];

            task.Issued = fields[8];

            task.Collected = fields[9];
            task.Station   = fields[10];
            task.Collector = fields[11];

            task.ResultHash = fields[12];
            task.BlobName   = fields[13];
            task.Processed  = fields[14];

            return(task);
        }
        //Table to Q
        internal static string T_CollectionsTaskToMessage(T_CollectionTask t_task)
        {
            CollectionsTask task = new CollectionsTask();

            task.Id      = t_task.Id.ToString();
            task.State   = t_task.State;
            task.Created = t_task.Created.ToUniversalTime().ToString();
            task.Project = t_task.Project;
            task.Source  = t_task.Source;

            task.Command    = t_task.Command;
            task.Target     = t_task.Target;
            task.Parameters = t_task.Parameters;

            task.Issued = t_task.Issued.GetValueOrDefault().ToString() ?? "";

            task.Collected = t_task.Collected.GetValueOrDefault().ToString() ?? "";
            task.Station   = t_task.Station;
            task.Collector = t_task.Collector;

            task.ResultHash = t_task.ResultHash;
            task.BlobName   = t_task.BlobName;
            task.Processed  = t_task.Processed.GetValueOrDefault().ToString() ?? "";

            string message = CollectionsTaskToMessage(task);

            return(message);
        }
        //Q to Table
        internal static T_CollectionTask MessageToT_CollectionTask(string message)
        {
            CollectionsTask task = MessageToCollectionsTask(message);

            T_CollectionTask t_task = new T_CollectionTask();

            t_task.Id      = int.Parse(task.Id);
            t_task.State   = task.State;
            t_task.Created = DateTime.Parse(task.Created);
            t_task.Project = task.Project;
            t_task.Source  = task.Source;

            t_task.Command    = task.Command;
            t_task.Target     = task.Target;
            t_task.Parameters = task.Parameters;

            t_task.Issued = DateTime.Parse(task.Issued);

            t_task.Collected = DateTime.Parse(task.Collected);
            t_task.Station   = task.Station;
            t_task.Collector = task.Collector;

            t_task.ResultHash = task.ResultHash;
            t_task.BlobName   = task.BlobName;
            t_task.Processed  = DateTime.Parse(task.Processed);

            return(t_task);
        }
        public static void Delete()
        {
            CloudQueue queue        = AzureClientService.GetCloudQueue(QueueTypeEnum.ProcessingTwitter);
            int        messageCount = queue.RetrieveApproximateMessageCount();

            for (int i = 0; i < messageCount; i++)
            {
                CloudQueueMessage message = queue.GetMessage();
                CollectionsTask   task    = CollectionsTaskHelper.MessageToCollectionsTask(message.AsString);

                //GetBlob
                CloudBlob blob = AzureClientService.GetBlobReference(task.Project, task.BlobName);
#if DEBUG
                blob.DeleteIfExists();
#endif
                queue.DeleteMessage(message);
            }
        }
Exemple #7
0
        //2-GetCollectionTask
        protected bool GetCollectionTask()
        {
            Logger.Log(GetContext() + "GetCollectionTask()");


            CloudQueueMessage queueMessage = AzureClientService.GetQueueMessage(_collectionsQueue);

            if (queueMessage != null)
            {
                _currentQueueMessage      = queueMessage;
                _currentTask              = CollectionsTaskHelper.MessageToCollectionsTask(_currentQueueMessage.AsString);
                _currentTask.QueueMessage = _currentQueueMessage;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #8
0
        public CollectionsOfficer(string station, string collector, QueueTypeEnum collectionsQueue)
        {
            _station          = station;
            _collector        = collector;
            _collectionsQueue = collectionsQueue;
            _loopOfficer      = true;
            _currentTask      = new CollectionsTask();
            _currentTask.Id   = "NO ID"; //placeholder for no new task
#if DEBUG
            //Sleep for 1 Minute
            _sleepOfficer = 60000;
#else
            //Sleep for 20 Minutes
            _sleepOfficer = 1200000;
#endif
            worker                            = new BackgroundWorker();
            worker.DoWork                    += worker_DoWork;
            worker.RunWorkerCompleted        += worker_RunWorkerCompleted;
            worker.WorkerSupportsCancellation = true;
        }