Exemplo n.º 1
0
        public void CreateDelivery()
        {
            List <Status>   statuses;
            List <Delivery> deliveries;
            int             indexStatusNew = -1;

            using (QueueServiceContext context = new QueueServiceContext())
            {
                statuses = context.Statuses.ToList();

                Delivery tempDelivery = new Delivery();
                context.Deliveries.Add(tempDelivery);
                context.SaveChanges();

                deliveries = context.Deliveries.ToList();

                Exercise tempExcercise = new Exercise();
                foreach (var i in statuses)
                {
                    if (i.StatusName == "Новый")
                    {
                        indexStatusNew = i.Id;
                    }
                }
                tempExcercise.StatusId   = indexStatusNew;
                tempExcercise.Status     = statuses[indexStatusNew];
                tempExcercise.DeliveryId = deliveries.Last().Id;
                tempExcercise.Delivery   = deliveries.Last();
                context.Exercises.Add(tempExcercise);
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public void GetExercise(ref Task <int> task)
        {
            List <Exercise> exercises;
            Exercise        exercise = new Exercise();

            using (QueueServiceContext context = new QueueServiceContext())
            {
                exercises = context.Exercises.ToList();
                for (int i = 0; i < exercises.Count; i++)
                {
                    if (exercises[i].Status.StatusName != "Новая")
                    {
                        exercises.RemoveAt(i);
                    }
                }

                if (exercises.Count != 0)
                {
                    exercise = exercises.Last();
                }
            }

            //
            //
            //Проблема
            task = Task <int> .Run(new Func <Exercise>(TaskWork(exercise)));

            //
            //
            // task = Task.Factory.StartNew(new Action<Exercise>(TaskWork(exercise)));
        }
Exemplo n.º 3
0
        public static void TaskWork(Exercise exercise)
        {
            List <Exercise> exercises;
            List <Status>   statuses;

            using (QueueServiceContext context = new QueueServiceContext())
            {
                exercises = context.Exercises.ToList();
                statuses  = context.Statuses.ToList();

                context.Exercises.Remove(exercise);

                foreach (var i in statuses)
                {
                    if (i.StatusName == "Выполняется")
                    {
                        exercise.Status   = i;
                        exercise.StatusId = i.Id;
                    }
                }
                exercise.TaskId = Thread.CurrentThread.ManagedThreadId;
                context.Exercises.Add(exercise);
                context.SaveChanges();

                Random rand = new Random();
                Thread.Sleep(rand.Next(6, 9));

                context.Exercises.Remove(exercise);

                foreach (var i in statuses)
                {
                    if (i.StatusName == "Выполнен")
                    {
                        exercise.Status   = i;
                        exercise.StatusId = i.Id;
                    }
                }
                context.Exercises.Add(exercise);
                context.SaveChanges();
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            using (QueueServiceContext context = new QueueServiceContext())
            {
                context.Exercises.ToList();

                Status statusNew = new Status();
                statusNew.StatusName = "Новый";
                Status statusWork = new Status();
                statusWork.StatusName = "Выполняется";
                Status statusOverdue = new Status();
                statusOverdue.StatusName = "Просроченный";
                Status statusComplete = new Status();
                statusComplete.StatusName = "Выполненый";

                context.Statuses.Add(statusNew);
                context.Statuses.Add(statusWork);
                context.Statuses.Add(statusOverdue);
                context.Statuses.Add(statusComplete);

                context.SaveChanges();
            }
        }