Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c9121169

Přidáno uživatelem aitakaitov před více než 1 rok

Added rollback of tag addition/removal

Zobrazit rozdíly:

Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
239 239
                // The annotation has been modified and we need to either add the new tag or remove the tag
240 240
                if (annotation.ModifiedType != EModified.NONE)
241 241
                {
242
                    if (annotation.ModifiedType == EModified.ADDED)
242
                    // Try to add or remove the tag
243
                    try
243 244
                    {
244

  
245
                        AnnotationTagGeneric lastModifiedTag = isFinal ? context.FinalAnnotationTags.Where(at => at.Id == annotation.LastModifiedTagId).First() :
246
                            context.AnnotationTags.Where(at => at.Id == annotation.LastModifiedTagId).First();
247

  
248
                        var result = htmlService.PartialPreprocessHTMLAddTag(docToRender, documentContent.Content, lastModifiedTag, tags, cachedInfoToReturn);
249
                        docToRender = result.Item1;
250
                        cachedInfoToReturn = result.Item2;
245
                        if (annotation.ModifiedType == EModified.ADDED)
246
                        {
247

  
248
                            AnnotationTagGeneric lastModifiedTag = isFinal ? context.FinalAnnotationTags.Where(at => at.Id == annotation.LastModifiedTagId).First() :
249
                                context.AnnotationTags.Where(at => at.Id == annotation.LastModifiedTagId).First();
250

  
251
                            var result = htmlService.PartialPreprocessHTMLAddTag(docToRender, documentContent.Content, lastModifiedTag, tags, cachedInfoToReturn);
252
                            docToRender = result.Item1;
253
                            cachedInfoToReturn = result.Item2;
254
                        }
255
                        else if (annotation.ModifiedType == EModified.REMOVED)
256
                        {
257
                            var result = htmlService.PartialPreprocessHTMLRemoveTag(docToRender, documentContent.Content, new AnnotationTag() { Id = annotation.LastModifiedTagId.Value }, tags, cachedInfoToReturn);
258
                            docToRender = result.Item1;
259
                            cachedInfoToReturn = result.Item2;
260
                        }
261

  
262
                        annotation.ModifiedType = EModified.NONE;
263
                        annotation.CachedStartPositions = JsonConvert.SerializeObject(cachedInfoToReturn.TagStartPositions);
264
                        annotation.CachedLengths = JsonConvert.SerializeObject(cachedInfoToReturn.TagStartLengths);
265
                        annotation.CachedClosingPositions = JsonConvert.SerializeObject(cachedInfoToReturn.TagClosingPositions);
266
                        annotation.CachedClosingLengths = JsonConvert.SerializeObject(cachedInfoToReturn.TagClosingLengths);
267
                        annotation.CachedDocumentHTML = docToRender;
268
                        annotation.CachedCSS = JsonConvert.SerializeObject(cachedInfoToReturn.TagInstanceCSS);
269
                        context.SaveChanges();
251 270
                    }
252
                    else if (annotation.ModifiedType == EModified.REMOVED)
271
                    catch (Exception ex)
253 272
                    {
254
                        var result = htmlService.PartialPreprocessHTMLRemoveTag(docToRender, documentContent.Content, new AnnotationTag() { Id = annotation.LastModifiedTagId.Value }, tags, cachedInfoToReturn);
255
                        docToRender = result.Item1;
256
                        cachedInfoToReturn = result.Item2;
273
                        // If the adding or removing fails, then undo the changes, make the selection invalid and revert to previous state
274
                        if (isFinal)
275
                        {
276
                            FinalAnnotationTag fat = context.FinalAnnotationTags.Where(at => at.Id == annotation.LastModifiedTagId).First();
277
                            context.FinalAnnotationTags.Remove(fat);
278
                        }
279
                        else 
280
                        {
281
                            AnnotationTag at = context.AnnotationTags.Where(at => at.Id == annotation.LastModifiedTagId).First();
282
                            context.AnnotationTags.Remove(at);
283
                        }
284

  
285
                        annotation.ModifiedType = EModified.NONE;
286
                        context.SaveChanges();
287

  
288
                        throw new InvalidOperationException("The selection is invalid.");
257 289
                    }
258

  
259
                    annotation.ModifiedType = EModified.NONE;
260
                    annotation.CachedStartPositions = JsonConvert.SerializeObject(cachedInfoToReturn.TagStartPositions);
261
                    annotation.CachedLengths = JsonConvert.SerializeObject(cachedInfoToReturn.TagStartLengths);
262
                    annotation.CachedClosingPositions = JsonConvert.SerializeObject(cachedInfoToReturn.TagClosingPositions);
263
                    annotation.CachedClosingLengths = JsonConvert.SerializeObject(cachedInfoToReturn.TagClosingLengths);
264
                    annotation.CachedDocumentHTML = docToRender;
265
                    annotation.CachedCSS = JsonConvert.SerializeObject(cachedInfoToReturn.TagInstanceCSS);
266
                    context.SaveChanges();
267 290
                }
268 291
            }
269 292

  

Také k dispozici: Unified diff