@@ -115,56 +115,64 @@ private static string CalculateContentHash(TipModel tip)
115115 // Entity doesn't exist or other error - treat as not found
116116 return null ;
117117 }
118- }
119-
120- public static async Task UploadToTableStorage ( TipModel tip , string connectionString )
118+ } public static async Task < UploadStatus > UploadToTableStorage ( TipModel tip , string connectionString )
121119 {
122- var serviceClient = new TableServiceClient ( connectionString ) ;
123- var tableName = "Content" ;
124- await serviceClient . CreateTableIfNotExistsAsync ( tableName ) ;
125- var tableClient = serviceClient . GetTableClient ( tableName ) ;
126-
127- var partitionKey = tip . Category . ToLowerInvariant ( ) ;
128- var rowKey = ! string . IsNullOrWhiteSpace ( tip . UrlSlug ) ? tip . UrlSlug : tip . FileName ;
129-
130- // Calculate content hash for change detection
131- var contentHash = CalculateContentHash ( tip ) ;
132-
133- // Check if entity already exists
134- var existingEntity = await GetExistingContent ( tableClient , partitionKey , rowKey ) ;
135-
136- if ( existingEntity != null && existingEntity . ContentHash == contentHash )
120+ try
137121 {
138- Console . WriteLine ( $ "Skipping { tip . FileName } - no changes detected") ;
139- return ;
140- }
122+ var serviceClient = new TableServiceClient ( connectionString ) ;
123+ var tableName = "Content" ;
124+ await serviceClient . CreateTableIfNotExistsAsync ( tableName ) ;
125+ var tableClient = serviceClient . GetTableClient ( tableName ) ;
141126
142- var entity = new ContentEntity
143- {
144- PartitionKey = partitionKey ,
145- RowKey = rowKey ,
146- Slug = tip . UrlSlug ,
147- Title = tip . Title ,
148- Category = tip . Category ,
149- Tags = string . Join ( "," , tip . Tags ) ,
150- Difficulty = tip . Difficulty ,
151- Author = tip . Author ,
152- PublishedDate = DateTime . SpecifyKind ( tip . PublishedDate , DateTimeKind . Utc ) ,
153- Description = tip . Description ,
154- Content = tip . Content ,
155- FileName = tip . FileName ,
156- ContentHash = contentHash
157- } ;
158-
159- await tableClient . UpsertEntityAsync ( entity ) ;
160-
161- if ( existingEntity == null )
162- {
163- Console . WriteLine ( $ "Uploaded new content: { tip . FileName } ") ;
127+ var partitionKey = tip . Category . ToLowerInvariant ( ) ;
128+ var rowKey = ! string . IsNullOrWhiteSpace ( tip . UrlSlug ) ? tip . UrlSlug : tip . FileName ;
129+
130+ // Calculate content hash for change detection
131+ var contentHash = CalculateContentHash ( tip ) ;
132+
133+ // Check if entity already exists
134+ var existingEntity = await GetExistingContent ( tableClient , partitionKey , rowKey ) ;
135+
136+ if ( existingEntity != null && existingEntity . ContentHash == contentHash )
137+ {
138+ Console . WriteLine ( $ "Skipping { tip . FileName } - no changes detected") ;
139+ return UploadStatus . Unchanged ;
140+ }
141+
142+ var entity = new ContentEntity
143+ {
144+ PartitionKey = partitionKey ,
145+ RowKey = rowKey ,
146+ Slug = tip . UrlSlug ,
147+ Title = tip . Title ,
148+ Category = tip . Category ,
149+ Tags = string . Join ( "," , tip . Tags ) ,
150+ Difficulty = tip . Difficulty ,
151+ Author = tip . Author ,
152+ PublishedDate = DateTime . SpecifyKind ( tip . PublishedDate , DateTimeKind . Utc ) ,
153+ Description = tip . Description ,
154+ Content = tip . Content ,
155+ FileName = tip . FileName ,
156+ ContentHash = contentHash
157+ } ;
158+
159+ await tableClient . UpsertEntityAsync ( entity ) ;
160+
161+ if ( existingEntity == null )
162+ {
163+ Console . WriteLine ( $ "Uploaded new content: { tip . FileName } ") ;
164+ return UploadStatus . Added ;
165+ }
166+ else
167+ {
168+ Console . WriteLine ( $ "Updated changed content: { tip . FileName } ") ;
169+ return UploadStatus . Updated ;
170+ }
164171 }
165- else
172+ catch ( Exception ex )
166173 {
167- Console . WriteLine ( $ "Updated changed content: { tip . FileName } ") ;
174+ Console . WriteLine ( $ "Failed to upload { tip . FileName } : { ex . Message } ") ;
175+ return UploadStatus . Failed ;
168176 }
169177 }
170178 }
0 commit comments