コード例 #1
0
        /// <summary>
        ///     Expects the directory to contain an infopath manifest.xsf & template.xml files. The contents are then persisted &
        ///     indexed by DocTypeName & DocTypeRev (aka solutionVersion) for OpenStream & OpenText operations. As of this writing,
        ///     this application must have write access to the parent folder of the given directory for cab compression operations.
        /// </summary>
        /// <param name="importFolderPath"></param>
        /// <param name="workingFolderPath">default is parent of importFolderPath</param>
        public static List <ImporterLightDoc> ImportContentFolder(string sourceFolderPath, string workingFolderPath = null)
        {
            List <ImporterLightDoc> List_ImporterLightDoc = new List <ImporterLightDoc>();

            DirectoryInfo _DirectoryInfo = new DirectoryInfo(sourceFolderPath);

            if (workingFolderPath == null)
            {
                workingFolderPath = RequestPaths.GetPhysicalApplicationPath(Resources.import_DirectoryPath);
            }

            //// ensure the import folder actually exists
            new DirectoryInfo(workingFolderPath)
            .mkdir()
            .Attributes = FileAttributes.NotContentIndexed | FileAttributes.Hidden;

            string DocMD5, DocTypeVer;
            string DocTypeName = FilesystemTemplateController.ScanContentFolder(_DirectoryInfo, out DocTypeVer, out DocMD5);

            if (!DocExchange.LuceneController.List(new List <string> {
                EmbededInterpreter.MY_ONLY_DOC_NAME
            }, null, null, DocMD5).Any())
            {
                IList <string> relativeFilePathsInDirectoryTree = GetRelativeFilePathsInDirectoryTree(_DirectoryInfo.FullName, true);
                IDictionary <string, string> files = CreateStringDictionary(relativeFilePathsInDirectoryTree, relativeFilePathsInDirectoryTree);
                IDocRev DocRevBaseDoc = (IDocRev)DocInterpreter.Instance.Create(EmbededInterpreter.MY_ONLY_DOC_NAME);

                DocRevBaseDoc.Target.DocTypeName     = DocTypeName;
                DocRevBaseDoc.Target.solutionVersion = DocTypeVer;
                DocRevBaseDoc.DocChecksum            = int.MinValue;
                DocRevBaseDoc.DocStatus   = true;
                DocRevBaseDoc.DocTitle    = String.Format("{0} {1}", DocTypeName, DocTypeVer);
                DocRevBaseDoc.DocTypeName = EmbededInterpreter.MY_ONLY_DOC_NAME;
                DocRevBaseDoc.MD5         = DocMD5;
                DocRevBaseDoc.DocKeys     = new Dictionary <string, string>
                {
                    { Properties.Resources.TargetDocTypeNameKey, DocTypeName },
                    { Properties.Resources.TargetDocTypeVerKey, DocTypeVer }
                };

                foreach (KeyValuePair <string, string> file in files)
                {
                    FileInfo AddFileInfo = new FileInfo(_DirectoryInfo.FullName + "\\" + file.Value);
                    DocRevBaseDoc.FileList.Add(
                        new DocRevEntry()
                    {
                        Bytes = AddFileInfo.OpenRead().AsBytes(),
                        Name  = file.Key
                    });
                }

                List_ImporterLightDoc.Add(
                    new ImporterLightDoc
                {
                    LightDoc = DocExchange.Instance.Import(
                        DocInterpreter.Instance.WriteStream((BaseDoc)DocRevBaseDoc))
                });
            }
            return(List_ImporterLightDoc);
        }
コード例 #2
0
        public override byte[] WriteByte <T>(T source, bool includeProcessingInformation = true)
        {
            using (MemoryStream fsOut = new MemoryStream())
                using (ZipOutputStream _ZipOutputStream = new ZipOutputStream(fsOut)
                {
                    IsStreamOwner = false
                })
                {
                    IDocRev _DocRev = (IDocRev)source;
                    _ZipOutputStream.SetLevel(9); //0-9, 9 being the highest level of compression

                    foreach (DocRevEntry file in _DocRev.FileList)
                    {
                        if (file.Bytes.Length > 0)
                        {
                            // Zip the file in buffered chunks
                            // the "using" will close the stream even if an exception occurs
                            byte[] buffer = new byte[4096];

                            using (MemoryStream streamReader = new MemoryStream(file.Bytes))
                            {
                                _ZipOutputStream.PutNextEntry(
                                    new ZipEntry(string.Format("{0}\\{1}\\{2}", _DocRev.Target.DocTypeName, _DocRev.Target.solutionVersion, file.Name))
                                {
                                    // Note the zip format stores 2 second granularity
                                    DateTime = DateTime.Now,
                                    // To permit the zip to be unpacked by built-in extractor in WinXP and Server2003, WinZip 8, Java, and other older code,
                                    // you need to do one of the following: Specify UseZip64.Off, or set the Size.
                                    // If the file may be bigger than 4GB, or you do not need WinXP built-in compatibility, you do not need either,
                                    // but the zip will be in Zip64 format which not all utilities can understand.
                                    //   zipStream.UseZip64 = UseZip64.Off;
                                    Size = file.Bytes.Length
                                });
                                StreamUtils.Copy(streamReader, _ZipOutputStream, buffer);
                                _ZipOutputStream.CloseEntry();
                            }
                        }
                    }

                    _ZipOutputStream.Close();
                    return(fsOut.ToBytes());
                }
        }
コード例 #3
0
        public MemoryStream OpenRead(string DocTypeName, string DocTypeVer, string filename)
        {
            IDocRev o = (IDocRev)DocExchange.LuceneController.Get(
                EmbededInterpreter.MY_ONLY_DOC_NAME,
                new Dictionary <string, string> {
                { Resources.TargetDocTypeVerKey, DocTypeVer }, { Resources.TargetDocTypeNameKey, DocTypeName }
            });

            if (o == null)
            {
                o = (IDocRev)DocExchange.LuceneController.Get(
                    EmbededInterpreter.MY_ONLY_DOC_NAME,
                    new Dictionary <string, string> {
                    { "DocTypeVer", DocTypeVer }, { "DocTypeName", DocTypeName }
                });
            }

            byte[] bytes = o.FileList?.FirstOrDefault(f => f.Name.Equals(filename, StringComparison.InvariantCultureIgnoreCase))?.Bytes;

            return(bytes == null
                ? null
                : new MemoryStream(bytes));
        }