Exemplo n.º 1
0
        public static async Task <string> GetName(SettingsCommon settings)
        {
            if (settings.Naming == null)
            {
                return($"{DateTime.Now:yyyyMMdd_HHmmss}");
            }
            else if (settings.Naming.Specific != null)
            {
                return(settings.Naming.Specific);
            }
            else
            {
                if (acceptName)
                {
                    await Console.Out.WriteLineAsync("Any key to re-generate, leave 10 seconds (or Y) to accept");

                    do
                    {
                        var candidate = GetRandomNameInternal(settings);
                        Console.Write(candidate);
                        if (await Accept())
                        {
                            return(candidate);
                        }
                    } while (true);
                }
                else
                {
                    return(GetRandomNameInternal(settings));
                }
            }
        }
Exemplo n.º 2
0
 public RiseApplier(SettingsCommon settings, RisesModel riseModel, IGetRandom randomizer)
 {
     this.settings   = settings;
     this.randomizer = randomizer;
     this.riseModel  = riseModel;
     rises           = MakeRises(riseModel).ToArray();
 }
 public IContainer GetFullFeatureContainer(SettingsCommon settings) => DependencyConfig.ConfigureContainer(settings, a =>
 {
     a.AddTransient <IProgressReporter, WebProgressReporter>();
     a.AddTransient <IJobProgressProvider, JobProgressProvider>();
     a.AddTransient <Ultimate.ORM.IObjectMapper, Ultimate.ORM.ObjectMapper>();
     a.AddInstance <IConfiguration>(configuration);
     a.AddInstance <ILoggerFactory>(loggerProvider);
     a.AddTransient <IOutputDirectoryProvider, WebOutputDirectoryProvider>();
 });
Exemplo n.º 4
0
        public static string GetRandomNameInternal(SettingsCommon settings)
        {
            var    possibleNameListFiles = new[] { "female-first-names.txt", "male-first-names.txt" };
            var    nameListFilesToUse    = possibleNameListFiles.Where((l, i) => ((i + 1) & (int)settings.Naming.Strategy.Value) != 0).ToArray();
            var    nameListFile          = nameListFilesToUse[random.Next(0, nameListFilesToUse.Length)];
            var    nameList        = nameListCache.GetOrAdd(nameListFile, s => File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, s)).Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToArray());
            string randomName      = nameList[(int)(Math.Pow(random.NextDouble(), 1.5) * nameList.Length)];
            var    randomNameCased = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(randomName.ToLower());

            return(randomNameCased);
        }
Exemplo n.º 5
0
 public WaveStreamBase(SettingsCommon settings, ISamplingFrequencyProvider samplingFrequencyProvider, IProgressReporter progressReporter)
 {
     Channels = settings.GetNumberOfChannels();
     if (Channels < 1 || Channels > 2)
     {
         throw new InvalidOperationException("Channels must be either 1 or 2.");
     }
     LengthSeconds   = settings.TrackLength.TotalSeconds;
     N               = (int)(LengthSeconds * samplingFrequencyProvider.SamplingFrequency);
     overallDataSize = N * Channels * BytesPerSample;
     overallFileSize = overallDataSize + 44;
     this.samplingFrequencyProvider = samplingFrequencyProvider;
     this.progressReporter          = progressReporter;
 }
Exemplo n.º 6
0
        private static async Task WriteFile(IContainer componentContext, SettingsCommon settings, string name)
        {
            var    compositionName = $"{name}_{DateTime.Now.ToString("yyyyMMdd_HHmm")}";
            var    mp3Stream       = componentContext.Resolve <Mp3Stream>();
            string json            = JsonConvert.SerializeObject(settings, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                ContractResolver  = new BaseClassPropertiesFirstContractResolver(),
                Formatting        = Formatting.Indented
            });
            await File.WriteAllTextAsync($"{compositionName}.parameters.json", json);

            await mp3Stream.Write($"{compositionName}.mp3");
        }
Exemplo n.º 7
0
        public JsonNetResult Featured()
        {
            var accountNameKey = Common.GetSubDomain(Request.Url);

            var featuredProperties         = SettingsCommon.GetProperties(accountNameKey, "featured");
            var featuredPropertiesListings = new List <ApplicationPropertiesService.PropertyModel>();

            foreach (var property in featuredProperties)
            {
                if (property.Listing && property.PropertyTypeNameKey != "location" && property.PropertyTypeNameKey != "paragraph")
                {
                    //We ONLY extract listing types and non- locations:
                    featuredPropertiesListings.Add(property);
                }
            }

            JsonNetResult jsonNetResult = new JsonNetResult();

            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = featuredPropertiesListings;

            return(jsonNetResult);
        }
Exemplo n.º 8
0
 public BreakApplier(SettingsCommon settings, BreaksModel breaksSettings, IGetRandom randomizer)
 {
     this.settings   = settings;
     this.randomizer = randomizer;
     breaks          = MakeBreaks(breaksSettings).ToArray();
 }
Exemplo n.º 9
0
        public static List <ImageRecordGroupModel> GetImageRecordsForObject(string accountNameKey, string storagePartitionName, string imageFormatGroupTypeNameKey, string objectId, bool listingsOnly = false)
        {
            var imageRecords = new List <ImageRecordGroupModel>();

            var accountId = AuthenticationCookieManager.GetAuthenticationCookie().AccountID.ToString();

            #region Get Image Formats/FormatGroups for this ImageFormatGroupTypeNameKey (Local cache first ---> Then Redis --> Then WCF/SQL)

            List <ImageFormatGroupModel> imageFormats = null;

            #region (Plan A) Get ImageFormats for this ImageFormatGroupType from Local Cache

            bool   localCacheEmpty = false;
            string localCacheKey   = accountNameKey + ":imageFormats:" + imageFormatGroupTypeNameKey;

            try
            {
                imageFormats = (List <ImageFormatGroupModel>)HttpRuntime.Cache[localCacheKey];
            }
            catch (Exception e)
            {
                var error = e.Message;
                //TODO: Log: error message for local cache call
            }

            #endregion

            if (imageFormats == null)
            {
                localCacheEmpty = true;

                #region (Plan B) Get ImageFormats from ImageFormatsManager Shared Method (Redis or WCF call)

                imageFormats = SettingsCommon.GetImageFormatsHelper(accountNameKey, imageFormatGroupTypeNameKey);

                #endregion
            }


            if (localCacheEmpty)
            {
                #region store Account into local cache

                //store formats in local cache for 60 seconds:
                HttpRuntime.Cache.Insert(localCacheKey, imageFormats, null, DateTime.Now.AddSeconds(20), TimeSpan.Zero);

                #endregion
            }

            #endregion

            #region Get all image records for this object

            #region Connect to Table Storage & Set Retry Policy (Legacy)

            /*
             * CloudStorageAccount storageAccount;
             *
             * // Credentials are from centralized CoreServiceSettings
             * StorageCredentials storageCredentials = new StorageCredentials(CoreServices.PlatformSettings.Storage.AccountName, CoreServices.PlatformSettings.Storage.AccountKey);
             * storageAccount = new CloudStorageAccount(storageCredentials, false);
             * storageAccount = new CloudStorageAccount(storageCredentials, false);
             * CloudTableClient cloudTableClient = storageAccount.CreateCloudTableClient();
             *
             * //Create and set retry policy
             * //IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 4);
             * IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(1), 4);
             * cloudTableClient.DefaultRequestOptions.RetryPolicy = linearRetryPolicy;
             */
            #endregion

            #region Connect to table storage partition & Set Retry Policy

            #region Get Storage Partition

            if (CoreServices.PlatformSettings.StorageParitions == null || CoreServices.PlatformSettings.StorageParitions.ToList().Count == 0)
            {
                //No Storage Partitions Available in Static List, refresh list from Core Services
                Common.RefreshPlatformSettings();
            }

            //Get the storage partition for this account
            var storagePartition = CoreServices.PlatformSettings.StorageParitions.FirstOrDefault(partition => partition.Name == storagePartitionName);

            if (storagePartition == null)
            {
                //May be a new partition, refresh platform setting and try again
                Common.RefreshPlatformSettings();
                storagePartition = CoreServices.PlatformSettings.StorageParitions.FirstOrDefault(partition => partition.Name == storagePartitionName);
            }

            #endregion

            var cdnEndpoint = "https://" + storagePartition.CDN + "/";

            CloudStorageAccount storageAccount;
            StorageCredentials  storageCredentials = new StorageCredentials(storagePartition.Name, storagePartition.Key);
            storageAccount = new CloudStorageAccount(storageCredentials, false);
            CloudTableClient cloudTableClient = storageAccount.CreateCloudTableClient();

            //Create and set retry policy for logging
            //IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 4);
            IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(1), 4);
            cloudTableClient.DefaultRequestOptions.RetryPolicy = linearRetryPolicy;


            #endregion

            CloudTable cloudTable = null;

            if (!listingsOnly)
            {
                cloudTable = cloudTableClient.GetTableReference("acc" + accountId.Replace("-", "").ToLower() + imageFormatGroupTypeNameKey + "imgs");
            }
            else
            {
                cloudTable = cloudTableClient.GetTableReference("acc" + accountId.Replace("-", "").ToLower() + imageFormatGroupTypeNameKey + "lstimgs");
            }

            List <ImageRecordTableEntity> imageRecordEntities;

            //var imageRecordEntities = Internal.ImageRecordTableStorage.RetrieveImageRecords(accountId, imageFormatGroupTypeNameKey, objectId, listingsOnly);
            try
            {
                imageRecordEntities = (from record in cloudTable.CreateQuery <ImageRecordTableEntity>().Where(p => p.PartitionKey == objectId) select record).ToList(); //new TableQuery<ImageRecordTableEntity>().AsQueryable().Where(p => p.PartitionKey == objectId).ToList();
            }
            catch
            {
                //Table may not exist yet, return empty record set (We do not use CreateIfNotExists on TableClient in case imageFormatGroupTypeNameKey is not valid!!!!)
                imageRecordEntities = new List <ImageRecordTableEntity>();
            }

            #endregion

            #region  Convert FormatGroups/Formats to RecordGroups/Records And merge them with Records (Where records exist)

            foreach (ImageFormatGroupModel imageFormatGroup in imageFormats)
            {
                var imageRecordGroupModel = new ImageRecordGroupModel
                {
                    GroupName    = imageFormatGroup.ImageFormatGroupName,
                    GroupNameKey = imageFormatGroup.ImageFormatGroupNameKey
                };

                imageRecordGroupModel.ImageRecords = new List <ImageRecordModel>();

                foreach (ImageFormatModel imageFormat in imageFormatGroup.ImageFormats)
                {
                    if (listingsOnly && !imageFormat.Listing)
                    {
                        //ignore
                    }
                    else
                    {
                        #region Get the associated record for each format (if one exists, or create a null object for it if a record does not

                        var recordExists = false;

                        foreach (ImageRecordTableEntity tableEntity in imageRecordEntities)
                        {
                            if (tableEntity.ImageKey == imageFormat.ImageFormatGroupNameKey + "-" + imageFormat.ImageFormatNameKey)
                            {
                                recordExists = true;

                                #region A record exists for this format, convert and remove from list

                                imageRecordGroupModel.ImageRecords.Add(Transforms.TableEntity_To_ImageRecord(cdnEndpoint, tableEntity, imageFormat, imageFormat.Gallery));

                                #endregion
                            }
                        }

                        if (!recordExists)
                        {
                            #region A record does not exist, use a null version of the format slug instead

                            imageRecordGroupModel.ImageRecords.Add(Transforms.ImageFormat_To_ImageRecord(imageFormat));

                            #endregion
                        }

                        #endregion
                    }
                }

                if (imageRecordGroupModel.ImageRecords.Count > 0)
                {
                    imageRecords.Add(imageRecordGroupModel);  //<-- Only append if group has records or format slugs
                }
            }

            #endregion

            return(imageRecords);
        }
Exemplo n.º 10
0
 public Randomizer(SettingsCommon settings)
 {
     this.settings = settings;
 }
Exemplo n.º 11
0
 public static IContainer ConfigureContainer(SettingsCommon settings, Action <IContainer> additionalRegistrations = null) => ConfigureContainer(a =>