/// <include file='doc\VsCheckoutService.uex' path='docs/doc[@for="VsCheckoutService.CheckoutFile2"]/*' />
        /// <devdoc>
        ///     Checks out the given file, if possible. If the file is already checked out, or
        ///     does not need to be checked out, no Exception is thrown and the function returns.
        ///     This also checks out any additional buffers passed in through the additionalBuffers
        ///     parameter.
        ///     If the file needs be be checked out ot be edited, and it cannot be checked out,
        ///     an exception is thrown.
        ///
        /// </devdoc>
        public virtual void CheckoutFile(string fileName, string[] additionalBuffers)
        {
            EnsureTextManager();
            if (disable)
            {
                return;
            }

            Debug.Assert(textManagerService != null, "Couldn't get text manager service!");
            if (fileName == null)
            {
                throw new ArgumentException(SR.GetString(SR.InvalidArgument, "fileName", "null"));
            }
            if ((!DoesFileNeedCheckout(fileName)) && (additionalBuffers == null || additionalBuffers.Length == 0))
            {
                return;
            }
            bool userCanceled = false;
            bool pSuccess     = false;
            int  errorCode    = 0;

            try{
                IVsQueryEditQuerySave2 qeqs = (IVsQueryEditQuerySave2)serviceProvider.GetService(typeof(SVsQueryEditQuerySave2));

                if (qeqs != null)
                {
                    _VSQueryEditResult editVerdict;

                    string [] files = GetFilesFromHierarchy(fileName, additionalBuffers);
                    if (files.Length == 0)
                    {
                        return;
                    }
                    IntPtr fileMemory = GetWStrArray(files);
                    try {
                        _VSQueryEditResultFlags result = qeqs.QueryEditFiles(0, files.Length, fileMemory, new int[files.Length], 0, out editVerdict);
                        pSuccess = editVerdict == _VSQueryEditResult.QER_EditOK;
                        if (!pSuccess &&
                            ((int)result & (int)_VSQueryEditResultFlags.QER_CheckoutCanceledOrFailed) != 0)
                        {
                            userCanceled = true;
                        }
                    }
                    finally {
                        FreeWStrArray(fileMemory, files.Length);
                    }
                }
                else
                {
                    int result = textManagerService.AttemptToCheckOutBufferFromScc2(fileName, ref pSuccess);
                    if (!pSuccess &&
                        (result & (int)_VSQueryEditResultFlags.QER_CheckoutCanceledOrFailed) != 0)
                    {
                        userCanceled = true;
                    }
                }
            } catch (ExternalException ex) {
                errorCode = ex.ErrorCode;
            }

            if (!pSuccess)
            {
                if (!userCanceled)
                {
                    throw new CheckoutException(SR.GetString(SR.CHECKOUTSERVICEUnableToCheckout), errorCode);
                }
                else
                {
                    throw CheckoutException.Canceled;
                }
            }

            // You can actually configure SSC to edit a read only file, so do not fail the checkout if
            // the file is read only.
            //

            /*
             * if (IsFileReadOnly(fileName)){
             *  Debug.Fail("Checkout returned success, but file is still readonly.  SCC failed to correctly checkout the file.");
             *  throw CheckoutException.Canceled;
             * }
             */
        }
Exemplo n.º 2
0
        /// <include file='doc\DesignerService.uex' path='docs/doc[@for="DesignerService.IVSMDDesignerService.RegisterDesignViewAttribute"]/*' />
        /// <devdoc>
        ///     This class is called to report the value of the design view attribute on
        ///     a particular class.  It is generally called by a compiler.
        /// </devdoc>
        void IVSMDDesignerService.RegisterDesignViewAttribute(object pHier, int itemid, int cClass, string pwszAttributeValue)
        {
            // Check the attribute container
            //
            if (!(pHier is IVsHierarchy))
            {
                throw new ArgumentException("pHier");
            }

            // If the project file is not checked out, then don't make any changes to the subitem type.
            // We can get called as the compiler rolls through the classes, and we don't want to
            // flip bits in the project system if it is checked into source code control.
            //
            bool saveAttribute = true;

            object obj;
            int    hr = ((IVsHierarchy)pHier).GetProperty(__VSITEMID.VSITEMID_ROOT, __VSHPROPID.VSHPROPID_ExtObject, out obj);

            if (NativeMethods.Succeeded(hr))
            {
                Project project = (Project)obj;

                IVsQueryEditQuerySave2 qeqs = (IVsQueryEditQuerySave2)GetService(typeof(SVsQueryEditQuerySave2));

                if (qeqs != null)
                {
                    string projectFile = project.FileName;
                    IntPtr memBlock    = Marshal.AllocCoTaskMem(IntPtr.Size);
                    Marshal.WriteIntPtr(memBlock, 0, Marshal.StringToCoTaskMemUni(projectFile));

                    try {
                        _VSQueryEditResult      editVerdict;
                        _VSQueryEditResultFlags result = qeqs.QueryEditFiles((int)tagVSQueryEditFlags.QEF_ReportOnly, 1, memBlock, new int[1], 0, out editVerdict);
                        saveAttribute = editVerdict == _VSQueryEditResult.QER_EditOK;
                    }
                    finally {
                        IntPtr str = Marshal.ReadIntPtr(memBlock, 0);
                        Marshal.FreeCoTaskMem(str);
                        Marshal.FreeCoTaskMem(memBlock);
                    }
                }
            }

            AttributeBucket attributeBucket = (AttributeBucket)attributeHash[itemid];

            if (attributeBucket == null)
            {
                attributeBucket       = new AttributeBucket();
                attributeHash[itemid] = attributeBucket;
            }

            // Attribute registration does a number of things. What comes out the
            // other end of attributeBucket, however, is a string containing the
            // best attribute so far.
            attributeBucket.RegisterAttribute(cClass, pwszAttributeValue);

            string bestAttribute = attributeBucket.BestAttribute;

            if (saveAttribute)
            {
                Debug.Assert(pHier != null, "Invalid hierarchy passed to us");
                ((IVsHierarchy)pHier).SetProperty(itemid, __VSHPROPID.VSHPROPID_ItemSubType, bestAttribute);
            }
        }