Example #1
0
        private void InitClick(object sender, RoutedEventArgs e)
        {
            var originalCursor = Cursor;

            try
            {
                Cursor = Cursors.Wait;
                var    edmxName               = Path.GetFileNameWithoutExtension((string)edmx.SelectedValue);
                var    project                = _viewModel.ContainingProject;
                var    defaultNamespace       = project.Properties.Cast <EnvDTE.Property>().FirstOrDefault(p => p.Name == "RootNamespace")?.Value;
                string targetFrameworkMoniker = project.GetTargetFrameworkMoniker();
                string clientVersion;
                if (targetFrameworkMoniker.StartsWith(".NETFramework,"))
                {
                    clientVersion = "WPF";
                }
                else if (targetFrameworkMoniker.StartsWith(".NETPortable,"))
                {
                    clientVersion = "PCL";
                }
                else
                {
                    throw new NotImplementedException();
                }
                var waqsFilePath  = _dte.Solution.FindProjectItem(Path.Combine(Path.GetDirectoryName(project.FullName), "WAQS." + edmxName, edmxName + ".Client." + clientVersion + ".waqs")).GetFilePath();
                var viewModelPath = _viewModel.GetFilePath();
                var viewPath      = (string)view.SelectedValue;
                try
                {
                    _dte.SourceControl.CheckOutItem(viewModelPath);
                    if (viewPath != null)
                    {
                        _dte.SourceControl.CheckOutItem(viewPath);
                    }
                }
                catch
                {
                }
                var toolsPath       = Path.Combine(_packageInstallerServices.GetPackageLocation("WAQS.Client." + clientVersion), "tools");
                var toolsPathServer = Path.Combine(toolsPath, "Client." + clientVersion);
                var exePath         = Path.Combine(toolsPathServer, "InitViewModel.exe");
                var exeArgs         = "\"" + edmxName + "\" \"" + defaultNamespace + "\" \"" + viewModelPath + "\" \"" + waqsFilePath + "\" \"" + viewPath + "\"";
                var process         = new Process();
                process.StartInfo.FileName    = exePath;
                process.StartInfo.Arguments   = exeArgs.ToString();
                process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                process.Start();
                process.WaitForExit();
                Close();
            }
            finally
            {
                Cursor = originalCursor;
            }
        }