示例#1
0
        public static CollectionOcrData FromCollection(ITisCollectionData collection)
#endif
        {
            try
            {
                if (collection != null)
                {
                    CollectionOcrData res = new CollectionOcrData();
                    res.CollectionID = collection.Name;
                    res.FlowType     = collection.FlowType;
                    List <PageOcrData> pgs = new List <PageOcrData>();

                    //-- Iterate collection pages and add them to the class Pages property. --\\
                    foreach (ITisPageData page in collection.Pages)
                    {
                        pgs.Add(PageOcrData.FromPRD(page));
                    }

                    if (pgs != null && pgs.Count > 0)
                    {
                        res.pages = pgs.ToArray();
                        return(res);
                    }
                }
                else
                {
                    throw new Exception(String.Format("ITisCollectionData specified in: [{0}] is not valid", MethodBase.GetCurrentMethod().Name));
                }
            }
            catch (Exception ex)
            {
                ILog.LogError(ex);
            }
            return(null);
        }
示例#2
0
            public static new PageOcrData FromXml(String xmlFilePath)
#endif
            {
                try
                {
                    try
                    {
                        PageOcrData res = FromXml(xmlFilePath, typeof(PageOcrData)) as PageOcrData;
                        if (res != null)
                        {
                            return(res);
                        }
                    }
                    catch { }

                    //-- Try a collection ocr data --\\
                    CollectionOcrData coll = FromXml(xmlFilePath, typeof(CollectionOcrData)) as CollectionOcrData;
                    if (coll != null && coll.Pages.Length > 0)
                    {
                        return(coll.Pages[0]);
                    }
                }
                catch (Exception ex)
                {
                    ILog.LogError(ex);
                }
                return(null);
            }
示例#3
0
        /// <summary>
        /// Show an open file dialog for source PRD and save File dialog for atrget XML, then convert source PRD to XML.
        /// when multiple are selected they will be inserted into one XML file representing a collection
        /// </summary>>
        public static bool PRDToXml(string targetXML, params string[] sourcePRDs)
        {
            try
            {
                if (File.Exists(targetXML))
                {
                    File.Delete(targetXML);
                }

                if (sourcePRDs != null && sourcePRDs.Length == 1)
                {
                    if (PageOcrData.FromPRD(sourcePRDs[0]).ToXml(targetXML) && File.Exists(targetXML))
                    {
                        ILog.LogDebug(string.Format("Done converting PRD file [{0}] to XML file [{1}]", sourcePRDs[0], targetXML));
                        return(true);
                    }
                }
                else if (sourcePRDs != null && sourcePRDs.Length > 1)
                {
                    CollectionOcrData  collOcr = new CollectionOcrData();
                    List <PageOcrData> pages   = new List <PageOcrData>();
                    foreach (string srcPrd in sourcePRDs)
                    {
                        if (File.Exists(srcPrd))
                        {
                            pages.Add(PageOcrData.FromPRD(srcPrd));
                        }
                    }
                    collOcr.pages        = pages.ToArray();
                    collOcr.CollectionID = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fffff");
                    return(collOcr.ToXml(targetXML));
                }
            }
            catch (Exception ex)
            {
                ILog.LogError(ex);
            }
            return(false);
        }
示例#4
0
        /// <summary>
        /// Convert XML file\s to PRD .
        /// </summary>
        /// <param name="targetPRD">The target PRD file to create</param>
        /// <param name="sourceXMLs">Source XML files.</param>
        /// <returns>true when successfull.</returns>
        public static bool XMLToPRD(string targetPRD, params string[] sourceXMLs)
        {
            bool result = false;

            try
            {
                foreach (string sourceXML in sourceXMLs)
                {
                    if (!File.Exists(sourceXML))
                    {
                        continue;
                    }

                    //-- Try loading as a single page --\\
                    PageOcrData pod = PageOcrData.FromXml(sourceXML);
                    if (pod != null && pod.ToPRD(targetPRD) != null)
                    {
                        if (File.Exists(targetPRD))
                        {
                            File.Delete(targetPRD);
                        }

                        ILog.LogDebug(string.Format("Done converting XML file [{0}] to PRD file [{1}]", sourceXML, targetPRD));
                        continue;
                    }

                    //-- Try as a whole collection in a single XML --\\
                    if (pod == null)
                    {
                        CollectionOcrData cod = CollectionOcrData.FromXml(sourceXML);
                        if (cod != null)
                        {
                            if (cod.Pages != null)
                            {
                                int lastIndex = -1;
                                int maxIndex  = 0;

                                foreach (PageOcrData pd in cod.Pages)
                                {
                                    lastIndex = pd.Index;

                                    while (lastIndex < 0 || lastIndex == pd.Index || lastIndex <= maxIndex)
                                    {
                                        lastIndex++;
                                    }
                                    maxIndex = lastIndex;

                                    //-- Create a PRD file per page --\\
                                    string newPageName = Path.Combine(Path.GetDirectoryName(targetPRD), string.Format("{0}_P{1}.{2}", Path.GetFileNameWithoutExtension(targetPRD), (lastIndex).ToString("X").PadLeft(3, '0'), Path.GetExtension(targetPRD).TrimStart('.')));
                                    if (File.Exists(newPageName))
                                    {
                                        File.Delete(newPageName);
                                    }
                                    pd.ToPRD(newPageName);
                                }
                            }

                            ILog.LogDebug(string.Format("Done converting XML file [{0}] to PRD file [{1}]", sourceXML, targetPRD));
                            result = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ILog.LogError(ex);
            }
            return(result);
        }
示例#5
0
            public static void XMLToPRD(object sender, EventArgs e)
#endif
            {
                CollectionOcrData.XMLToPRD(sender, e);
            }
示例#6
0
            public static void PRDToXml(object sender, EventArgs e)
#endif
            {
                CollectionOcrData.PRDToXml(sender, e);
            }