Exemple #1
0
 // add a NEW setting into project settings.  (or ignore if already there)
 // does NOT save the setting to the database.
 public void Inject(String key, ProjectSetting setting)
 {
     if (!Settings.ContainsKey(key))
     {
         Settings.Add(key, setting);
     }
 }
Exemple #2
0
        // REPLACEs (insert or update) a setting in the settings list
        public void SetSetting(String key, ProjectSetting setting)
        {
            if (!Database.IsOpen(Conn))
            {
                throw new Exception("Settings database not connected");
            }
            if (String.IsNullOrEmpty(key))
            {
                throw new Exception("Invalid key");
            }
            if (key.Length > 128 || setting.Value.Length > 1024)
            {
                throw new Exception("Invalid setting size");
            }

            // update the database, then the setting
            try
            {
                Dictionary <String, String> values = new Dictionary <string, string>();
                values.Add("name", setting.Name);
                values.Add("value", setting.Value);
                values.Add("module", setting.Module);
                values.Add("display_name", setting.Display_Name);
                values.Add("display_type", setting.Display_Type);
                values.Add("display_weight", setting.Display_Weight.ToString());
                values.Add("description", setting.Description);

                if (!Database.ReplaceRow(Conn, values, "settings"))
                {
                    MessageBox.Show("Could not replace database row.  We suggest you exit TAMS and check the project file.");
                }

                Settings[key] = setting;
                //Settings.TryGetValue(key, out setting);
                //setting.Value = value;
            }
            catch (Exception e)
            {
                Log.Error("Could not update setting.\n" + e.ToString());
                MessageBox.Show("Could not update setting " + key);
            }
            // update settings dictionary
        }
Exemple #3
0
        private void newSHPFile(object sender, EventArgs e)
        {
            SaveFileDialog save = new SaveFileDialog();

            save.Filter = "GIS ShapeFile (*.SHP)|*.shp";
            if (save.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string filename = save.FileName;

            if (createSHPFile(filename))
            {
                openFile(filename, "point");
                ProjectSetting shpSetting  = new ProjectSetting(name: ModuleName + "_file", value: Filepath, module: ModuleName);
                ProjectSetting shpRelative = new ProjectSetting(name: ModuleName + "_relative", value: Util.MakeRelativePath(Properties.Settings.Default.lastProject, Filepath), module: ModuleName);
                Project.settings.SetSetting(shpSetting);
                Project.settings.SetSetting(shpRelative);
            }
        }
Exemple #4
0
        // Insert or update key to = value (doesn't change other parts or the setting)
        public void SetValue(String key, String value)
        {
            if (!Database.IsOpen(Conn))
            {
                throw new Exception("Settings database not connected");
            }
            if (String.IsNullOrEmpty(key))
            {
                throw new Exception("Invalid key");
            }

            // this limitation is arbitrary although the database may have some limitations
            if (key.Length > 128 || value.Length > 1024)
            {
                throw new Exception("Invalid setting size");
            }

            ProjectSetting setting;

            if (Settings.ContainsKey(key))
            {
                setting = Settings[key];
            }
            else
            {
                setting = new ProjectSetting(key);
            }

            setting.Value = value;

            try
            {
                SetSetting(key, setting);
            }
            catch (Exception e)
            {
                MessageBox.Show("Could not update setting with key: " + key);
                Log.Error("Could not update setting with key:" + key + "\n\n" + e.ToString());
            }
        }
Exemple #5
0
        // seems like this version is really all we need?
        public void SetSetting(ProjectSetting setting)
        {
            String key = setting.Name;

            SetSetting(key, setting);
        }
Exemple #6
0
        /// <summary>
        /// Override this, opens the shapefile and adds it to dotspatial map.
        /// </summary>
        /// <param name="thePath"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public virtual Boolean openFile(String thePath = "", String type = "")
        {
            if (isOpen())
            {
                Log.Error("Module " + ModuleName + "attempted to open file (" + thePath + ") when file was already opened (" + Filepath + ")");
                return(false);
            }

            // if we didn't specify a path in this call, check the data member "Filepath"
            if (thePath == "")
            {
                thePath = Filepath;
            }

            if (String.IsNullOrEmpty(thePath))
            {
                MessageBox.Show("Invalid filename specified");
                this.close();
                return(false);
            }

            try
            {
                // try to add the file to the map
                Layer = Project.map.AddLayer(thePath);
                FeatureLayer L = Layer as FeatureLayer;
                L.Name = ModuleName;
                if (Layer.Projection != DotSpatial.Projections.KnownCoordinateSystems.Projected.World.WebMercator)
                {
                    // SHP File is not in Web Mercator projection.  Attempting to reproject.
                    Layer.Reproject(DotSpatial.Projections.KnownCoordinateSystems.Projected.World.WebMercator);
                    Log.Warning("Attempted to reproject " + thePath + "\nRESULT: " + Layer.Projection.ToString());

                    if (Layer.Projection != DotSpatial.Projections.KnownCoordinateSystems.Projected.World.WebMercator)
                    {
                        MessageBox.Show("Could not reproject SHP file.  Please adjust the projection to WebMercator in a GIS program (such as ArcMap or MapWindow).");
                        close();
                        return(false);
                    }
                }
                Project.map.Projection = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.WebMercator;
                foreach (var comp in linkedComponents)
                {
                    comp.Enabled = true;
                }
                Project.map.ZoomToMaxExtent();
                Filepath = thePath;
            }
            catch (Exception e)
            {
                MessageBox.Show("Could not open " + thePath + Environment.NewLine + e.ToString());
                Log.Error("Could not open SHP file (" + thePath + ") for module " + ModuleName);
                this.close();

                return(false);
            }

            // set shpfile setting for this module
            ProjectSetting shpSetting  = new ProjectSetting(name: ModuleName + "_file", value: Filepath, module: ModuleName);
            ProjectSetting shpRelative = new ProjectSetting(name: ModuleName + "_relative", value: Util.MakeRelativePath(Properties.Settings.Default.lastProject, Filepath), module: ModuleName);

            Project.settings.SetSetting(shpSetting);
            Project.settings.SetSetting(shpRelative);


            List <String> fields = shpFields();

            foreach (ProjectSetting setting in ModuleSettings)
            {
                if (setting.Display_Type == "field")
                {
                    setting.options = fields;
                }
            }

            checkSettings();
            select();

            Log.Note("Loaded road file " + thePath);
            return(true);
        }