public void SaveSettingsObject(object settingsObject, Type settingsType = null)
        {
            //this bit of a hack but the XrmConnections module tries to save a settings object
            //we dont want because we use the package settings
            //instead so lets just ignore it
            if (settingsObject is SavedXrmConnections)
            {
                return;
            }
            var type = settingsType ?? settingsObject.GetType();

            if (settingsObject is XrmRecordConfiguration)
            {
                type = typeof(XrmRecordConfiguration);
            }
            var savedFileSetting = GetSavedSolutionFileSetting(type);

            if (savedFileSetting != null)
            {
                VisualStudioService.AddVsixSetting(savedFileSetting.UsePersonalisedFile ? savedFileSetting.PersonalisedFileName : savedFileSetting.FileName, settingsObject);
            }
            else
            {
                DesktopSettingsManager.SaveSettingsObject(settingsObject, settingsType: settingsType);
            }
        }
        public TSettingsObject Resolve <TSettingsObject>(Type settingsType = null) where TSettingsObject : new()
        {
            var type             = settingsType ?? typeof(TSettingsObject);
            var savedFileSetting = GetSavedSolutionFileSetting(type);

            if (savedFileSetting != null)
            {
                string readFileContents = null;

                var fileName = savedFileSetting.FileName;
                if (savedFileSetting.UsePersonalisedFile)
                {
                    readFileContents = VisualStudioService.GetVsixSettingText(savedFileSetting.PersonalisedFileName);
                }
                if (readFileContents == null)
                {
                    readFileContents = VisualStudioService.GetVsixSettingText(fileName);
                }

                if (string.IsNullOrEmpty(readFileContents))
                {
                    return(new TSettingsObject());
                }
                else
                {
                    if (type == typeof(XrmRecordConfiguration))
                    {
                        //this saved as a dictionary rather than object
                        //because the solution template test project
                        //needs to deserialise it to a new defined type
                        //with different namespaces
                        var dictionary = string.IsNullOrEmpty(readFileContents)
                            ? new Dictionary <string, string>()
                            : (Dictionary <string, string>)
                                         JsonHelper.JsonStringToObject(readFileContents, typeof(Dictionary <string, string>));

                        var xrmConfig = new TSettingsObject();
                        foreach (var prop in xrmConfig.GetType().GetReadWriteProperties())
                        {
                            if (dictionary.ContainsKey(prop.Name))
                            {
                                xrmConfig.SetPropertyByString(prop.Name, dictionary[prop.Name]);
                            }
                        }
                        return(xrmConfig);
                    }
                    else
                    {
                        return((TSettingsObject)JsonHelper.JsonStringToObject(readFileContents, type));
                    }
                }
            }
            else
            {
                return(DesktopSettingsManager.Resolve <TSettingsObject>(settingsType: settingsType));
            }
        }
Ejemplo n.º 3
0
        public TSettingsObject Resolve <TSettingsObject>(Type settingsType = null) where TSettingsObject : new()
        {
            var type = settingsType ?? typeof(TSettingsObject);

            if (SolutionSettingTypes.ContainsKey(type))
            {
                var fileName = MapTypeToFileName(settingsType ?? typeof(TSettingsObject));

                string read = fileName != null?VisualStudioService.GetSolutionItemText(fileName) : null;

                if (string.IsNullOrEmpty(read))
                {
                    return(new TSettingsObject());
                }
                else
                {
                    if (type == typeof(XrmRecordConfiguration))
                    {
                        //csan't recall why but this type is saved as a dictionary rather than just an object
                        //maybe due to interfaces
                        var dictionary = string.IsNullOrEmpty(read)
                            ? new Dictionary <string, string>()
                            : (Dictionary <string, string>)
                                         JsonHelper.JsonStringToObject(read, typeof(Dictionary <string, string>));

                        var xrmConfig = new TSettingsObject();
                        foreach (var prop in xrmConfig.GetType().GetReadWriteProperties())
                        {
                            if (dictionary.ContainsKey(prop.Name))
                            {
                                xrmConfig.SetPropertyByString(prop.Name, dictionary[prop.Name]);
                            }
                        }
                        return(xrmConfig);
                    }
                    else
                    {
                        return((TSettingsObject)JsonHelper.JsonStringToObject(read, type));
                    }
                }
            }
            else
            {
                return(DesktopSettingsManager.Resolve <TSettingsObject>(settingsType: settingsType));
            }
        }
Ejemplo n.º 4
0
        public void SaveSettingsObject(object settingsObject, Type settingsType = null)
        {
            //this bit of a hack but the XrmConnections module tries to save a settings object
            //we dont want because we use the package settings
            //instead so lets just ignore it
            if (settingsObject is SavedXrmConnections)
            {
                return;
            }
            var type = settingsType ?? settingsObject.GetType();

            if (SolutionSettingTypes.ContainsKey(type))
            {
                VisualStudioService.AddSolutionItem(MapTypeToFileName(type), settingsObject);
            }
            else
            {
                DesktopSettingsManager.SaveSettingsObject(settingsObject, settingsType: settingsType);
            }
        }