Example #1
0
        public MainViewModel()
        {
            DisplayName = "Jira flow metrics";

            var dataPath = GetPathToData();

            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }

            string databaseFile = Path.Combine(dataPath, @"issuesCache.db");

            _cacheRepository = new SqliteJiraLocalCacheRepository(databaseFile);
            TasksSourceJiraCacheAdapter jiraCacheAdapter = new TasksSourceJiraCacheAdapter(_cacheRepository);
            JsonStatesRepository        statesRepository = new JsonStatesRepository(Path.Combine(dataPath, @"analysisSettings.json"));
            var stateFilteringProvider = new StateFilteringProvider(jiraCacheAdapter, statesRepository);
            var tasksSource            = new TasksSource(jiraCacheAdapter);

            var issuesFrom = DateTime.Now.AddYears(-1);

            ProjectSelector = new ProjectSelectorViewModel(tasksSource);

            Items.Add(new JiraUpdateViewModel(tasksSource, new CurrentTime()));
            Items.Add(new StoryFilteringViewModel(stateFilteringProvider));
            Items.Add(new IssuesGridViewModel(tasksSource, stateFilteringProvider, ProjectSelector));
            Items.Add(new CumulativeFlowViewModel(tasksSource, stateFilteringProvider, ProjectSelector));
            Items.Add(new CycleTimeScatterplotViewModel(tasksSource, issuesFrom, stateFilteringProvider, ProjectSelector));
            Items.Add(new CycleTimeHistogramViewModel(tasksSource, issuesFrom, stateFilteringProvider, ProjectSelector));
            Items.Add(new CycleTimeHistogramSmoothViewModel(tasksSource, issuesFrom, stateFilteringProvider, ProjectSelector));
            Items.Add(new CycleTimeHistoryViewModel(tasksSource, stateFilteringProvider, ProjectSelector));
            Items.Add(new StoryPointCycleTimeViewModel(tasksSource, issuesFrom, stateFilteringProvider, ProjectSelector));
            Items.Add(new SimulationViewModel(tasksSource, issuesFrom, stateFilteringProvider, ProjectSelector));
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            GetActiveIde().ExecuteCommand("File.SaveAll");

            var projects = GetProjects().Select(p => new ProjectDefinition()
            {
                Name = p.Name, Path = p.UniqueName
            }).ToList();

            var viewModel = new ProjectSelectorViewModel();

            viewModel.Projects = projects;

            DebugDefinition debugDefinition = null;

            using (ProjectSelector ps = new ProjectSelector(viewModel))
            {
                if (ps.ShowDialog().GetValueOrDefault(false))
                {
                    debugDefinition = ps.DebugDefinition;
                }
            }


            if (debugDefinition != null)
            {
                var solution = GetSolution();
                var tempFile = Path.Combine(Path.GetTempPath(), string.Format("{0}.zip", Path.GetFileName(solution.FileName)));

                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }

                //Test Endpoint
                //Package Solution
                ZipFile.CreateFromDirectory(Path.GetDirectoryName(solution.FullName), tempFile);
                ExecutionParameters parameters = new ExecutionParameters();
                parameters.Command          = Command.DebugContent;
                parameters.ProjectPath      = debugDefinition.Project.Path;
                parameters.ExecutionCommand = debugDefinition.Command;
                parameters.Payload          = File.ReadAllBytes(tempFile);

                Shared.Client.Client client = new Shared.Client.Client(debugDefinition.Endpoint, Server.ServicePort);

                client.Send(parameters);
                client.WaitForAnswer();
                //Transmit Package

                var dte = (DTE)Package.GetGlobalService(typeof(DTE));

                IntPtr pInfo = GetDebugInfo(debugDefinition.Endpoint, debugDefinition.Project.Path, debugDefinition.Project.Path);
                var    sp    = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte);
                try
                {
                    var dbg = (IVsDebugger)sp.GetService(typeof(SVsShellDebugger));
                    int hr  = dbg.LaunchDebugTargets(1, pInfo);
                    Marshal.ThrowExceptionForHR(hr);

                    DebuggedProcess.Instance.AssociateDebugSession(client);
                }
                catch (Exception ex)
                {
                    //logger.Error(ex);
                    string msg;
                    var    sh = (IVsUIShell)sp.GetService(typeof(SVsUIShell));
                    sh.GetErrorInfo(out msg);

                    if (!string.IsNullOrWhiteSpace(msg))
                    {
                        //logger.Error(msg);
                    }
                    throw;
                }
                finally
                {
                    if (pInfo != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(pInfo);
                    }
                }
            }

            //string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName);
            //string title = "AttachDebuggerCommand";

            //// Show a message box to prove we were here
            //VsShellUtilities.ShowMessageBox(
            //    this.ServiceProvider,
            //    message,
            //    title,
            //    OLEMSGICON.OLEMSGICON_INFO,
            //    OLEMSGBUTTON.OLEMSGBUTTON_OK,
            //    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
        }