Ejemplo n.º 1
0
        public TableMetadataEntity(TableEntity data)
            : this()
        {
            foreach (var prop in data.GetProperties())
            {
                if (prop.Name.ToLower() == "name")
                    Name = prop.Value.ToString();
                if (prop.Name.ToLower() == "category")
                    Category = prop.Value.ToString();
                if (prop.Name.ToLower() == "description")
                    Description = prop.Value.ToString();
                if (prop.Name.ToLower() == "source")
                    Source = prop.Value.ToString();
                if (prop.Name.ToLower() == "metadataurl")
                    MetadataUrl = prop.Value.ToString();
                if (prop.Name.ToLower() == "entityset")
                    EntitySet = prop.Value.ToString();
                if (prop.Name.ToLower() == "updatefrequency")
                    UpdateFrequency = prop.Value.ToString();
                if (prop.Name.ToLower() == "entitykind")
                    EntityKind = prop.Value.ToString();
                if (prop.Name.ToLower() == "keywords")
                    Keywords = prop.Value.ToString();
                if (prop.Name.ToLower() == "links")
                    Links = prop.Value.ToString();
                if (prop.Name.ToLower() == "periodcovered")
                    PeriodCovered = prop.Value.ToString();
                if (prop.Name.ToLower() == "geographiccoverage")
                    GeographicCoverage = prop.Value.ToString();
                if (prop.Name.ToLower() == "collectionmode")
                    CollectionMode = prop.Value.ToString();

                if (prop.Name.ToLower() == "lastupdatedate")
                {
                    LastUpdateDate = DateTime.Parse(prop.Value.ToString());
                }
                if (prop.Name.ToLower() == "releaseddate")
                {
                    ReleasedDate = DateTime.Parse(prop.Value.ToString());
                }
                if (prop.Name.ToLower() == "expireddate")
                {
                    ExpiredDate = DateTime.Parse(prop.Value.ToString());
                }

                if (prop.Name.ToLower() == "technicalinfo")
                    TechnicalInfo = prop.Value.ToString();
                if (prop.Name.ToLower() == "collectioninstruments")
                    CollectionInstruments = prop.Value.ToString();
                if (prop.Name.ToLower() == "datadictionary_variables")
                    DataDictionary_Variables = prop.Value.ToString();
                if (prop.Name.ToLower() == "additionalinfo")
                    AdditionalInfo = prop.Value.ToString();

                if (prop.Name.ToLower() == "isempty")
                    IsEmpty = prop.Value.ToString().Length == 4;
            }
        }
Ejemplo n.º 2
0
 public TableProcessorParams(TableEntity data)
 {
     foreach (var prop in data.GetProperties())
     {
         if (prop.Name.ToLower() == "sourcetimezonename")
         {
             SourceTimeZoneName = prop.Value.ToString();
         }
         if (prop.Name.ToLower() == "partitionkeypropertyname")
         {
             PartitionKeyPropertyName = prop.Value.ToString();
         }
         if (prop.Name.ToLower() == "RowKeyPropertyName")
         {
             RowKeyPropertyName = prop.Value.ToString();
         }
         if (prop.Name.ToLower() == "tablecolumnsmetadatapartitionkeypropertyname")
         {
             TableColumnsMetadataPartitionKeyPropertyName = prop.Value.ToString();
         }
         if (prop.Name.ToLower() == "tablecolumnsmetadatarowkeypropertyname")
         {
             TableColumnsMetadataRowKeyPropertyName = prop.Value.ToString();
         }
         if (prop.Name.ToLower() == "tablemetadatapartitionkeypropertyname")
         {
             TableMetadataPartitionKeyPropertyName = prop.Value.ToString();
         }
         if (prop.Name.ToLower() == "tablemetadatarowkeypropertyname")
         {
             TableMetadataRowKeyPropertyName = prop.Value.ToString();
         }
         if (prop.Name.ToLower() == "entitymetadatapartitionkeypropertyname")
         {
             EntityMetadataPartitionKeyPropertyName = prop.Value.ToString();
         }
         if (prop.Name.ToLower() == "entitymetadatarowkeypropertyname")
         {
             EntityMetadataRowKeyPropertyName = prop.Value.ToString();
         }
         if (prop.Name.ToLower() == "entityset")
         {
             EntitySet = prop.Value.ToString();
         }
         if (prop.Name.ToLower() == "entitykind")
         {
             EntityKind = prop.Value.ToString();
         }
     }
 }
Ejemplo n.º 3
0
        public TableMetadataEntity(TableEntity data) : this()
        {
            foreach (var prop in data.GetProperties())
            {
                if (prop.Name.ToLower() == "name")
                {
                    Name = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "category")
                {
                    Category = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "description")
                {
                    Description = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "source")
                {
                    Source = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "metadataurl")
                {
                    MetadataUrl = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "entityset")
                {
                    EntitySet = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "updatefrequency")
                {
                    UpdateFrequency = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "entitykind")
                {
                    EntityKind = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "keywords")
                {
                    Keywords = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "links")
                {
                    Links = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "periodcovered")
                {
                    PeriodCovered = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "geographiccoverage")
                {
                    GeographicCoverage = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "collectionmode")
                {
                    CollectionMode = prop.Value.ToString();
                }

                if (prop.Name.ToLower() == "lastupdatedate")
                {
                    LastUpdateDate = DateTime.Parse(prop.Value.ToString());
                }
                if (prop.Name.ToLower() == "releaseddate")
                {
                    ReleasedDate = DateTime.Parse(prop.Value.ToString());
                }
                if (prop.Name.ToLower() == "expireddate")
                {
                    ExpiredDate = DateTime.Parse(prop.Value.ToString());
                }

                if (prop.Name.ToLower() == "technicalinfo")
                {
                    TechnicalInfo = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "collectioninstruments")
                {
                    CollectionInstruments = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "datadictionary_variables")
                {
                    DataDictionary_Variables = prop.Value.ToString();
                }
                if (prop.Name.ToLower() == "additionalinfo")
                {
                    AdditionalInfo = prop.Value.ToString();
                }

                if (prop.Name.ToLower() == "isempty")
                {
                    IsEmpty = prop.Value.ToString().Length == 4;
                }
            }
        }
Ejemplo n.º 4
0
        private void StoreEntity(string entitySetName, string parKeyPropName, string rowKeyPropName, Entity entity)
        {
            var account =
                CloudStorageAccount.Parse(ConfigurationManager.AppSettings["DataConnectionString"]);
            var context = new TableContext(account.TableEndpoint.ToString(), account.Credentials, _parameters)
            {
                RetryPolicy = RetryPolicies.RetryExponential(5, new TimeSpan(0, 0, 1))
            };

            var kmlSnippet = (string)entity[DataLoaderConstants.PropNameKmlSnippet];

            if (kmlSnippet != null && kmlSnippet.Length > 32 * 1024)
            {
                string blobName      = Guid.NewGuid().ToString();
                string containerName = entitySetName.ToLower();
                StoreKmlSnippetAsBlob(containerName, blobName, kmlSnippet);
                entity[DataLoaderConstants.PropNameKmlSnippet] = string.Format(DataLoaderConstants.KmlSnippetReference,
                                                                               containerName, blobName);
            }

            var kmlCoords = (string)entity[DataLoaderConstants.PropNameKmlCoords];

            if (kmlCoords != null && kmlCoords.Length > 32 * 1024)
            {
                string blobName      = Guid.NewGuid().ToString();
                string containerName = entitySetName.ToLower();
                StoreKmlSnippetAsBlob(containerName, blobName, kmlCoords);
                entity[DataLoaderConstants.PropNameKmlCoords] = string.Format(DataLoaderConstants.KmlSnippetReference,
                                                                              containerName, blobName);
            }

            TableEntity tableEntity = null;
            bool        isUpdate    = false;

            if (_parameters != null)
            {
                string parKey;
                object pk = entity[parKeyPropName];
                if (string.IsNullOrEmpty(entity.Number))
                {
                    parKey = (pk != null) ? ConvertToProperPartitionKey(ConvertValueToString(pk)) : entity.Id.ToString();
                }
                else
                {
                    parKey = entity.Number;
                }

                string rowKey = null;
                object rk     = entity[rowKeyPropName];
                if (rowKeyPropName.ToLower() == DataLoaderConstants.ValueUniqueAutoGen)
                {
                    rowKey = Guid.NewGuid().ToString();
                }
                else
                {
                    rowKey = (rk != null) ? ConvertValueToString(entity[rowKeyPropName]) : Guid.NewGuid().ToString();
                }


                //try to load entity from storage
                if (_overwriteMode == TableOverwriteMode.Add || _overwriteMode == TableOverwriteMode.Update)
                {
                    tableEntity = LoadEntity(context, entitySetName, rowKeyPropName, rowKey, rk, parKeyPropName, parKey, pk);
                    if (tableEntity != null && _overwriteMode == TableOverwriteMode.Add)
                    {
                        throw new EntityAlreadyExistsException(entitySetName, rowKeyPropName, rowKey, parKeyPropName,
                                                               parKey);
                    }
                    if (tableEntity != null)
                    {
                        tableEntity.UpdateEntity(entity);
                        isUpdate = true;
                    }
                }
                //if not found, create new
                if (tableEntity == null)
                {
                    tableEntity = new TableEntity(entity, parKey, rowKey);
                }
            }
            else
            {
                tableEntity = new TableEntity(entity);
            }

            if (!isUpdate)
            {
                context.AddObject(entitySetName, tableEntity);
            }
            else
            {
                context.UpdateObject(tableEntity);
            }

            try
            {
                context.SaveChanges();
            }
            catch (StorageClientException e)
            {
                if (e.ErrorCode == StorageErrorCode.ResourceAlreadyExists && e.StatusCode == HttpStatusCode.Conflict)
                {
                    throw new DuplicateEntityException(tableEntity.ToString(), e);
                }
            }
            catch (DataServiceRequestException e)
            {
                if (e.InnerException != null &&
                    ((DataServiceClientException)e.InnerException).StatusCode == (int)HttpStatusCode.Conflict)
                {
                    throw new DuplicateEntityException(tableEntity.ToString(), e);
                }
            }
        }
        private void StoreEntity(string entitySetName, string parKeyPropName, string rowKeyPropName, Entity entity)
        {
            var account =
                CloudStorageAccount.Parse(ConfigurationManager.AppSettings["DataConnectionString"]);
            var context = new TableContext(account.TableEndpoint.ToString(), account.Credentials, _parameters)
                              {
                                  RetryPolicy = RetryPolicies.RetryExponential(5, new TimeSpan(0, 0, 1))
                              };

            var kmlSnippet = (string)entity[DataLoaderConstants.PropNameKmlSnippet];
            if (kmlSnippet != null && kmlSnippet.Length > 32 * 1024)
            {
                string blobName = Guid.NewGuid().ToString();
                string containerName = entitySetName.ToLower();
                StoreKmlSnippetAsBlob(containerName, blobName, kmlSnippet);
                entity[DataLoaderConstants.PropNameKmlSnippet] = string.Format(DataLoaderConstants.KmlSnippetReference,
                                                                               containerName, blobName);
            }

            var kmlCoords = (string)entity[DataLoaderConstants.PropNameKmlCoords];
            if (kmlCoords != null && kmlCoords.Length > 32 * 1024)
            {
                string blobName = Guid.NewGuid().ToString();
                string containerName = entitySetName.ToLower();
                StoreKmlSnippetAsBlob(containerName, blobName, kmlCoords);
                entity[DataLoaderConstants.PropNameKmlCoords] = string.Format(DataLoaderConstants.KmlSnippetReference,
                                                                              containerName, blobName);
            }

            TableEntity tableEntity = null;
            bool isUpdate = false;
            if (_parameters != null)
            {
                string parKey;
                object pk = entity[parKeyPropName];
                if (string.IsNullOrEmpty(entity.Number))
                {
                    parKey = (pk != null) ? ConvertToProperPartitionKey(ConvertValueToString(pk)) : entity.Id.ToString();
                }
                else
                {
                    parKey = entity.Number;
                }

                string rowKey = null;
                object rk = entity[rowKeyPropName];
                if (rowKeyPropName.ToLower() == DataLoaderConstants.ValueUniqueAutoGen)
                {
                    rowKey = Guid.NewGuid().ToString();
                }
                else
                {
                    rowKey = (rk != null) ? ConvertValueToString(entity[rowKeyPropName]) : Guid.NewGuid().ToString();
                }

                //try to load entity from storage
                if (_overwriteMode == TableOverwriteMode.Add || _overwriteMode == TableOverwriteMode.Update)
                {
                    tableEntity = LoadEntity(context, entitySetName, rowKeyPropName, rowKey, rk, parKeyPropName, parKey, pk);
                    if (tableEntity != null && _overwriteMode == TableOverwriteMode.Add)
                        throw new EntityAlreadyExistsException(entitySetName, rowKeyPropName, rowKey, parKeyPropName,
                                                               parKey);
                    if (tableEntity != null)
                    {
                        tableEntity.UpdateEntity(entity);
                        isUpdate = true;
                    }
                }
                //if not found, create new
                if (tableEntity == null)
                    tableEntity = new TableEntity(entity, parKey, rowKey);
            }
            else
            {
                tableEntity = new TableEntity(entity);
            }

            if (!isUpdate)
                context.AddObject(entitySetName, tableEntity);
            else
                context.UpdateObject(tableEntity);

            try
            {
                context.SaveChanges();
            }
            catch (StorageClientException e)
            {
                if (e.ErrorCode == StorageErrorCode.ResourceAlreadyExists && e.StatusCode == HttpStatusCode.Conflict)
                {
                    throw new DuplicateEntityException(tableEntity.ToString(), e);
                }
            }
            catch (DataServiceRequestException e)
            {
                if (e.InnerException != null &&
                    ((DataServiceClientException)e.InnerException).StatusCode == (int)HttpStatusCode.Conflict)
                {
                    throw new DuplicateEntityException(tableEntity.ToString(), e);
                }
            }
        }