Пример #1
0
        /// <summary>
        /// Create a new CswNbtResources
        /// </summary>
        public static CswNbtResources makeCswNbtResources(CswEnumAppType AppType, CswEnumSetupMode SetupMode, bool ExcludeDisabledModules, ICswSuperCycleCache CswSuperCycleCache = null, ChemSW.RscAdo.CswEnumPooledConnectionState PooledConnectionState = RscAdo.CswEnumPooledConnectionState.Open, ICswResources CswResourcesMaster = null, ICswLogger CswLogger = null)
        {
            if (null == CswSuperCycleCache)
            {
                CswSuperCycleCache = new CswSuperCycleCacheDefault();
            }

            CswSetupVbls SetupVbls  = new CswSetupVbls(SetupMode);
            CswDbCfgInfo ConfigInfo = new CswDbCfgInfo(SetupMode);

            CswNbtResources ReturnVal = new CswNbtResources(AppType, SetupVbls, ConfigInfo, ExcludeDisabledModules, CswSuperCycleCache, CswResourcesMaster, CswLogger);

            ReturnVal.SetDbResources(PooledConnectionState);

            ////bz # 9896: This events must only be assigned when we first instance the class;
            ////if we also assign them to cached resources, we get duplicate events occuring :-(
            //CswNbtMetaDataEvents CswNbtMetaDataEvents = new CswNbtMetaDataEvents( ReturnVal );
            //ReturnVal.OnMakeNewNodeType += new CswNbtResources.NewNodeTypeEventHandler( CswNbtMetaDataEvents.OnMakeNewNodeType );
            //ReturnVal.OnCopyNodeType += new CswNbtResources.CopyNodeTypeEventHandler( CswNbtMetaDataEvents.OnCopyNodeType );
            //ReturnVal.OnMakeNewNodeTypeProp += new CswNbtResources.NewNodeTypePropEventHandler( CswNbtMetaDataEvents.OnMakeNewNodeTypeProp );
            //ReturnVal.OnEditNodeTypePropName += new CswNbtResources.EditPropNameEventHandler( CswNbtMetaDataEvents.OnEditNodeTypePropName );
            //ReturnVal.OnDeleteNodeTypeProp += new CswNbtResources.DeletePropEventHandler( CswNbtMetaDataEvents.OnDeleteNodeTypeProp );
            //ReturnVal.OnEditNodeTypeName += new CswNbtResources.EditNodeTypeNameEventHandler( CswNbtMetaDataEvents.OnEditNodeTypeName );

            return(ReturnVal);
        }
Пример #2
0
        public static void CreateAllCAFProps(CswNbtResources NbtResources, CswEnumSetupMode SetupMode)
        {
            // Chemical Class -- Excluding Constituents
            CswNbtMetaDataObjectClass ChemicalOC  = NbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.ChemicalClass);
            List <string>             ChemicalNts = (from NodeType in ChemicalOC.getNodeTypes() where NodeType.NodeTypeName != "Constituent" select NodeType.NodeTypeName).ToList();

            // Container Class
            CswNbtMetaDataObjectClass ContainerOC  = NbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.ContainerClass);
            List <string>             ContainerNts = ContainerOC.getNodeTypes().Select(NodeType => NodeType.NodeTypeName).ToList();

            // Receipt Lot Class
            CswNbtMetaDataObjectClass ReceiptLotOC  = NbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.ReceiptLotClass);
            List <string>             ReceiptLotNts = ReceiptLotOC.getNodeTypes().Select(NodeType => NodeType.NodeTypeName).ToList();

            // User Class
            CswNbtMetaDataObjectClass UserOC  = NbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.UserClass);
            List <string>             UserNts = UserOC.getNodeTypes().Select(NodeType => NodeType.NodeTypeName).ToList();

            CreateCafProps(NbtResources, ChemicalNts, "properties_values", "propertiesvaluesid", SetupMode);
            CreateCafProps(NbtResources, ContainerNts, "properties_values_cont", "contpropsvaluesid", SetupMode);
            CreateCafProps(NbtResources, ReceiptLotNts, "properties_values_lot", "lotpropsvaluesid", SetupMode);
            CreateCafProps(NbtResources, UserNts, "properties_values_user", "userpropsvaluesid", SetupMode);

            // See CIS-53426: We only want to import Equipment if IMCS is enabled else EquipmentOC is null
            if (NbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.IMCS))
            {
                CswNbtMetaDataObjectClass EquipmentOC  = NbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.EquipmentClass);
                List <string>             EquipmentNTs = EquipmentOC.getNodeTypes().Select(NodeType => NodeType.NodeTypeName).ToList();

                //Equipment get both Container AND Material custom props
                CreateCafProps(NbtResources, EquipmentNTs, "properties_values", "propertiesvaluesid", SetupMode);
                CreateCafProps(NbtResources, EquipmentNTs, "properties_values_cont", "contpropsvaluesid", SetupMode);
            }
        }
Пример #3
0
        public CswSetupVblsNbt(CswEnumSetupMode SetupMode)
        {
            _cswSetupVariables = new CswSetupVariables(SetupMode);

            //_cswOracleSetupVbls.addVblDef( "LogFileLocation", "c:\\", "Location of logfile in local filesystem.", false );
            //_cswOracleSetupVbls.addVblDef( "LogOutputToFlatText", "0", "If 1, log data will be sent to a flat txt file in the LogFileLocation.", false );
            //_cswOracleSetupVbls.addVblDef( "LogOutputToXml", "1", "If 1, log data will be sent to an xml file in the LogFileLocation.", false );
            //_cswOracleSetupVbls.addVblDef( "LogOutputToDb", "0", "If 1, log data will be sent to the database.", false );
            //_cswOracleSetupVbls.addVblDef( "LogErrorMessages", "1", "If 1, Error messages should be included in the log.", false );
            //_cswOracleSetupVbls.addVblDef( "LogApplicationState", "0", "If 1, Application State messages should be included in the log.", false );
            //_cswOracleSetupVbls.addVblDef( "LogTraceMessages", "0", "If 1, Trace messages should be included in the log.", false );
            //_cswOracleSetupVbls.addVblDef( "SchedulerPollMinutes", "1", "Interval in minutes for the Scheduler to run.", false );
            //_cswOracleSetupVbls.addVblDef( "ChooseAccessIDFromDropDown", "0", "If 1, allow users to select their Customer ID from a drop down list.\nIf 0, the user must enter the correct Customer ID in a text box.", false );
            //_cswOracleSetupVbls.addVblDef( "ForceGcCollectInScheduler", "0", "If 1, the scheduler service will force a garbage collection on each cycle.\nIf 0, the schedule service will not interfere with garbage collection.", false );
            //_cswOracleSetupVbls.addVblDef( "SmtpServer", "", "Domain name or ip address of SMTP server", false );
            //_cswOracleSetupVbls.addVblDef( "SmtpPort", "", "Port number of SMTP server", false );
            //_cswOracleSetupVbls.addVblDef( "SmtpSender", "", "Email address for origination of outgoing email", false );
            //_cswOracleSetupVbls.addVblDef( "SmtpSenderDisplayName", "", "Name to display in 'from' field of outgoing email", false );
            //_cswOracleSetupVbls.addVblDef( "SmtpType", "", "'Plain' for non-authenticated SMTP; 'Authenticated' for Authenticated SMTP", false );
            //_cswOracleSetupVbls.addVblDef( "SmtpUserId", "", "For 'Authenticated' SmtpType, specifies the logon id", true );
            //_cswOracleSetupVbls.addVblDef( "SmtpPassword", "", "For 'Authenticated' SmtpType, specifies the password to go with the SmtpLogOnId", true );
        }//ctor
Пример #4
0
 public CswDbCfgInfoNbt(CswEnumSetupMode SetupMode, bool IsMobile)
 {
     _CswDbCfgInfo = new CswDbCfgInfo(SetupMode, IsMobile);
     _IsMobile     = IsMobile;
 }//ctor
Пример #5
0
        /// <summary>
        /// Public accessor for the _CAFOrder dictionary so we can use it to change the order in the future
        /// </summary>
        //public Dictionary<string, Int32> CAFImportOrder
        //{
        //    get { return _CAFOrder; }
        //}

        /// <summary>
        /// Build a new UpdateImportMgr for a particular definition
        /// </summary>
        /// <param name="SchemaModTrnsctn">The schema script resources class</param>
        /// <param name="DefinitionName">The IMPORT_DEF definition (use "CAF" for caf imports)</param>
        /// <param name="CafDbLink">Legacy: this should probably change/go away after case 31124</param>
        /// <param name="ImporterSetUpMode">NbtExe or NbtWeb - depending on where you are using the Imp mgr</param>
        public CswNbtSchemaUpdateImportMgr(CswNbtSchemaModTrnsctn SchemaModTrnsctn, string DefinitionName, string CafDbLink = null, CswEnumSetupMode ImporterSetUpMode = CswEnumSetupMode.NbtExe)
        {
            _CAFDbLink            = CafDbLink ?? CswScheduleLogicNbtCAFImport.CAFDbLink;
            _NbtImporter          = new CswNbtImporter(SchemaModTrnsctn.Accessid, ImporterSetUpMode);
            this.SchemaModTrnsctn = SchemaModTrnsctn;

            _importDefTable           = SchemaModTrnsctn.makeCswTableUpdate("Import_getDefs", "import_def").getTable();
            _importOrderTable         = SchemaModTrnsctn.makeCswTableUpdate("Import_getOrder", "import_def_order").getTable();
            _importBindingsTable      = SchemaModTrnsctn.makeCswTableUpdate("Import_getBindings", "import_def_bindings").getTable();
            _importRelationshipsTable = SchemaModTrnsctn.makeCswTableUpdate("Import_getRelationships", "import_def_relationships").getTable();


            _DefinitionName = DefinitionName;
            _SourceColumns  = new CswCommaDelimitedString();

            _SheetDefinitions = SchemaModTrnsctn.createImportDefinitionEntries(DefinitionName, _importDefTable);
        }//ctor
Пример #6
0
        public CswSessionResourcesNbt(HttpApplicationState HttpApplicationState, HttpRequest HttpRequest, HttpResponse HttpResponse, HttpContext Context, string LoginAccessId, CswEnumSetupMode SetupMode)
        {
            //SuperCycleCache configuraiton has to happen here because here is where we can stash the cache,
            //so to speak, in the wrapper class -- the resource factory is agnostic with respect to cache type
            CswSetupVbls SetupVbls = new CswSetupVbls(CswEnumSetupMode.NbtWeb);

            ICswSuperCycleCache CswSuperCycleCache = new CswSuperCycleCacheWeb(Context.Cache);

            // Set the cache to drop anything 10 minutes old
            CswSuperCycleCache.CacheDirtyThreshold = DateTime.Now.Subtract(new TimeSpan(0, 10, 0));


            CswDbCfgInfo CswDbCfgInfo = new CswDbCfgInfo(CswEnumSetupMode.NbtWeb);

            CswResourcesMaster = new CswResources(CswEnumAppType.Nbt, SetupVbls, CswDbCfgInfo, new CswSuperCycleCacheDefault(), null);
            CswResourcesMaster.SetDbResources(ChemSW.RscAdo.CswEnumPooledConnectionState.Open);
            CswResourcesMaster.AccessId = CswDbCfgInfo.MasterAccessId;

            CswNbtResources = CswNbtResourcesFactory.makeCswNbtResources(CswEnumAppType.Nbt, SetupMode, true, CswSuperCycleCache, RscAdo.CswEnumPooledConnectionState.Open, CswResourcesMaster, CswResourcesMaster.CswLogger);

            bool RecordStatistics = CswConvert.ToBoolean(CswNbtResources.SetupVbls[CswEnumSetupVariableNames.RecordUserStatistics]);

            //Dictionary<string, string> Cookies = new Dictionary<string, string>();
            //foreach( string CookieName in Context.Request.Cookies )
            //{
            //    Cookies[CookieName] = Context.Request.Cookies[CookieName].Value;
            //}

            CswNbtSchemaAuthenticatorFactory AuthenticatorFactory = new CswNbtSchemaAuthenticatorFactory(CswNbtResources);
            ICswSchemaAuthenticater          Authenticator        = AuthenticatorFactory.Make(CswNbtResources.SetupVbls);

            CswSessionManager = new CswSessionManager(CswEnumAppType.Nbt,
                                                      new CswWebClientStorageHttpHeader(HttpRequest, HttpResponse),
                                                      //new CswWebClientStorageCookies( HttpRequest, HttpResponse ),
                                                      LoginAccessId,
                                                      CswNbtResources.SetupVbls,
                                                      CswNbtResources.CswDbCfgInfo,
                                                      CswNbtResources,
                                                      CswResourcesMaster,
                                                      Authenticator,
                                                      //Cookies,
                                                      _CswNbtStatistics = new CswNbtStatistics(new CswNbtStatisticsStorageDb(CswNbtResources),
                                                                                               new CswNbtStatisticsStorageStateServer(),
                                                                                               RecordStatistics));
            CswNbtResources.CswSessionManager = CswSessionManager;
            CswNbtStatisticsEvents            = _CswNbtStatistics.CswNbtStatisticsEvents;

            CswSessionManager.OnDeauthenticate += new CswSessionManager.DeathenticationHandler(OnDeauthenticate);

            CswNbtResources.AccessId = CswSessionManager.AccessId;
        }//ctor()
Пример #7
0
        public static void CreateCafProps(CswNbtResources NbtResources, List <string> NodeTypes, string PropsValsTblName, string PropsValsPKName, CswEnumSetupMode SetupMode)
        {
            CswNbtSchemaUpdateImportMgr ImpMgr = new CswNbtSchemaUpdateImportMgr(new CswNbtSchemaModTrnsctn(NbtResources), "CAF", ImporterSetUpMode: SetupMode);

            string             sql            = GetCAFPropertiesSQL(PropsValsTblName, NodeTypes);
            CswArbitrarySelect cafChemPropAS  = NbtResources.makeCswArbitrarySelect("cafProps_" + PropsValsPKName, sql);
            DataTable          cafChemPropsDT = cafChemPropAS.getTable();

            foreach (DataRow row in cafChemPropsDT.Rows)
            {
                foreach (string nt in NodeTypes)
                {
                    CswNbtMetaDataNodeType NodeType = NbtResources.MetaData.getNodeType(nt);

                    string PropName = row["propertyname"].ToString();
                    int    PropId   = CswConvert.ToInt32(row["propertyid"]);
                    PropName = GetUniquePropName(NodeType, PropName);   //keep appending numbers until we have a unique prop name

                    CswEnumNbtFieldType        propFT  = GetFieldTypeFromCAFPropTypeCode(row["propertytype"].ToString());
                    CswNbtMetaDataNodeTypeProp newProp = NbtResources.MetaData.makeNewProp(new CswNbtWcfMetaDataModel.NodeTypeProp(NodeType, NbtResources.MetaData.getFieldType(propFT), PropName)
                    {
                        IsRequired  = CswConvert.ToBoolean(row["required"]),
                        ReadOnly    = CswConvert.ToBoolean(row["readonly"]),
                        ListOptions = CswConvert.ToString(row["listopts"])
                    });
                    newProp.removeFromAllLayouts();

                    string cafColPropName = "prop" + row["propertyid"];
                    string cafSourceCol   = "propvaltext";
                    if (CswEnumNbtFieldType.DateTime == propFT)
                    {
                        cafSourceCol = "propvaldate";
                    }
                    else if (CswEnumNbtFieldType.Number == propFT)
                    {
                        cafSourceCol = "propvalnumber";
                    }

                    ImpMgr.importBinding(cafSourceCol, PropName, "", "CAF", NodeType.NodeTypeName,
                                         ClobTableName: PropsValsTblName,
                                         LobDataPkColOverride: cafColPropName,
                                         LobDataPkColName: PropsValsPKName,
                                         LegacyPropId: PropId);
                }
            }

            NbtResources.commitTransaction();
            ImpMgr.finalize();
        }
Пример #8
0
        public static void startCAFImportImpl(ICswResources CswResources, string CAFDatabase, string CAFSchema, string CAFPassword, CswEnumSetupMode SetupMode)
        {
            CswNbtResources _CswNbtResources = (CswNbtResources)CswResources;

            //connect to the CAF database
            CswDbVendorOpsOracle CAFConnection = new CswDbVendorOpsOracle("CAFImport", CAFDatabase, CAFSchema, CAFPassword, (CswDataDictionary)_CswNbtResources.DataDictionary, _CswNbtResources.CswLogger, CswEnumPooledConnectionState.Open, "");

            string Error = "";

            if (false == CAFConnection.IsDbConnectionHealthy(ref Error))
            {
                throw new CswDniException(CswEnumErrorType.Error, "Check the supplied parameters for the CAF database.", Error);
            }

            //Run the SQL to generate the table, views, triggers, and other setup operations.
            //there is no clean solution for running the contents of .SQL file from inside C#, so please forgive the horrible hacks that follow.
            //Assumptions made here:
            //   the only PL/SQL blocks are the deletes at the top of the script and the triggers at the bottom,
            //   the / at the end of PL/SQL is always at the beginning of a line,
            //   triggers always have two lines of spaces before them, except the very first trigger, which has 3

            string CAFSql = generateCAFSql(_CswNbtResources);

            //add a / before the first trigger and split the file into an array of strings on space-only preceded / chars (breaking off potential PL/SQL blocks)
            string[] SQLCommands = Regex.Split(CAFSql
                                               .Replace(");\r\n\r\n\r\ncreate or replace trigger", ");\r\n\r\n\r\n/\r\ncreate or replace trigger")
                                               .Replace("create or replace procedure", "\r\n/\r\ncreate or replace procedure")
                                               .Replace("/*+", "*+"),//Strip slash out of Oracle Hints to prevent splitting the view query
                                               @"\s+/");

            foreach (string Command in SQLCommands)
            {
                //If we stripped a slash out of an Oracle Hint, put it back in
                string SQLCommand = Command.Replace("*+", "/*+");
                //if the string starts with any of these, it's a PL/SQL block and can be sent as-is
                if (SQLCommand.Trim().StartsWith("begin") || SQLCommand.Trim().StartsWith("create or replace trigger") || SQLCommand.Trim().StartsWith("create or replace procedure"))
                {
                    CAFConnection.execArbitraryPlatformNeutralSql(SQLCommand);
                }
                //otherwise, we need to further split out each command on ; chars
                else
                {
                    foreach (string SingleCommand in SQLCommand.Split(';'))
                    {
                        if (SingleCommand.Trim() != String.Empty)
                        {
                            CAFConnection.execArbitraryPlatformNeutralSql(SingleCommand.Trim());
                        }
                    }
                }
            }//foreach PL/SQL block in CAF.sql


            //create the database link, after cleaning up an old one if it exists
            _CswNbtResources.execArbitraryPlatformNeutralSql(@"
              begin
                execute immediate 'drop database link caflink';
                exception when others then null;
              end;
            ");

            _CswNbtResources.execArbitraryPlatformNeutralSql("create database link caflink connect to " + CAFSchema + " identified by " + CAFPassword + " using '" + CAFDatabase + "'");



            //Create custom NodeTypeProps from CAF Properties collections and set up bindings for them
            CreateAllCAFProps(_CswNbtResources, SetupMode);

            // Enable the CAFImport rule
            CswTableUpdate TableUpdate = _CswNbtResources.makeCswTableUpdate("enableCafImportRule", "scheduledrules");
            DataTable      DataTable   = TableUpdate.getTable("where rulename = '" + CswEnumNbtScheduleRuleNames.CAFImport + "'");

            if (DataTable.Rows.Count > 0)
            {
                DataTable.Rows[0]["disabled"] = CswConvert.ToDbVal(false);
                TableUpdate.update(DataTable);
            }


            //create a connection to the schedule service
            WSHttpBinding   Binding  = new WSHttpBinding();
            EndpointAddress Endpoint = new EndpointAddress(CswResources.SetupVbls["SchedServiceUri"]);
            CswSchedSvcAdminEndPointClient SchedSvcRef = new CswSchedSvcAdminEndPointClient(Binding, Endpoint);


            //fetch the CAFImport rule from ScheduleService
            CswSchedSvcParams CswSchedSvcParams = new CswSchedSvcParams();

            CswSchedSvcParams.CustomerId = _CswNbtResources.AccessId;
            CswSchedSvcParams.RuleName   = CswEnumNbtScheduleRuleNames.CAFImport;
            CswSchedSvcReturn CAFRuleResponse;

            try
            {
                CAFRuleResponse = SchedSvcRef.getRules(CswSchedSvcParams);
            }
            catch (Exception e)
            {
                throw new CswDniException(CswEnumErrorType.Error, "Could not connect to schedule service", e.Message);
            }


            //take the rule that was returned from the last request, set disabled to false, then send it back as an update
            CswScheduleLogicDetail CAFImport = CAFRuleResponse.Data[0];

            CAFImport.Disabled             = false;
            CswSchedSvcParams.LogicDetails = new Collection <CswScheduleLogicDetail>();
            CswSchedSvcParams.LogicDetails.Add(CAFImport);

            CswSchedSvcReturn svcReturn = SchedSvcRef.updateScheduledRules(CswSchedSvcParams);

            if (false == svcReturn.Status.Success)
            {
                throw new CswDniException(svcReturn.Status.Errors[0].Message);
            }
        }//startCAFImport