public void AddListOfImages()
 {
     var MultiThreadResizer = new MultiThreadResizerWorker();
     var files = new List<string>();
     MultiThreadResizer.GetListOfFiles(Path, out files);
     MultiThreadResizer.AddListOfImages(files);
     Assert.AreEqual(string.Concat("Added ", MultiThreadResizer.ListOfResizeSettingsDefault.Count* files.Count, " FileAndCustomResizeSettings"), MultiThreadResizer.AddListOfImages(files));
 }
        public void AddListOfImagesForFile()
        {
            var MultiThreadResizer = new MultiThreadResizerWorker();
            var files = new List<string>();
            MultiThreadResizer.GetListOfFiles(Path, out files);

            MultiThreadResizer.AddListOfImagesForFile(files[0]);
            Assert.AreEqual(MultiThreadResizer.ListOfResizeSettingsDefault.Count, MultiThreadResizer.ListOfFileAndCustomResizeSettings.Count);
        }
 public static MultiThreadResizerWorker 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 MultiThreadResizerWorker(MaxTaskCount, MaxImagesCountinOneThread);
         worker.ListOfResizeSettings.Add(
             new CustomResizeSettings(PreviewName, PreviewSize, PreviewSize));
         return worker;
     });
 }
        public void ResizeImages()
        {
            var MultiThreadResizer = new MultiThreadResizerWorker(CountOfThreads, CountOfImage);
            MultiThreadResizer.NameSubFolderForNewFiles = @"\NewImages\ResizeImages";
            MultiThreadResizer.SetFolderWithImages(Path);
            var images = MultiThreadResizer.TakeImagesForThread();
            MultiThreadResizer.ResizeImages(images);
            Assert.AreEqual(string.Concat("Sized =", images.Count, " Successfully =", images.Count, " with errors=", 0), MultiThreadResizer.GetLogMessage());
            Assert.AreEqual(images.Count, images.Where(f => MultiThreadResizer.ListOfFileAndCustomResizeSettings[f].Status == 3).Count());

            var images2 = MultiThreadResizer.TakeImagesForThread();
            MultiThreadResizer.ResizeImages(images2);
            Assert.AreEqual(string.Concat("Sized =", images2.Count, " Successfully =", images2.Count, " with errors=", 0), MultiThreadResizer.GetLogMessage());
            Assert.AreEqual(images2.Count, images2.Where(f => MultiThreadResizer.ListOfFileAndCustomResizeSettings[f].Status == 3).Count());
            Assert.AreEqual(CountOfImage, MultiThreadResizer.ListOfFileAndCustomResizeSettings.Where(f => f.Value.Status == 3).Count());
        }
        public void ChangeFlagToFree()
        {
            var MultiThreadResizer = new MultiThreadResizerWorker(CountOfThreads, CountOfImage);
            Assert.AreEqual(GetFakeShortSummary(0, 0, 0, 0, 0, 0), MultiThreadResizer.ShortStateSummary);
            MultiThreadResizer.SetFolderWithImages(Path);

            Assert.AreEqual(GetFakeShortSummary(CountFiles,
                CountFiles * MultiThreadResizer.ListOfResizeSettings.Count,
                CountFiles * MultiThreadResizer.ListOfResizeSettings.Count,
                0, 0, 0), MultiThreadResizer.ShortStateSummary);
            var result = MultiThreadResizer.TakeImagesForThread();

            Assert.AreEqual(GetFakeShortSummary(CountFiles,
                CountFiles * MultiThreadResizer.ListOfResizeSettings.Count,
                CountFiles * MultiThreadResizer.ListOfResizeSettings.Count - CountOfThreads * CountOfImage,
                CountOfThreads * CountOfImage, 0, 0), MultiThreadResizer.ShortStateSummary);

            MultiThreadResizer.ChangeFlagToFree(result);

            Assert.AreEqual(GetFakeShortSummary(CountFiles,
                CountFiles * MultiThreadResizer.ListOfResizeSettings.Count,
                CountFiles * MultiThreadResizer.ListOfResizeSettings.Count,
                0, 0, 0), MultiThreadResizer.ShortStateSummary);
        }
 public void GetListOfFiles()
 {
     var MultiThreadResizer = new MultiThreadResizerWorker();
     var files = new List<string>();
     Assert.AreEqual(string.Concat("Found ", CountFiles, " files"), MultiThreadResizer.GetListOfFiles(Path, out files));
 }
        public void TestMultiThreadResizerClass()
        {
            var MultiThreadResizer = new MultiThreadResizerWorker();

            Assert.AreEqual(0,MultiThreadResizer.ListOfFileAndCustomResizeSettings.Count);
        }
        public void TakeImagesForThread()
        {
            var MultiThreadResizer = new MultiThreadResizerWorker(CountOfThreads, CountOfImage);
            MultiThreadResizer.SetFolderWithImages(Path);

            var result = MultiThreadResizer.TakeImagesForThread();

            Assert.AreEqual(CountOfImage, result.Count);
            Assert.AreEqual(CountOfImage,
                result.Where(f=> MultiThreadResizer.ListOfFileAndCustomResizeSettings[f].Status==2).Count());
            result = MultiThreadResizer.TakeImagesForThread();

            Assert.AreEqual(0, result.Count);
            Assert.AreEqual(0,
                result.Where(f => MultiThreadResizer.ListOfFileAndCustomResizeSettings[f].Status == 2).Count());
        }
 public void StateSummary()
 {
     int CountOfImage = 10;
     var MultiThreadResizer = new MultiThreadResizerWorker(2, CountOfImage);
     MultiThreadResizer.NameSubFolderForNewFiles = @"\NewImages\StateSummary";
     Assert.AreEqual(GetFakeShortSummary(0, 0, 0, 0, 0, 0),MultiThreadResizer.ShortStateSummary);
     MultiThreadResizer.SetFolderWithImages(Path);
     Assert.AreEqual(GetFakeShortSummary(CountFiles, CountFiles * MultiThreadResizer.ListOfResizeSettings.Count, CountFiles * MultiThreadResizer.ListOfResizeSettings.Count, 0, 0, 0),MultiThreadResizer.ShortStateSummary);
 }
        public void StartResizingByFiles()
        {
            var MultiThreadResizer = new MultiThreadResizerWorker(CountOfThreads, CountOfImage);

            MultiThreadResizer.NameSubFolderForNewFiles = @"\NewImages";
            Assert.AreEqual(GetFakeShortSummary(0, 0,0, 0, 0, 0), MultiThreadResizer.ShortStateSummary);
            MultiThreadResizer.ListOfResizeSettings.Add(new CustomResizeSettings("_2", 200, 300));
            var addedImagesResult = MultiThreadResizer.AddListOfImages(new List<string>() {
                @"C:\Users\Дмитрий\Pictures\1.jpg",
                @"C:\Users\Дмитрий\Pictures\2.png" });
            Assert.AreEqual(GetFakeShortSummary(2,
                2 * MultiThreadResizer.ListOfResizeSettings.Count,
                2 * MultiThreadResizer.ListOfResizeSettings.Count,
                0, 0, 0),
                MultiThreadResizer.ShortStateSummary);
            var result = MultiThreadResizer.ShortStateSummary;
            var task = MultiThreadResizer.StartResizingTask(60);
            task.Wait();
            Assert.AreEqual(MultiThreadResizer.ShortStateSummary, GetFakeShortSummary(2,4, 0, 0, 4, 0));
        }
 public void StartResizing()
 {
     var MultiThreadResizer = new MultiThreadResizerWorker(CountOfThreads, CountOfImage);
     MultiThreadResizer.NameSubFolderForNewFiles = @"\NewImages\StartResizing";
     Assert.AreEqual(GetFakeShortSummary(0, 0, 0, 0, 0,0), MultiThreadResizer.ShortStateSummary);
     MultiThreadResizer.SetFolderWithImages(Path);
     Assert.AreEqual(GetFakeShortSummary(CountFiles, CountFiles * MultiThreadResizer.ListOfResizeSettings.Count, CountFiles * MultiThreadResizer.ListOfResizeSettings.Count, 0, 0, 0), MultiThreadResizer.ShortStateSummary);
     var result = MultiThreadResizer.ShortStateSummary;
     var task = MultiThreadResizer.StartResizingTask(60);
     task.Wait();
     Assert.AreEqual(MultiThreadResizer.ShortStateSummary, GetFakeShortSummary(6, 6, 0, 0, 6, 0));
 }
 public void SetFolderWithImages()
 {
     var MultiThreadResizer = new MultiThreadResizerWorker();
     Assert.AreEqual(string.Concat("Added ", MultiThreadResizer.ListOfResizeSettingsDefault.Count* CountFiles, " FileAndCustomResizeSettings"), MultiThreadResizer.SetFolderWithImages(Path));
 }
示例#13
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);
		}