Exemplo n.º 1
0
        public async Task <WebsiteExtractionMap> FindExtractionMap(WebsiteExtractionMap extractMap)
        {
            if (extractMap.WebsiteKey == null)
            {
                throw new ArgumentNullException("Need websiteKey in order to create a extraction record");
            }
            var query = @"SELECT WebsiteKey, DataName, DocumentLocation, LocationType, LocationValue, FormatFunction,ValueFunction,Priority
                          FROM [ScriptingAgentDatabase].[dbo].[dsa_websiteExtractionMapping] 
                          WHERE websiteKey = @websiteKey 
                          AND DataName = @dataName 
                          AND Priority = @priority";

            var p = new DynamicParameters();

            p.Add("@websiteKey", extractMap.WebsiteKey);
            p.Add("@dataName", extractMap.DataName);
            p.Add("@priority", extractMap.Priority);

            try
            {
                var result = await _db.QueryAsync <WebsiteExtractionMap>(query, p);

                return(result.SingleOrDefault());
            }
            catch (SqlException)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task Add_ExtractionMap_Test()
        {
            var container = new UnityContainer();
            var em        = new WebsiteExtractionMap();

            em.WebsiteKey       = new Guid("86ee2f58-33f9-4dbb-8db2-a43c89da5dfc");
            em.DataName         = "Status";
            em.DocumentLocation = "table";
            em.LocationType     = "Containsl";
            em.LocationValue    = "Status";
            em.FormatFunction   = null;
            em.ValueFunction    = null;
            em.Priority         = 1;

            Func <WebsiteExtractionMap, string, Task <WebsiteExtractionMap> > AddRecord = async(newRecord, configName) =>
            {
                using (var db = new SqlConnection(ConfigurationManager.ConnectionStrings[configName].ConnectionString))
                {
                    container.RegisterType <IScriptCreation, ScriptCreationRepo>(new InjectionConstructor(db));
                    var repo = container.Resolve <IScriptCreation>();
                    return(await repo.CreateExtractionMap(em));
                }
            };

            var newExtractionRecord = await AddRecord(em, _devSmartAgent);

            Console.WriteLine(newExtractionRecord.WebsiteKey.ToString());

            var prodRecord = await AddRecord(em, _prodSmartAgentDb);

            Console.WriteLine(prodRecord.WebsiteKey.ToString());
        }
Exemplo n.º 3
0
        public async Task <WebsiteExtractionMap> CreateExtractionMap(WebsiteExtractionMap extractMap)
        {
            if (extractMap.WebsiteKey == null)
            {
                throw new ArgumentNullException("Need websiteKey in order to create a extraction record");
            }
            var query = @"INSERT INTO [ScriptingAgentDatabase].[dbo].[dsa_websiteExtractionMapping]
                           ([WebsiteKey]
                           ,[DataName]
                           ,[DocumentLocation]
                           ,[LocationType]
                           ,[LocationValue]
                           ,[FormatFunction]
                           ,[ValueFunction]
                           ,[Priority])
                     VALUES
                           (@websiteKey
                           ,@dataName
                           ,@documentLocation
                           ,@locationType
                           ,@locationValue
                           ,@formatFunction
                           ,@valueFunction
                           ,@priority)";

            var p = new DynamicParameters();

            p.Add("@websiteKey", extractMap.WebsiteKey);
            p.Add("@dataName", extractMap.DataName);
            p.Add("@documentLocation", extractMap.DocumentLocation);
            p.Add("@locationType", extractMap.LocationType);
            p.Add("@locationValue", extractMap.LocationValue);
            p.Add("@formatFunction", extractMap.FormatFunction);
            p.Add("@valueFunction", extractMap.ValueFunction);
            p.Add("@priority", extractMap.Priority);
            try
            {
                await _db.ExecuteAsync(query, p);

                return(await FindExtractionMap(extractMap));
            }
            catch (SqlException)
            {
                throw;
            }
        }