Ejemplo n.º 1
0
        public virtual ActionResult UndoPendingEdits(string id, string version)
        {
            var package = _packageService.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return(HttpNotFound());
            }

            if (!package.IsOwner(User))
            {
                return(new HttpStatusCodeResult(403, "Forbidden"));
            }

            // To do as much successful cancellation as possible, Will not batch, but will instead try to cancel
            // pending edits 1 at a time, starting with oldest first.
            var pendingEdits = _entitiesContext.Set <PackageEdit>()
                               .Where(pe => pe.PackageKey == package.Key)
                               .OrderBy(pe => pe.Timestamp)
                               .ToList();

            int numOK        = 0;
            int numConflicts = 0;

            foreach (var result in pendingEdits)
            {
                try
                {
                    _entitiesContext.DeleteOnCommit(result);
                    _entitiesContext.SaveChanges();
                    numOK += 1;
                }
                catch (DataException)
                {
                    numConflicts += 1;
                }
            }

            if (numConflicts > 0)
            {
                TempData["Message"] = "Your pending edit has already been completed and could not be canceled.";
            }
            else if (numOK > 0)
            {
                TempData["Message"] = "Your pending edits for this package were successfully canceled.";
            }
            else
            {
                TempData["Message"] = "No pending edits were found for this package. The edits may have already been completed.";
            }

            return(Redirect(Url.Package(id, version)));
        }
 public void CommitChanges()
 {
     if (TraceLogEvents)
     {
         MethodExtensionWrappers.WrapExecutionTracingTime(
             () => entities.SaveChanges(),
             "Save all changes to database");
     }
     else
     {
         entities.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public void CommitTransaction()
 {
     if (_context.ChangeTracker.HasChanges())
     {
         _context.SaveChanges();
     }
     _transaction.Complete();
 }
Ejemplo n.º 4
0
        public virtual async Task <ActionResult> VerifyPackage(bool?listed)
        {
            var currentUser = _userService.FindByUsername(GetIdentity().Name);

            Package package;

            using (Stream uploadFile = await _uploadFileService.GetUploadFileAsync(currentUser.Key))
            {
                if (uploadFile == null)
                {
                    return(HttpNotFound());
                }

                INupkg nugetPackage = CreatePackage(uploadFile);

                // update relevant database tables
                package = _packageService.CreatePackage(nugetPackage, currentUser, commitChanges: false);
                Debug.Assert(package.PackageRegistration != null);

                _packageService.PublishPackage(package, commitChanges: false);

                if (listed == false)
                {
                    _packageService.MarkPackageUnlisted(package, commitChanges: false);
                }

                _autoCuratedPackageCmd.Execute(package, nugetPackage, commitChanges: false);

                // save package to blob storage
                uploadFile.Position = 0;
                await _packageFileService.SavePackageFileAsync(package, uploadFile);

                // commit all changes to database as an atomic transaction
                _entitiesContext.SaveChanges();

                // tell Lucene to update index for the new package
                _indexingService.UpdateIndex();

                // If we're pushing a new stable version of NuGet.CommandLine, update the extracted executable.
                if (package.PackageRegistration.Id.Equals(Constants.NuGetCommandLinePackageId, StringComparison.OrdinalIgnoreCase) &&
                    package.IsLatestStable)
                {
                    await _nugetExeDownloaderService.UpdateExecutableAsync(nugetPackage);
                }
            }

            // delete the uploaded binary in the Uploads container
            await _uploadFileService.DeleteUploadFileAsync(currentUser.Key);

            TempData["Message"] = String.Format(
                CultureInfo.CurrentCulture, Strings.SuccessfullyUploadedPackage, package.PackageRegistration.Id, package.Version);

            return(RedirectToRoute(RouteName.DisplayPackage, new { package.PackageRegistration.Id, package.Version }));
        }
Ejemplo n.º 5
0
 public void CommitChanges()
 {
     _entities.SaveChanges();
 }
Ejemplo n.º 6
0
 public int SaveChanges()
 {
     return(_context.SaveChanges());
 }
 public int Save()
 {
     return(_dbContext.SaveChanges());
 }
Ejemplo n.º 8
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }
Ejemplo n.º 9
0
 public void Save()
 {
     _dbContext.SaveChanges();
 }
 protected void SaveChanges()
 {
     _context.SaveChanges();
 }
Ejemplo n.º 11
0
 public int CommitChanges()
 {
     return(Context.SaveChanges());
 }
Ejemplo n.º 12
0
 public void Commit()
 {
     _context.SaveChanges();
 }
Ejemplo n.º 13
0
        public void SaveChanges()
        {
            //Added By Chander
            // 18-2-2015
            TypesToLog = this.Repository <LogTypes>().GetAll().ToList();
            //get a list of the changes that the user made
            var      logs       = new List <Log>();
            var      properties = new List <LogPropertyChange>();
            int?     userId     = null;
            DateTime now        = DateTime.Now;

            foreach (var entry in _context.ChangeTracker.Entries <object>())
            {
                var entryType = entry.Entity.GetType();
                var typeInfo  = (from i in TypesToLog
                                 where i.Key == entryType.Name || entryType.Name.StartsWith(i.Key + "_")
                                 select i).FirstOrDefault();
                if (typeInfo != null)
                {
                    int    objectId = 0;
                    string clientId = "";
                    int?   parentId = null;
                    Guid   logId    = Guid.NewGuid();
                    var    message  = "";
                    switch (entry.State)
                    {
                    case EntityState.Added:
                        objectId = (int)entry.CurrentValues[typeInfo.IdName];
                        if (!string.IsNullOrWhiteSpace(typeInfo.ClientIdName))
                        {
                            //Value that identifies the object for the user (Name, number, etc)
                            clientId = (entry.CurrentValues[typeInfo.ClientIdName] ?? string.Empty).ToString();
                        }
                        message = string.Format("A new {0} was created ({1})", typeInfo.Name, clientId);
                        if (!string.IsNullOrWhiteSpace(typeInfo.ParentIdName))
                        {
                            //Id of the parent (to be logged in children objects)
                            parentId = (int)entry.CurrentValues[typeInfo.ParentIdName];
                        }
                        break;

                    case EntityState.Deleted:
                        objectId = (int)entry.OriginalValues[typeInfo.IdName];
                        if (!string.IsNullOrWhiteSpace(typeInfo.ClientIdName))
                        {
                            //Value that identifies the object for the user (Name, number, etc)
                            clientId = (entry.OriginalValues[typeInfo.ClientIdName] ?? string.Empty).ToString();
                        }
                        message = string.Format("The {0} {1} was deleted.", typeInfo.Name, clientId);
                        if (!string.IsNullOrWhiteSpace(typeInfo.ParentIdName))
                        {
                            //Id of the parent (to be logged in children objects)
                            parentId = (int)entry.OriginalValues[typeInfo.ParentIdName];
                        }
                        break;

                    case EntityState.Detached:
                        break;

                    case EntityState.Modified:
                        objectId = (int)entry.CurrentValues[typeInfo.IdName];

                        if (!string.IsNullOrWhiteSpace(typeInfo.ParentIdName))
                        {
                            //Id of the parent (to be logged in children objects)
                            parentId = (int)entry.CurrentValues[typeInfo.ParentIdName];
                        }
                        if (!string.IsNullOrWhiteSpace(typeInfo.ClientIdName))
                        {
                            //Value that identifies the object for the user (Name, number, etc)
                            clientId = (entry.OriginalValues[typeInfo.ClientIdName] ?? string.Empty).ToString();
                        }
                        var sb = new StringBuilder();
                        sb.AppendLine(string.Format("The {0} {1} was updated.", typeInfo.Name, clientId));
                        //Go through each of the properties that will be logged
                        foreach (var property in FieldsToLog(entryType))
                        {
                            string originalValue = entry.OriginalValues[property.Key] == null ? "" : entry.OriginalValues[property.Key].ToString();
                            string currentValue  = entry.CurrentValues[property.Key] == null ? "" : entry.CurrentValues[property.Key].ToString();

                            if (originalValue != currentValue)
                            {
                                if (property.LogValues)
                                {
                                    sb.AppendLine(string.Format("-The value of {0} changed from {1} to {2}.", property.Name, originalValue, currentValue));
                                    //Log the changes to each property
                                    Guid LogPropertyChangeId = Guid.NewGuid();
                                    properties.Add(new LogPropertyChange {
                                        LogId = logId, LogPropertyChangeId = LogPropertyChangeId, PropertyKey = property.Key, PreviousValue = originalValue, NewValue = currentValue, EncryptionKey = LogHelper.GetSHA1HashData(logId + LogPropertyChangeId.ToString() + property.Key + originalValue + currentValue)
                                    });
                                }
                                else
                                {
                                    sb.AppendLine(string.Format("-The value of {0} was changed.", property.Name));
                                }
                            }
                        }
                        message = sb.ToString();
                        break;

                    case EntityState.Unchanged:
                        break;

                    default:
                        break;
                    }

                    if (!string.IsNullOrWhiteSpace(message))
                    {
                        logs.Add(new Log
                        {
                            LogId          = logId,
                            ObjectId       = objectId,
                            ParentId       = parentId,
                            TypeKey        = typeInfo.Key,
                            OperationKey   = entry.State.ToString(),
                            UserId         = userId,
                            Representative = false,
                            Message        = message,
                            Created        = now,
                            Processed      = true,
                            SendEmail      = false,
                            WriteAsFile    = false
                        });
                    }
                }
            }

            try
            {
                _context.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                var msg = string.Empty;

                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        msg += string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage) + Environment.NewLine;
                    }
                }

                var fail = new Exception(msg, dbEx);
                //Debug.WriteLine(fail.Message, fail);
                throw fail;
            }


            //write the list of user changes to the log table
            foreach (var log in logs)
            {
                this.Repository <Log>().Add(log);
            }

            foreach (var property in properties)
            {
                this.Repository <LogPropertyChange>().Add(property);
            }

            _context.SaveChanges();
        }