コード例 #1
0
        public LoadedPackage(string fileName, byte[] package)
        {
            FileName = fileName;
            var arch = new ZipArchive(new MemoryStream(package));

            foreach (var e in arch.Entries)
            {
                using (var s = e.Open())
                {
                    var ms = new MemoryStream();
                    s.CopyTo(ms);
                    BinaryContents.Add(e.FullName.Replace("\\", "/"), ms.ToArray());
                }
            }

            var nuspecItem = BinaryContents.First(c => c.Key.EndsWith("nuspec"));

            _nuspecName = nuspecItem.Key;

            Spec = new LoadedNuspec(nuspecItem.Value);
            BinaryContents.Remove(_nuspecName);

            ContentTypes = new ContentTypes(BinaryContents[ContentTypesFileName]);
            BinaryContents.Remove(ContentTypesFileName);
        }
コード例 #2
0
        public void Save(Stream stream)
        {
            var contents = BinaryContents.ToDictionary(x => x.Key, x => x.Value);

            contents[_nuspecName]          = Spec.Serialize();
            contents[ContentTypesFileName] = ContentTypes.Serialize();
            using (var arch = new ZipArchive(stream, ZipArchiveMode.Create))
            {
                foreach (var c in contents)
                {
                    var e = arch.CreateEntry(c.Key, CompressionLevel.Optimal);
                    using (var es = e.Open())
                        es.Write(c.Value, 0, c.Value.Length);
                }
            }
        }
コード例 #3
0
        public void MergeContents(INumergeLogger logger, LoadedPackage victim,
                                  PackageMergeConfiguration config)
        {
            var ignoredPrefixes = new[] { "lib/", "_rels/", "package/" };

            foreach (var item in victim.BinaryContents.Where(x =>
                                                             x.Key.Contains("/") && !ignoredPrefixes.Any(p => x.Key.StartsWith(p))))
            {
                if (BinaryContents.ContainsKey(item.Key))
                {
                    logger.Warning($"{Spec.Id}: Refusing to replace item {item.Key} with item from {victim.Spec.Id}");
                }
                else
                {
                    BinaryContents[item.Key] = item.Value;
                }
            }

            var libs = victim.BinaryContents.Where(x => x.Key.StartsWith("lib/"))
                       .Select(x => new { sp = x.Key.Split(new[] { '/' }, 3), data = x.Value })
                       .Select(x => new { Tfm = x.sp[1], File = x.sp[2], Data = x.data }).GroupBy(x => x.Tfm)
                       .ToDictionary(x => x.Key, x => x.ToList());

            var ourFrameworks = BinaryContents.Where(x => x.Key.StartsWith("lib/")).Select(x => x.Key.Split('/')[1])
                                .Distinct().ToList();

            foreach (var foreignTfm in libs)
            {
                if (!ourFrameworks.Contains(foreignTfm.Key))
                {
                    throw new MergeAbortedException(
                              $"Error merging {victim.Spec.Id}: Package {Spec.Id} doesn't have target framework {foreignTfm.Key}");
                }
            }

            //TODO: Actually detect compatibility with .NET Standard
            libs.TryGetValue("netstandard2.0", out var netstandardLibs);

            foreach (var framework in ourFrameworks)
            {
                libs.TryGetValue(framework, out var frameworkLibs);
                frameworkLibs = frameworkLibs ?? netstandardLibs;
                if (frameworkLibs == null)
                {
                    if (!config.IgnoreMissingFrameworkBinaries)
                    {
                        throw new MergeAbortedException(
                                  $"Unable to merge {victim.Spec.Id} to {Spec.Id}: {victim.Spec.Id} doesn't support {framework} or netstandard2.0");
                    }
                }
                else
                {
                    foreach (var lib in frameworkLibs)
                    {
                        var targetPath = $"lib/{framework}/{lib.File}";
                        if (BinaryContents.ContainsKey(targetPath))
                        {
                            logger.Warning(
                                $"{Spec.Id}: Refusing to replace item {targetPath} with item from {victim.Spec.Id}");
                        }
                        else
                        {
                            BinaryContents[targetPath] = lib.Data;
                        }
                    }
                }
            }



            if (!config.DoNotMergeDependencies)
            {
                //TODO: Actually detect compatibility with .NET Standard
                if (!victim.Spec.Dependencies.TryGetValue(".NETStandard2.0", out var netstandardDeps))
                {
                    victim.Spec.Dependencies.TryGetValue("netstandard2.0", out netstandardDeps);
                }

                var handledDepFrameworks = new HashSet <string>();
                foreach (var group in victim.Spec.Dependencies)
                {
                    Spec.Dependencies.GetOrCreateGroup(group.Key)
                    .AddRange(group.Value);
                    handledDepFrameworks.Add(group.Key);
                }

                foreach (var ourGroup in Spec.Dependencies)
                {
                    // Merge deps
                    if (!handledDepFrameworks.Contains(ourGroup.Key))
                    {
                        if (netstandardDeps == null)
                        {
                            if (!config.IgnoreMissingFrameworkDependencies)
                            {
                                throw new MergeAbortedException(
                                          $"Unable to merge dependencies from {victim.Spec.Id} to {Spec.Id}: {victim.Spec.Id} doesn't have deps for {ourGroup.Key} or netstandard2.0");
                            }
                        }
                        else
                        {
                            ourGroup.Value.AddRange(netstandardDeps);
                        }
                    }
                }
            }

            foreach (var ct in victim.ContentTypes)
            {
                if (!ContentTypes.ContainsKey(ct.Key))
                {
                    ContentTypes[ct.Key] = ct.Value;
                }
            }
        }
コード例 #4
0
        static void OutItems(Table gtable, Item it, ref int row)
        {
            int myrow = row;

            //sl.InsertRow();
            //row++;
            Console.Write(".");

            {
                LinkedItem linked_item  = null;
                List       linked_items = null;
                Navigation nav          = null;
                int        num_linked_items;
                nav = new Navigation();

                nav.Type = "Включает";

                nav.Direction = CAPI_XREF_DIR.ONLY_DOWN;
                // Get linked items
                if (it.GetLinkedItems(CAPI_LINKS.ALL, nav, CAPI_INFO.NOTE, CAPI_SUBTYPE.NULL, "", null, default(int), default(QueryStereotypeTest), default(QueryModelviewTest), null, out linked_items))
                {
                    num_linked_items = linked_items.Length;
                    var loopTo = num_linked_items - 1;
                    for (int i = 0; i <= loopTo; i++)
                    {
                        if (linked_items.GetElement(i, out linked_item))
                        {
                            var            l_it       = linked_item.Item;
                            Frame          frame      = null;
                            string         frame_text = null;
                            BinaryContents frame_tbl  = null;
                            BinaryContents frame_pic  = null;
                            DocX           docin      = null;
                            Table          tins       = null;
                            Picture        pins       = null;
                            Paragraph      par        = null;
                            l_it.Open(false);
                            if (!l_it.GetFrame("TEXT", out frame))
                            {
                                return;
                            }

                            // Get TEXT frame contents
                            if (!frame.GetContents(out frame_text))
                            {
                                return;
                            }
                            if (l_it.NoteType != "Титульный лист")
                            {
                                if (!l_it.GetFrame("Таблица", out frame))
                                {
                                    return;
                                }

                                // Get  frame contents
                                if (!frame.GetContents(out frame_tbl))
                                {
                                    return;
                                }
                                if (frame_tbl.Size != 0)
                                {
                                    byte[] memdocx = new byte[frame_tbl.Size];
                                    IntPtr pnt     = frame_tbl.Data;

                                    Marshal.Copy(pnt, memdocx, 0, memdocx.Length);
                                    docin = DocX.Load(BRtfDocx(memdocx));
                                    tins  = docin.Tables[0];
                                }
                                if (!l_it.GetFrame("Рисунок", out frame))
                                {
                                    return;
                                }

                                // Get  frame contents
                                if (!frame.GetContents(out frame_pic))
                                {
                                    return;
                                }
                                if (frame_pic.Size != 0)
                                {
                                    byte[] memdocx = new byte[frame_pic.Size];
                                    IntPtr pnt     = frame_pic.Data;

                                    Marshal.Copy(pnt, memdocx, 0, memdocx.Length);
                                    Stream stream = BRtfImage(memdocx);
                                    stream.Position = 0;

                                    Image img = doc.AddImage(stream);
                                    pic = img.CreatePicture();
                                    double scale = (double)pic.Width / (double)pic.Height;
                                    pic.WidthInches  = 3;
                                    pic.HeightInches = pic.WidthInches / scale;
                                }
                            }

                            l_it.Close();

                            gtable.InsertRow();
                            row++;
                            gtable.Rows[row].Cells[1].Paragraphs.First().Append(l_it.Identity);
                            //gtable.Rows[row].Cells[2].InsertParagraph().Append(frame_text);
                            gtable.Rows[row].Cells[2].Paragraphs.First().Append(frame_text);
                            if (frame_tbl != null)
                            {
                                if (frame_tbl.Size != 0)
                                {
                                    gtable.Rows[row].Cells[2].InsertParagraph().InsertTableAfterSelf(tins);
                                    gtable.Rows[row].Cells[2].InsertParagraph(docin.InsertParagraph(""));
                                }
                            }
                            if (frame_pic != null)
                            {
                                if (frame_pic.Size != 0)
                                {
                                    //Image img = doc.AddImage(bRtfDocx(memdocx));
                                    //Picture pic = img.CreatePicture();
                                    //gtable.Rows[row].Cells[0].Paragraphs.First().InsertPicture(pic);
                                    gtable.Rows[row].Cells[2].InsertParagraph().InsertPicture(pic);
                                    //gtable.Rows[row].Cells[2].InsertParagraph(doc.InsertParagraph(""));
                                }
                            }
                            //sl.InsertRow();
                        }
                    }
                    linked_items.Dispose();
                }

                nav.Type = "Содержит";

                nav.Direction = CAPI_XREF_DIR.ONLY_DOWN;
                // Get linked items
                if (it.GetLinkedItems(CAPI_LINKS.ALL, nav, CAPI_INFO.NOTE, CAPI_SUBTYPE.NULL, "", null, default(int), default(QueryStereotypeTest), default(QueryModelviewTest), null, out linked_items))
                {
                    num_linked_items = linked_items.Length;
                    var loopTo = num_linked_items - 1;
                    for (int i = 0; i <= loopTo; i++)
                    {
                        if (linked_items.GetElement(i, out linked_item))
                        {
                            var l_it = linked_item.Item;
                            gtable.InsertRow();
                            row++;
                            OutItems(gtable, l_it, ref row);
                        }
                    }
                    linked_items.Dispose();
                }

                gtable.Rows[myrow].Cells[1].Paragraphs.First().Append(it.Identity);
                gtable.Rows[myrow].Cells[2].Paragraphs.First().Append(it.Name);
                //sl.InsertRow();

                return;
            }
        }