Exemplo n.º 1
0
 private static void StartNextInProcessingQueue()
 {
     if (c_queue.Count > 0)
     {
         if (!c_backgroundWorker.IsBusy)
         {
             FileHandlerBase inputHandler = c_queue.Dequeue();
             OnProcessingStarted(inputHandler);
             c_backgroundWorker.RunWorkerAsync(inputHandler);
         }
     }
 }
Exemplo n.º 2
0
        private void DoWork(InstructionSet instructionSet)
        {
            if (ItemsInProgess)
            {
                DebugMessage("Im still working....");
                return; // still working
            }

            // Dequeue
            var item = ProcessingQueue.Dequeue();


            // Wait if nothing More todo.
            if (item == null)
            {
                // No more work
                DebugMessage("Nothing more Ready in Queue!");
                return;
            }

            DebugMessage("Start With " + item.WorkSchedule.Name);
            ItemsInProgess = true;
            item.Status    = Status.Processed;


            // TODO: Roll delay here
            var duration = WorkTimeGenerator.GetRandomWorkTime(item.WorkSchedule.Duration);

            //Debug.WriteLine("Duration: " + duration + " for " + item.WorkSchedule.Name);
            Statistics.UpdateSimulationWorkSchedule(item.Id.ToString(), (int)Context.TimePeriod, duration - 1, this.Machine);

            // get item = ready and lowest priority
            CreateAndEnqueueInstuction(methodName: MachineAgent.InstuctionsMethods.FinishWork.ToString(),
                                       objectToProcess: item,
                                       targetAgent: this,
                                       waitFor: duration);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Main graph build method.
        /// Recursively builds the graph either until the size suffices or we are out of the nodes.
        /// </summary>
        /// <param name="startingPerson"></param>
        /// <param name="depth"></param>
        /// <param name="includePointingTo"></param>
        /// <param name="includeNonPersons"></param>
        /// <param name="aggressive"></param>
        private void BuildGraph(Person startingPerson, bool includePointingTo, bool includeNonPersons, bool aggressive = false)
        {
            List <GraphRelationRaw> branchList = new List <GraphRelationRaw>();

            // TODO: Don't open new connection every time.
            // Use connection pool.
            using (var connection = new QC.SqlConnection(GetConnectionString(HomeController.DefaultProviderName)))
            {
                connection.Open();
                using (var command = new QC.SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandType = DT.CommandType.Text;

                    // Queries here are not very optimized. Do better.
                    if (includePointingTo && !includeNonPersons)
                    {
                        command.CommandText = @"  
                            select entity_name as node_from, property_name as branch_name, link2 as node_to from properties1 
                            where link2 = @name and  exists (select name from persons where name = entity_name)
                            select entity_name as node_from, property_name as branch_name, link2 as node_to from properties1 
                            where entity_name = @name and link2 is not null and isPerson = 1
                        ";
                    }
                    else if (!includePointingTo && includeNonPersons)
                    {
                        command.CommandText = @"  
                            select entity_name as node_from, property_name as branch_name, link2 as node_to from properties1 
                            where entity_name = @name and link2 is not null
                        ";
                    }
                    else if (includePointingTo && includeNonPersons)
                    {
                        command.CommandText = @"
                            select entity_name as node_from, property_name as branch_name, link2 as node_to from properties1 
                            where (link2 = @name) or (entity_name = @name and link2 is not null)
                        ";
                    }
                    else
                    {
                        command.CommandText = @"  
                            select entity_name as node_from, property_name as branch_name, link2 as node_to from properties1 
                            where entity_name = @name and link2 is not null and isPerson = 1
                        ";
                    }

                    command.Parameters.AddWithValue("@name", startingPerson.Name);

                    QC.SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        branchList.Add(
                            new GraphRelationRaw
                        {
                            From = reader.GetString(0),
                            Name = reader.GetString(1),
                            To   = reader.GetString(2)
                        });
                    }
                }
            }

            // Premature return if this is a dominant node
            // later in search.
            // This is an ugly edge case and should be removed at some point.
            if (branchList.Count > 20 && startingPerson.DistanceFromCenter > 1)
            {
                return;
            }

            foreach (var branch in branchList)
            {
                Person personFrom;
                Person personTo;

                bool isPersonFromNew = false;
                bool isPersonToNew   = false;

                if (!Persons.TryGetValue(branch.From, out personFrom))
                {
                    personFrom = new Person(branch.From, startingPerson.DistanceFromCenter + 1);
                    Persons.Add(personFrom.Name, personFrom);
                    isPersonFromNew = true;
                    ProcessingQueue.Enqueue(personFrom);
                }

                if (!Persons.TryGetValue(branch.To, out personTo))
                {
                    personTo = new Person(branch.To, startingPerson.DistanceFromCenter + 1);
                    Persons.Add(personTo.Name, personTo);
                    isPersonToNew = true;
                    ProcessingQueue.Enqueue(personTo);
                }

                if (isPersonFromNew)
                {
                    personFrom.DistanceFromCenter = personTo.DistanceFromCenter + 1;
                }

                if (isPersonToNew)
                {
                    personTo.DistanceFromCenter = personFrom.DistanceFromCenter + 1;
                }

                PersonConnections.Add(new Relation(personFrom, personTo, branch.Name));
            }

            // One more check, if we are early in the graph and we still don't have many results
            // do more aggressive search.
            if (startingPerson.DistanceFromCenter == 0 && Persons.Count < 5 && (!includePointingTo || !includeNonPersons))
            {
                if (!includePointingTo)
                {
                    BuildGraph(startingPerson, true, false);
                }
                else
                {
                    // Do full search.
                    BuildGraph(startingPerson, true, true);
                }
            }

            while (ProcessingQueue.Count != 0 && Persons.Count < MaxNumberOfPersonsPerGraph)
            {
                if (aggressive && startingPerson.DistanceFromCenter < 3)
                {
                    BuildGraph(ProcessingQueue.Dequeue(), true, true, aggressive);
                }
                else if (aggressive && startingPerson.DistanceFromCenter < 4)
                {
                    BuildGraph(ProcessingQueue.Dequeue(), true, false, aggressive);
                }
                if (startingPerson.DistanceFromCenter < 2 && Persons.Count < 5 && ProcessingQueue.Count < 5)
                {
                    BuildGraph(ProcessingQueue.Dequeue(), true, false);
                }
                else
                {
                    BuildGraph(ProcessingQueue.Dequeue(), false, false);
                }
            }
        }