Ejemplo n.º 1
0
        // write QSYS metadata (TEXT, RECORDLEN, ATTRIBUTE, etc)
        private void WriteQsysMetadata(KanpachiClient client, string downloadPath, string lib, string spf, SrcMbr mbr)
        {
            Library library      = null;
            var     metadataPath = Path.Combine(ClientUtils.BuildDownloadPath(downloadPath, Profile), "QSYS", lib, $"{lib}.json");

            if (File.Exists(metadataPath))
            {
                // read existing metadata file for update
                using (StreamReader f = File.OpenText(metadataPath)){
                    library = (Library) new JsonSerializer().Deserialize(f, typeof(Library));
                    int spfIdx = library.SrcPfs.FindIndex(x => x.Name == spf);

                    // source physical file not found in library metadata, so add it
                    if (spfIdx == -1)
                    {
                        library.SrcPfs.Add(client.GetSrcPfDetails(lib, spf));
                        spfIdx = library.SrcPfs.Count - 1;
                    }

                    SrcPf srcPf  = library.SrcPfs[spfIdx];
                    int   mbrIdx = srcPf.Members.FindIndex(x => x.Name == mbr.Name);

                    // source member not found in source physical file metadata, so add it
                    if (mbrIdx == -1)
                    {
                        srcPf.Members.Add(mbr);
                        mbrIdx = srcPf.Members.Count - 1;
                    }
                    library.SrcPfs[spfIdx].Members[mbrIdx] = mbr;
                }
            }
            else
            {
                // library doesn't exist in metadata, setup new one
                library = client.GetLibraryDetails(lib);
                SrcPf srcPf = client.GetSrcPfDetails(lib, spf);
                srcPf.Members.Add(mbr);
                library.SrcPfs.Add(srcPf);
            }

            // update metadata file
            using (StreamWriter f = File.CreateText(metadataPath)){
                f.Write(JsonConvert.SerializeObject(library, Formatting.Indented, new JsonSerializerSettings {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                }));
            }
        }
Ejemplo n.º 2
0
        // Download source physical file at LIB/SRCPF
        public void GetSpf(string qsysPath, string downloadPath)
        {
            if (!RegexUtils.MatchSrcPfPath(qsysPath))
            {
                throw new KanpachiFormatException("Invalid QSYS path. Expected source physical file path of format LIB/SRCPF.");
            }
            var splitPath = qsysPath.ToUpper().Split('/');

            (string lib, string spf) = (splitPath[0], splitPath[1]);

            using (KanpachiClient client = new KanpachiClient(Profile)){
                SrcPf srcPf   = client.GetSrcPfDetails(lib, spf);
                var   members = client.GetSrcMbrList(lib, spf);

                foreach (SrcMbr srcMbr in members)
                {
                    // TODO: progress output
                    DownloadSrcMbr(client, downloadPath, lib, spf, srcMbr);
                }
            }
        }