Ejemplo n.º 1
0
        protected virtual void SaveSettings(IControlTool tool)
        {
            var settingsProperties = tool.GetType()
                                     .GetProperties()
                                     .Where(prop => Attribute.IsDefined(prop, typeof(ToolSettingsAttribute)));

            foreach (var settingsProperty in settingsProperties)
            {
                var settings = settingsProperty.GetValue(tool);
                if (settings is null)
                {
                    continue;
                }

                var serializer       = SerializationFactory.GetXmlSerializer();
                var settingsFilePath = GetSettingsFilePath(tool, settingsProperty);
                using (var fileStream = File.Open(settingsFilePath, FileMode.Create))
                {
                    try
                    {
                        serializer.Serialize(settings, fileStream);
                    }
                    catch (Exception e)
                    {
                        //Vladimir:Don't crash if something went wrong while saving tool settings into file
                        Log.Error(e);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void SetActiveDataFrame2CurrentTool()
        {
            IDataFrame df = ActiveDataFrame;

            if (df != null)
            {
                _currentTool = df as IControlTool;
            }
        }
Ejemplo n.º 3
0
        private string GetSettingsFilePath(IControlTool tool, PropertyInfo settingsProperty)
        {
            var toolSettingsAttribute = Attribute.GetCustomAttribute(settingsProperty, typeof(ToolSettingsAttribute)) as ToolSettingsAttribute;
            var settingsStorage       = toolSettingsAttribute.Storage;
            var appDataDirectory      = Catel.IO.Path.GetApplicationDataDirectory();
            var fileName = settingsProperty.Name + ".xml";

            if (string.IsNullOrWhiteSpace(settingsStorage))
            {
                settingsStorage = Path.Combine(appDataDirectory, tool.Name);
            }
            else
            {
                var companyDirectory = Catel.IO.Path.GetParentDirectory(appDataDirectory);

                settingsStorage = Regex.Replace(settingsStorage, "%AppData%", appDataDirectory, RegexOptions.IgnoreCase);
                settingsStorage = Regex.Replace(settingsStorage, "%Company%", companyDirectory, RegexOptions.IgnoreCase);
                settingsStorage = Regex.Replace(settingsStorage, "%Name%", tool.Name, RegexOptions.IgnoreCase);
            }

            _directoryService.Create(settingsStorage);
            return(Path.Combine(settingsStorage, fileName));
        }
Ejemplo n.º 4
0
        public ToolManagementEventArgs(IControlTool tool)
        {
            Argument.IsNotNull(() => tool);

            Tool = tool;
        }