/// <summary>
        /// Provides the value.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <returns>the 'string'</returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            // TODO: review this, it's not right but works in the designer...
            var candidate = string.Empty;

            try
            {
                if (!Cache.Holds(ResourceKey))
                {
                    candidate = RunSafe.Try(() => Resources.GetString(ResourceKey), () => $"resource key not found: {ResourceKey}");
                    Cache.Add(ResourceKey, candidate);
                }

                candidate = Cache.Fetch(ResourceKey);

                if (It.Has(StringFormat))
                {
                    candidate = Format.String(StringFormat, candidate);
                }

                return(candidate);
            }
            catch
            {
                return(null);
            }
        }
 public void WriteOutUKPRN(int UKPRN, IContainSessionContext containerSessionContext)
 {
     // create table or trumcate
     Emitter.Publish($"Creating UKPRN table");
     try
     {
         string createTable = $"IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UKPRNForProcedures]') AND type in (N'U')) DROP TABLE [dbo].[UKPRNForProcedures] CREATE TABLE [dbo].[UKPRNForProcedures] ([UKPRN] [int] NOT NULL) ON [PRIMARY]";
         RunSafe.Try(() => Coordinate.ExecuteCommand(createTable, containerSessionContext.ProcessingLocation));
         Emitter.Publish("Table created sucessfully");
     }
     catch (Exception e)
     {
         Emitter.Publish($"Failed to create table: {e.Message}");
         throw;
     }
     // insert ukprn
     Emitter.Publish($"Writeing out {UKPRN}");
     try
     {
         string insertUKPRN = $"INSERT INTO [dbo].[UKPRNForProcedures] ([UKPRN]) VALUES ({UKPRN})";
         RunSafe.Try(() => Coordinate.ExecuteCommand(insertUKPRN, containerSessionContext.ProcessingLocation));
         Emitter.Publish("Writing out sucessful");
     }
     catch (Exception e)
     {
         Emitter.Publish($"Failed to insert UKPRN {UKPRN} into table: {e.Message}");
         throw;
     }
 }
        /// <summary>
        /// Builds the store.
        /// </summary>
        /// <param name="usingContext">using context.</param>
        /// <param name="forProvider">for provider.</param>
        /// <param name="inYear">in year.</param>
        public override void BuildStore(IContainSessionContext usingContext, int forProvider, BatchOperatingYear inYear)
        {
            var batch = Batches.GetBatch(BatchProcessName.BuildResultsDataStore, inYear);

            Emitter.Publish(batch.Description);

            //CreateDataStoreUsing(usingContext, batch.Scripts.First());

            var    command     = $"select TOP(1) [FileName] from [Valid].[File] WHERE [FileName] like '%{forProvider}%';";
            string ilrFileName = RunSafe.Try(() => Coordinate.GetAtom <string>(command, usingContext.SourceLocation));
            var    forTarget   = usingContext.ResultsDestination;

            CreateSchemaFor(
                forTarget,
                batch.Scripts.AsSafeReadOnlyList(),
                x => Token.DoSecondaryPass(x, inYear, forTarget, usingContext.ReturnPeriod, ilrFileName, forProvider.ToString()));
        }
Пример #4
0
        /// <summary>
        /// Converts a value.
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>
        /// A converted value. If the method returns null, the valid null value is used.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var key        = $"{value}Key";
            var dictionary = parameter as StringDictionary;

            if (It.Has(dictionary) && dictionary.Contains(key))
            {
                key = dictionary.GetValue(key);
            }

            if (!Cache.Holds(key))
            {
                var candidate = RunSafe.Try(() => Resources.GetString(key), () => $"resource key not found: {key}");
                Cache.Add(key, candidate);
            }

            return(Cache.Fetch(key));
        }
        public string GetILRFileName(IConnectionDetail forConnection)
        {
            var command = "select TOP(1) concat('ILR-', UKPRN,'-', FORMAT([DateTime], 'ddMMyyyy'),'-',FORMAT([DateTime],'hhmmss'), '-' , SerialNo) from dbo.Source;";

            return(RunSafe.Try(() => Coordinate.GetAtom <string>(command, forConnection)));
        }
        /// <summary>
        /// Gets the schema learner count.
        /// </summary>
        /// <param name="forConnection">For connection</param>
        /// <param name="thisSchema">(and) this schema</param>
        /// <returns>the count</returns>
        public int GetSchemaLearnerCount(IConnectionDetail forConnection, string thisSchema)
        {
            var command = $"select count(*) from {thisSchema}.Learner";

            return(RunSafe.Try(() => Coordinate.GetAtom <int>(command, forConnection)));
        }