Beispiel #1
0
        public CCTimerSearch(ITisClientServicesModule oCSM, String configPath, String profileName)
        {
            try
            {
                CSM = oCSM;
                CollectionsCreator = new CCreator();
                if (CSM != null)
                {
                    CSM.Session.OnMessage += StationMessage;
                    workDir = CSM.PathLocator.get_Path(CCEnums.CCFilesExt.TIF.ToString());
                }

                //-- Initialize profile --\\
                if (File.Exists(configPath ?? String.Empty))
                {
                    config = CCConfiguration.FromXml(configPath);
                }
                else
                {
                    config = CCConfiguration.FromCSM(CSM);
                }

                //-- Initialize profile --\\
                if (String.IsNullOrEmpty(profileName))
                {
                    profileName = CSM.Application.AppName;
                }
                currentProfile = config != null?config.GetConfiguration(profileName) : null;

                if (currentProfile == null)
                {
                    currentProfile = new CCConfiguration.CCConfigurationData();                        //-- create a default profile --\\
                }
                //-- Define collections creator settings --\\
                CollectionsCreator.CurrentProfile = currentProfile;

                //collectionsCreator.OnPostFileLock += PostFileLock;
                CollectionsCreator.OnCollectionCreated += CollectionCreated;

                if (SearchHandler == null)
                {
                    SearchHandler = new CCSearchFiles(currentProfile);
                }
                SearchHandler.OnPostFileLock += PostFileLock;
                SearchHandler.OnPreFileLock  += PreFileLock;

                PollingTimer.Enabled = currentProfile.SearchPaths != null && currentProfile.SearchPaths.Length > 0 && currentProfile.SearchExtensions != null && currentProfile.SearchExtensions.Length > 0;
                CreateEvent();//-- fire OnCreate  event --\
            }
            catch (Exception ex)
            {
                ILog.LogError(ex);
            }
        }
Beispiel #2
0
            /// <summary>
            /// From XMl function, deserializes a profile from XML
            /// </summary>
            /// <param name="xmlPath">The XML file path</param>
            /// <param name="profileName">the profile name to load.</param>
            /// <returns>CCConfigurationData</returns>
            public static CCConfigurationData FromXml(String xmlPath, String profileName)
            {
                CCConfiguration.CCConfigurationData result = null;

                try
                {
                    CCConfiguration cfg = CCConfiguration.FromXml(xmlPath);
                    return(cfg.GetConfiguration(profileName));
                }
                catch (Exception ex)
                {
                    ILog.LogError(ex);
                    if (result != null && result.ThrowAllExceptions)
                    {
                        throw ex;
                    }
                }
                return(result);
            }
Beispiel #3
0
        /*
         * /// <summary>
         * /// Create an eFlow collection from the specified DataTable.
         * /// </summary>
         * /// <param name="collectionData">The collection data in the specified data table.</param>
         * /// <param name="applicationName">The eFlow application name to insert the collection to.</param>
         * /// <param name="copySourceFiles">Copy the source file when true (as opposed to move).</param>
         * /// <param name="errMsg">Will return the error message if any error occured.</param>
         * /// <returns>The error code, 1 = sucsess.</returns>
         * public bool TestCreateCollection(String filePath, String stationName, String applicationName)
         * {
         *  try
         *  {
         *      List<ITisPageParams> pages = new List<ITisPageParams>();
         *      ITisClientServicesModule csm = csmManager.GetCsm(applicationName, stationName, true);
         *      pages.Add(csm.Setup.get_FlowByIndex(0).get_FormByIndex(0).get_PageByIndex(0));
         *      CCCollection.CCPage pg = new CCCollection.CCPage(null, pages[0], "Demo");
         *      CCCollection col = new CCCollection();
         *      for (int i = 0; i < 7; i++)
         *      {
         *          col.AddForm(new CCCollection.CCForm(null, null, csm.Setup.get_FlowByIndex(0).get_FormByIndex(0).Name, pg));
         *      }
         *      col.ImagePath = filePath;// @"C:\Program Files\TIS\eFlow 4.5\Sample Applications\SimpleDemo\Office7Pages.TIF";
         *     // col.FlowType = "OfficeStore";
         *
         *      //-- Create and define the Creator class --\\
         *      using (CCreator crt = new CCreator())
         *      {
         *          crt.ValidatePagePerImagePage = false;
         *          crt.CurrentProfile = CCConfiguration.CCConfigurationData.FromXml("Default2");
         *          int errCode=0;
         *         String[] res= crt.CreateCollections(csm,  out errCode, col);
         *         if (res.Length > 0)
         *         {
         *             return true;
         *         }
         *      }
         *  }
         *  catch (Exception ex)
         *  {
         *      ILog.LogError(ex);
         *  }
         *  return false;
         * }
         */

        /// <summary>
        /// Create an eFlow collection from the specified DataTable.
        /// </summary>
        /// <param name="collectionData">The collection data in the specified data table.</param>
        /// <param name="applicationName">The eFlow application name to insert the collection to.</param>
        /// <param name="copySourceFiles">Copy the source file\s when true (as opposed to move).</param>
        /// <param name="errMsg">Will return the error message if any error occured.</param>
        /// <returns>The error code, 1 = sucsess.</returns>
        public bool CreateCollection(DataTable collectionData, String applicationName, bool copySourceFiles, out int errCode, out String errMsg)
        {
            //-- Set returning values --\\
            errCode = (int)CCEnums.CCErrorCodes.E0000;
            errMsg  = null;
            String[]     createdFiles = null;
            CCCollection coll         = null;

            try
            {
                #region //-- Load and validate profile --\\
                if (config == null)
                {
                    errCode = (int)CCEnums.CCErrorCodes.E0101;
                    errMsg  = String.Format("{0}:, error code [{1}]", CCConstants.E0101, errCode);
                    throw new Exception(errMsg);
                }

                if (String.IsNullOrEmpty(applicationName))
                {
                    applicationName = CCEnums.CCNames.Default.ToString();
                }
                currCfg = config.GetConfiguration(applicationName);

                if (currCfg == null)
                {
                    errCode = (int)CCEnums.CCErrorCodes.E0102;
                    errMsg  = String.Format("{0}: [{1}], error code [{2}]", CCConstants.E0102, applicationName, errCode);
                    throw new Exception(errMsg);
                }
                #endregion

                //-- Create and define the Creator class --\\
                using (CCreator crt = new CCreator())
                {
                    crt.CurrentProfile.CopySourceFiles = copySourceFiles;
                    if (currCfg != null)
                    {
                        crt.CurrentProfile.LockExtension = currCfg.LockExtension;
                    }

                    ITisClientServicesModule csm = csmManager.GetCsm(String.IsNullOrEmpty(currCfg.LoginApplication) ? applicationName : currCfg.LoginApplication, currCfg.LoginStation, true);

                    if (csm == null)
                    {
                        errCode = (int)CCEnums.CCErrorCodes.E0210;
                        errMsg  = String.Format("{0}, Application name: [{1}], Station name: [{2}] error code [{3}]", CCConstants.E0210, String.IsNullOrEmpty(currCfg.LoginApplication) ? applicationName ?? String.Empty : currCfg.LoginApplication ?? String.Empty, currCfg.LoginStation ?? String.Empty, errCode);
                        throw new Exception(errMsg);
                    }

                    //-- Load CCCollection from a data table (and validate all the data) --\\
                    coll = CCDataTable.FromDataTable(currCfg, out errCode, out errMsg, copySourceFiles, out createdFiles, collectionData);

                    if (errCode != 1)
                    {
                        errMsg = String.Format("{0}, table name: [{1}], error code [{2}]", CCConstants.E0091, collectionData != null ? collectionData.TableName ?? String.Empty : String.Empty, errCode);
                        throw new Exception(errMsg);
                    }

                    if (coll == null)
                    {
                        errCode = (int)CCEnums.CCErrorCodes.E0091;
                        errMsg  = String.Format("{0}, table name: [{1}], error code [{2}]", CCConstants.E0091, collectionData != null ? collectionData.TableName ?? String.Empty : String.Empty, errCode);
                        throw new Exception(errMsg);
                    }

                    try
                    {
                        //--<< Call eFlow to create the collection >>--\\
                        String[] resCols = crt.CreateCollections(csm, out errCode, coll);
                        if (resCols == null || resCols.Length != 1)
                        {
                            errCode = errCode <= 0 ? (int)CCEnums.CCErrorCodes.E0092: errCode;
                            errMsg  = crt.LastErrors;
                            throw new Exception(String.Format("{0}, {1}, error code [{2}]", CCConstants.E0092, errMsg, errCode));
                        }
                        else
                        {
                            ILog.LogInfo("Done creating collection [{0}] in eFlow system", resCols[0]);
                            errCode = (int)CCEnums.CCErrorCodes.E0001;
                            errMsg  = resCols[0];//-- Return the name of the created collection --\\
                            //\\ return errCode == (int)CCEnums.CCErrorCodes.E0001;
                        }
                    }
                    catch (Exception ec)
                    {
                        errCode = (int)CCEnums.CCErrorCodes.E0092;
                        errMsg  = crt.LastErrors;
                        if (String.IsNullOrEmpty(errMsg))
                        {
                            errMsg = CCConstants.E0092 + "," + ec.Message;
                        }
                        throw new Exception(String.Format("{0}, {1}, {2}, error code [{3}]", CCConstants.E0092, errMsg, ec.Message, errCode));
                    }
                }
            }
            catch (Exception ex)
            {
                //\\ if (errCode < (int)CCEnums.CCErrorCodes.E0000) errCode = (int)CCEnums.CCErrorCodes.E0000;
                ILog.LogError(ex);
                //-- Move collections to errror folder --\\
                if (coll != null && coll.Files.Length > 0 && currCfg != null && !String.IsNullOrEmpty(currCfg.ErrorFolderPath))
                {
                    CCFileList.MoveToFolder(currCfg.ErrorFolderPath, coll.Files);
                }
                if (currCfg == null || currCfg.ThrowAllExceptions)
                {
                    throw ex;
                }
            }
            finally
            {
                //-- Delete files created by this method --\\ 
                if (copySourceFiles && createdFiles != null && createdFiles.Length > 0)
                {
                    foreach (String sf in createdFiles)
                    {
                        try
                        {
                            if (File.Exists(sf ?? String.Empty))
                            {
                                File.SetAttributes(sf, FileAttributes.Normal);
                                File.Delete(sf);
                            }
                        }
                        catch (Exception ex)
                        {
                            ILog.LogError(ex);
                            throw ex;
                        }
                    }
                }
            }
            //\\  return false;
            return(errCode == (int)CCEnums.CCErrorCodes.E0001);
        }