Exemple #1
0
        public virtual void SetDocumentStorage(Sungero.Docflow.Server.AsyncHandlerInvokeArgs.SetDocumentStorageInvokeArgs args)
        {
            int documentId = args.DocumentId;
            int storageId  = args.StorageId;

            Logger.DebugFormat("SetDocumentStorage: start set storage to document {0}.", documentId);

            var document = OfficialDocuments.GetAll(d => d.Id == documentId).FirstOrDefault();

            if (document == null)
            {
                Logger.DebugFormat("SetDocumentStorage: not found document with id {0}.", documentId);
                return;
            }

            var storage = Storages.GetAll(s => s.Id == storageId).FirstOrDefault();

            if (storage == null)
            {
                Logger.DebugFormat("SetDocumentStorage: not found storage with id {0}.", storageId);
                return;
            }

            if (Locks.GetLockInfo(document).IsLockedByOther)
            {
                Logger.DebugFormat("SetDocumentStorage: cannot change storage, document {0} is locked.", documentId);
                args.Retry = true;
                return;
            }
            try
            {
                foreach (var version in document.Versions.Where(v => !Equals(v.Body.Storage, storage) || !Equals(v.PublicBody.Storage, storage)))
                {
                    if (!Equals(version.Body.Storage, storage))
                    {
                        version.Body.SetStorage(storage);
                    }

                    if (!Equals(version.PublicBody.Storage, storage))
                    {
                        version.PublicBody.SetStorage(storage);
                    }
                }

                document.Storage = storage;

                ((Domain.Shared.IExtendedEntity)document).Params[Docflow.PublicConstants.OfficialDocument.DontUpdateModified] = true;
                document.Save();
            }
            catch (Exception ex)
            {
                Logger.Error("SetDocumentStorage: cannot change storage.", ex);
                args.Retry = true;
                return;
            }
            Logger.DebugFormat("SetDocumentStorage: set storage to document {0} successfully.", documentId);
        }