public static IntPtr GetIcon(IVsHierarchy hierarchy, uint itemId, out bool deleteIcon)
        {
            deleteIcon = false;
            object pvar;

            hierarchy.GetProperty(itemId, -2005, out pvar);
            if (pvar == null)
            {
                hierarchy.GetProperty(itemId, -2013, out pvar);
                return(TFCommonUtil.GetImageHandle(pvar));
            }
            var num = (uint)pvar;

            hierarchy.GetProperty(4294967294U, -2004, out pvar);
            var imageHandle = TFCommonUtil.GetImageHandle(pvar);

            if (imageHandle != IntPtr.Zero)
            {
                var imageCount = NativeMethods.ImageList_GetImageCount(imageHandle);
                if ((int)num < imageCount)
                {
                    var icon = NativeMethods.ImageList_GetIcon(imageHandle, (int)num, 0U);
                    if (icon != IntPtr.Zero)
                    {
                        deleteIcon = true;
                        return(icon);
                    }
                }
            }
            return(IntPtr.Zero);
        }
Example #2
0
        /// <summary>
        /// Downloads the content of a file and copies it to the specified stream if the request succeeds.
        /// </summary>
        /// <param name="client">Http client.</param>
        /// <param name="requestUri">Download uri.</param>
        /// <param name="stream">Stream to write file content to.</param>
        /// <returns>Http response message.</returns>
        public static async Task <HttpResponseMessage> DownloadFileFromTfsAsync(this HttpClient client, Uri requestUri, Stream stream)
        {
            TFCommonUtil.CheckForNull(client, "client");
            TFCommonUtil.CheckForNull(requestUri, "requestUri");
            TFCommonUtil.CheckForNull(stream, "stream");

            HttpResponseMessage response = await client.GetAsync(requestUri.ToString());

            if (response.IsSuccessStatusCode && response.StatusCode != HttpStatusCode.NoContent)
            {
                bool decompress;
                if (StringComparer.OrdinalIgnoreCase.Equals(response.Content.Headers.ContentType.MediaType, "application/octet-stream"))
                {
                    decompress = false;
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(response.Content.Headers.ContentType.MediaType, "application/gzip"))
                {
                    decompress = true;
                }
                else
                {
                    throw new Exception(string.Format("Unsupported Content Type {0}", response.Content.Headers.ContentType.MediaType));
                }

                using (DownloadStream downloadStream = new DownloadStream(stream, decompress, response.Content.Headers.ContentMD5))
                {
                    await response.Content.CopyToAsync(downloadStream);

                    downloadStream.ValidateHash();
                }
            }

            return(response);
        }
Example #3
0
        protected override IList <BatchSaveError> Execute(CodeActivityContext context)
        {
            var workItems = this.WorkItems.Get(context);
            var errors    = new List <BatchSaveError>();

            TFCommonUtil.CheckForNull(workItems, "WorkItems");
            if (workItems.Any())
            {
                errors.AddRange(workItems.First().Store.BatchSave(workItems.ToArray(), SaveFlags.None));
            }

            return(errors);
        }
        public static void ProcessRDTDocuments(RDTDocumentsDelegate processAction)
        {
            var runningDocumentTable = (IVsRunningDocumentTable)GetService(typeof(SVsRunningDocumentTable));
            IEnumRunningDocuments ppenum;

            runningDocumentTable.GetRunningDocumentsEnum(out ppenum);
            var  rgelt = new uint[10];
            uint pceltFetched;

            while (HResult.Succeeded(ppenum.Next((uint)rgelt.Length, rgelt, out pceltFetched)) && pceltFetched > 0U)
            {
                for (var index = 0; (long)index < (long)pceltFetched; ++index)
                {
                    uint         pgrfRDTFlags;
                    uint         pdwReadLocks;
                    uint         pdwEditLocks;
                    string       pbstrMkDocument;
                    IVsHierarchy ppHier;
                    uint         pitemid;
                    IntPtr       ppunkDocData;
                    var          documentInfo = runningDocumentTable.GetDocumentInfo(rgelt[index], out pgrfRDTFlags, out pdwReadLocks,
                                                                                     out pdwEditLocks, out pbstrMkDocument, out ppHier, out pitemid, out ppunkDocData);
                    try
                    {
                        if (HResult.Succeeded(documentInfo))
                        {
                            if (!(ppunkDocData == IntPtr.Zero))
                            {
                                processAction(pgrfRDTFlags, pdwReadLocks, pdwEditLocks, pbstrMkDocument, ppHier, pitemid, ppunkDocData);
                            }
                        }
                    }
                    finally
                    {
                        TFCommonUtil.SafeRelease(ppunkDocData);
                    }
                }
            }
        }
        public static IVsHierarchy GetNestedHierarchy(IVsHierarchy hierarchy, uint itemId, out uint nestedItemId)
        {
            var    iidHierarchyNested = IID_IVsHierarchy;
            IntPtr ppHierarchyNested;
            var    nestedHierarchy = hierarchy.GetNestedHierarchy(itemId, ref iidHierarchyNested, out ppHierarchyNested,
                                                                  out nestedItemId);
            IVsHierarchy vsHierarchy = null;

            try
            {
                if (HResult.Succeeded(nestedHierarchy))
                {
                    if (ppHierarchyNested != IntPtr.Zero)
                    {
                        vsHierarchy = (IVsHierarchy)Marshal.GetObjectForIUnknown(ppHierarchyNested);
                    }
                }
            }
            finally
            {
                TFCommonUtil.SafeRelease(ppHierarchyNested);
            }
            return(vsHierarchy);
        }