/// <summary>
        /// Get store from container identifier
        /// </summary>
        /// <param name="containerIdentifier">Container identifier</param>
        /// <returns>CT store</returns>
        public async Task <CTStore> GetStore(ContainerIdentifier containerIdentifier)
        {
            // refuse to provide the store if the version check fails, or if it has not been executed
            if (this.initialized == false)
            {
                return(null);
            }

            ContainerDescriptor containerDescriptor = ContainerTableDescriptorProvider.Containers[containerIdentifier];
            string azureStorageConnectionString     = await this.connectionStringProvider.GetTablesAzureStorageConnectionString(containerDescriptor.AzureStorageInstanceType);

            string redisConnectionString = await this.connectionStringProvider.GetRedisConnectionString(containerDescriptor.RedisInstanceType);

            string uniqueStoreIdentity = string.Join(":", azureStorageConnectionString, redisConnectionString);

            // cachedStoreObjects is a thread-safe dictionary (ConcurrentDictionary). If uniqueStoreIdentity is not present
            // in cachedStoreObects, try adding it. Since GetStore can be called concurrently by
            // different threads, it is possible for two (or more) threads to attempt inserting uniqueStoreIdentity
            // concurrently in the cachedStoreObjects. That's ok, because the call to TryAdd is guaranteed to be thread-safe.
            // One of the threads will not be able to insert (i.e., TryAdd will return false), but the code will happily execute
            // and fall through to the return statement.
            // This code makes no use of locking on the common path (i.e., reads of cachedStoreObjects).
            if (!this.cachedStoreObjects.ContainsKey(uniqueStoreIdentity))
            {
                AzureTableStorage azureTableStorage = new AzureTableStorage(azureStorageConnectionString);
                azureTableStorage.TableRequestOptions = AzureStorageConfiguration.GetTableRequestOptions();
                RedisCache redisCache = new RedisCache(redisConnectionString);

                CTStore store = new CTStore(azureTableStorage, redisCache);
                this.cachedStoreObjects.TryAdd(uniqueStoreIdentity, store);
            }

            return(this.cachedStoreObjects[uniqueStoreIdentity]);
        }
        /// <summary>
        /// Get store from container identifier
        /// </summary>
        /// <param name="containerIdentifier">Container identifier</param>
        /// <returns>CB store</returns>
        public async Task <CBStore> GetStore(ContainerIdentifier containerIdentifier)
        {
            ContainerDescriptor containerDescriptor = ContainerDescriptorProvider.Containers[containerIdentifier];
            string azureStorageConnectionString     = await this.connectionStringProvider.GetBlobsAzureStorageConnectionString(containerDescriptor.AzureStorageInstanceType);

            string azureCdnUrl = await this.connectionStringProvider.GetAzureCdnUrl(containerDescriptor.AzureCdnInstanceType);

            string uniqueStoreIdentity = string.Join(":", azureStorageConnectionString, azureCdnUrl);

            // cachedStoreObjects is a thread-safe dictionary (ConcurrentDictionary). If uniqueStoreIdentity is not present
            // in cachedStoreObjects, try adding it. Since GetStore can be called concurrently by
            // different threads, it is possible for two (or more) threads to attempt inserting uniqueStoreIdentity
            // concurrently in the cachedStoreObjects. That's ok, because the call to TryAdd is guaranteed to be thread-safe.
            // One of the threads will not be able to insert (i.e., TryAdd will return false), but the code will happily execute
            // and fall through to the return statement.
            // This code makes no use of locking on the common path (i.e., reads of cachedStoreObjects).
            if (!cachedStoreObjects.ContainsKey(uniqueStoreIdentity))
            {
                AzureBlobStorage azureBlobStorage = new AzureBlobStorage(azureStorageConnectionString);
                azureBlobStorage.BlobRequestOptions = AzureStorageConfiguration.GetBlobRequestOptions();
                AzureCdn azureCdn = new AzureCdn(azureCdnUrl);

                CBStore store = new CBStore(azureBlobStorage, azureCdn);
                cachedStoreObjects.TryAdd(uniqueStoreIdentity, store);
            }

            return(cachedStoreObjects[uniqueStoreIdentity]);
        }
Esempio n. 3
0
        /// <inheritdoc/>
        public string ToDelimitedString()
        {
            CultureInfo culture = CultureInfo.CurrentCulture;

            return(string.Format(
                       culture,
                       StringHelper.StringFormatSequence(0, 50, Configuration.FieldSeparator),
                       Id,
                       ExternalAccessionIdentifier?.ToDelimitedString(),
                       AccessionIdentifier?.ToDelimitedString(),
                       ContainerIdentifier?.ToDelimitedString(),
                       PrimaryParentContainerIdentifier?.ToDelimitedString(),
                       EquipmentContainerIdentifier?.ToDelimitedString(),
                       SpecimenSource,
                       RegistrationDateTime.HasValue ? RegistrationDateTime.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null,
                       ContainerStatus?.ToDelimitedString(),
                       CarrierType?.ToDelimitedString(),
                       CarrierIdentifier?.ToDelimitedString(),
                       PositionInCarrier?.ToDelimitedString(),
                       TrayTypeSac?.ToDelimitedString(),
                       TrayIdentifier?.ToDelimitedString(),
                       PositionInTray?.ToDelimitedString(),
                       Location != null ? string.Join(Configuration.FieldRepeatSeparator, Location.Select(x => x.ToDelimitedString())) : null,
                       ContainerHeight.HasValue ? ContainerHeight.Value.ToString(Consts.NumericFormat, culture) : null,
                       ContainerDiameter.HasValue ? ContainerDiameter.Value.ToString(Consts.NumericFormat, culture) : null,
                       BarrierDelta.HasValue ? BarrierDelta.Value.ToString(Consts.NumericFormat, culture) : null,
                       BottomDelta.HasValue ? BottomDelta.Value.ToString(Consts.NumericFormat, culture) : null,
                       ContainerHeightDiameterDeltaUnits?.ToDelimitedString(),
                       ContainerVolume.HasValue ? ContainerVolume.Value.ToString(Consts.NumericFormat, culture) : null,
                       AvailableSpecimenVolume.HasValue ? AvailableSpecimenVolume.Value.ToString(Consts.NumericFormat, culture) : null,
                       InitialSpecimenVolume.HasValue ? InitialSpecimenVolume.Value.ToString(Consts.NumericFormat, culture) : null,
                       VolumeUnits?.ToDelimitedString(),
                       SeparatorType?.ToDelimitedString(),
                       CapType?.ToDelimitedString(),
                       Additive != null ? string.Join(Configuration.FieldRepeatSeparator, Additive.Select(x => x.ToDelimitedString())) : null,
                       SpecimenComponent?.ToDelimitedString(),
                       DilutionFactor?.ToDelimitedString(),
                       Treatment?.ToDelimitedString(),
                       Temperature?.ToDelimitedString(),
                       HemolysisIndex.HasValue ? HemolysisIndex.Value.ToString(Consts.NumericFormat, culture) : null,
                       HemolysisIndexUnits?.ToDelimitedString(),
                       LipemiaIndex.HasValue ? LipemiaIndex.Value.ToString(Consts.NumericFormat, culture) : null,
                       LipemiaIndexUnits?.ToDelimitedString(),
                       IcterusIndex.HasValue ? IcterusIndex.Value.ToString(Consts.NumericFormat, culture) : null,
                       IcterusIndexUnits?.ToDelimitedString(),
                       FibrinIndex.HasValue ? FibrinIndex.Value.ToString(Consts.NumericFormat, culture) : null,
                       FibrinIndexUnits?.ToDelimitedString(),
                       SystemInducedContaminants != null ? string.Join(Configuration.FieldRepeatSeparator, SystemInducedContaminants.Select(x => x.ToDelimitedString())) : null,
                       DrugInterference != null ? string.Join(Configuration.FieldRepeatSeparator, DrugInterference.Select(x => x.ToDelimitedString())) : null,
                       ArtificialBlood?.ToDelimitedString(),
                       SpecialHandlingCode != null ? string.Join(Configuration.FieldRepeatSeparator, SpecialHandlingCode.Select(x => x.ToDelimitedString())) : null,
                       OtherEnvironmentalFactors != null ? string.Join(Configuration.FieldRepeatSeparator, OtherEnvironmentalFactors.Select(x => x.ToDelimitedString())) : null,
                       ContainerLength?.ToDelimitedString(),
                       ContainerWidth?.ToDelimitedString(),
                       ContainerForm?.ToDelimitedString(),
                       ContainerMaterial?.ToDelimitedString(),
                       ContainerCommonName?.ToDelimitedString()
                       ).TrimEnd(Configuration.FieldSeparator.ToCharArray()));
        }
        /// <summary>
        /// Get table from container identifier and table identifier
        /// </summary>
        /// <param name="containerIdentifier">Container identifier</param>
        /// <param name="tableIdentifier">Table identifier</param>
        /// <returns>Store table</returns>
        public Table GetTable(ContainerIdentifier containerIdentifier, TableIdentifier tableIdentifier)
        {
            // refuse to provide the table if the version check fails, or if it has not been executed
            if (this.initialized == false)
            {
                return(null);
            }

            ContainerDescriptor containerDescriptor = ContainerTableDescriptorProvider.Containers[containerIdentifier];
            TableDescriptor     tableDescriptor     = containerDescriptor.Tables[tableIdentifier];

            if (tableDescriptor.TableType == TableType.Object)
            {
                return(Table.GetObjectTable(
                           containerDescriptor.ContainerName,
                           containerDescriptor.ContainerInitial,
                           tableDescriptor.TableName,
                           tableDescriptor.TableInitial,
                           tableDescriptor.StorageMode));
            }

            if (tableDescriptor.TableType == TableType.Count)
            {
                return(Table.GetCountTable(
                           containerDescriptor.ContainerName,
                           containerDescriptor.ContainerInitial,
                           tableDescriptor.TableName,
                           tableDescriptor.TableInitial,
                           tableDescriptor.StorageMode));
            }

            if (tableDescriptor.TableType == TableType.Feed)
            {
                return(Table.GetFeedTable(
                           containerDescriptor.ContainerName,
                           containerDescriptor.ContainerInitial,
                           tableDescriptor.TableName,
                           tableDescriptor.TableInitial,
                           tableDescriptor.StorageMode,
                           tableDescriptor.MaxFeedSizeInCache));
            }

            if (tableDescriptor.TableType == TableType.RankFeed)
            {
                return(Table.GetRankFeedTable(
                           containerDescriptor.ContainerName,
                           containerDescriptor.ContainerInitial,
                           tableDescriptor.TableName,
                           tableDescriptor.TableInitial,
                           tableDescriptor.StorageMode,
                           tableDescriptor.MaxFeedSizeInCache));
            }

            return(null);
        }
Esempio n. 5
0
 /// <summary>
 /// Add container descriptor for container identifier
 /// </summary>
 /// <param name="containerIdentifier">Container identifier</param>
 /// <param name="containerDescriptor">Container descriptor</param>
 private static void Add(ContainerIdentifier containerIdentifier, ContainerDescriptor containerDescriptor)
 {
     containers.Add(containerIdentifier, containerDescriptor);
 }
        /// <summary>
        /// Get container name for container identifier
        /// </summary>
        /// <param name="containerIdentifier">Container identifier</param>
        /// <returns>Container name</returns>
        public string GetContainerName(ContainerIdentifier containerIdentifier)
        {
            ContainerDescriptor containerDescriptor = ContainerDescriptorProvider.Containers[containerIdentifier];

            return(containerDescriptor.ContainerName);
        }
Esempio n. 7
0
        private void BtnConvert_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(TxtInputFolder.Text))
            {
                MessageBox.Show(
                    "Input folder not found!",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);

                return;
            }

            if (!Directory.Exists(TxtOutFolder.Text))
            {
                MessageBox.Show(
                    "Output folder not found!",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);

                return;
            }

            string[] Files = Directory.GetFiles(TxtInputFolder.Text);

            bool ExportModels = ChkExportModels.Checked;
            bool ExportAnims  = ChkExportAnimations.Checked;
            bool ExportTexs   = ChkExportTextures.Checked;
            bool PrefixNames  = ChkPrefixNames.Checked;

            int Format = CmbFormat.SelectedIndex;

            int FileIndex = 0;

            //TODO: Use Parallel loop for more speed and keep UI responsive
            foreach (string File in Files)
            {
                H3D Data = ContainerIdentifier.IdentifyAndOpen(File);

                if (Data != null)
                {
                    string BaseName = PrefixNames ? Path.GetFileNameWithoutExtension(File) + "_" : string.Empty;

                    BaseName = Path.Combine(TxtOutFolder.Text, BaseName);

                    if (!PrefixNames)
                    {
                        BaseName += Path.DirectorySeparatorChar;
                    }

                    if (ExportModels)
                    {
                        for (int Index = 0; Index < Data.Models.Count; Index++)
                        {
                            string FileName = BaseName + Data.Models[Index].Name;

                            switch (Format)
                            {
                            case 0: new DAE(Data, Index).Save(FileName + ".dae"); break;

                            case 1: new SMD(Data, Index).Save(FileName + ".smd"); break;
                            }
                        }
                    }

                    if (ExportAnims && Data.Models.Count > 0)
                    {
                        for (int Index = 0; Index < Data.SkeletalAnimations.Count; Index++)
                        {
                            string FileName = BaseName + Data.Models[0].Name + "_" + Data.SkeletalAnimations[Index].Name;

                            switch (Format)
                            {
                            case 0: new DAE(Data, 0, Index).Save(FileName + ".dae"); break;

                            case 1: new SMD(Data, 0, Index).Save(FileName + ".smd"); break;
                            }
                        }
                    }

                    if (ExportTexs)
                    {
                        foreach (H3DTexture Tex in Data.Textures)
                        {
                            Tex.ToBitmap().Save(Path.Combine(TxtOutFolder.Text, Tex.Name + ".png"));
                        }
                    }
                }

                float Progress = ++FileIndex;

                Progress = (Progress / Files.Length) * 100;

                ProgressConv.Value = (int)Progress;

                Application.DoEvents();
            }
        }