public static ImagesAndSettingsForResizing GetWorker(string uuid)
 {
     return workers.GetOrAdd(uuid, (s) => {
         int maxTaskCount;
         int.TryParse(ConfigurationManager.AppSettings["maxTaskCount"], out maxTaskCount);
         int maxImagesCountinOneThread;
         int.TryParse(ConfigurationManager.AppSettings["maxImagesCountinOneThread"], out maxImagesCountinOneThread);
         var worker = new ImagesAndSettingsForResizing(MaxTaskCount, MaxImagesCountinOneThread);
         worker.Settings.Add(
             new ResizeSettingsModel() { Name = PreviewName, Height = PreviewSize, Width = PreviewSize });
         return worker;
     });
 }
Exemplo n.º 2
0
 public static ImagesAndSettingsForResizing GetWorker(string uuid)
 {
     return(workers.GetOrAdd(uuid, (s) => {
         int maxTaskCount;
         int.TryParse(ConfigurationManager.AppSettings["maxTaskCount"], out maxTaskCount);
         int maxImagesCountinOneThread;
         int.TryParse(ConfigurationManager.AppSettings["maxImagesCountinOneThread"], out maxImagesCountinOneThread);
         var worker = new ImagesAndSettingsForResizing(MaxTaskCount, MaxImagesCountinOneThread);
         worker.Settings.Add(
             new ResizeSettingsModel()
         {
             Name = PreviewName, Height = PreviewSize, Width = PreviewSize
         });
         return worker;
     }));
 }
Exemplo n.º 3
0
        protected void WorkProcedure(object obj)
        {
            EventLog.WriteEntry("WorkProcedure starting");
            MessageQueue todoQueue = InitializeMQ(todoMessageQueue, new XmlMessageFormatter(
                                                      new Type[] { typeof(ImagesAndSettingsForResizing), typeof(ResizeSettingsModel) }));
            MessageQueue doneQueue = InitializeMQ(doneMessageQueue, new XmlMessageFormatter(
                                                      new Type[] { typeof(ResizedImageInfo) }));

            EventLog.WriteEntry("MessageQueue started");

            Task task = null;
            MultiThreadResizerWorker worker = null;

            do
            {
                if (task == null)
                {
                    using (todoQueue)
                    {
                        Message message = null;
                        try
                        {
                            EventLog.WriteEntry("Receiving");
                            message = todoQueue.Receive();
                            EventLog.WriteEntry("Received");
                        }
                        catch (Exception ex)
                        {
                            EventLog.WriteEntry("Receive ex" + ex.Message + ex.StackTrace);
                        }

                        ImagesAndSettingsForResizing todo = message.Body as ImagesAndSettingsForResizing;

                        EventLog.WriteEntry("check todo");
                        if (todo != null)
                        {
                            EventLog.WriteEntry("worker starting");
                            try
                            {
                                worker = new MultiThreadResizerWorker(maxTaskCount, maxImagesCountinOneThread);
                                todo.Settings.ForEach(set =>
                                {
                                    worker.ListOfResizeSettings.Add(new CustomResizeSettings(set.Name, set.Width, set.Height));
                                });
                                worker.AddListOfImages(todo.ImagesForWorker);
                                task = worker.StartResizingTask(600);
                            }
                            catch (Exception ex)
                            {
                                EventLog.WriteEntry("worker ex" + ex.Message + ex.StackTrace);
                            }
                            EventLog.WriteEntry("worker started");
                        }
                    }
                }
                else
                {
                    EventLog.WriteEntry("Task is not null");
                    if (task.IsCompleted)
                    {
                        EventLog.WriteEntry("Task is completed");
                        using (doneQueue)
                        {
                            try
                            {
                                EventLog.WriteEntry("Sending");
                                doneQueue.Send(worker.ResizedImagesList);
                                EventLog.WriteEntry("Sent");
                                task = null;
                            }
                            catch (Exception ex)
                            {
                                EventLog.WriteEntry("Sent ex" + ex.Message + ex.StackTrace);
                            }
                        }
                    }
                    else
                    {
                        EventLog.WriteEntry("Task is not completed");
                    }
                }
            }           while (WaitHandle.WaitAny(new WaitHandle[] { stopWorkEvent },
                                                  TimeSpan.FromMilliseconds(10000)) != 0);
        }