コード例 #1
0
ファイル: AgentProvider.cs プロジェクト: heyena/iring-tools
        public void ProcessTask(AgentConfig config)
        {
            string              project    = string.Empty;
            string              app        = string.Empty;
            string              dataObject = string.Empty;
            AdapterSettings     adapterSettings;
            NameValueCollection settings;

            string baseUrl    = string.Empty;
            string scope      = string.Empty;;
            string exchangeId = string.Empty;

            try
            {
                project    = config.Scope; //config.Project;
                app        = config.App;
                dataObject = config.DataObject;
                baseUrl    = config.ExchangeUrl;
                scope      = config.Scope;
                exchangeId = config.ExchangeId;

                _ssoURL       = config.SsoUrl;
                _clientId     = config.ClientId;
                _clientSecret = config.ClientSecret;
                _authType     = config.GrantType;

                _clientSecret           = EncryptionUtility.Decrypt(_clientSecret);
                settings                = ConfigurationManager.AppSettings;
                settings["AppKey"]      = config.AppKey;
                settings["AccessToken"] = config.AccessToken;

                adapterSettings = new AdapterSettings();
                adapterSettings.AppendSettings(settings);

                Initialize();
                string clientToken = GetClientToken();

                if (config.IsExchange == 0)
                {
                    if (!string.IsNullOrEmpty(clientToken))
                    {
                        _settings["AllowImpersonation"] = "True";
                        _settings["ImpersonatedUser"]   = _clientId;
                        _settings["Authorization"]      = clientToken;
                        _settings["ClientToken"]        = clientToken;
                        _settings["UserName"]           = _clientId;
                    }
                    if (string.IsNullOrEmpty(dataObject))
                    {
                        RefreshCache(project, app, false);
                    }
                    else
                    {
                        RefreshCache(project, app, dataObject, false);
                    }
                }
                else
                {
                    string     url     = string.Format("{0}?scope={1}&xid={2}", baseUrl, scope, exchangeId);
                    WebRequest request = CreateWebRequest(url);

                    if (!string.IsNullOrEmpty(clientToken))
                    {
                        _logger.Info("Use client token.");
                        request.Headers.Add("AuthType", _authType);
                        request.Headers.Add("ClientToken", clientToken);
                        request.Headers.Add("UserName", _clientId);
                    }

                    request.Timeout = _requestTimeout;
                    string responseText = GetResponseText(request);
                }

                _logger.Info("Task finished: ");
            }
            catch (Exception e)
            {
                _logger.Error("Error processing task: " + config.JobId + "  " + e.Message);
            }
        }
コード例 #2
0
        private void StartProcess(int k)
        {
            AdapterSettings             adapterSettings;
            NameValueCollection         settings;
            Dictionary <string, string> idSQLMap = new Dictionary <string, string>();
            string   updateSQL = null;
            DateTime currentDateTime;
            DateTime endTime;
            DateTime endDateTime;
            DateTime startDateTime;

            try
            {
                settings = ConfigurationManager.AppSettings;
                if (!string.IsNullOrEmpty(_configList[k].CachePageSize))
                {
                    if (int.Parse(_configList[k].CachePageSize) > 0)
                    {
                        settings.Set("cachePage", _configList[k].CachePageSize);
                        settings.Set("CachePageSize", _configList[k].CachePageSize);
                    }
                }

                adapterSettings = new AdapterSettings();
                adapterSettings.AppendSettings(settings);


                //Call agent provider
                AgentProvider agentProvider = new AgentProvider(adapterSettings);

                //update status to Busy in DB
                updateSQL = string.Format(UPDATE_SQL_TPL, "Schedule", "Status = 'Busy'", " where Schedule_Id = '" + _configList[k].ScheduleId + "'");
                idSQLMap[_configList[k].JobId] = updateSQL;
                DBManager.Instance.ExecuteUpdate(_agentConnStr, idSQLMap);

                updateSQL = string.Format(UPDATE_SQL_TPL, "JobSchedule", "Last_Start_DateTime = '" + DateTime.Now + "'", " where Schedule_Id = '" + _configList[k].ScheduleId + "' and Job_Id = '" + _configList[k].JobId + "'");
                idSQLMap[_configList[k].JobId] = updateSQL;
                DBManager.Instance.ExecuteUpdate(_agentConnStr, idSQLMap);

                AgentConfig agentConfig = (AgentConfig)_configList[k];
                _logger.Debug("Calling task with config no. " + k);
                agentProvider.ProcessTask(agentConfig);

                //update status and completion time in DB
                updateSQL = string.Format(UPDATE_SQL_TPL, "Schedule", "Status = 'Ready'", " where Schedule_Id = '" + _configList[k].ScheduleId + "'");
                idSQLMap[_configList[k].JobId] = updateSQL;
                DBManager.Instance.ExecuteUpdate(_agentConnStr, idSQLMap);

                //update nextstartdatetime
                string currentDate = DateTime.Now.ToString("hh:mm:ss tt", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                currentDateTime = DateTime.Parse(currentDate, System.Globalization.CultureInfo.CurrentCulture);
                endTime         = DateTime.Parse(_configList[k].EndDateTime.ToString(), System.Globalization.CultureInfo.CurrentCulture);
                endDateTime     = DateTime.Parse(_configList[k].EndDateTime.ToString(), System.Globalization.CultureInfo.CurrentCulture);
                startDateTime   = DateTime.Parse(_configList[k].StartDateTime.ToString(), System.Globalization.CultureInfo.CurrentCulture);
                DateTime nextStartDateTime = currentDateTime;
                string   occurance         = _configList[k].Occurance;
                switch (occurance)
                {
                case "Immediate":
                    nextStartDateTime = currentDateTime;
                    break;

                case "Daily":
                    nextStartDateTime = currentDateTime.AddHours(24);
                    break;

                case "Weekly":
                    nextStartDateTime = currentDateTime.AddDays(7);
                    break;

                case "Monthly":
                    nextStartDateTime = currentDateTime.AddMonths(1);
                    break;
                }
                updateSQL = string.Format(UPDATE_SQL_TPL, "JobSchedule", "Next_Start_DateTime = '" + nextStartDateTime + "'", " where Schedule_Id = '" + _configList[k].ScheduleId + "' and Job_Id = '" + _configList[k].JobId + "'");
                idSQLMap[_configList[k].JobId] = updateSQL;
                DBManager.Instance.ExecuteUpdate(_agentConnStr, idSQLMap);

                //if currenttime is greater than enddatetime then set active flag to 0
                if (currentDateTime >= endDateTime)
                {
                    updateSQL = string.Format(UPDATE_SQL_TPL, "JobSchedule", "Active = 0 ", " where Schedule_Id = '" + _configList[k].ScheduleId + "' and Job_Id = '" + _configList[k].JobId + "'");
                    idSQLMap[_configList[k].JobId] = updateSQL;
                    DBManager.Instance.ExecuteUpdate(_agentConnStr, idSQLMap);
                }
            }
            catch (Exception ex)
            {
                _eventLog1.WriteEntry("Error in StartProcess " + _configList[k].JobId + " : " + ex.Message);
            }
        }