AVEVA OMI Software Developer Kit
AppConfig Sample Class

The following is a sample editor class that was derived from IEditorConfig.

Sample Class for AppConfig (SampleAppEditor)
Copy Code
namespace SampleAppConfig
{
    public class SampleActivity : EditorActivityViewModelBase
    {
        private string userText = "SampleText";
        private string userText2 = "App Specific data 2";
        IEditorBase editor;
        public SampleActivity(IEditorBase editor): base(editor)
        {
            this.editor = editor;
        }
        public override string Label { get { return "Asset"; } }
        public void Load(Dictionary<string, byte[]> appData)
        {
            var data = appData["mydata"];
            this.userText = Encoding.UTF8.GetString(data);
            var data2 = appData["mydata2"];
            this.userText2 = Encoding.UTF8.GetString(data2);
        }
        public Dictionary<string, byte[]> Save()
        {
            /////this.Editor.Preferences.SetPreference("Value", "MyValue");
            var byteString = Encoding.UTF8.GetBytes(this.userText);
            var byteString2 = Encoding.UTF8.GetBytes(this.userText2);
            var appData = new Dictionary<string, byte[]>();
            appData.Add("mydata", byteString);
            appData.Add("mydata2", byteString2);
            return appData;
        }
        public string UserText
        {
            get { return this.userText; }
            set               
            {
                if (!this.editor.IsReadOnly)
                {
                    this.userText = value;
                    this.SetDirty();
                }
            }
        }
        public string UserText2
        {
            get { return this.userText2; }
            set
            {
                if (!this.editor.IsReadOnly)
                {
                    this.userText2 = value;
                    this.SetDirty();
                }
            }
        }
        public bool IsNotReadOnly
        {
            get
            {
                return !this.editor.IsReadOnly;
            }
        }
        public Uri GetResourceUri(Assembly assembly, string path)       {
          
            return new Uri(string.Format(CultureInfo.InvariantCulture, "pack://application:,,,/{0};Component/{1}", new AssemblyName(assembly.FullName).Name, path), UriKind.Absolute);
        }
        public override void RegisterCommands()
        {
            ResourceDictionary icons = new ResourceDictionary() { Source = GetResourceUri((typeof(SampleActivity).Assembly), "Resources/Icons.xaml") };
            DrawingBrush comIcon1 = icons["Undo_Icon"] as DrawingBrush;
            IAppCommandUI commandUI1 = this.editor.AppCommandManager.CreateAppCommandUI("Import", "Import:Custom Command can be used in Map Editor", comIcon1);
            IAppCommandUI commandUI2 = this.editor.AppCommandManager.CreateAppCommandUI("Export", "Export:Custom Command can be used in Map Editor", null);
            this.editor.AppCommandManager
                .BeginCommandGroup()
                   .AddSimpleCommand(this.CompoundTestItemCommand1, commandUI1)
                   .AddSimpleCommand(this.CompoundTestItemCommand2, commandUI2);
        }
        private ICommand compoundTestItemCommand1;
        private ICommand compoundTestItemCommand2;
        public ICommand CompoundTestItemCommand1
        {
            get
            {
                return RelayCommand.Create(ref this.compoundTestItemCommand1, () => { MessageBox.Show("Import is click"); }, CanExecuteCommands);
            }
        }
        public ICommand CompoundTestItemCommand2
        {
            get
            {
                return RelayCommand.Create(ref this.compoundTestItemCommand2, () => { MessageBox.Show("Export is click"); }, CanExecuteCommands);
            }
        }
        public bool CanExecuteCommands()
        {
            return this.IsNotReadOnly;
        }
    }
}

 

The following is a sample class for activity (page/tab):

Sample Class for Activity  (SampleViewModel)
Copy Code
Sample class for activity.
public class SampleViewModel : EditorActivityViewModelBase
    {
       /// <summary>
        /// Constructor for SampleViewModel that uses IEditorBase
        /// </summary>
        /// <param name="editor">IEditorBase</param>
        public SampleViewModel(IEditorBase editor)
            : base(editor)
        {
         
        }
 /// <summary>
        /// Name of the page/tab/activity
        /// </summary>
        public override string Label
        {
             get
             {
                 return "sample activity";
             }
        }
    }

 

See Also