Beispiel #1
0
        void Start()
        {
            //usedAxis = this.axis;

            _endPoint = new IPEndPoint(IPAddress.Any, listenPort);

            _client = new UdpClient(_endPoint);
            _thread = new Thread(async() =>
            {
                while (_runReceiveThread)
                {
                    try
                    {
                        var result    = await _client.ReceiveAsync();
                        var rawString = Encoding.UTF8.GetString(result.Buffer);
                        //usedAxis = this.axis;
                        var packet     = RawParser.Parse(rawString);
                        _currentPacket = packet;
                    }
                    catch (ObjectDisposedException)
                    {
                    }
                    catch (Exception e)
                    {
                        Debug.Log("Parsing Error: " + e);
                    }
                }
            });
            _thread.Start();
        }
Beispiel #2
0
        private static void SaveAsPng(string gpFile, string pngDirectory)
        {
            IRenderer renderer = new BitmapRenderer();

            var imagePaletteBytes = new Extractor().GetPaletteBytes(gpFile);
            var extractResult     = new Extractor().GetImagesFromOutput(gpFile).ToList();

            var rawParser = new RawParser();

            var paletteBytes    = File.ReadAllBytes(@"..\..\..\..\palette\0\agew_1.pal");
            var colorCollection = rawParser.GetColorCollectionFromPalleteFile(paletteBytes);

            var imagePaletteColors = ImageGenerator.OffsetsToColors(imagePaletteBytes, colorCollection);

            var nationColorOffset = NationColorOffset.Red;

            using (var bitMap = new Runner().Run(extractResult, nationColorOffset, 0, rawParser, renderer, imagePaletteColors, colorCollection))
            {
                using (var stream = new MemoryStream())
                {
                    bitMap.Save(stream, ImageFormat.Png);
                    File.WriteAllBytes(Path.Combine(pngDirectory, Path.GetFileNameWithoutExtension(gpFile) + ".png"),
                                       stream.ToArray());
                }
            }
        }
Beispiel #3
0
        // helper functions
        Expr parseExpr(string str)
        {
            var expr = RawParser.ParseExpr(str);

            exprs_.Add(expr);
            return(expr);
        }
Beispiel #4
0
        //Initialize values
        protected void Initialize(FieldInfo cfgFieldInfo)
        {
            // Default values
            Dictionary <string, string> config_data
                = new Dictionary <string, string> {
                { "server", "localhost" },
                { "database", "facturación" },
                { "uid", "root" },
                { "password", "armagedon2" }
                };

            if (cfgFieldInfo != null)
            {
                config_data = (Dictionary <string, string>)cfgFieldInfo
                              .GetValue(null);
            }
            else if (File.Exists("dbconfig.ini"))
            {
                RawParser.Parse1(Raw.Raw.Get("dbconfig.ini"), config_data);
            }

            server   = config_data["server"];
            database = config_data["database"];
            uid      = config_data["uid"];
            password = config_data["password"];

            string connectionString = string.Format(
                "SERVER={0};DATABASE={1};UID={2};PASSWORD={3};",
                server, database, uid, password);

            connection = new MySqlConnection(connectionString);
        }
Beispiel #5
0
        public Form1()
        {
            InitializeComponent();

            var image = RawParser.Open("Images\\JPCLN001.IMG");

            var image2 = image
                         .SmoothMedian(3)
                         .Convert <Gray, double>()
                         .Mul(1.0 / 4096.0);

            //var image3 = image2.Convert<Gray, float>();
            // image3.ROI = new Rectangle(100, 100, 2048 - 200, 2048 - 200);
            // image3 = image3.Copy();

            //image3 = image3.SmoothGaussian(21).Sub(image3);

            //var image4 = image3.Pow(2);//.SmoothGaussian(51).Pow(0.5);
            //Emgu.CV.CvInvoke.Divide(image3, image4, image3, 1);

            //image5 = image5.ThresholdAdaptive(new Gray(255), Emgu.CV.CvEnum.AdaptiveThresholdType.GaussianC, Emgu.CV.CvEnum.ThresholdType.Binary, 41, new Gray(0));

            //image3.Draw(new Ellipse(new PointF(1634, 692), new SizeF(150, 150), 0), new Gray(1000), 2);

            pictureBox1.Image = image2.Bitmap;
        }
Beispiel #6
0
        private static async Task <bool> ParseHeadingLineAsync(StreamReader reader,
                                                               Action <string, string, string> onHeadingLine)
        {
            var line = await reader.ReadLineAsync();

            return(RawParser.ParseHeadingLine(line, onHeadingLine));
        }
Beispiel #7
0
        public static void Generate(ILogger logger)
        {
            EEDID instance = EEDID.Parse(MacBookPro2018.IntegratedLaptopPanelEdidTable);

            var parser = new RawParser {
                Logger = logger
            };

            parser.Parse(instance);
        }
Beispiel #8
0
 public CreateIndexStmt(string indexname,
                        BaseTableRef target, bool unique, List <string> columns, Expr where, string text) : base(text)
 {
     targetref_    = target;
     def_          = new IndexDef();
     def_.name_    = indexname;
     def_.unique_  = unique;
     def_.columns_ = columns;
     def_.table_   = target;
     select_       = RawParser.ParseSingleSqlStatement
                         ($"select sysrid_, {string.Join(",", columns)} from {def_.table_.relname_}") as SelectStmt;
 }
Beispiel #9
0
        private static async Task <bool?> ParseHeaderLineAsync(StreamReader reader,
                                                               Action <string, string> onHeaderLine)
        {
            var line = await reader.ReadLineAsync();

            if (line.Length == 0)
            {
                return(null);
            }

            return(RawParser.ParseHeaderLine(line, onHeaderLine));
        }
Beispiel #10
0
        public static void Generate(ILogger logger)
        {
            var parser = new RawParser {
                Logger = logger
            };

            EEDID[] instances = EEDID.Instance;
            foreach (var instance in instances)
            {
                parser.Parse(instance);
            }
        }
Beispiel #11
0
 public CreateIndexStmt(string indexname,
                        BaseTableRef target, bool unique, List <string> columns, Expr where, string text) : base(text)
 {
     targetref_ = target;
     def_       = new IndexDef
     {
         name_    = indexname,
         unique_  = unique,
         columns_ = columns,
         table_   = target
     };
     select_ = RawParser.ParseSingleSqlStatement
                   ($"select sysrid_, {string.Join(",", columns)} from {def_.table_.relname_}") as SelectStmt;
     // select_ is a different statement, binding their options
     select_.queryOpt_ = queryOpt_;
 }
Beispiel #12
0
        public AnalyzeStmt(BaseTableRef target, string text,
                           SelectStmt.TableSample ts) : base(text)
        {
            // SELECT statement is used so later optimizations can be kicked in easier
            targetref_ = target;
            string sql = $"select * from {target.relname_} ";

            if (ts != null)
            {
                sql += $" tablesample row ({ts.rowcnt_})";
            }

            select_ = RawParser.ParseSingleSqlStatement(sql) as SelectStmt;
            // select_ is a different statement, binding their options
            select_.queryOpt_ = queryOpt_;
        }
Beispiel #13
0
        public static bool ParseMessage(Stream stream,
                                        Action <string, string, string> onHeadingLine,
                                        Action <string, string> onHeaderLine)
        {
            // why Debug.Assert? in production code there's no excuse to pass null delegates
            Debug.Assert(onHeadingLine != null);
            Debug.Assert(onHeaderLine != null);

            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            var reader = new StreamReader(stream);

            var headingParsing = RawParser.ParseHeadingLine(reader.ReadLine(), onHeadingLine);

            if (!headingParsing)
            {
                return(false);
            }

            while (true)
            {
                var headerLine = reader.ReadLine();
                headerLine = headerLine ?? string.Empty;
                if (headerLine.Length == 0)
                {
                    break;
                }
                var headerParsing = RawParser.ParseHeaderLine(headerLine, onHeaderLine);
                if (!headerParsing)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #14
0
        private void Do()
        {
            var filePath = @"../../../../gp/test.gp";

            var imagePaletteBytes = new Extractor().GetPaletteBytes(filePath);
            var extractResult     = new Extractor().GetImagesFromOutput(filePath).ToList();

            IRenderer renderer = new BitmapRenderer();

            var paletteBytes = File.ReadAllBytes(@"../../../../palette/0/agew_1.pal");

            var rawParser = new RawParser();

            var colorCollection = rawParser.GetColorCollectionFromPalleteFile(paletteBytes);

            var imagePaletteColors = ImageGenerator.OffsetsToColors(imagePaletteBytes, colorCollection);

            var nationColorOffset = NationColorOffset.Blue;

            //Watch(extractResult);

            var bitmapList = DrawImage(extractResult, nationColorOffset, extractResult.Count, rawParser, renderer, imagePaletteColors, colorCollection);

            var itemsForListBox = Enumerable.Range(0, bitmapList.Count).Select(it => it.ToString()).ToList();

            listBox1.DataSource = itemsForListBox;

            listBox1.SelectedIndexChanged += (sender, args) =>
            {
                if ((sender as ListBox).SelectedIndex > -1)
                {
                    pictureBox2.Image = bitmapList[(sender as ListBox).SelectedIndex];
                }
            };

            listBox1.ClearSelected();
            listBox1.SelectedIndex = 0;
        }
Beispiel #15
0
        private void SetCurrentImage(int imageIndex)
        {
            currentImage            = imageIndex;
            nextImageButton.Enabled = currentImage < images.Count - 1;

            var image = RawParser.Open(images[currentImage].FullName).Convert <Bgr, byte>();

            currentDescriptionData = descriptionsData.FirstOrDefault(i => i.ImageName == images[currentImage].Name);

            if (currentDescriptionData != null)
            {
                image.Draw(
                    new CircleF(new PointF(currentDescriptionData.X, currentDescriptionData.Y), currentDescriptionData.NoduleSize / pixelSize),
                    new Bgr(0, 0, 255), 2);

                currentFileNameLabel.Text = $"{images[currentImage].Name} {currentDescriptionData.Class} {currentDescriptionData.Sex} {currentDescriptionData.Years}";
            }
            else
            {
                currentFileNameLabel.Text = images[currentImage].Name;
            }

            currentImagePictureBox.Image = image.Bitmap;
        }
Beispiel #16
0
        private async void Request()
        {
            try
            {
                IsBusy = true;
                HasErrors = false;
                NoItems = false;
                DataProviderRawData = string.Empty;
                Items.Clear();
                
                var config = new BingDataConfig() { Query = BingQueryParam, Country = BingCountrySelectedItem };
               
                var items = await bingDataProvider.LoadDataAsync(config, MaxRecordsParam);

                NoItems = !items.Any();

                foreach (var item in items)
                {
                    Items.Add(item);
                }
                
                var rawParser = new RawParser();
                var rawData = await rawDataProvider.LoadDataAsync(config, MaxRecordsParam, rawParser);
                DataProviderRawData = rawData.FirstOrDefault()?.Raw;
            }
            catch (Exception ex)
            {
                DataProviderRawData += ex.Message;
                DataProviderRawData += ex.StackTrace;
                HasErrors = true;
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #17
0
        private async void Request()
        {
            try
            {
                IsBusy = true;
                HasErrors = false;
                NoItems = false;
                DataProviderRawData = string.Empty;
                Items.Clear();

                var config = new RssDataConfig
                {
                    Url = new Uri(RssQuery, UriKind.Absolute),
                    OrderBy = OrderBy != RssSampleOrderBy.None ? OrderBy.ToString() : string.Empty,
                    OrderDirection = SortDirection
                };

                var items = await rssDataProvider.LoadDataAsync(config, MaxRecordsParam);

                NoItems = !items.Any();

                foreach (var item in items)
                {
                    Items.Add(item);
                }

                var rawParser = new RawParser();
                var rawData = await rawDataProvider.LoadDataAsync(config, MaxRecordsParam, rawParser);
                DataProviderRawData = rawData.FirstOrDefault()?.Raw;
            }
            catch (Exception ex)
            {
                DataProviderRawData += ex.Message;
                DataProviderRawData += ex.StackTrace;
                HasErrors = true;
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #18
0
        private async void Request()
        {
            try
            {
                IsBusy = true;
                HasErrors = false;
                NoItems = false;
                DataProviderRawData = string.Empty;
                Items.Clear();

                var config = new RestApiDataConfig()
                {
                    Url = new Uri(RestApiQuery),
                };

                var paginationConfig = GetPaginationConfig();
                if (paginationConfig != null)
                {
                    config.PaginationConfig = paginationConfig;
                }

                var parser = new RestApiSampleParser();
                parser.InitializeSample(RestApiMainRoot, TextProperty1, TextProperty2, ImageProperty);
                var items = await restApiDataProvider.LoadDataAsync(config, MaxRecordsParam, parser);

                NoItems = !items.Any();

                foreach (var item in items)
                {
                    Items.Add(item);
                }

                var rawParser = new RawParser();
                var rawData = await rawDataProvider.LoadDataAsync(config, MaxRecordsParam, rawParser);
                DataProviderRawData = rawData.FirstOrDefault()?.Raw;
            }
            catch (Exception ex)
            {
                DataProviderRawData += ex.Message;
                DataProviderRawData += ex.StackTrace;
                HasErrors = true;
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #19
0
        private T MapCommandPositionalOptionsAndOptions(T model, string[] args)
        {
            var command = _mapper.Commands.Get(args[0], _mapper.Settings.StringComparison);

            if (command is null || command.IsDisabled)
            {
                throw new UnknownCommandException(args[0]);
            }

            var commandInstance = _reflectionService.SetValue(command, model);

            var optionsStartIndex = 1;

            for (; optionsStartIndex < args.Length; optionsStartIndex++)
            {
                if (command.Options.Any(x => x.IsPositionalOption))
                {
                    break;
                }

                var arg = args[optionsStartIndex];

                if (arg.IsValidOption())
                {
                    break;
                }

                var subcommand = command.Subcommands.Get(arg, _mapper.Settings.StringComparison);

                if (subcommand is null || subcommand.IsDisabled)
                {
                    throw new UnknownCommandException(arg);
                }

                var subcommandInstance = _reflectionService.SetValue(subcommand, commandInstance);

                command = subcommand;
                commandInstance = subcommandInstance;
            }

            var proceededOptions = new HashSet<Option>();
            var parsedOptions = RawParser.ParseOptions(args, optionsStartIndex);

            var groupedOptions = new Dictionary<Option, List<string>>(
                new OptionPropertyInfoEqualityComparer());

            foreach (var ((key, matchType), values) in parsedOptions)
            {
                var option = command.Options.Get(matchType, 
                    key.RemoveOptionPrefix(), _mapper.Settings.StringComparison);

                if (option is null || option.IsDisabled)
                {
                    throw new UnknownCommandOptionException(command.ToString(), key);
                }

                proceededOptions.Add(option);
                groupedOptions.AddOrMergeValues(option, values);
            }

            var positionalOptionsStartIndex = 0;
            var hasPositionalOptionSeparator = false;

            for (var i = 0; i < args.Length; i++)
            {
                if (!args[i].IsPositionalOptionsSeparator())
                {
                    continue;
                }

                positionalOptionsStartIndex = i + 1;
                hasPositionalOptionSeparator = true;

                break;
            }

            positionalOptionsStartIndex = Math.Max(optionsStartIndex, positionalOptionsStartIndex);

            if (command.Options.Any(x => x.IsPositionalOption && x.Type.IsList()))
            {
                var listPositionalOptionValues = new List<string>();

                for (var i = positionalOptionsStartIndex; i < args.Length; i++)
                {
                    if (!hasPositionalOptionSeparator && args[i].IsValidOption())
                    {
                        break;
                    }

                    listPositionalOptionValues.Add(args[i]);
                }

                if (listPositionalOptionValues.Any())
                {
                    var option = command.Options.GetByPosition(0);

                    _reflectionService.SetValue(option, commandInstance,
                        listPositionalOptionValues, _mapper.Settings.Culture);

                    proceededOptions.Add(option);
                }
            }
            else
            {
                for (var i = positionalOptionsStartIndex; i < args.Length; i++)
                {
                    if (!hasPositionalOptionSeparator && args[i].IsValidOption())
                    {
                        break;
                    }

                    var option = command.Options.GetByPosition(i - positionalOptionsStartIndex);

                    if (option is null)
                    {
                        throw new NoMatchedValueForCommandPositionalOptionException(command.ToString(), args[i]);
                    }

                    _reflectionService.SetValue(option, commandInstance, args[i], _mapper.Settings.Culture);

                    proceededOptions.Add(option);
                }
            }

            foreach (var option in command.Options)
            {
                if (option.IsRequired && !proceededOptions.Contains(option))
                {
                    throw new RequiredCommandOptionException(command.ToString(), option.ToString());
                }
            }

            foreach (var option in command.Options)
            {
                if (proceededOptions.Contains(option))
                {
                    continue;
                }

                _reflectionService.SetValue(option, commandInstance, option.DefaultValue);
            }

            foreach (var (option, values) in groupedOptions)
            {
                _reflectionService.SetValue(option, commandInstance, values, _mapper.Settings.Culture);
            }

            return model;
        }
Beispiel #20
0
        private IList <Bitmap> DrawImage(IList <ImageLayout> extractResult, NationColorOffset nationColorOffset, int numberOfImages, RawParser rawParser, IRenderer renderer, Color[] imagePaletteArray,
                                         Color[] generalPalleteArray)
        {
            return(Helper.WithMeasurement(
                       () =>
            {
                var bitMapCollection = new Collection <Bitmap>();

                //var idsForProcessing = new[] { 0 };
                var idsForProcessing = Enumerable.Range(1, numberOfImages - 1).ToList();

                foreach (var imageNumber in idsForProcessing)
                {
                    Debug.WriteLine("***************************** " + imageNumber);
                    Watch(extractResult[imageNumber].PartialLayouts.ToList());
                }

                foreach (int i in idsForProcessing)
                {
                    Helper.WithMeasurement(() =>
                    {
                        try
                        {
                            var bitMap = new Runner().Run(extractResult, nationColorOffset, i, rawParser, renderer, imagePaletteArray, generalPalleteArray);
                            bitMapCollection.Add(bitMap);
                        }
                        catch (Exception ex)
                        {
                        }
                    }, "Image", onFinish: elapsed => richTextBox1.Text += String.Format("[{0,4}] - {1:g}\n", i, elapsed));
                }

                return bitMapCollection;
            },
                       name: "Run",
                       onFinish: elapsed => richTextBox1.Text += String.Format("Finished in {0:c}\n ", elapsed)));
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            Catalog.Init();

            string sql = "";

            //TestTpcds_LoadData();

            if (false)
            {
                JOBench.CreateTables();
                sql = File.ReadAllText("../../../jobench/10a.sql");
                goto doit;
            }

            if (false)
            {
                Tpch.CreateTables();
                Tpch.LoadTables("0001");
                //Tpch.CreateIndexes();
                Tpch.AnalyzeTables();
                sql = File.ReadAllText("../../../tpch/q20.sql");
                goto doit;
            }

            if (true)
            {
                Tpcds.CreateTables();
                //Tpcds.LoadTables("tiny");
                //Tpcds.AnalyzeTables();
                // 1, 2,3,7,10,
                // long time: 4 bad plan
                // 6: distinct not supported, causing wrong result
                sql = File.ReadAllText("../../../tpcds/q7.sql");
                goto doit;
            }

doit:
            sql = "with cte as (select * from d) select * from cte where d1=1;";
            sql = "with cte as (select * from a) select cte1.a1, cte2.a2 from cte cte1, cte cte2 where cte2.a3<3";  // ok
            sql = "with cte as (select * from a) select * from cte cte1, cte cte2 where cte1.a2=cte2.a3 and cte1.a1> 0 order by 1;";
            sql = "select ab.a1, cd.c1 from (select * from a join b on a1=b1) ab , (select * from c join d on c1=d1) cd where ab.a1=cd.c1";
            sql = "select * from (select avg(a2) from a join b on a1=b1) a (a1) join b on a1=b1;";
            sql = "with cte as (select * from a join b on a1=b1 join c on a2=c2) select * from cte cte1, cte cte2;"; // ok
            sql = "with cte as (select count(*) from a join b on a1=b1) select * from cte cte1;";                    // ok
            sql = "with cte as (select count(*) from a join b on a1=b1) select * from cte cte1, cte cte2;";
            sql = "with cte as (select * from d where d1=1) select * from cte cte1, cte cte2;";
            sql = "with cte as (select * from a where a1=1) select * from cte cte1, cte cte2;";

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            Console.WriteLine(sql);
            var a = RawParser.ParseSingleSqlStatement(sql);

            a.queryOpt_.profile_.enabled_ = true;
            a.queryOpt_.optimize_.enable_subquery_unnest_ = true;
            a.queryOpt_.optimize_.remove_from_            = false;
            a.queryOpt_.optimize_.use_memo_        = true;
            a.queryOpt_.optimize_.enable_cte_plan_ = false;
            a.queryOpt_.optimize_.use_codegen_     = false;

            //a.queryOpt_.optimize_.memo_disable_crossjoin = false;
            //a.queryOpt_.optimize_.use_joinorder_solver = true;

            // -- Semantic analysis:
            //  - bind the query
            a.queryOpt_.optimize_.ValidateOptions();
            a.Bind(null);

            // -- generate an initial plan
            ExplainOption.show_tablename_     = false;
            a.queryOpt_.explain_.show_output_ = false;
            a.queryOpt_.explain_.show_cost_   = a.queryOpt_.optimize_.use_memo_;
            var rawplan = a.CreatePlan();

            Console.WriteLine("***************** raw plan *************");
            Console.WriteLine(rawplan.Explain(0));

            physic.PhysicNode phyplan = null;
            if (a.queryOpt_.optimize_.use_memo_)
            {
                Console.WriteLine("***************** optimized plan *************");
                var optplan = a.SubstitutionOptimize();
                Console.WriteLine(optplan.Explain(0, a.queryOpt_.explain_));
                a.optimizer_.InitRootPlan(a);
                a.optimizer_.OptimizeRootPlan(a, null);
                Console.WriteLine(a.optimizer_.PrintMemo());
                phyplan = a.optimizer_.CopyOutOptimalPlan();
                Console.WriteLine(a.optimizer_.PrintMemo());
                Console.WriteLine("***************** Memo plan *************");
                Console.WriteLine(phyplan.Explain(0, a.queryOpt_.explain_));
            }
            else
            {
                // -- optimize the plan
                Console.WriteLine("-- optimized plan --");
                var optplan = a.SubstitutionOptimize();
                Console.WriteLine(optplan.Explain(0, a.queryOpt_.explain_));

                // -- physical plan
                Console.WriteLine("-- physical plan --");
                phyplan = a.physicPlan_;
                Console.WriteLine(phyplan.Explain(0, a.queryOpt_.explain_));
            }

            Console.WriteLine("-- profiling plan --");
            var final = new PhysicCollect(phyplan);

            a.physicPlan_ = final;
            var context = new ExecContext(a.queryOpt_);

            final.ValidateThis();
            if (a is SelectStmt select)
            {
                select.OpenSubQueries(context);
            }
            var code = final.Open(context);

            code += final.Exec(null);
            code += final.Close();

            if (a.queryOpt_.optimize_.use_codegen_)
            {
                CodeWriter.WriteLine(code);
                Compiler.Run(Compiler.Compile(), a, context);
            }
            Console.WriteLine(phyplan.Explain(0, a.queryOpt_.explain_));

            stopWatch.Stop();
            Console.WriteLine("RunTime: " + stopWatch.Elapsed);
            Console.ReadKey();
        }
Beispiel #22
0
        private void OpenFile(StorageFile file)
        {
            //Add a loading screen
            if (rawImage != null)
            {
                EmptyImage();
            }
            Load.Show();
            ImageSelected = true;
            isBindingEnabled = false;

            Task.Run(async () =>
            {
                try
                {
                    var watchTotal = Stopwatch.StartNew();
                    using (Stream stream = (await file.OpenReadAsync()).AsStreamForRead())
                    {
                        var watchdecode = Stopwatch.StartNew();
                        RawDecoder decoder = RawParser.GetDecoder(stream, file);
                        try
                        {
                            thumbnail = decoder.DecodeThumb();
                            Task.Run(() =>
                            {
                                var result = thumbnail?.GetBitmap();
                                DisplayImage(result, true);
                            });
                        }
                        //since thumbnail are optionnal, we ignore all errors           
                        catch (Exception ex) { }

                        decoder.DecodeRaw();
                        decoder.DecodeMetadata();
                        rawImage = decoder.rawImage;

                        watchdecode.Stop();
                        Debug.WriteLine("Decoding done in " + watchdecode.ElapsedMilliseconds + " ms");

                        var watchLook = Stopwatch.StartNew();
                        rawImage.ApplyTableLookUp();
                        watchLook.Stop();
                        Debug.WriteLine("Lookup done in " + watchLook.ElapsedMilliseconds + " ms");

                        var watchScale = Stopwatch.StartNew();
                        ImageHelper.ScaleValues(rawImage);
                        watchScale.Stop();
                        Debug.WriteLine("Scale done in " + watchScale.ElapsedMilliseconds + " ms");
                    }

                    rawImage.metadata.SetFileMetatdata(file);

                    if (rawImage.isCFA)
                    {
                        var watchDemos = Stopwatch.StartNew();
                        //get the algo from the settings
                        DemosaicAlgorithm algo;
                        try
                        {
                            algo = SettingStorage.DemosAlgo;
                        }
                        catch (Exception)
                        {
                            algo = DemosaicAlgorithm.FastAdams;
                        }
                        Demosaic.Demos(rawImage, algo);

                        watchDemos.Stop();
                        Debug.WriteLine("Demos done in " + watchDemos.ElapsedMilliseconds + " ms");
                    }

                    if (rawImage.convertionM != null)
                    {
                        var watchConvert = Stopwatch.StartNew();
                        rawImage.ConvertRGB();
                        watchConvert.Stop();
                        Debug.WriteLine("ConvertRGB done in " + watchConvert.ElapsedMilliseconds + " ms");
                    }

                    var watchPreview = Stopwatch.StartNew();
                    ImageHelper.CreatePreview(SettingStorage.PreviewFactor, ImageDisplay.ViewportHeight, ImageDisplay.ViewportWidth, rawImage);
                    watchPreview.Stop();
                    Debug.WriteLine("Preview done in " + watchPreview.ElapsedMilliseconds + " ms");

                    watchTotal.Stop();
                    rawImage.metadata.ParsingTime = watchTotal.ElapsedMilliseconds;
                    GC.Collect();
                    //check if enough memory
                    if (MemoryManager.AppMemoryUsageLimit - MemoryManager.AppMemoryUsage < ((ulong)rawImage.fullSize.green.Length * 6) || MemoryManager.AppMemoryUsageLevel == AppMemoryUsageLevel.High)
                    {
                        TextDisplay.DisplayWarning("The image is bigger than what your device support, this application may fail when saving. Only " + ((MemoryManager.AppMemoryUsageLimit - MemoryManager.AppMemoryUsage) / (1024 * 1024)) + "Mb left of memory for this app to use");
                    }
#if !DEBUG
                    //send an event with file extension, camera model and make
                    logger.Log("SuccessOpening " + rawImage?.metadata?.FileExtension.ToLower() + " " + rawImage?.metadata?.Make + " " + rawImage?.metadata?.Model);
#endif
                    DefaultValue.Rotation = rawImage.metadata.OriginalRotation;
                    DefaultValue.ReverseGamma = rawImage.IsGammaCorrected;
                    DefaultValue.RMul = rawImage?.metadata.WbCoeffs?.Red ?? 1;
                    DefaultValue.GMul = rawImage?.metadata.WbCoeffs?.Green ?? 1;
                    DefaultValue.BMul = rawImage?.metadata.WbCoeffs?.Blue ?? 1;
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        var exif = rawImage.ParseExif();
                        //Group the data
                        var groups = from x in exif group x by x.Group into grp orderby grp.Key select grp;
                        //Set the grouped data to CollectionViewSource
                        ExifSource.Source = groups;
                        ResetControls();
                        UpdatePreview(true);
                        ControlVisibilty.Value = true;
                        SetImageSizeText();
                    });
                    if (rawImage.errors.Count > 0)
                    {
                        var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
                        TextDisplay.DisplayWarning(loader.GetString("ErrorOnLoadWarning"));
#if !DEBUG
                        //send an event with file extension and camera model and make if any                   
                        logger.Log("ErrorOnOpen " + file?.FileType.ToLower() + " " + rawImage?.metadata?.Make + " " + rawImage?.metadata?.Model + "" + rawImage.errors.Count);
#endif
                    }
                    isBindingEnabled = true;
                    thumbnail = null;
                }
                catch (Exception ex)
                {
#if !DEBUG
                    //send an event with file extension and camera model and make if any                   
                    logger.Log("FailOpening " + file?.FileType.ToLower() + " " + rawImage?.metadata?.Make + " " + rawImage?.metadata?.Model);
#endif

                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        EmptyImage();
                    });
                    ImageSelected = false;
                    var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
                    TextDisplay.DisplayError(loader.GetString("ExceptionText"));
                }

                CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // Blur(false);
                    Load.Hide();
                });
                ImageSelected = false;
            });
        }
Beispiel #23
0
        public Bitmap Run(IList <ImageLayout> extractResult, NationColorOffset nationColorOffset, int imageNumber, RawParser rawParser, IRenderer renderer, Color[] imagePaletteArray, Color[] generalPaletteColors)
        {
            var imageGenerator = new ImageGenerator();

            var partialLayouts = extractResult[imageNumber].PartialLayouts;

            var largestWidth = partialLayouts
                               .Select(it => it.Width + it.offsetX)
                               .OrderByDescending(it => it)
                               .First();

            var largestHeight = partialLayouts
                                .Select(it => it.Height + it.offsetY)
                                .OrderByDescending(it => it)
                                .First();

            var bitMap = new Bitmap(largestWidth, largestHeight);

            renderer.SetupCanvas(bitMap);

            foreach (var layout in partialLayouts)
            {
                ImageLayoutInfo layout1 = layout;

                var imageView = new ImageView(layout1.Width + layout1.offsetX, layout1.Height + layout1.offsetY);

                var firstPartBlocks = Helper.WithMeasurement(() =>
                {
                    var rawFirstPartBlocks = rawParser.ParseRawBlockGroups(layout1.Bytes, layout1.NumberOfRows);
                    return(rawFirstPartBlocks.ConvertToAbsoluteCoordinatesBlocks());
                }, "firstPartBlocks");

                var secondPartBlocks = Helper.WithMeasurement(() => rawParser.GetRawColorBlocks(layout1.Bytes, layout1.ColorBlocksSectionOffset, (int)layout1.GlobalByteOffsetStart + layout1.ColorBlocksSectionOffset + layout1.HeaderBytes.Length, layout1.IsNationColorImage), "secondPartBlocks");

                Helper.WithMeasurement(() =>
                {
                    imageGenerator.RenderShapeBlocks(imageView, firstPartBlocks, layout1);
                    imageGenerator.RenderCounterBlocksOnBitmap(imageView, nationColorOffset, firstPartBlocks, secondPartBlocks, layout1, imagePaletteArray, generalPaletteColors);
                }, "RenderCounterBlocksOnBitmap");

                Helper.WithMeasurement(() => renderer.RenderImage(bitMap, imageView), "Render on bitmap");
            }

            return(bitMap);
        }
        private async void MoreItemsRequest()
        {
            try
            {
                IsBusy = true;
                HasErrors = false;
                NoItems = false;
                DataProviderRawData = string.Empty;
                Items.Clear();

                var items = await localStorageDataProvider.LoadMoreDataAsync();

                NoItems = !items.Any();

                foreach (var item in items)
                {
                    Items.Add(item);
                }

                var rawParser = new RawParser();
                var rawData = await rawDataProvider.LoadMoreDataAsync();
                DataProviderRawData = rawData.FirstOrDefault()?.Raw;
            }
            catch (Exception ex)
            {
                DataProviderRawData += ex.Message;
                DataProviderRawData += ex.StackTrace;
                HasErrors = true;
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            Catalog.Init();

            string sql = "";

            if (args.Length != 0)
            {
                sql = args[0];
            }

#pragma warning disable CS0162 // Unreachable code detected
            // The warnings are annoying, so using a pragma to suppress them.
            if (false)
            {
                JOBench.CreateTables();
                var stats_fn = "../../../../jobench/statistics/jobench_stats";
                Catalog.sysstat_.read_serialized_stats(stats_fn);
                sql = File.ReadAllText("../../../../jobench/10a.sql");
                goto doit;
            }

            if (false)
            {
                Tpch.CreateTables();
                Tpch.LoadTables("0001");
                //Tpch.CreateIndexes();
                Tpch.AnalyzeTables();
                sql = File.ReadAllText("../../../../tpch/q20.sql");
                goto doit;
            }

            if (false)
            {
                //84
                sql = File.ReadAllText("../../../../tpcds/q33.sql");
                Tpcds.CreateTables();
                Tpcds.LoadTables("tiny");
                Tpcds.AnalyzeTables();
                // long time: 4 bad plan
                // 6: distinct not supported, causing wrong result
                // q23, q33, q56, q60: in-subquery plan bug
                // 10,11,13, 31, 38, 41, 48, 54, 66, 72, 74: too slow
                goto doit;
            }
#pragma warning restore CS0162 // Unreachable code detected

doit:
            bool convMode = false;

            // Application Arguments in Project properties seem to be
            // effective only after rebuilding.
            // This is a last ditch effort to be able to debug arbitrary
            // statements without rebuilding the solution.
            string inputFile = "";
            if (sql.Length == 2 && sql == "-i")
            {
                convMode = true;
            }
            else if (sql.Length == 2 && sql.StartsWith("-f"))
            {
                inputFile = args[1];
            }
            else if (sql.Length == 0)
            {
                sql = "select * from a tablesample row (2);";
            }

            do
            {
                if (convMode == true || (sql.Length == 1 && sql.Equals("-")))
                {
                    System.Console.Write("QSQL> ");
                    sql = System.Console.ReadLine();
                    System.Console.WriteLine(sql);
                }

                var datetime = new DateTime();
                datetime = DateTime.Now;

                var stopWatch = new Stopwatch();
                stopWatch.Start();

                if (inputFile.Length != 0)
                {
                    // read the file and execute all statements in it.
                    RunSQLFromFile(inputFile);
                    goto done;
                }

                // query options might be conflicting or incomplete
                Console.WriteLine(sql);
                var a = RawParser.ParseSingleSqlStatement(sql);
                ExplainOption.show_tablename_ = true;
                a.queryOpt_.profile_.enabled_ = true;
                a.queryOpt_.optimize_.enable_subquery_unnest_ = true;
                a.queryOpt_.optimize_.remove_from_            = true;
                a.queryOpt_.optimize_.use_memo_                  = true;
                a.queryOpt_.optimize_.enable_cte_plan_           = true;
                a.queryOpt_.optimize_.use_codegen_               = false;
                a.queryOpt_.optimize_.memo_disable_crossjoin_    = false;
                a.queryOpt_.optimize_.memo_use_joinorder_solver_ = false;
                a.queryOpt_.explain_.show_output_                = true;
                a.queryOpt_.explain_.show_id_      = true;
                a.queryOpt_.explain_.show_estCost_ = a.queryOpt_.optimize_.use_memo_;
                a.queryOpt_.explain_.mode_         = ExplainMode.full;

                // -- Semantic analysis:
                //  - bind the query
                a.queryOpt_.optimize_.ValidateOptions();

                if (!(a is SelectStmt))
                {
                    SQLStatement.ExecSQLList(sql);
                    goto done;
                }

                a.Bind(null);

                // -- generate an initial plan
                var rawplan = a.CreatePlan();
                Console.WriteLine("***************** raw plan *************");
                Console.WriteLine(rawplan.Explain());

                // -- optimize the plan
                PhysicNode phyplan = null;
                if (a.queryOpt_.optimize_.use_memo_)
                {
                    Console.WriteLine("***************** optimized plan *************");
                    var optplan = a.SubstitutionOptimize();
                    Console.WriteLine(optplan.Explain(a.queryOpt_.explain_));
                    a.optimizer_ = new Optimizer(a);
                    a.optimizer_.ExploreRootPlan(a);
                    phyplan = a.optimizer_.CopyOutOptimalPlan();
                    Console.WriteLine(a.optimizer_.PrintMemo());
                    Console.WriteLine("***************** Memo plan *************");
                    Console.WriteLine(phyplan.Explain(a.queryOpt_.explain_));
                }
                else
                {
                    // -- optimize the plan
                    Console.WriteLine("-- optimized plan --");
                    var optplan = a.SubstitutionOptimize();
                    Console.WriteLine(optplan.Explain(a.queryOpt_.explain_));

                    // -- physical plan
                    Console.WriteLine("-- physical plan --");
                    phyplan = a.physicPlan_;
                    Console.WriteLine(phyplan.Explain(a.queryOpt_.explain_));
                }

                // -- output profile and query result
                Console.WriteLine("-- profiling plan --");
                var final = new PhysicCollect(phyplan);
                a.physicPlan_ = final;
                ExecContext context = a.CreateExecContext();

                final.ValidateThis();
                if (a is SelectStmt select)
                {
                    select.OpenSubQueries(context);
                }

                final.Open(context);
                final.Exec(null);
                final.Close();

                if (a.queryOpt_.optimize_.use_codegen_)
                {
                    CodeWriter.WriteLine(context.code_);
                    Compiler.Run(Compiler.Compile(), a, context);
                }
                Console.WriteLine(phyplan.Explain(a.queryOpt_.explain_));
done:
                stopWatch.Stop();
                Console.WriteLine("RunTime: " + stopWatch.Elapsed);
            } while (convMode == true);

            Console.ReadKey();
        }
Beispiel #26
0
 public AnalyzeStmt(BaseTableRef target, string text) : base(text)
 {
     // SELECT statement is used so later optimizations can be kicked in easier
     targetref_ = target;
     select_    = RawParser.ParseSingleSqlStatement($"select * from {target.relname_}") as SelectStmt;
 }
Beispiel #27
0
        static void Main(string[] args)
        {
            Catalog.Init();

            string sql = "";

            if (false)
            {
                JOBench.CreateTables();
                sql = File.ReadAllText("../../../jobench/10a.sql");
                goto doit;
            }

            if (false)
            {
                Tpch.CreateTables();
                Tpch.LoadTables("0001");
                //Tpch.CreateIndexes();
                Tpch.AnalyzeTables();
                sql = File.ReadAllText("../../../tpch/q20.sql");
                goto doit;
            }

            if (false)
            {
                Tpcds.CreateTables();
                Tpcds.LoadTables("tiny");
                Tpcds.AnalyzeTables();
                // 1, 2,3,7,10,
                // long time: 4 bad plan
                // 6: distinct not supported, causing wrong result
                sql = File.ReadAllText("../../../tpcds/q7.sql");
                goto doit;
            }

doit:
            sql = "select a2,b2,c2,d2 from ad, bd, cd, dd where a2=b2 and c2 = b2 and c2=d2 order by a2";
            sql = "select count(*) from ast group by tumble(a0, interval '10' second)";
            sql = "select round(a1, 10), count(*) from a group by round(a1, 10)";
            sql = "select count(*) from a group by round(a1, 10)";
            sql = "select count(*) from ast group by hop(a0, interval '5' second, interval '10' second)";
            sql = "select round(a1, 10) from a group by a1;";
            sql = "select abs(-a1*2), count(*) from a group by round(a1, 10);";
            sql = "select abs(-a1*2), count(*) from a group by a1;";
            sql = "select tumble_start(a0, interval '10' second), tumble_end(a0, interval '10' second), count(*) from ast group by tumble(a0, interval '10' second)";

            var datetime = new DateTime();

            datetime = DateTime.Now;

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            // query options might be conflicting or incomplete
            Console.WriteLine(sql);
            var a = RawParser.ParseSingleSqlStatement(sql);

            ExplainOption.show_tablename_ = false;
            a.queryOpt_.profile_.enabled_ = true;
            a.queryOpt_.optimize_.enable_subquery_unnest_ = false;
            a.queryOpt_.optimize_.remove_from_            = false;
            a.queryOpt_.optimize_.use_memo_                  = true;
            a.queryOpt_.optimize_.enable_cte_plan_           = false;
            a.queryOpt_.optimize_.use_codegen_               = false;
            a.queryOpt_.optimize_.memo_disable_crossjoin_    = false;
            a.queryOpt_.optimize_.memo_use_joinorder_solver_ = false;
            a.queryOpt_.explain_.show_output_                = true;
            a.queryOpt_.explain_.show_id_   = false;
            a.queryOpt_.explain_.show_cost_ = a.queryOpt_.optimize_.use_memo_;

            // -- Semantic analysis:
            //  - bind the query
            a.queryOpt_.optimize_.ValidateOptions();
            a.Bind(null);

            // -- generate an initial plan
            var rawplan = a.CreatePlan();

            Console.WriteLine("***************** raw plan *************");
            Console.WriteLine(rawplan.Explain());

            // -- optimize the plan
            PhysicNode phyplan = null;

            if (a.queryOpt_.optimize_.use_memo_)
            {
                Console.WriteLine("***************** optimized plan *************");
                var optplan = a.SubstitutionOptimize();
                Console.WriteLine(optplan.Explain(a.queryOpt_.explain_));
                a.optimizer_.InitRootPlan(a);
                a.optimizer_.OptimizeRootPlan(a, null);
                Console.WriteLine(a.optimizer_.PrintMemo());
                phyplan = a.optimizer_.CopyOutOptimalPlan();
                Console.WriteLine(a.optimizer_.PrintMemo());
                Console.WriteLine("***************** Memo plan *************");
                Console.WriteLine(phyplan.Explain(a.queryOpt_.explain_));
            }
            else
            {
                // -- optimize the plan
                Console.WriteLine("-- optimized plan --");
                var optplan = a.SubstitutionOptimize();
                Console.WriteLine(optplan.Explain(a.queryOpt_.explain_));

                // -- physical plan
                Console.WriteLine("-- physical plan --");
                phyplan = a.physicPlan_;
                Console.WriteLine(phyplan.Explain(a.queryOpt_.explain_));
            }

            // -- output profile and query result
            Console.WriteLine("-- profiling plan --");
            var final = new PhysicCollect(phyplan);

            a.physicPlan_ = final;
            ExecContext context = a.CreateExecContext();

            final.ValidateThis();
            if (a is SelectStmt select)
            {
                select.OpenSubQueries(context);
            }
            var code = final.Open(context);

            code += final.Exec(null);
            code += final.Close();

            if (a.queryOpt_.optimize_.use_codegen_)
            {
                CodeWriter.WriteLine(code);
                Compiler.Run(Compiler.Compile(), a, context);
            }
            Console.WriteLine(phyplan.Explain(a.queryOpt_.explain_));

            stopWatch.Stop();
            Console.WriteLine("RunTime: " + stopWatch.Elapsed);
            Console.ReadKey();
        }
        private async void Request()
        {
            try
            {
                IsBusy = true;
                HasErrors = false;
                NoItems = false;
                DataProviderRawData = string.Empty;
                Items.Clear();

                var config = new LocalStorageDataConfig
                {
                    FilePath = LocalStorageQuery,
                    OrderBy = OrderBy.ToString(),
                    OrderDirection = SortDirection
                };

                var items = await localStorageDataProvider.LoadDataAsync(config, MaxRecordsParam);

                NoItems = !items.Any();

                foreach (var item in items)
                {
                    Items.Add(item);
                }

                var rawParser = new RawParser();
                var rawData = await rawDataProvider.LoadDataAsync(config, MaxRecordsParam, rawParser);
                DataProviderRawData = rawData.FirstOrDefault()?.Raw;
            }
            catch (Exception ex)
            {
                DataProviderRawData += ex.Message;
                DataProviderRawData += ex.StackTrace;
                HasErrors = true;
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #29
0
        private void OpenFile(StorageFile file)
        {
            //Add a loading screen
            progressDisplay.Visibility = Visibility.Visible;
            histoLoadingBar.Visibility = Visibility.Visible;
            emptyImage();
            Task t = Task.Run(async() =>
            {
                try
                {
                    Stream stream         = (await file.OpenReadAsync()).AsStreamForRead();
                    RawParser parser      = new RawParser(ref stream);
                    RawDecoder decoder    = parser.decoder;
                    decoder.failOnUnknown = false;
                    decoder.checkSupport(metadata);


                    thumbnail = decoder.decodeThumb();
                    if (thumbnail != null)
                    {
                        //read the thumbnail
                        Task.Run(() =>
                        {
                            if (thumbnail.type == ThumbnailType.JPEG)
                            {
                                displayImage(JpegHelper.getJpegInArrayAsync(thumbnail.data));
                            }
                            else if (thumbnail.type == ThumbnailType.RAW)
                            {
                                //this is a raw image in an array
                                JpegHelper.getThumbnailAsSoftwareBitmap(thumbnail);
                            }
                        });
                    }

                    raw = decoder.decodeRaw();
                    decoder.decodeMetaData(metadata);
                    raw.fileName = file.DisplayName;
                    //read the exifs
                    displayExif();
                    //scale the value
                    //raw.scaleValues();

                    //correctWB
                    //raw.CorrectWB();

                    //demos
                    if (raw.cfa != null && raw.cpp == 1)
                    {
                        Demosaic.demos(ref raw, demosAlgorithm.NearNeighbour);
                    }
                    createPreview();
                    updatePreview();

                    //activate the editing control
                    enableEditingControl(true);
                    //dispose
                    file   = null;
                    parser = null;
                }
                catch (FormatException e)
                {
                    var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
                    var str    = loader.GetString("ExceptionText");
                    ExceptionDisplay.display(str);
                }

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    //Hide the loading screen
                    progressDisplay.Visibility = Visibility.Collapsed;
                });
            });
        }
Beispiel #30
0
        private async void Request()
        {
            try
            {
                IsBusy = true;
                HasErrors = false;
                NoItems = false;
                DataProviderRawData = string.Empty;
                Items.Clear();               
                var config = new WordPressDataConfig()
                {
                    Query = WordPressQuery,
                    QueryType = WordPressQueryTypeSelectedItem,
                    FilterBy = WordPressQueryFilterBy,
                    OrderBy = OrderBy,
                    OrderDirection = SortDirection
                };  
                var items = await wordPressDataProvider.LoadDataAsync(config, MaxRecordsParam);

                NoItems = !items.Any();

                foreach (var item in items)
                {
                    Items.Add(item);
                }

                var rawParser = new RawParser();
                var rawData = await rawDataProvider.LoadDataAsync(config, MaxRecordsParam, rawParser);
                DataProviderRawData = rawData.FirstOrDefault()?.Raw;
            }
            catch (Exception ex)
            {
                DataProviderRawData += ex.Message;
                DataProviderRawData += ex.StackTrace;
                HasErrors = true;
            }
            finally
            {
                IsBusy = false;
            }
        }