Exemplo n.º 1
0
        private static void NewCommandFileEvent(object sender, ValueEventArgs <Guid, string> e)
        {
            Task.Factory.StartNew((o) =>
            {
                var r         = (ValueEventArgs <Guid, string>)o;
                FileInfo file = new FileInfo(r.Value2);
                try
                {
                    using (var matcher = new TemplateMatcher(file.FullName))
                    {
                        if (!matcher.MatchTemplate())
                        {
                            if (!MatchForm.Run(file.FullName))
                            {
                                AppContext.Default.SaveResult(r.Value1, "");
                                return;
                            }
                        }

                        if (matcher.MatchTemplate())
                        {
                            var @out = new DirectoryInfo(Config.OUT_FOLDER);
                            @out.EnsureDirectory();

                            var imgcc = @out.CombineFileName(string.Concat(file.GetFileNameWithoutExtension(), "_ccimg", file.Extension));
                            matcher.PixellateHiddenAreasAndSaveUnderArea(imgcc.FullName);

                            var img = @out.CombineFileName(string.Concat(file.GetFileNameWithoutExtension(), "_cc", file.Extension));
                            matcher.SaveResult(img.FullName);

                            AppContext.Default.SaveResult(r.Value1, imgcc.FullName, img.FullName);
                        }
                        else
                        {
                            throw new ApplicationException("Cannot match template");
                        }
                    }
                }
                catch (Exception ex)
                {
                    AppContext.Default.FireError(ex);
                }
            }, e, TaskCreationOptions.LongRunning);
        }