Exemple #1
0
 public RenderThreads(MapTilingConfiguration invoker, TilingRunCollection parent, int scale, string group, string mapdef, int rows, int cols, int rowOffset, int colOffset, bool randomize)
 {
     this.TileSet   = new Queue <KeyValuePair <int, int> >();
     _syncLock      = new object();
     _event         = new AutoResetEvent(false);
     _completeFlag  = parent.Config.ThreadCount;
     _raiseEvents   = new Queue <EventPassing>();
     _scale         = scale;
     _group         = group;
     _parent        = parent;
     _mapDefinition = mapdef;
     _invoker       = invoker;
     _randomize     = randomize;
     _rows          = rows;
     _cols          = cols;
     _rowOffset     = rowOffset;
     _colOffset     = colOffset;
 }
Exemple #2
0
 public RenderThreads(MapTilingConfiguration invoker, TilingRunCollection parent, int scale, string group, string mapdef, int rows, int cols, int rowOffset, int colOffset, bool randomize)
 {
     TileSet = new Queue<KeyValuePair<int, int>>();
     SyncLock = new object();
     Event = new AutoResetEvent(false);
     CompleteFlag = parent.Config.ThreadCount;
     RaiseEvents = new Queue<EventPassing>();
     this.Scale = scale;
     this.Group = group;
     this.Parent = parent;
     this.MapDefinition = mapdef;
     this.Invoker = invoker;
     Randomize = randomize;
     Rows = rows;
     Cols = cols;
     this.RowOffset = rowOffset;
     this.ColOffset = colOffset;
 }
Exemple #3
0
        public Progress(TilingRunCollection bx)
            : this()
        {
            m_bx = bx;
            bx.BeginRenderingMap += new ProgressCallback(bx_BeginRenderingMap);
            bx.BeginRenderingGroup += new ProgressCallback(bx_BeginRenderingGroup);
            bx.BeginRenderingScale += new ProgressCallback(bx_BeginRenderingScale);
            bx.BeginRenderingTile += new ProgressCallback(bx_BeginRenderingTile);

            bx.FinishRenderingTile += new ProgressCallback(bx_FinishRenderingTile);
            bx.FinishRenderingMaps += new ProgressCallback(bx_FinishRenderingMaps);
            bx.FailedRenderingTile += new ErrorCallback(bx_FailedRenderingTile);
            m_tileRuns = new List<TimeSpan>();

            m_grandTotalTiles = 0;
            foreach (MapTilingConfiguration bm in m_bx.Maps)
                m_grandTotalTiles += bm.TotalTiles;

            m_grandBegin = DateTime.Now;
        }
        /// <summary>
        /// Constructs a new map to be processed
        /// </summary>
        /// <param name="parent">The parent entry</param>
        /// <param name="map">The resource id for the mapdefinition</param>
        public MapTilingConfiguration(TilingRunCollection parent, string map)
        {
            m_parent = parent;

            IResource          res = parent.Connection.ResourceService.GetResource(map);
            IMapDefinition     mdf = res as IMapDefinition;
            ITileSetDefinition tsd = res as ITileSetDefinition;

            if (mdf != null)
            {
                m_tileSetResourceID = mdf.ResourceID;
                m_tileSetExtents    = mdf.Extents.Clone();
                m_tileset           = mdf.BaseMap;
            }
            else if (tsd != null && tsd.SupportsCustomFiniteDisplayScales)
            {
                m_tileSetResourceID = tsd.ResourceID;
                m_tileSetExtents    = tsd.Extents.Clone();
                m_tileset           = tsd;
            }

            if (m_tileset == null)
            {
                throw new InvalidOperationException(OSGeo.MapGuide.MaestroAPI.Strings.UnseedableTileSet);
            }

            var baseMap = m_tileset;

            if (baseMap != null &&
                baseMap.ScaleCount > 0)
            {
                m_groups = new string[baseMap.GroupCount];
                for (int i = 0; i < baseMap.GroupCount; i++)
                {
                    m_groups[i] = baseMap.GetGroupAt(i).Name;
                }

                m_maxscale = baseMap.GetMaxScale();
                CalculateDimensions();
            }
        }
Exemple #5
0
        /// <summary>
        /// Constructs a new map to be processed
        /// </summary>
        /// <param name="parent">The parent entry</param>
        /// <param name="map">The resource id for the mapdefinition</param>
        public MapTilingConfiguration(TilingRunCollection parent, string map)
        {
            m_parent = parent;
            m_mapdefinition = (IMapDefinition)parent.Connection.ResourceService.GetResource(map);
            var baseMap = m_mapdefinition.BaseMap;

            if (baseMap != null &&
                baseMap.ScaleCount > 0)
            {
                m_groups = new string[baseMap.GroupCount];
                for (int i = 0; i < baseMap.GroupCount; i++)
                    m_groups[i] = baseMap.GetGroupAt(i).Name;

                m_maxscale = baseMap.GetMaxScale();
                CalculateDimensions();
            }
        }
Exemple #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            IServerConnection con = m_connection;
            if (chkUseDifferentConnection.Checked)
            {
                if (UseNativeAPI.Checked)
                {
                    string webconfig = System.IO.Path.Combine(Application.StartupPath, "webconfig.ini"); //NOXLATE
                    if (!System.IO.File.Exists(webconfig))
                    {
                        MessageBox.Show(this, string.Format(Strings.MissingWebConfigFile, webconfig), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    try
                    {
                        var initP = new NameValueCollection();

                        initP["ConfigFile"] = webconfig; //NOXLATE
                        initP["Username"] = Username.Text; //NOXLATE
                        initP["Password"] = Password.Text; //NOXLATE

                        con = ConnectionProviderRegistry.CreateConnection("Maestro.LocalNative", initP); //NOXLATE
                    }
                    catch (Exception ex)
                    {
                        string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                        MessageBox.Show(this, string.Format(Strings.ConnectionError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    try
                    {
                        var initP = new NameValueCollection();

                        initP["Url"] = MapAgent.Text; //NOXLATE
                        initP["Username"] = Username.Text; //NOXLATE
                        initP["Password"] = Password.Text; //NOXLATE
                        initP["AllowUntestedVersion"] = "true"; //NOXLATE

                        con = ConnectionProviderRegistry.CreateConnection("Maestro.Http", initP); //NOXLATE
                    }
                    catch (Exception ex)
                    {
                        string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                        MessageBox.Show(this, string.Format(Strings.ConnectionError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            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);
                }

                if (UseOfficialMethod.Checked)
                {
                    bx.Config.MetersPerUnit = (double)MetersPerUnit.Value;
                    bx.Config.UseOfficialMethod = true;
                }

                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(new string[] { c.Group });
                    bm.SetScalesAndExtend(c.ScaleIndexes,c.ExtentOverride);

                    bx.Maps.Add(bm);
                }

                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);
            }
        }
Exemple #7
0
        public static void Main(string[] args)
        {
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.DoEvents();
            PreferredSiteList.InitCulture();
            ModelSetup.Initialize(); //Ensures that > 1.0.0 Map Definitions are recognised
            //Parameters:
            //mapagent=
            //username=
            //password=
            //mapdefinition=
            //scaleindex=0,1,2,3,4,5
            //basegroups="x","y"
            //extentoverride=minx,miny,maxx,maxy

            Boolean batchMode = false;

            string mapagent = "http://localhost/mapguide";
            string username = "******";
            string password = "";
            string mapdefinitions = "";
            string scaleindex = "";
            string basegroups = "";

            string limitRows = "";
            string limitCols = "";

            string tileWidth = "";
            string tileHeight = "";

            string DPI = "";
            string metersPerUnit = "";

            IEnvelope overrideExtents = null;

            List<string> largs = new List<string>(args);
            Dictionary<string, string> opts = CommandLineParser.ExtractOptions(largs);
            if (opts.ContainsKey("mapagent"))
                mapagent = opts["mapagent"];
            if (opts.ContainsKey("username"))
                username = opts["username"];
            if (opts.ContainsKey("password"))
                password = opts["password"];
            if (opts.ContainsKey("mapdefinitions"))
                mapdefinitions = opts["mapdefinitions"];
            if (opts.ContainsKey("scaleindex"))
                scaleindex = opts["scaleindex"];
            if (opts.ContainsKey("basegroups"))
                basegroups = opts["basegroups"];

            if (opts.ContainsKey("limitrows"))
                limitRows = opts["limitrows"];
            if (opts.ContainsKey("limitcols"))
                limitCols = opts["limitcols"];

            if (opts.ContainsKey("tilewidth"))
                tileWidth = opts["tilewidth"];
            if (opts.ContainsKey("tileheight"))
                tileHeight = opts["tileheight"];

            if (opts.ContainsKey("DPI"))
                DPI = opts["DPI"];
            if (opts.ContainsKey("metersperunit"))
                metersPerUnit = opts["metersperunit"];
            if (opts.ContainsKey("extentoverride"))
            {
                string[] parts = opts["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)
            {
                batchMode = true;
            }

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

            IServerConnection connection = null;

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

            SetupRun sr = null;
            if (!opts.ContainsKey("username") || (!opts.ContainsKey("mapagent")))
            {
                if (!batchMode)
                {
                    if (opts.ContainsKey("provider") && opts.ContainsKey("connection-params"))
                    {
                        var initP = ConnectionProviderRegistry.ParseConnectionString(opts["connection-params"]);
                        connection = ConnectionProviderRegistry.CreateConnection(opts["provider"], initP);
                        sr = new SetupRun(connection, maps, opts);
                    }
                    else
                    {
                        var frm = new LoginDialog();
                        if (frm.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                            return;

                        connection = frm.Connection;
                        sr = new SetupRun(frm.Username, frm.Password, connection, maps, opts);
                    }
                    try
                    {
                        mapagent = connection.GetCustomProperty("BaseUrl").ToString();
                    }
                    catch { }

                }
            }

            if (connection == null)
            {
                var initP = new NameValueCollection();
                if (!opts.ContainsKey("native-connection"))
                {
                    initP["Url"] = mapagent;
                    initP["Username"] = username;
                    initP["Password"] = password;
                    initP["Locale"] = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
                    initP["AllowUntestedVersion"] = "true";

                    connection = ConnectionProviderRegistry.CreateConnection("Maestro.Http", initP);
                }
                else if (opts.ContainsKey("provider") && opts.ContainsKey("connection-params"))
                {
                    initP = ConnectionProviderRegistry.ParseConnectionString(opts["connection-params"]);

                    connection = ConnectionProviderRegistry.CreateConnection(opts["provider"], initP);
                }
                else
                {
                    string serverconfig = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "webconfig.ini");

                    initP["ConfigFile"] = serverconfig;
                    initP["Username"] = username;
                    initP["Password"] = password;
                    initP["Locale"] = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;

                    connection = ConnectionProviderRegistry.CreateConnection("Maestro.LocalNative", initP);
                }
            }

            if (!batchMode)
            {
                if (sr == null)
                    sr = new SetupRun(connection, maps, opts);

                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;
                bx.Config.UseOfficialMethod = true;
            }

            if (opts.ContainsKey("random-tile-order"))
                bx.Config.RandomizeTileSequence = true;

            if (opts.ContainsKey("threadcount") && int.TryParse(opts["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 (!batchMode)
            {
                Progress pg = new Progress(bx);
                pg.ShowDialog();
            }
            else
            {
                bx.BeginRenderingMap += new ProgressCallback(bx_BeginRenderingMap);
                bx.FinishRenderingMap += new ProgressCallback(bx_FinishRenderingMap);
                bx.BeginRenderingGroup += new ProgressCallback(bx_BeginRenderingGroup);
                bx.FinishRenderingGroup += new ProgressCallback(bx_FinishRenderingGroup);
                bx.BeginRenderingScale += new ProgressCallback(bx_BeginRenderingScale);
                bx.FinishRenderingScale += new ProgressCallback(bx_FinishRenderingScale);
                bx.BeginRenderingTile += new ProgressCallback(bx_BeginRenderingTile);
                bx.FinishRenderingTile += new ProgressCallback(bx_FinishRenderingTile);

                bx.FailedRenderingTile += new ErrorCallback(bx_FailedRenderingTile);

                mapCount = 0;
                lastUpdate = DateTime.Now;

                bx.RenderAll();
            }
        }