Example #1
0
        private void btnBuild_Click(object sender, EventArgs e)
        {
            IServerConnection con = m_connection;

            try
            {
                TilingRunCollection bx = new TilingRunCollection(con);

                if (LimitTileset.Checked)
                {
                    if (MaxRowLimit.Value > 0)
                    {
                        bx.LimitRows((int)MaxRowLimit.Value);
                    }
                    if (MaxColLimit.Value > 0)
                    {
                        bx.LimitCols((int)MaxColLimit.Value);
                    }
                }

                bx.Config.MetersPerUnit = (double)MetersPerUnit.Value;

                bx.Config.ThreadCount           = (int)ThreadCount.Value;
                bx.Config.RandomizeTileSequence = RandomTileOrder.Checked;

                foreach (Config c in ReadTree())
                {
                    MapTilingConfiguration bm = new MapTilingConfiguration(bx, c.MapDefinition);
                    bm.SetGroups(c.Group);
                    bm.SetScalesAndExtend(c.ScaleIndexes, c.ExtentOverride);

                    bx.Maps.Add(bm);
                }

                if (bx.Maps.Count == 0)
                {
                    MessageBox.Show(Strings.NoMapsOrTileSetsSelected);
                    return;
                }

                Progress p = new Progress(bx);
                if (p.ShowDialog(this) != DialogResult.Cancel)
                {
                    var ts = p.TotalTime;
                    MessageBox.Show(string.Format(Strings.TileGenerationCompleted, ((ts.Days * 24) + ts.Hours), ts.Minutes, ts.Seconds));
                }
            }
            catch (Exception ex)
            {
                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                MessageBox.Show(this, string.Format(Strings.InternalError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        public static void Main(string[] args)
        {
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.DoEvents();
            PreferredSiteList.InitCulture();

            //Init the Maestro connection registry with additional providers from ConnectionProviders.xml
            ConnectionProviderRegistry.InitRegistry();

            //Parameters:
            //mapagent=
            //username=
            //password=
            //mapdefinition=
            //scaleindex=0,1,2,3,4,5
            //basegroups="x","y"
            //extentoverride=minx,miny,maxx,maxy

            bool cmdLineMode = false;

            string mapdefinitions = string.Empty;
            string scaleindex     = string.Empty;
            string basegroups     = string.Empty;

            string limitRows = string.Empty;
            string limitCols = string.Empty;

            string tileWidth  = string.Empty;
            string tileHeight = string.Empty;

            string DPI           = string.Empty;
            string metersPerUnit = string.Empty;

            IEnvelope overrideExtents = null;

            List <string> largs = new List <string>(args);
            Dictionary <string, string> opts = CommandLineParser.ExtractOptions(largs);

            if (opts.ContainsKey(TileRunParameters.MAPDEFINITIONS))
            {
                mapdefinitions = opts[TileRunParameters.MAPDEFINITIONS];
            }
            if (opts.ContainsKey(TileRunParameters.SCALEINDEX))
            {
                scaleindex = opts[TileRunParameters.SCALEINDEX];
            }
            if (opts.ContainsKey(TileRunParameters.BASEGROUPS))
            {
                basegroups = opts[TileRunParameters.BASEGROUPS];
            }

            if (opts.ContainsKey(TileRunParameters.LIMITROWS))
            {
                limitRows = opts[TileRunParameters.LIMITROWS];
            }
            if (opts.ContainsKey(TileRunParameters.LIMITCOLS))
            {
                limitCols = opts[TileRunParameters.LIMITCOLS];
            }

            if (opts.ContainsKey(TileRunParameters.TILEWIDTH))
            {
                tileWidth = opts[TileRunParameters.TILEWIDTH];
            }
            if (opts.ContainsKey(TileRunParameters.TILEHEIGHT))
            {
                tileHeight = opts[TileRunParameters.TILEHEIGHT];
            }

            if (opts.ContainsKey(TileRunParameters.DOTSPERINCH))
            {
                DPI = opts[TileRunParameters.DOTSPERINCH];
            }
            if (opts.ContainsKey(TileRunParameters.METERSPERUNIT))
            {
                metersPerUnit = opts[TileRunParameters.METERSPERUNIT];
            }
            if (opts.ContainsKey(TileRunParameters.EXTENTOVERRIDE))
            {
                string[] parts = opts[TileRunParameters.EXTENTOVERRIDE].Split(',');
                if (parts.Length == 4)
                {
                    double minx;
                    double miny;
                    double maxx;
                    double maxy;
                    if (
                        double.TryParse(parts[0], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out minx) &&
                        double.TryParse(parts[1], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out miny) &&
                        double.TryParse(parts[2], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out maxx) &&
                        double.TryParse(parts[3], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out maxy)
                        )
                    {
                        overrideExtents = ObjectFactory.CreateEnvelope(minx, miny, maxx, maxy);
                    }
                }
            }

            if (largs.IndexOf("batch") >= 0 || largs.IndexOf("/batch") >= 0 || largs.IndexOf("commandline") >= 0 || largs.IndexOf("/commandline") >= 0)
            {
                cmdLineMode = true;
            }

            try
            {
                Console.Clear();
                m_loggableProgress = true;
            }
            catch
            {
                hasConsole         = false;
                m_loggableProgress = false;
            }

            IServerConnection connection = null;

            string[] maps = mapdefinitions.Split(',');

            string username = string.Empty;
            string password = string.Empty;

            if (opts.ContainsKey(TileRunParameters.PROVIDER) && opts.ContainsKey(TileRunParameters.CONNECTIONPARAMS))
            {
                var initP = ConnectionProviderRegistry.ParseConnectionString(opts[TileRunParameters.CONNECTIONPARAMS]);
                connection = ConnectionProviderRegistry.CreateConnection(opts[TileRunParameters.PROVIDER], initP);
            }
            else
            {
                if (cmdLineMode)
                {
                    throw new ArgumentException(string.Format(Strings.MissingRequiredConnectionParameters, TileRunParameters.PROVIDER, TileRunParameters.CONNECTIONPARAMS));
                }

                var frm = new LoginDialog();
                if (frm.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                username = frm.Username;
                password = frm.Password;

                connection = frm.Connection;
            }

            if (connection == null)
            {
                if (opts.ContainsKey(TileRunParameters.PROVIDER) && opts.ContainsKey(TileRunParameters.CONNECTIONPARAMS))
                {
                    var initP = ConnectionProviderRegistry.ParseConnectionString(opts[TileRunParameters.CONNECTIONPARAMS]);
                    connection = ConnectionProviderRegistry.CreateConnection(opts[TileRunParameters.PROVIDER], initP);
                }
                else
                {
                    throw new ArgumentException(string.Format(Strings.MissingRequiredConnectionParameters, TileRunParameters.PROVIDER, TileRunParameters.CONNECTIONPARAMS));
                }
            }

            if (!cmdLineMode)
            {
                SetupRun sr = null;
                if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
                {
                    sr = new SetupRun(username, password, connection, maps, opts);
                }
                else
                {
                    sr = new SetupRun(connection, maps, opts);
                }

                using (sr)
                {
                    sr.ShowDialog();
                    return;
                }
            }

            TilingRunCollection bx = new TilingRunCollection(connection);

            int x;

            if (!string.IsNullOrEmpty(limitCols) && int.TryParse(limitCols, out x))
            {
                bx.LimitCols(x);
            }
            if (!string.IsNullOrEmpty(limitRows) && int.TryParse(limitRows, out x))
            {
                bx.LimitRows(x);
            }

            if (!string.IsNullOrEmpty(tileWidth) && int.TryParse(tileWidth, out x))
            {
                bx.Config.TileWidth = x;
            }
            if (!string.IsNullOrEmpty(tileHeight) && int.TryParse(tileHeight, out x))
            {
                bx.Config.TileHeight = x;
            }

            if (!string.IsNullOrEmpty(DPI) && int.TryParse(DPI, out x))
            {
                bx.Config.DPI = x;
            }

            double d;

            if (!string.IsNullOrEmpty(metersPerUnit) && double.TryParse(metersPerUnit, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.CurrentCulture, out d))
            {
                bx.Config.MetersPerUnit = d;
            }

            if (opts.ContainsKey(TileRunParameters.RANDOMTILEORDER))
            {
                bx.Config.RandomizeTileSequence = true;
            }

            if (opts.ContainsKey(TileRunParameters.THREADCOUNT) && int.TryParse(opts[TileRunParameters.THREADCOUNT], out x) && x > 0)
            {
                bx.Config.ThreadCount = x;
            }

            //Now that all global parameters are set, we can now add the map definitions
            bx.AddMapDefinitions(maps);

            //basegroups must be set in each mapdefinition
            if (!string.IsNullOrEmpty(basegroups))
            {
                List <string> groups = new List <string>();
                foreach (string s in basegroups.Split(','))
                {
                    string f = s;
                    if (f.StartsWith("\""))
                    {
                        f = f.Substring(1);
                    }
                    if (f.EndsWith("\""))
                    {
                        f = f.Substring(0, f.Length - 1);
                    }
                    groups.Add(f);
                }
                bx.SetGroups(groups.ToArray());
            }

            if (overrideExtents != null)
            {
                List <int> scales = new List <int>();
                int        tmp;
                foreach (string s in scaleindex.Split(','))
                {
                    if (int.TryParse(s, out tmp))
                    {
                        scales.Add(tmp);
                    }
                }
                foreach (MapTilingConfiguration bm in bx.Maps)
                {
                    bm.SetScalesAndExtend(scales.ToArray(), overrideExtents);
                }
            }
            else if (!string.IsNullOrEmpty(scaleindex))
            {
                List <int> scales = new List <int>();
                int        tmp;
                foreach (string s in scaleindex.Split(','))
                {
                    if (int.TryParse(s, out tmp))
                    {
                        scales.Add(tmp);
                    }
                }
                bx.SetScales(scales.ToArray());
            }

            if (!cmdLineMode)
            {
                Progress pg = new Progress(bx);
                pg.ShowDialog();
            }
            else
            {
                bx.BeginRenderingMap    += OnBeginRenderingMap;
                bx.FinishRenderingMap   += OnFinishRenderingMap;
                bx.BeginRenderingGroup  += OnBeginRenderingGroup;
                bx.FinishRenderingGroup += OnFinishRenderingGroup;
                bx.BeginRenderingScale  += OnBeginRenderingScale;
                bx.FinishRenderingScale += OnFinishRenderingScale;
                bx.BeginRenderingTile   += OnBeginRenderingTile;
                bx.FinishRenderingTile  += OnFinishRenderingTile;
                bx.FailedRenderingTile  += OnFailedRenderingTile;

                mapCount   = 0;
                lastUpdate = DateTime.Now;

                bx.RenderAll();
            }
        }