/// <summary> /// Looks up the custom data with the given name, returns the value if it was found, or returns a default value if not found. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <returns></returns> public T GetCustomData <T>(string name) { if (CustomData.ContainsKey(name)) { return((T)CustomData[name]); } return(default(T)); }
protected T GetDialogCustomData <T>(string key = "") { CustomData data = GetDialogCustomData(); if (!data.ContainsKey(key)) { var instance = (T)Activator.CreateInstance(typeof(T)); SetDialogCustomData(key, instance); } return((T)GetDialogCustomData()[key]); }
/// <summary> /// Action to take when additional data that wasn't deserialized is found. /// </summary> /// <param name="extensionData"></param> protected virtual void OnExtensionData(IEnumerable <KeyValuePair <string, object> > extensionData) { if (CustomData == null) { CustomData = new Dictionary <string, object>(); } foreach (var item in extensionData) { string key = item.Key; if (!CustomData.ContainsKey(key)) { CustomData[key] = item.Value; } } }
public T Get <T>(string group, string key) { if (!CustomData.ContainsKey(group)) { return(default(T)); } Dictionary <string, object> storage = CustomData[group]; if (!storage.ContainsKey(key)) { return(default(T)); } return((T)storage[key]); }
public void Remove(string group, string key) { if (!CustomData.ContainsKey(group)) { return; } Dictionary <string, object> storage = CustomData[group]; if (!storage.ContainsKey(key)) { return; } storage.Remove(key); }
/// <summary> /// 从一个类获取数据 /// </summary> /// <param name="data"></param> public void DataFromDataItem(object data) { Type type = data.GetType(); foreach (PropertyInfo pinfo in type.GetProperties(BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Public)) { if (CustomData.ContainsKey(pinfo.Name)) { continue; } object value = type.InvokeMember(pinfo.Name, BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic, null, data, null); if (value != null) { CustomData.Add(pinfo.Name, value); } } }
public void Set <T>(string group, string key, T value) { if (!CustomData.ContainsKey(group)) { CustomData.Add(group, new Dictionary <string, object>()); } Dictionary <string, object> storage = CustomData[group]; if (storage.ContainsKey(key)) { storage.Add(key, value); } else { storage[key] = value; } }
void addOrOverrideCustomData(Guid g, string name, string value) { if (!CustomData.ContainsKey(g)) { CustomData.Add(g, new Dictionary <string, string>()); } var dict = CustomData[g]; if (dict.ContainsKey(name)) { dict[name] = value; } else { dict.Add(name, value); } }
private void GisEditorOutputWindow_Loaded(object sender, RoutedEventArgs e) { ViewModel.OutputMode = OutputMode; entities = new Collection <ColumnEntity>(); if (CustomData.ContainsKey("Columns")) { var columns = (Collection <FeatureSourceColumn>)CustomData["Columns"]; Collection <string> fixedColumns = new Collection <string>(); foreach (var column in columns) { string editedName = column.ColumnName; if (column.ColumnName.Contains(".")) { int index = column.ColumnName.IndexOf(".") + 1; editedName = column.ColumnName.Substring(index, column.ColumnName.Length - index); } if (fixedColumns.Contains(editedName)) { int i = 1; while (fixedColumns.Select(a => a).Contains(editedName)) { int length = i.ToString(CultureInfo.InvariantCulture).Length; editedName = editedName.Substring(0, editedName.Length - length) + i; i++; } } fixedColumns.Add(editedName); entities.Add(new ColumnEntity() { ColumnName = column.ColumnName, EditedColumnName = editedName, ColumnType = column.TypeName, IsChecked = true }); } ColumnList.ItemsSource = entities; } if (CustomData.ContainsKey("CustomizeColumnNames")) { GridView.Columns.Insert(2, (GridViewColumn)Resources["EditedColumn"]); } }
private void OKClick(object sender, RoutedEventArgs e) { try { //If column's count is more than 128, we will trim them. Becasue esri cannot support more than 128 columns. if (entities.Where(n => n.IsChecked).Count() > 128 && ExtensionFilter.EndsWith(".shp")) { var result = MessageBox.Show("The column count is out of Shapefile structure limit(Max 128 fields). It might cause compatibility problem when opening with some other Shapefile utilities. Click Yes to keep top of 128 columns, or click No to keep origin.", "Info", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { entities = new Collection <ColumnEntity>(entities.Take(128).ToList()); } else if (result == MessageBoxResult.Cancel) { return; } } LayerUri = ViewModel.OutputMode == OutputMode.ToFile ? new Uri(ViewModel.OutputPathFileName) : new Uri(Path.Combine(FolderHelper.GetCurrentProjectTaskResultFolder(), ViewModel.TempFileName + Extension)); string folderPath = Path.GetDirectoryName(LayerUri.LocalPath); if (!LayerUri.LocalPath.EndsWith(Extension, StringComparison.InvariantCultureIgnoreCase)) { var result = MessageBox.Show("The path you entered is not valid, please re-enter.", "Info"); } else if (!Directory.Exists(folderPath)) { var result = MessageBox.Show("Directory does not exsit, do you want to create it?", "Info", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { Directory.CreateDirectory(folderPath); DialogResult = true; } } else { Collection <string> columnNames = new Collection <string>(); Dictionary <string, string> editColumnNames = new Dictionary <string, string>(); foreach (var entry in entities) { if (entry.IsChecked) { columnNames.Add(entry.ColumnName); editColumnNames[entry.ColumnName] = entry.EditedColumnName; } } if (CustomData.ContainsKey("CustomizeColumnNames")) { bool isTooLong = editColumnNames.Values.Any(c => c.Length > 10); if (isTooLong) { MessageBoxResult result = MessageBox.Show("One or more columns are longer than 10 bytes. A column cannot be more than 10 bytes in a shape file through specification. Click 'Yes' would truncate the column name to 10 bytes. Do you want to continue?", "Info", MessageBoxButton.YesNo); if (result == MessageBoxResult.No) { return; } } } if (columnNames.Count == 0) { MessageBox.Show("Please select at least one column.", "Info", MessageBoxButton.OK); } else { CustomData["Columns"] = columnNames; CustomData["EditedColumns"] = editColumnNames; DialogResult = true; } } } catch { var result = MessageBox.Show("The path you entered is not valid, please re-enter.", "Info"); } }