//  -------------------------------------------------------------------
        /// <summary>
        /// Creates a new instance of the choose projects dialog.
        /// </summary>
        /// <param name="dte">
        /// The DTE object to use to access Visual Studio services.
        /// </param>
        /// <param name="selection">
        /// The initial selection that should be displayed in the dialog.
        /// </param>
        public ChooseProjectsToSubmitDialog(IServiceProvider sp,
			ISubmittableItem[] selection)
        {
            this.serviceProvider = sp;
            this.selection = selection;

            InitializeComponent();

            PopulateTree();
        }
        //  -------------------------------------------------------------------
        /// <summary>
        /// Creates a new instance of the submission wizard.
        /// </summary>
        /// <param name="engine">
        /// The submission engine instance to use to make the submission.
        /// </param>
        /// <param name="dte">
        /// The DTE object to use to access Visual Studio services.
        /// </param>
        /// <param name="submittables">
        /// The array of items to be submitted.
        /// </param>
        public SubmitterWizard(SubmissionEngine engine, IServiceProvider sp,
			ISubmittableItem[] submittables, string username)
        {
            InitializeComponent();

            this.serviceProvider = sp;
            this.engine = engine;
            this.submittables = submittables;

            Controls.Remove(summaryPage);

            usernameField.Text = username;
            wizardDescriptionLabel.Text = Messages.WizardStartDescription;
        }
Beispiel #3
0
        //  -------------------------------------------------------------------
        /// <summary>
        /// Adds a submittable item to the package that was started by a call
        /// to StartPackage.
        /// </summary>
        /// <param name="item"></param>
        public void AddSubmittableItem(ISubmittableItem item)
        {
            if (item.Kind == SubmittableItemKind.Folder)
            {
                if (item.Filename != "" && item.Filename != "\\")
                {
                    ZipEntry entry =
                        zipFactory.MakeDirectoryEntry(item.Filename);

                    zipStream.PutNextEntry(entry);
                    zipStream.CloseEntry();
                }
            }
            else if (item.Kind == SubmittableItemKind.File)
            {
                Stream itemStream = item.GetStream();

                // If we try to stream the file directly into the zip file
                // without determining its size for the zip entry, the archive
                // will not expand properly under OS X. Until we can fix this,
                // we stream each file entirely into memory to compute its
                // length, then stream the memory buffer out to the zip file.

                MemoryStream memStream = new MemoryStream();
                StreamUtils.Copy(itemStream, memStream, buffer);
                itemStream.Close();

                long length = memStream.Length;

                ZipEntry entry = zipFactory.MakeFileEntry(item.Filename);
                entry.Size = length;
                zipStream.PutNextEntry(entry);

                memStream.Seek(0, SeekOrigin.Begin);
                StreamUtils.Copy(memStream, zipStream, buffer);

                zipStream.CloseEntry();
            }
        }
        //  -------------------------------------------------------------------
        /// <summary>
        /// Appends to a selection list the submittable item in the given node,
        /// if it is checked.
        /// </summary>
        /// <remarks>
        /// This method handles nested elements -- if the parent of an item is
        /// checked, that means that all of its children are as well, so only
        /// the parent needs to be added to the selection. If a parent node is
        /// not checked, then we recursively look at its children to determine
        /// if any of them need to be added to the selection.
        /// </remarks>
        /// <param name="items">
        /// The list that will be built up to contain the selection.
        /// </param>
        /// <param name="node">
        /// The node to possibly add to the selection.
        /// </param>
        private void AppendSelectionFromNode(List <ISubmittableItem> items,
                                             TreeNode node)
        {
            if (node.Checked)
            {
                string      solutionDir, solutionFile, solutionUser;
                IVsSolution solution = VsShellUtils.GetSolution(serviceProvider);
                solution.GetSolutionInfo(out solutionDir, out solutionFile,
                                         out solutionUser);

                ISubmittableItem item = null;

                if (node.Tag is IVsSolution)
                {
                    item = new SubmittableSolution((IVsSolution)node.Tag);
                }
                else if (node.Tag is HierarchyItem)
                {
                    HierarchyItem hierarchy = (HierarchyItem)node.Tag;

                    item = new SubmittableProject(solutionDir, hierarchy);
                }

                if (item != null)
                {
                    items.Add(item);
                }
            }
            else
            {
                foreach (TreeNode child in node.Nodes)
                {
                    AppendSelectionFromNode(items, child);
                }
            }
        }
        //  -------------------------------------------------------------------
        /// <summary>
        /// Displays the submission wizard with the specified array of
        /// submittable items as its initial selection.
        /// </summary>
        /// <param name="items">
        /// The initial selection of submittable items.
        /// </param>
        private void ShowSubmissionWizard(ISubmittableItem[] items)
        {
            IntPtr owningHwnd;
            IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            uiShell.GetDialogOwnerHwnd(out owningHwnd);
            HWndWrapper windowWrapper = new HWndWrapper(owningHwnd);

            SubmissionEngine engine = new SubmissionEngine();

            SubmitterOptionsPage options = (SubmitterOptionsPage)
                GetDialogPage(typeof(SubmitterOptionsPage));

            Exception openException = null;

            BackgroundWorkerDialog dlg = new BackgroundWorkerDialog(
                Messages.LoadingSubmissionTargetsProgress, true,
                delegate(object sender, DoWorkEventArgs e)
                {
                    BackgroundWorker worker = (BackgroundWorker)sender;

                    try
                    {
                        Uri uri = new Uri(options.SubmissionDefinitionsUri);
                        engine.OpenDefinitions(uri);
                    }
                    catch (Exception ex)
                    {
                        openException = ex;
                    }
                });

            dlg.ShowDialog(windowWrapper);

            if (engine.Root != null)
            {
                SubmitterWizard wizard = new SubmitterWizard(engine,
                    this, items, options.DefaultUsername);

                wizard.ShowDialog(windowWrapper);

                if (engine.HasResponse)
                {
                    DisplaySubmissionResponse(engine);
                }
            }
            else
            {
                if (openException != null)
                {
                    MessageBox.Show(windowWrapper,
                        String.Format(Messages.LoadingSubmissionTargetsError,
                        openException.Message),
                        Messages.LoadingSubmissionTargetsErrorTitle,
                        MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show(windowWrapper,
                        Messages.LoadingSubmissionTargetsUnknownError,
                        Messages.LoadingSubmissionTargetsErrorTitle,
                        MessageBoxButtons.OK);
                }
            }
        }
        //  -------------------------------------------------------------------
        private string[] VerifyRequiredFiles(ITargetAssignment assignment,
			ISubmittableItem[] items)
        {
            Dictionary<string, bool> requiredFiles =
                new Dictionary<string, bool>();

            string[] patterns = assignment.AllRequiredFiles;
            foreach(string pattern in patterns)
                requiredFiles.Add(pattern, false);

            foreach (ISubmittableItem item in
                new DepthFirstTraversal<ISubmittableItem>(items,
                delegate(ISubmittableItem i) { return i.Children; }))
            {
                if (item.Kind == SubmittableItemKind.File)
                {
                    foreach (string reqPattern in patterns)
                    {
                        FilePattern pattern = new FilePattern(reqPattern);
                        if(pattern.Matches(item.Filename))
                        {
                            requiredFiles[reqPattern] = true;
                        }
                    }
                }
            }

            List<string> missingFiles = new List<string>();
            foreach (string requiredFile in requiredFiles.Keys)
            {
                if (requiredFiles[requiredFile] == false)
                {
                    missingFiles.Add(requiredFile);
                }
            }

            if (missingFiles.Count == 0)
            {
                return null;
            }
            else
            {
                return missingFiles.ToArray();
            }
        }