public static void getScheduledRulesGrid(ICswResources CswResources, CswNbtScheduledRulesReturn Return, string AccessId)
        {
            try
            {
                CswNbtResources NbtResources = (CswNbtResources)CswResources;

                //Here we are using the web reference for the schedule service,
                //overwriting the app.config endpoint uri with the one defined in SetupVbls.
                //The CswSchedSvcAdminEndPointClient::getRules() method will return a collection of objects,
                //each of which represents a scheduled rule for the accessid specified as in CswSchedSvcParams.
                //You can find the server side of this connection in /CswCommon/Csw/MtSched/port
                CswSchedSvcAdminEndPointClient SchedSvcRef = new CswSchedSvcAdminEndPointClient();
                EndpointAddress URI = new EndpointAddress(CswResources.SetupVbls["SchedServiceUri"]);
                SchedSvcRef.Endpoint.Address = URI;
                CswSchedSvcParams CswSchedSvcParams = new CswSchedSvcParams();
                CswSchedSvcParams.CustomerId = AccessId;
                CswSchedSvcReturn svcReturn = SchedSvcRef.getRules(CswSchedSvcParams);

                if (null != svcReturn)
                {
                    _addScheduledRulesGrid(NbtResources, svcReturn.Data, Return);
                }
                Return.Data.CustomerId = AccessId;
            }
            catch (Exception ex)
            {
                throw new CswDniException(CswEnumErrorType.Error, "Could not find the Schedule Service.  Check to make sure the service is running and that the endpoint url is configured correctly.", ex.Message, ex);
            }
        }//getScheduledRulesGrid()
        }//getScheduledRulesGrid()

        public static void updateAllScheduledRules(ICswResources CswResources, CswNbtScheduledRulesReturn Return, CswNbtScheduledRulesReturn.Ret Request)
        {
            CswNbtResources   NbtResources             = (CswNbtResources)CswResources;
            CswSchedSvcReturn svcReturn                = new CswSchedSvcReturn();
            CswSchedSvcAdminEndPointClient SchedSvcRef = new CswSchedSvcAdminEndPointClient();
            //Overwrite the app.config endpoint uri with the one defined in SetupVbls
            EndpointAddress URI = new EndpointAddress(CswResources.SetupVbls["SchedServiceUri"]);

            SchedSvcRef.Endpoint.Address = URI;

            CswSchedSvcParams CswSchedSvcParams = new CswSchedSvcParams();

            CswSchedSvcParams.CustomerId   = Request.CustomerId;
            CswSchedSvcParams.LogicDetails = new Collection <CswScheduleLogicDetail>();
            foreach (CswExtJsGridRow GridRow in Request.Grid.rowData.rows)
            {
                if (CswConvert.ToBoolean(GridRow.data[new CswExtJsGridDataIndex("ScheduledRules", CswEnumScheduleLogicDetailColumnNames.HasChanged)]))
                {
                    CswScheduleLogicDetail Rule = _getLogicDetailFromGridRow(GridRow, "ScheduledRules");
                    CswSchedSvcParams.LogicDetails.Add(Rule);
                }
            }

            svcReturn = SchedSvcRef.updateScheduledRules(CswSchedSvcParams);
            if (null != svcReturn)
            {
                _updateScheduledRulesTable(NbtResources, CswSchedSvcParams.LogicDetails);
                _addScheduledRulesGrid(NbtResources, svcReturn.Data, Return);
            }
        }
Ejemplo n.º 3
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