Beispiel #1
0
        public static void SaveConfigs(SettingsArray settings)
        {
            Status.Update("Writing settings ... ", false);

            var dte     = Package.GetGlobalService(typeof(SDTE)) as DTE;
            var project = dte.GetSelectedProject();
            var file    = project.GetProjectDirectory() + "\\" + FileName + ".dat";

            var newLine = false;

            if (!File.Exists(file))
            {
                File.Create(file).Dispose();
                project.ProjectItems.AddFromFile(file);
                Status.Update("\n\tCreated a new settings file.");
                newLine = true;
            }

            // check out file if in TFS
            try
            {
                var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(file);

                if (workspaceInfo != null)
                {
                    var server    = new TfsTeamProjectCollection(workspaceInfo.ServerUri);
                    var workspace = workspaceInfo.GetWorkspace(server);

                    var pending = workspace.GetPendingChanges(new[] { file });

                    if (!pending.Any())
                    {
                        workspace.Get(new[] { file }, VersionSpec.Latest, RecursionType.Full, GetOptions.GetAll | GetOptions.Overwrite);
                        Status.Update((newLine ? "" : "\n") + "\tRetrieved latest settings file from TFS' current workspace.");

                        workspace.PendEdit(file);
                        Status.Update("\tChecked out settings file from TFS' current workspace.");

                        newLine = true;
                    }
                }
            }
            catch (Exception)
            {
                // ignored
            }

            using (var stream = File.Open(file, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                // clear the file to start from scratch
                stream.SetLength(0);

                var bformatter = new BinaryFormatter {
                    Binder = new Binder()
                };
                bformatter.Serialize(stream, settings);

                Status.Update(newLine ? "Done writing settings!" : "done!");
            }
        }
Beispiel #2
0
        public Login(DTE2 dte)
        {
            Assembly.Load("Xceed.Wpf.Toolkit");

            InitializeComponent();

            var main = dte.GetMainWindow();

            Owner = main;
            //Loaded += delegate  { this.CenterWindow(main); };

            assemblyRegistration = new AssemblyRegistration();

            RegisterEvents();

            settingsArray = Configuration.LoadConfigs();
        }
Beispiel #3
0
        public Login(DTE2 dte)
        {
            Assembly.Load("Xceed.Wpf.Toolkit");

            InitializeComponent();

            var main = dte.GetMainWindow();

            Owner = main;

            settingsArray = Configuration.LoadConfigs();

            EventManager.RegisterClassHandler(typeof(TextBox), MouseDoubleClickEvent, new RoutedEventHandler(SelectAddress));
            EventManager.RegisterClassHandler(typeof(TextBox), GotKeyboardFocusEvent, new RoutedEventHandler(SelectAddress));
            EventManager.RegisterClassHandler(typeof(TextBox), PreviewMouseLeftButtonDownEvent,
                                              new MouseButtonEventHandler(SelectivelyIgnoreMouseButton));
            EventManager.RegisterClassHandler(typeof(PasswordBox), MouseDoubleClickEvent, new RoutedEventHandler(SelectAddress));
            EventManager.RegisterClassHandler(typeof(PasswordBox), GotKeyboardFocusEvent, new RoutedEventHandler(SelectAddress));
            EventManager.RegisterClassHandler(typeof(PasswordBox), PreviewMouseLeftButtonDownEvent,
                                              new MouseButtonEventHandler(SelectivelyIgnoreMouseButton));
        }
        public static void SaveConfigs(SettingsArray settings)
        {
            Status.Update("Writing settings ... ");

            var file = $@"{BuildBaseFileName()}-Config.json";

            if (!File.Exists(file))
            {
                File.Create(file).Dispose();
                Status.Update("\tCreated a new settings file.");
            }

            Status.Update("\tSerialising settings ...");
            var serialisedSettings = JsonConvert.SerializeObject(settings, Formatting.Indented);

            Status.Update("\tWriting to file ...");
            File.WriteAllText(file, serialisedSettings);

            SaveConnection(settings.SettingsList);

            Status.Update(">>> Finished writing settings.");
        }
        public static SettingsArray LoadSettings()
        {
            try
            {
                Status.Update("Loading settings ... ");

                var file = $@"{BuildBaseFileName()}-Config.json";

                if (File.Exists(file))
                {
                    Status.Update($"\tFound settings file: {file}.");
                    Status.Update($"\tReading content ...");

                    var fileContent = File.ReadAllText(file);
                    var settings    = JsonConvert.DeserializeObject <SettingsArray>(fileContent);
                    FillConnectionStrings(settings?.SettingsList);

                    Status.Update(">>> Finished loading settings.");

                    return(settings);
                }

                Status.Update("\tSettings file does not exist.");
            }
            catch (Exception ex)
            {
                Status.Update("\t [ERROR] Failed to load settings.");
                Status.Update(ex.BuildExceptionMessage(isUseExStackTrace: true));
            }

            var newSettings = new SettingsArray();

            newSettings.SettingsList.Add(new Settings());
            newSettings.SelectedSettingsIndex = 0;

            return(newSettings);
        }
Beispiel #6
0
        public static SettingsArray LoadConfigs()
        {
            try
            {
                Status.Update("Reading settings ... ", false);

                var dte     = Package.GetGlobalService(typeof(SDTE)) as DTE;
                var project = dte.GetSelectedProject();
                var file    = project.GetProjectDirectory() + "\\" + FileName + ".dat";

                var newLine = false;

                if (File.Exists(file))
                {
                    // get latest file if in TFS
                    try
                    {
                        var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(file);

                        if (workspaceInfo != null)
                        {
                            var server    = new TfsTeamProjectCollection(workspaceInfo.ServerUri);
                            var workspace = workspaceInfo.GetWorkspace(server);

                            var pending = workspace.GetPendingChanges(new[] { file });

                            if (!pending.Any())
                            {
                                workspace.Get(new[] { file }, VersionSpec.Latest, RecursionType.Full, GetOptions.GetAll | GetOptions.Overwrite);
                                Status.Update("\n\tRetrieved latest settings file from TFS' current workspace.");
                                newLine = true;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // ignored
                    }

                    //Open the file written above and read values from it.
                    using (var stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        var bformatter = new BinaryFormatter {
                            Binder = new Binder()
                        };
                        stream.Position = 0;
                        var settingsObject = bformatter.Deserialize(stream);

                        SettingsArray settings;

                        if (settingsObject is SettingsArray)
                        {
                            settings = (SettingsArray)settingsObject;
                        }
                        else if (settingsObject is Settings.SerializableSettings)
                        {
                            Status.Update("loading old formatted settings ... ", false);

                            settings = new SettingsArray();
                            settings.SettingsList.Add(
                                new Settings((Settings.SerializableSettings)settingsObject));
                            settings.SelectedSettingsIndex = 0;
                        }
                        else
                        {
                            throw new Exception("Invalid settings format.");
                        }

                        Status.Update(newLine ? "Done reading settings!" : "done!");

                        return(settings);
                    }
                }
                else
                {
                    Status.Update("[ERROR] settings file does not exist.");
                }
            }
            catch (Exception ex)
            {
                Status.Update("failed to read settings => " + ex.Message);
            }

            var newSettings = new SettingsArray();

            newSettings.SettingsList.Add(new Settings());
            newSettings.SelectedSettingsIndex = 0;
            return(newSettings);
        }
Beispiel #7
0
        private static bool CopySettings()
        {
            var projects = DteHelper.GetSelectedProjects().ToArray();

            if (projects.Length <= 1)
            {
                return(false);
            }

            var           currentProject      = DteHelper.CurrentProject;
            SettingsArray sourceSettingsArray = null;

            foreach (var project in projects)
            {
                DteHelper.SetCurrentProject(project);

                sourceSettingsArray = Configuration.LoadConfigs();
                var settings = sourceSettingsArray.GetSelectedSettings();

                if (settings.Id == Guid.Empty &&
                    (string.IsNullOrEmpty(settings.ServerName) || string.IsNullOrEmpty(settings.Username)))
                {
                    continue;
                }
                else
                {
                    break;
                }
            }

            if (sourceSettingsArray == null)
            {
                return(false);
            }

            Status.Update($"Copying settings from project: {DteHelper.CurrentProject.Name} ...");

            foreach (var settingsQ in sourceSettingsArray.SettingsList)
            {
                settingsQ.Id = Guid.Empty;
            }

            foreach (var project in projects)
            {
                DteHelper.SetCurrentProject(project);

                var settingsArray = Configuration.LoadConfigs();
                var settings      = settingsArray.GetSelectedSettings();

                if (settings.Id == Guid.Empty &&
                    (string.IsNullOrEmpty(settings.ServerName) || string.IsNullOrEmpty(settings.Username)))
                {
                    Configuration.SaveConfigs(sourceSettingsArray);
                    Status.Update($"Copied settings to project: {project.Name}.");
                }
            }

            DteHelper.SetCurrentProject(currentProject);

            return(true);
        }