Example #1
0
        public ObjectDataLayerTest()
        {
            _settings = new NameValueCollection();

            _settings["ProjectName"] = "12345_000";
            _settings["XmlPath"] = @"..\ObjectDataLayer.NUnit\12345_000\";
            _settings["ApplicationName"] = "OBJ";
            _settings["TestMode"] = "WriteFiles"; //UseFiles/WriteFiles

            _baseDirectory = Directory.GetCurrentDirectory();
            _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\bin"));
            _settings["BaseDirectoryPath"] = _baseDirectory;
            Directory.SetCurrentDirectory(_baseDirectory);

            _adapterSettings = new AdapterSettings();
            _adapterSettings.AppendSettings(_settings);

            string appSettingsPath = String.Format("{0}{1}.{2}.config",
                _adapterSettings["XmlPath"],
                _settings["ProjectName"],
                _settings["ApplicationName"]
            );

            if (File.Exists(appSettingsPath))
            {
                AppSettingsReader appSettings = new AppSettingsReader(appSettingsPath);
                _adapterSettings.AppendSettings(appSettings);
            }

            _dataLayer = new ObjectDataLayer(_adapterSettings);
        }
Example #2
0
        public Tests()
        {
            _objectType = "Function";

               string baseDir = Directory.GetCurrentDirectory();
               Directory.SetCurrentDirectory(baseDir.Substring(0, baseDir.LastIndexOf("\\bin")));

               AdapterSettings adapterSettings = new AdapterSettings();
               adapterSettings.AppendSettings(new AppSettingsReader("App.config"));

               FileInfo log4netConfig = new FileInfo("Log4net.config");
               log4net.Config.XmlConfigurator.Configure(log4netConfig);

               string twConfigFile = String.Format("{0}{1}.{2}.config",
             adapterSettings["AppDataPath"],
             adapterSettings["ProjectName"],
             adapterSettings["ApplicationName"]
               );

               AppSettingsReader twSettings = new AppSettingsReader(twConfigFile);
               adapterSettings.AppendSettings(twSettings);

               _dataLayer = new Bechtel.DataLayer.RestDataLayer2(adapterSettings);

               _filter = Utility.Read<DataFilter>(adapterSettings["FilterPath"]);

               //_scenarios = Utility.Read<Scenarios>("Scenarios.xml");
               _objectType = adapterSettings["ObjectType"];
               _modifiedProperty = adapterSettings["ModifiedProperty"];
               _modifiedValue = adapterSettings["ModifiedValue"];
               _objectDefinition = GetObjectDefinition(_objectType);
        }
        public SPRSynchronizationUtility(StreamWriter logFile, string scope, string app)
        {
            _logFile             = logFile;
            _settings            = new NameValueCollection();
            _settings["XmlPath"] = @".\App_Data\";

            _baseDirectory = Directory.GetCurrentDirectory();

            if (_baseDirectory.Contains("\\bin"))
            {
                _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\bin"));
                Directory.SetCurrentDirectory(_baseDirectory);
            }
            _settings["BaseDirectoryPath"] = _baseDirectory;
            _settings["ProjectName"]       = scope;
            _settings["ApplicationName"]   = app;

            _adapterSettings = new AdapterSettings();
            _adapterSettings.AppendSettings(_settings);
            string appSettingsPath = String.Format("{0}{1}.{2}.config",
                                                   _adapterSettings["XmlPath"],
                                                   _settings["ProjectName"],
                                                   _settings["ApplicationName"]
                                                   );

            if (File.Exists(appSettingsPath))
            {
                AppSettingsReader appSettings = new AppSettingsReader(appSettingsPath);
                _adapterSettings.AppendSettings(appSettings);
            }

            _dataLayer = new SPRDataLayer(_adapterSettings);
            _dataLayer.GetDictionary();
            _dataLayer.EnableLogging(_logFile);
        }
Example #4
0
        public SQLDataLayerTest()
        {
            _settings = new NameValueCollection();

            _settings["ProjectName"]     = "12345_000";
            _settings["XmlPath"]         = @"..\SQLDataLayer.NUnit\12345_000\";
            _settings["ApplicationName"] = "SQL";
            _settings["TestMode"]        = "WriteFiles"; //UseFiles/WriteFiles

            _baseDirectory = Directory.GetCurrentDirectory();
            _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\bin"));
            _settings["BaseDirectoryPath"] = _baseDirectory;
            Directory.SetCurrentDirectory(_baseDirectory);

            _adapterSettings = new AdapterSettings();
            _adapterSettings.AppendSettings(_settings);

            string appSettingsPath = String.Format("{0}{1}.{2}.config",
                                                   _adapterSettings["XmlPath"],
                                                   _settings["ProjectName"],
                                                   _settings["ApplicationName"]
                                                   );

            if (File.Exists(appSettingsPath))
            {
                AppSettingsReader appSettings = new AppSettingsReader(appSettingsPath);
                _adapterSettings.AppendSettings(appSettings);
            }

            _dataLayer = new SQLDataLayer(_adapterSettings);
        }
        public SPRSynchronizationUtility(StreamWriter logFile, string scope, string app)
        {
            _logFile = logFile;
            _settings = new NameValueCollection();
            _settings["XmlPath"] = @".\App_Data\";

            _baseDirectory = Directory.GetCurrentDirectory();

            if (_baseDirectory.Contains("\\bin"))
            {
                _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\bin"));
                Directory.SetCurrentDirectory(_baseDirectory);
            }
            _settings["BaseDirectoryPath"] = _baseDirectory;
            _settings["ProjectName"] = scope;
            _settings["ApplicationName"] = app;

            _adapterSettings = new AdapterSettings();
            _adapterSettings.AppendSettings(_settings);
            string appSettingsPath = String.Format("{0}{1}.{2}.config",
                _adapterSettings["XmlPath"],
                _settings["ProjectName"],
                _settings["ApplicationName"]
            );

            if (File.Exists(appSettingsPath))
            {
                AppSettingsReader appSettings = new AppSettingsReader(appSettingsPath);
                _adapterSettings.AppendSettings(appSettings);
            }

            _dataLayer = new SPRDataLayer(_adapterSettings);
            _dataLayer.GetDictionary();
            _dataLayer.EnableLogging(_logFile);
        }
Example #6
0
        public SP3DDataLayerTest()
        {
            _settings = new NameValueCollection();

            _settings["XmlPath"]         = @".\12345_000\";
            _settings["ProjectName"]     = "12345_000";
            _settings["ApplicationName"] = "SP3D";

            _baseDirectory = Directory.GetCurrentDirectory();
            _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\bin"));
            _settings["BaseDirectoryPath"] = _baseDirectory;
            Directory.SetCurrentDirectory(_baseDirectory);

            _adapterSettings = new AdapterSettings();
            _adapterSettings.AppendSettings(_settings);

            string appSettingsPath = String.Format("{0}12345_000.SP3D.config",
                                                   _adapterSettings["XmlPath"]
                                                   );

            if (File.Exists(appSettingsPath))
            {
                AppSettingsReader appSettings = new AppSettingsReader(appSettingsPath);
                _adapterSettings.AppendSettings(appSettings);
            }

            var ninjectSettings = new NinjectSettings {
                LoadExtensions = false
            };

            _kernel = new StandardKernel(ninjectSettings);

            _kernel.Load(new XmlExtensionModule());

            string relativePath = String.Format(@"{0}BindingConfiguration.{1}.{2}.xml",
                                                _settings["XmlPath"],
                                                _settings["ProjectName"],
                                                _settings["ApplicationName"]
                                                );

            //Ninject Extension requires fully qualified path.
            string bindingConfigurationPath = Path.Combine(
                _settings["BaseDirectoryPath"],
                relativePath
                );

            _kernel.Load(bindingConfigurationPath);

            // _sp3dDataLayer = _kernel.Get<SP3DDataLayer>(); This will reset the new updated adaptersettings with default values.

            _sp3dDataLayer = new SP3DDataLayer(_adapterSettings);
        }
Example #7
0
        public SP3DDataLayerTest()
        {
            _settings = new NameValueCollection();

            _settings["XmlPath"] = @".\12345_000\";
            _settings["ProjectName"] = "12345_000";
            _settings["ApplicationName"] = "SP3D";

            _baseDirectory = Directory.GetCurrentDirectory();
            _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\bin"));
            _settings["BaseDirectoryPath"] = _baseDirectory;
            Directory.SetCurrentDirectory(_baseDirectory);

            _adapterSettings = new AdapterSettings();
            _adapterSettings.AppendSettings(_settings);

            string appSettingsPath = String.Format("{0}12345_000.SP3D.config",
                _adapterSettings["XmlPath"]
            );

            if (File.Exists(appSettingsPath))
            {
                AppSettingsReader appSettings = new AppSettingsReader(appSettingsPath);
                _adapterSettings.AppendSettings(appSettings);
            }

            var ninjectSettings = new NinjectSettings { LoadExtensions = false };
            _kernel = new StandardKernel(ninjectSettings);

            _kernel.Load(new XmlExtensionModule());

            string relativePath = String.Format(@"{0}BindingConfiguration.{1}.{2}.xml",
            _settings["XmlPath"],
            _settings["ProjectName"],
            _settings["ApplicationName"]
              );

            //Ninject Extension requires fully qualified path.
            string bindingConfigurationPath = Path.Combine(
              _settings["BaseDirectoryPath"],
              relativePath
            );

            _kernel.Load(bindingConfigurationPath);

               // _sp3dDataLayer = _kernel.Get<SP3DDataLayer>(); This will reset the new updated adaptersettings with default values.

            _sp3dDataLayer = new SP3DDataLayer(_adapterSettings);
        }
Example #8
0
        static void RunTask()
        {
            _logger.Debug("RunTask ...");
            AdapterSettings     adapterSettings;
            NameValueCollection settings;

            foreach (Task task in _sequence.Tasks)
            {
                string project = task.Project;
                string app     = task.App;
                settings = ConfigurationManager.AppSettings;

                adapterSettings = new AdapterSettings();
                adapterSettings.AppendSettings(settings);
                adapterSettings["ProjectName"]     = project;
                adapterSettings["ApplicationName"] = app;
                adapterSettings["Scope"]           = project + "." + app;

                //Call agent provider
                AgentProvider agentProvider = new AgentProvider(adapterSettings);
                agentProvider.ProcessTask(task);
            }

            _logger.Info("Task finished: ");
        }
Example #9
0
        public ReferenceDataTests()
        {
            _baseDirectory = Directory.GetCurrentDirectory();
            _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\Bin"));
            Directory.SetCurrentDirectory(_baseDirectory);
            AdapterSettings adapterSettings = new AdapterSettings();

            adapterSettings.AppendSettings(new AppSettingsReader("App.config"));
            _settings = new ReferenceDataSettings();
            _settings.AppendSettings((ServiceSettings)adapterSettings);
            _settings["BaseDirectoryPath"] = _baseDirectory;
            _refdataProvider = new ReferenceDataProvider(_settings);
        }
Example #10
0
        public test()
        {
            string baseDir = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(baseDir.Substring(0, baseDir.LastIndexOf("\\bin")));

            AdapterSettings adapterSettings = new AdapterSettings();
            adapterSettings.AppendSettings(new AppSettingsReader("App.config"));

            _dataLayer = new Bechtel.iRING.SPR.SPRDataLayer(adapterSettings);
            _objectType = adapterSettings["ObjectType"];
            _objectDefinition = GetObjectDefinition(_objectType);
            _dataLayer.GetDictionary();
            //_dataLayer.RefreshAll();
        }
Example #11
0
File: Tests.cs Project: Vidisha/eb
        public Tests()
        {
            string baseDir = Directory.GetCurrentDirectory();
              Directory.SetCurrentDirectory(baseDir.Substring(0, baseDir.LastIndexOf("\\bin")));

              AdapterSettings adapterSettings = new AdapterSettings();
              adapterSettings.AppendSettings(new AppSettingsReader("App.config"));

              FileInfo log4netConfig = new FileInfo("Log4net.config");
              log4net.Config.XmlConfigurator.Configure(log4netConfig);

              _dataLayer = new ebDataLayer(adapterSettings);
              _scenarios = Utility.Read<Scenarios>("Scenarios.xml");
        }
Example #12
0
        public Tests()
        {
            string baseDir = Directory.GetCurrentDirectory();
              Directory.SetCurrentDirectory(baseDir.Substring(0, baseDir.LastIndexOf("\\bin")));

              AdapterSettings adapterSettings = new AdapterSettings();
              adapterSettings["ProjectName"] = project;
              adapterSettings["ApplicationName"] = app;

              string appConfigPath = string.Format("App_Data\\{0}.{1}.config", project, app);
              adapterSettings.AppendSettings(new AppSettingsReader(appConfigPath));

              _dataLayer = new SPPIDDataLayer(adapterSettings);
              _scenarios = org.iringtools.utility.Utility.Read<Scenarios>("Scenarios.xml");
        }
Example #13
0
        public test()
        {
            string baseDir = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(baseDir.Substring(0, baseDir.LastIndexOf("\\bin")));

            AdapterSettings adapterSettings = new AdapterSettings();

            adapterSettings.AppendSettings(new AppSettingsReader("App.config"));

            _dataLayer        = new Bechtel.iRING.SPR.SPRDataLayer(adapterSettings);
            _objectType       = adapterSettings["ObjectType"];
            _objectDefinition = GetObjectDefinition(_objectType);
            _dataLayer.GetDictionary();
            //_dataLayer.RefreshAll();
        }
Example #14
0
        public AdapterTest()
        {
            _settings = new AdapterSettings();

            _baseDirectory = Directory.GetCurrentDirectory();
            _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\Bin"));
            _settings["BaseDirectoryPath"] = _baseDirectory;
            Directory.SetCurrentDirectory(_baseDirectory);

            _settings.AppendSettings(new StaticDust.Configuration.AppSettingsReader("App.config"));

            _settings["ProjectName"]     = "12345_000";
            _settings["ApplicationName"] = "ABC";
            _settings["GraphName"]       = "Lines";

            _adapterProvider = new AdapterProvider(_settings);
        }
Example #15
0
        public Tests()
        {
            string baseDir = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(baseDir.Substring(0, baseDir.LastIndexOf("\\bin")));

            AdapterSettings adapterSettings = new AdapterSettings();

            adapterSettings.AppendSettings(new AppSettingsReader("App.config"));

            FileInfo log4netConfig = new FileInfo("Log4net.config");

            log4net.Config.XmlConfigurator.Configure(log4netConfig);

            _dataLayer = new ebDataLayer(adapterSettings);
            _scenarios = Utility.Read <Scenarios>("Scenarios.xml");
        }
Example #16
0
        public NHibernateTest()
        {
            _settings = new AdapterSettings();

            _baseDirectory = Directory.GetCurrentDirectory();
            _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\Bin"));
            _settings["BaseDirectoryPath"] = _baseDirectory;
            Directory.SetCurrentDirectory(_baseDirectory);

            _settings.AppendSettings(new StaticDust.Configuration.AppSettingsReader("App.config"));

            _settings["ProjectName"]           = "12345_000";
            _settings["ApplicationName"]       = "ABC";
            _settings["SchemaObjectName"]      = "LINES";
            _settings["ExecutingAssemblyName"] = "NUnit.Tests";

            _hibernateProvider = new NHibernateProvider(_settings);
        }
Example #17
0
        public Tests()
        {
            string baseDir = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(baseDir.Substring(0, baseDir.LastIndexOf("\\bin")));

            AdapterSettings adapterSettings = new AdapterSettings();

            adapterSettings["ProjectName"]     = project;
            adapterSettings["ApplicationName"] = app;

            string appConfigPath = string.Format("App_Data\\{0}.{1}.config", project, app);

            adapterSettings.AppendSettings(new AppSettingsReader(appConfigPath));

            _dataLayer = new SPPIDDataLayer(adapterSettings);
            _scenarios = org.iringtools.utility.Utility.Read <Scenarios>("Scenarios.xml");
        }
Example #18
0
        public ExchangeProvider(NameValueCollection settings)
        {
            var ninjectSettings = new NinjectSettings {
                LoadExtensions = false
            };

            _kernel = new StandardKernel(ninjectSettings, new AdapterModule());

            _kernel.Load(new XmlExtensionModule());
            _settings = _kernel.Get <AdapterSettings>();
            _settings.AppendSettings(settings);

            Directory.SetCurrentDirectory(_settings["BaseDirectoryPath"]);

            string scopesPath = String.Format("{0}Scopes.xml", _settings["XmlPath"]);

            _settings["ScopesPath"] = scopesPath;

            if (File.Exists(scopesPath))
            {
                _scopes = Utility.Read <ScopeProjects>(scopesPath);
            }
            else
            {
                _scopes = new ScopeProjects();
                Utility.Write <ScopeProjects>(_scopes, scopesPath);
            }

            _response            = new Response();
            _response.StatusList = new List <Status>();
            _kernel.Bind <Response>().ToConstant(_response);
            string relativePath = String.Format("{0}BindingConfiguration.Adapter.xml",
                                                _settings["XmlPath"]
                                                );
            string bindingConfigurationPath = Path.Combine(
                _settings["BaseDirectoryPath"],
                relativePath
                );

            _kernel.Load(bindingConfigurationPath);
            InitializeIdentity();
        }
Example #19
0
        public DxfrTest()
        {
            _settings = new AdapterSettings();

            _baseDirectory = Directory.GetCurrentDirectory();
            _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\Bin"));
            _settings["BaseDirectoryPath"] = _baseDirectory;
            Directory.SetCurrentDirectory(_baseDirectory);

            _settings.AppendSettings(new StaticDust.Configuration.AppSettingsReader("App.config"));

            _settings["ProjectName"]           = "12345_000";
            _settings["ApplicationName"]       = "ABC";
            _settings["GraphName"]             = "Lines";
            _settings["Identifier"]            = "90002-RV";
            _settings["ExecutingAssemblyName"] = "NUnit.Tests";
            _settings["GraphBaseUri"]          = "http://www.example.com/";
            _dxfrProvider = new DtoProvider(_settings);

            ResetDatabase();
        }
Example #20
0
        public DataTest()
        {
            _settings = new AdapterSettings();

            _baseDirectory = Directory.GetCurrentDirectory();
            _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\Bin"));
            _settings["BaseDirectoryPath"] = _baseDirectory;
            Directory.SetCurrentDirectory(_baseDirectory);

            _settings.AppendSettings(new StaticDust.Configuration.AppSettingsReader("App.config"));
            _settings["ProjectName"]     = "12345_000";
            _settings["ApplicationName"] = "ABC";
            _settings["GraphName"]       = "Lines";
            _settings["Identifier"]      = "90002-RV";
            _settings["TestMode"]        = "UseFiles"; //UseFiles/WriteFiles
            _settings["ClassName"]       = "PIPINGNETWORKSYSTEM";
            _settings["GraphBaseUri"]    = "http://www.example.com/";

            _adapterProvider = new AdapterProvider(_settings);

            ResetDatabase();
        }
 public SpreadsheetRepository()
 {
     _settings = new AdapterSettings();
     _settings.AppendSettings(ConfigurationManager.AppSettings);
     _client = new WebHttpClient(_settings["AdapterServiceUri"]);
 }
Example #22
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);
            }
        }
Example #23
0
        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);
            }
        }
Example #24
0
        private void InitializeScope(string projectName, string applicationName)
        {
            try
            {
                if (!_isScopeInitialized)
                {
                    bool isScopeValid = false;
                    foreach (ScopeProject project in _scopes)
                    {
                        if (project.Name == projectName)
                        {
                            foreach (ScopeApplication application in project.Applications)
                            {
                                if (application.Name == applicationName)
                                {
                                    isScopeValid = true;
                                }
                            }
                        }
                    }

                    string scope = String.Format("{0}.{1}", projectName, applicationName);

                    if (!isScopeValid)
                    {
                        throw new Exception(String.Format("Invalid scope [{0}].", scope));
                    }

                    _settings["ProjectName"]     = projectName;
                    _settings["ApplicationName"] = applicationName;
                    _settings["Scope"]           = scope;

                    string appSettingsPath = String.Format("{0}{1}.config",
                                                           _settings["XmlPath"],
                                                           scope
                                                           );

                    if (File.Exists(appSettingsPath))
                    {
                        AppSettingsReader appSettings = new AppSettingsReader(appSettingsPath);
                        _settings.AppendSettings(appSettings);
                    }
                    string relativePath = String.Format("{0}BindingConfiguration.{1}.xml",
                                                        _settings["XmlPath"],
                                                        scope
                                                        );

                    //Ninject Extension requires fully qualified path.
                    string bindingConfigurationPath = Path.Combine(
                        _settings["BaseDirectoryPath"],
                        relativePath
                        );

                    _settings["BindingConfigurationPath"] = bindingConfigurationPath;

                    if (!File.Exists(bindingConfigurationPath))
                    {
                        XElement binding = new XElement("module",
                                                        new XAttribute("name", _settings["Scope"]),
                                                        new XElement("bind",
                                                                     new XAttribute("name", "DataLayer"),
                                                                     new XAttribute("service", "org.iringtools.library.IDataLayer, iRINGLibrary"),
                                                                     new XAttribute("to", "org.iringtools.adapter.datalayer.NHibernateDataLayer, NHibernateDataLayer")
                                                                     )
                                                        );

                        binding.Save(bindingConfigurationPath);
                    }

                    _kernel.Load(bindingConfigurationPath);

                    string mappingPath = String.Format("{0}Mapping.{1}.xml",
                                                       _settings["XmlPath"],
                                                       scope
                                                       );

                    if (File.Exists(mappingPath))
                    {
                        _mapping = Utility.Read <Mapping>(mappingPath);
                    }
                    else
                    {
                        _mapping = new Mapping();
                        Utility.Write <Mapping>(_mapping, mappingPath);
                    }
                    _kernel.Bind <Mapping>().ToConstant(_mapping);

                    _isScopeInitialized = true;
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Error initializing application: {0}", ex));
                throw new Exception(string.Format("Error initializing application: {0})", ex));
            }
        }