Ejemplo n.º 1
0
        internal Document(MetadataReader reader, DocumentHandle handle)
        {
            Debug.Assert(reader != null);
            Debug.Assert(!handle.IsNil);

            _reader = reader;
            _rowId = handle.RowId;
        }
Ejemplo n.º 2
0
        public QueuedJobInfo[] GetJobsForHandle(TenantId tenantId, DocumentHandle handle, IEnumerable <string> queueNames)
        {
            if (queueNames == null || queueNames.Any() == false)
            {
                //we are interested in all queues
                queueNames = _queueHandlers.Select(h => h.Key).ToArray();
            }

            List <QueuedJobInfo> retValue = new List <QueuedJobInfo>();

            foreach (var queueName in queueNames)
            {
                var jobs = ExecuteWithQueueHandler("get job for handle", queueName, h => h.GetJobsForHandle(tenantId, handle));
                retValue.AddRange(jobs.Select(j => new QueuedJobInfo(
                                                  j.Id,
                                                  queueName,
                                                  j.Status == QueuedJobExecutionStatus.Succeeded || j.Status == QueuedJobExecutionStatus.Failed,
                                                  j.Status == QueuedJobExecutionStatus.Succeeded)));
            }
            return(retValue.ToArray());
        }
Ejemplo n.º 3
0
        internal SourceFile(AssemblyInfo assembly, int id, DocumentHandle docHandle, Uri sourceLinkUri, string url)
        {
            this.methods          = new Dictionary <int, MethodInfo>();
            this.SourceLinkUri    = sourceLinkUri;
            this.assembly         = assembly;
            this.id               = id;
            this.doc              = assembly.pdbMetadataReader.GetDocument(docHandle);
            this.docHandle        = docHandle;
            this.url              = url;
            this.DebuggerFileName = url.Replace("\\", "/").Replace(":", "");

            this.SourceUri = new Uri((Path.IsPathRooted(url) ? "file://" : "") + url, UriKind.RelativeOrAbsolute);
            if (SourceUri.IsFile && File.Exists(SourceUri.LocalPath))
            {
                this.Url = this.SourceUri.ToString();
            }
            else
            {
                this.Url = DotNetUrl;
            }
        }
 public DocumentCopied(
     DocumentHandle handle,
     DocumentDescriptorId documentDescriptorId,
     DocumentHandleInfo handleInfo)
 {
     if (handle == null)
     {
         throw new ArgumentNullException("handle");
     }
     if (documentDescriptorId == null)
     {
         throw new ArgumentNullException("documentDescriptorId");
     }
     if (handleInfo == null)
     {
         throw new ArgumentNullException("handleInfo");
     }
     DocumentDescriptorId = documentDescriptorId;
     NewHandle            = handle;
     HandleInfo           = handleInfo;
 }
Ejemplo n.º 5
0
        private static string GetFileName(MetadataReader reader, DocumentHandle documentHandle)
        {
            var document = reader.GetDocument(documentHandle);

            if (document.Name.IsNil)
            {
                return null;
            }

            var nameReader = reader.GetBlobReader(document.Name);

            int separator = nameReader.ReadByte();
            if (!FileNameUtilities.IsDirectorySeparator((char)separator))
            {
                return FileNameUtilities.GetFileName(reader.GetString(document.Name));
            }

            // find the last part handle:
            BlobHandle partHandle = default(BlobHandle);
            while (nameReader.RemainingBytes > 0)
            {
                partHandle = nameReader.ReadBlobHandle();
            }

            if (partHandle.IsNil)
            {
                return string.Empty;
            }

            var partReader = reader.GetBlobReader(partHandle);
            var part = partReader.ReadUTF8(partReader.Length);
            if (part.IndexOf('\0') >= 0)
            {
                // bad metadata
                return null;
            }

            // it is valid to encode document name so that the parts contain directory separators:
            return FileNameUtilities.GetFileName(part);
        }
        public void verify_stream_events_on_attachment()
        {
            SetHandleToReturn();
            var docRm = new DocumentDescriptorReadModel(1L, new DocumentDescriptorId(1), new BlobId("file_1"));
            var rev1  = new DocumentHandle("rev_1");

            docRm.AddHandle(rev1);
            rmDocuments.Add(docRm);

            var attachHandle = new DocumentHandle("rev_2");
            var docRmAttach  = new DocumentDescriptorReadModel(1L, new DocumentDescriptorId(1), new BlobId("file_2"));

            docRmAttach.AddHandle(attachHandle);
            rmDocuments.Add(docRmAttach);
            CreateSut();
            var evt = new DocumentDescriptorHasNewAttachment(attachHandle, "path.txt").AssignIdForTest(new DocumentId(1));

            _sut.Handle(evt, false); //Handle is linked to document.
            Assert.That(rmStream, Has.Count.EqualTo(1));
            Assert.That(rmStream[0].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewAttachment));
            Assert.That(rmStream[0].EventData[StreamReadModelEventDataKeys.ChildHandle], Is.EqualTo(attachHandle));
        }
Ejemplo n.º 7
0
        internal bool TryGetDocument(string fullPath, out DocumentHandle documentHandle)
        {
            var fileName = FileNameUtilities.GetFileName(fullPath);

            KeyValuePair <DocumentHandle, ImmutableArray <DocumentHandle> > documents;

            if (!_map.TryGetValue(fileName, out documents))
            {
                documentHandle = default(DocumentHandle);
                return(false);
            }

            // SymReader first attempts to find the document by the full path, then by file name with extension.

            if (!documents.Key.IsNil)
            {
                // There is only one document with the specified file name.
                // SymReader returns the document regardless of whether the path matches the name.
                documentHandle = documents.Key;
                return(true);
            }

            Debug.Assert(documents.Value.Length > 1);

            // We have multiple candidates with the same file name. Find the one whose name matches the specified full path.
            // If none does return the first one. It will be the one with the smallest handle, due to the multi-map construction implementation.

            foreach (DocumentHandle candidateHandle in documents.Value)
            {
                if (_reader.StringComparer.Equals(_reader.GetDocument(candidateHandle).Name, fullPath, ignoreCase: true))
                {
                    documentHandle = candidateHandle;
                    return(true);
                }
            }

            documentHandle = documents.Value[0];
            return(true);
        }
Ejemplo n.º 8
0
        internal bool TryGetDocument(string fullPath, out DocumentHandle documentHandle)
        {
            var fileName = FileNameUtilities.GetFileName(fullPath);

            KeyValuePair<DocumentHandle, ImmutableArray<DocumentHandle>> documents; 
            if (!_map.TryGetValue(fileName, out documents))
            {
                documentHandle = default(DocumentHandle);
                return false;
            }

            // SymReader first attempts to find the document by the full path, then by file name with extension.

            if (!documents.Key.IsNil)
            {
                // There is only one document with the specified file name.
                // SymReader returns the document regardless of whether the path matches the name.
                documentHandle = documents.Key;
                return true;
            }

            Debug.Assert(documents.Value.Length > 1);

            // We have multiple candidates with the same file name. Find the one whose name matches the specified full path.
            // If none does return the first one. It will be the one with the smallest handle, due to the multi-map construction implementation.

            foreach (DocumentHandle candidateHandle in documents.Value)
            {
                if (_reader.StringComparer.Equals(_reader.GetDocument(candidateHandle).Name, fullPath, ignoreCase: true))
                {
                    documentHandle = candidateHandle;
                    return true;
                }
            }

            documentHandle = documents.Value[0];
            return true;
        }
        public void Delete(DocumentHandle handle)
        {
            if (handle != DocumentHandle.Empty)
            {
                if (InternalState.IsValidHandle(handle))
                {
                    RaiseEvent(new DocumentHandleDetached(handle));
                }
                else
                {
                    Logger.WarnFormat("Invalid handle {0} on {1}", handle, this.Id);
                }
            }

            if (!InternalState.HasActiveHandles())
            {
                RaiseEvent(new DocumentDescriptorDeleted(
                               InternalState.BlobId,
                               InternalState.Formats.Select(x => x.Value).ToArray(),
                               InternalState.Attachments.ToArray()
                               ));
            }
        }
        /// <summary>
        /// Sets the document according to the active document.
        /// </summary>
        private void SetDocument()
        {
            if (this.application.OpenDocumentCount > 0)
            {
                DocumentContext context    = null;
                bool            newContext = false;
                DocumentHandle  handle     = this.MakeDocumentHandle(this.application.ActiveDocument);
                if (!this.openDocuments.TryGetValue(handle, out context))
                {
                    context = new DocumentContext(this.container.CreateChildContainer());
                    this.openDocuments.Add(handle, context);
                    newContext = true;
                }

                context.Container.RegisterInstance <IWordDocument>(this.application.ActiveDocument);
                this.ActiveDocument = context.Container.Resolve <ITeamProjectDocument>();
                if (newContext)
                {
                    this.ActiveDocument.Connected += new EventHandler(this.HandleDocumentConnection);
                }

                // Set the WordDocument property explicitly here becaused Unity does not set it again if the object already exists in the container.
                // Keeping WordDocument as a dependency property, even though it is redundant, purely for defensive coding reasons.
                this.ActiveDocument.WordDocument = this.application.ActiveDocument;
                this.ActiveContainer             = context.Container;

                this.application.ShowBookmarks = this.settings.ShowBookmarks.Value;

                this.logger.Log(TraceEventType.Information, "Document changed to: {0}", this.application.ActiveDocument.Name);
            }
            else
            {
                this.ActiveDocument  = null;
                this.ActiveContainer = null;
                this.logger.Log(TraceEventType.Information, "Document changed to: <none>");
            }
        }
Ejemplo n.º 11
0
        public static SourceText GetEmbeddedSource(this MetadataReader reader, DocumentHandle document)
        {
            byte[] bytes = (from handle in reader.GetCustomDebugInformation(document)
                            let cdi = reader.GetCustomDebugInformation(handle)
                                      where reader.GetGuid(cdi.Kind) == PortableCustomDebugInfoKinds.EmbeddedSource
                                      select reader.GetBlobBytes(cdi.Value)).SingleOrDefault();

            if (bytes == null)
            {
                return(null);
            }

            int uncompressedSize = BitConverter.ToInt32(bytes, 0);
            var stream           = new MemoryStream(bytes, sizeof(int), bytes.Length - sizeof(int));

            if (uncompressedSize != 0)
            {
                var decompressed = new MemoryStream(uncompressedSize);

                using (var deflater = new DeflateStream(stream, CompressionMode.Decompress))
                {
                    deflater.CopyTo(decompressed);
                }

                if (decompressed.Length != uncompressedSize)
                {
                    throw new InvalidDataException();
                }

                stream = decompressed;
            }

            using (stream)
            {
                return(EncodedStringText.Create(stream));
            }
        }
Ejemplo n.º 12
0
        internal bool TryGetMethodSourceExtent(DocumentHandle documentHandle, MethodDebugInformationHandle methodHandle, out int startLine, out int endLine)
        {
            MethodsInDocument methodsInDocument;

            if (!_methodsByDocument.TryGetValue(documentHandle, out methodsInDocument))
            {
                startLine = endLine = 0;
                return(false);
            }

            int index = methodsInDocument.ExtentsByMethod.BinarySearch(methodHandle, (ext, handle) => HandleComparer.Default.Compare(ext.Method, handle));

            if (index < 0)
            {
                startLine = endLine = 0;
                return(false);
            }

            var extent = methodsInDocument.ExtentsByMethod[index];

            startLine = extent.MinLine;
            endLine   = extent.MaxLine;
            return(true);
        }
 public void Upload_msg()
 {
     _docs.UploadAsync(TestConfig.PathToMsg, DocumentHandle.FromString("outlook_1")).Wait();
 }
 public void Upload_rtf()
 {
     _docs.UploadAsync(TestConfig.PathToRTFDocument, DocumentHandle.FromString("rtf")).Wait();
 }
Ejemplo n.º 15
0
 public DocumentNameAndHandle(DocumentHandle handle, string fileName)
 {
     Handle = handle;
     FileName = fileName;
 }
 public void Upload_many_docs_delete()
 {
     _docs.DeleteAsync(DocumentHandle.FromString("Doc1")).Wait();
     _docs.DeleteAsync(DocumentHandle.FromString("Doc2")).Wait();
     _docs.DeleteAsync(DocumentHandle.FromString("Doc3")).Wait();
 }
 public void Upload_pdf_then_delete()
 {
     _docs.UploadAsync(TestConfig.PathToDocumentPdf, DocumentHandle.FromString("Revision_42")).Wait();
     Thread.Sleep(3000);
     _docs.DeleteAsync(DocumentHandle.FromString("Revision_42")).Wait();
 }
 public void Upload_pdf_copyHandle_then_delete()
 {
     _docs.UploadAsync(TestConfig.PathToDocumentPdf, DocumentHandle.FromString("docs_to_copy")).Wait();
     _docs.CopyHandleAsync(DocumentHandle.FromString("docs_to_copy"), DocumentHandle.FromString("docs_to_copy_copied")).Wait();
     _docs.DeleteAsync(DocumentHandle.FromString("docs_to_copy")).Wait();
 }
 public void Upload_medium_jpg()
 {
     _docs.UploadAsync(TestConfig.PathToMediumJpg, DocumentHandle.FromString("jpg_1")).Wait();
 }
Ejemplo n.º 20
0
        internal BlobHandle GetHash(DocumentHandle handle)
        {
            int rowOffset = (handle.RowId - 1) * RowSize;

            return(BlobHandle.FromOffset(Block.PeekHeapReference(rowOffset + _hashOffset, _isBlobHeapRefSizeSmall)));
        }
Ejemplo n.º 21
0
        internal DocumentHandle GetDocument(MethodDebugInformationHandle handle)
        {
            int rowOffset = (handle.RowId - 1) * RowSize;

            return(DocumentHandle.FromRowId(Block.PeekReference(rowOffset + DocumentOffset, _isDocumentRefSmall)));
        }
Ejemplo n.º 22
0
 public Document GetDocument(DocumentHandle handle)
 {
     return new Document(this, handle);
 }
Ejemplo n.º 23
0
 internal GuidHandle GetLanguage(DocumentHandle handle)
 {
     int rowOffset = (handle.RowId - 1) * RowSize;
     return GuidHandle.FromIndex(Block.PeekHeapReference(rowOffset + _languageOffset, _isGuidHeapRefSizeSmall));
 }
Ejemplo n.º 24
0
 internal BlobHandle GetHash(DocumentHandle handle)
 {
     int rowOffset = (handle.RowId - 1) * RowSize;
     return BlobHandle.FromOffset(Block.PeekHeapReference(rowOffset + _hashOffset, _isBlobHeapRefSizeSmall));
 }
Ejemplo n.º 25
0
 internal GuidHandle GetHashAlgorithm(DocumentHandle handle)
 {
     int rowOffset = (handle.RowId - 1) * RowSize;
     return GuidHandle.FromIndex(Block.PeekHeapReference(rowOffset + _hashAlgorithmOffset, _isGuidHeapRefSizeSmall));
 }
Ejemplo n.º 26
0
 internal DocumentNameBlobHandle GetName(DocumentHandle handle)
 {
     int rowOffset = (handle.RowId - 1) * RowSize;
     return DocumentNameBlobHandle.FromOffset(Block.PeekHeapReference(rowOffset + NameOffset, _isBlobHeapRefSizeSmall));
 }
 public void Upload_video()
 {
     _docs.UploadAsync("C:\\temp\\rainingblood.mp4", DocumentHandle.FromString("slayer_raining_blood")).Wait();
 }
 public void Upload_eml()
 {
     _docs.UploadAsync(TestConfig.PathToEml, DocumentHandle.FromString("eml_1")).Wait();
 }
Ejemplo n.º 29
0
 internal SymDocument(SymReader symReader, DocumentHandle documentHandle)
 {
     Debug.Assert(symReader != null);
     SymReader = symReader;
     Handle    = documentHandle;
 }
 public void Upload_temp_zipFile()
 {
     _docs.UploadAsync("C:\\temp\\temp.zip", DocumentHandle.FromString("TempZip")).Wait();
 }
Ejemplo n.º 31
0
        public MethodDebugInformationHandle AddMethodDebugInformation(DocumentHandle document, BlobHandle sequencePoints)
        {
            _methodDebugInformationTable.Add(new MethodDebugInformationRow
            {
                Document = (uint)MetadataTokens.GetRowNumber(document),
                SequencePoints = sequencePoints
            });

            // TODO:
            return (MethodDebugInformationHandle)MetadataTokens.Handle(TableIndex.MethodDebugInformation, _methodDebugInformationTable.Count);
        }
 public void Upload_txt_document()
 {
     _docs.UploadAsync(TestConfig.PathToLoremIpsumTxt, DocumentHandle.FromString("text_document")).Wait();
 }
 public void Upload_odt()
 {
     _docs.UploadAsync(TestConfig.PathToOpenDocumentText, DocumentHandle.FromString("odt")).Wait();
 }
 public void Upload_many_docs()
 {
     _docs.UploadAsync(TestConfig.PathToDocumentPdf, DocumentHandle.FromString("Doc1")).Wait();
     _docs.UploadAsync(TestConfig.PathTo7Zip, DocumentHandle.FromString("Doc2")).Wait();
     _docs.UploadAsync(TestConfig.PathToEml, DocumentHandle.FromString("Doc3")).Wait();
 }
 public void Upload_ods()
 {
     _docs.UploadAsync(TestConfig.PathToOpenDocumentSpreadsheet, DocumentHandle.FromString("ods")).Wait();
 }
Ejemplo n.º 36
0
 internal SymDocument(SymReader symReader, DocumentHandle documentHandle)
 {
     Debug.Assert(symReader != null);
     _symReader = symReader;
     _handle = documentHandle;
 }
 public void Upload_odp()
 {
     _docs.UploadAsync(TestConfig.PathToOpenDocumentPresentation, DocumentHandle.FromString("odp")).Wait();
 }
Ejemplo n.º 38
0
        internal GuidHandle GetHashAlgorithm(DocumentHandle handle)
        {
            int rowOffset = (handle.RowId - 1) * RowSize;

            return(GuidHandle.FromIndex(Block.PeekHeapReference(rowOffset + _hashAlgorithmOffset, _isGuidHeapRefSizeSmall)));
        }
Ejemplo n.º 39
0
 public void AddMethodDebugInformation(DocumentHandle document, BlobHandle sequencePoints)
 {
     _methodDebugInformationTable.Add(new MethodDebugInformationRow
     {
         Document = (uint)MetadataTokens.GetRowNumber(document),
         SequencePoints = sequencePoints
     });
 }
Ejemplo n.º 40
0
        internal GuidHandle GetLanguage(DocumentHandle handle)
        {
            int rowOffset = (handle.RowId - 1) * RowSize;

            return(GuidHandle.FromIndex(Block.PeekHeapReference(rowOffset + _languageOffset, _isGuidHeapRefSizeSmall)));
        }
 public void Upload_excel()
 {
     _docs.UploadAsync(TestConfig.PathToExcelDocument, DocumentHandle.FromString("xlsx")).Wait();
 }
Ejemplo n.º 42
0
        public static SourceText GetEmbeddedSource(this MetadataReader reader, DocumentHandle document)
        {
            byte[] bytes = (from handle in reader.GetCustomDebugInformation(document)
                            let cdi = reader.GetCustomDebugInformation(handle)
                            where reader.GetGuid(cdi.Kind) == PortableCustomDebugInfoKinds.EmbeddedSource
                            select reader.GetBlobBytes(cdi.Value)).SingleOrDefault();

            if (bytes == null)
            {
                return null;
            }

            int uncompressedSize = BitConverter.ToInt32(bytes, 0);
            var stream = new MemoryStream(bytes, sizeof(int), bytes.Length - sizeof(int));

            if (uncompressedSize != 0)
            {
                var decompressed = new MemoryStream(uncompressedSize);

                using (var deflater = new DeflateStream(stream, CompressionMode.Decompress))
                {
                    deflater.CopyTo(decompressed);
                }

                if (decompressed.Length != uncompressedSize)
                {
                    throw new InvalidDataException();
                }

                stream = decompressed;
            }

            using (stream)
            {
                return EncodedStringText.Create(stream);
            }
        }
 public void Upload_pps()
 {
     _docs.UploadAsync(TestConfig.PathToPowerpointShow, DocumentHandle.FromString("ppsx")).Wait();
 }