Beispiel #1
0
        public Constituency ReadConstituencyDataFromFile(ConfigRecord configRecord)
        {
            // Open the file to read from on the local file system.
            // If this file is missing then return immediately from this method.

            if (!File.Exists(configRecord.Filename))
            {
                // Cannot open the file as it does not exist for whatever reason, so return immediately.
                return(null);
            }

            // Open file and load into memory as XML
            XDocument xmlDoc = XDocument.Load(configRecord.Filename);

            // Create constituency (should only be one in file but retrieve first to be sure)
            var constituencyName = (from c in xmlDoc.Descendants("Constituency")
                                    select c.Attribute("name").Value).First();

            Constituency constituency = new Constituency(constituencyName);

            //ConstituencyList constituencyList;

            // Create Vote report for this constituency
            constituency.VoteReportVotes = new VoteReport();

            // Retrieve data for measures and add to fit report
            // Local helper method used to select measures via LINQ query on XML document
            constituency.VoteReportVotes.constituencyTotalVotes = SelectDataMeasure(xmlDoc);
            constituency.VoteReportVotes.candidateInformation   = SelectDataMeasureCand(xmlDoc);
            constituency.VoteReportVotes.candidateInfoExt       = SelectDataMeasureCandExt(xmlDoc);

            return(constituency);
        }
Beispiel #2
0
        /// <summary>
        /// Thread code for the producer
        /// </summary>
        public void run()
        {
            ConfigRecord configRecord = null;

            // While not finished, generate a new work item and enqueue it on the PCQueue, output that this producer has
            // produced a new item (and what it is called)
            while (!Finished)
            {
                // Lock configuration file and obtain next filename to process
                // If there are no filenames left then set filename to null so that nothing is produced
                lock (configFile)
                {
                    if (configFile.NextRecord < configFile.configRecords.Count)
                    {
                        configRecord = configFile.configRecords[configFile.NextRecord++];
                    }
                    else
                    {
                        configRecord = null;
                    }
                }

                // only queue item if there is a config record to read
                if (configRecord != null)
                {
                    // Enqueue a new work item, increment the counter as this work is produced
                    pcQueue.enqueueItem(new Work(configRecord, IOhandler));

                    // Output a message to state that this producer has produced a work item
                    Console.WriteLine("Producer:{0} has created and enqueued Work Item:{1}", id, configRecord.ToString());
                }

                // Simulate producer activity running for duration milliseconds
                Thread.Sleep(duration);
            }

            // Decrement the number of running producer threads
            RunningThreads--;

            // Output that this producer has finished
            Console.WriteLine("Producer:{0} has finished", id);
        }
Beispiel #3
0
        }                                                       // Result of the work, when null indicates that the work has not yet
        // been completed, note this is a read-only property

        public Work(ConfigRecord data, IConstituencyFileReader IOhandler) //extra param for IconstituencyIO
        {
            constituency      = null;                                     // Result of the work is initially null, this shows that the work has not yet been completed
            this.configRecord = data;                                     // Data is initialised when the work is instantiated
            this.IOhandler    = IOhandler;
        }