Esempio n. 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);
        }
Esempio n. 2
0
        /// <summary>
        /// Thread code for the consumer
        /// </summary>
        public void run()
        {
            // While not finished, dequeue a work item from the PCQueue and consume this work item by invoking
            // its ReadData() method and then outputting to the console a message to show this has happened
            while (!Finished)
            {
                // Dequeue a work item
                var item = pcQueue.dequeueItem();

                if (!ReferenceEquals(null, item))
                {
                    // Invoke the work item's ReadData() method, which returns a constituency
                    Constituency constituency = item.ReadData();

                    // Ensure null returns are ignored (will happen if data not in correct format or can't open file)
                    if (!ReferenceEquals(null, constituency))
                    {
                        // Add this constituency to the constituency list (lock it while modifying)
                        lock (constituencyList)
                        {
                            constituencyList.constituency.Add(constituency);
                        }
                        // Output to the console
                        Console.WriteLine("Consumer:{0} has consumed Work Item:{1}", id, item.configRecord.ToString());
                    }
                    else
                    {
                        // Output to the console
                        Console.WriteLine("Consumer:{0} has rejected Work Item:{1}", id, item.configRecord.ToString());
                    }

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

                    progManager.ItemsRemaining--;
                }
            }

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

            // Output that this consumer has finished
            Console.WriteLine("Consumer:{0} has finished", id);
        }
Esempio n. 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;
        }