Exemplo n.º 1
0
        public void StoreVersion(IResource resource, string userName, string reason, Guid workSpaceId)
        {
            if (workSpaceId == Guid.Empty)
            {
                lock (LockObject)
                {
                    var old = _catalogue.GetResource(Guid.Empty, resource.ResourceID);
                    if (old != null)
                    {
                        var versions = GetVersions(resource.ResourceID).FirstOrDefault();
                        old.VersionInfo = _versionStrategy.GetCurrentVersion(resource, versions == null? null :versions.VersionInfo, userName, reason);
                        var folderPath = GetVersionFolderFromResource(resource);

                        var fileName = string.Format("{0}_{1}_{2}_{3}.xml", old.VersionInfo.VersionId, old.VersionInfo.VersionNumber, GetDateString(old.VersionInfo.DateTimeStamp), reason);
                        if (!_file.Exists(Path.Combine(folderPath, fileName))) //todo: remove this and stop save on workspace
                        {
                            var sourceFile = Path.Combine(GetFolderFromResource(resource), old.ResourceName) + ".xml";
                            if (_file.Exists(sourceFile))
                            {
                                _file.Copy(sourceFile, Path.Combine(folderPath, fileName));
                            }
                        }

                        resource.VersionInfo = _versionStrategy.GetNextVersion(resource, old, userName, reason);
                    }
                }
            }
        }
        public void StoreVersion(IResource resource, string userName, string reason, Guid workSpaceId, string resourcePath)
        {
            if (workSpaceId == Guid.Empty)
            {
                if (string.IsNullOrEmpty(userName))
                {
                    userName = Thread.CurrentPrincipal.Identity.Name;
                }

                lock (LockObject)
                {
                    var old = _catalogue.GetResource(Guid.Empty, resource.ResourceID);
                    if (old != null)
                    {
                        var versions = GetVersions(resource.ResourceID).FirstOrDefault();
                        old.VersionInfo = _versionStrategy.GetCurrentVersion(resource, versions?.VersionInfo, userName, reason);
                        var folderPath = GetVersionFolderFromResource(old.GetResourcePath(workSpaceId));

                        var fileName = $"{old.VersionInfo.VersionId}_{old.VersionInfo.VersionNumber}_{GetDateString(old.VersionInfo.DateTimeStamp)}_{reason}.xml";
                        if (!_file.Exists(Path.Combine(folderPath, fileName))) //todo: remove this and stop save on workspace
                        {
                            var sourceFile = Path.Combine(GetFolderFromResource(old.GetResourcePath(workSpaceId)), old.ResourceName) + ".xml";
                            if (_file.Exists(sourceFile))
                            {
                                _file.Copy(sourceFile, Path.Combine(folderPath, fileName));
                            }
                        }

                        resource.VersionInfo = _versionStrategy.GetNextVersion(resource, old, userName, reason);
                    }
                }
            }
        }
        public void StoreVersion(IResource resource, string userName, string reason, Guid workSpaceId, string resourcePath)
        {
            var versionFolder = GetVersionFolderPath(resource.ResourceID.ToString());
            var _userName     = userName;

            if (workSpaceId == Guid.Empty)
            {
                if (string.IsNullOrEmpty(_userName))
                {
                    _userName = Thread.CurrentPrincipal.Identity.Name;
                }

                lock (LockObject)
                {
                    var old = _catalogue.GetResource(Guid.Empty, resource.ResourceID);
                    if (old == null)
                    {
                        return;
                    }
                    var versions = GetVersions(resource.ResourceID).FirstOrDefault();
                    old.VersionInfo = _versionStrategy.GetCurrentVersion(resource, versions?.VersionInfo, _userName, reason);

                    var fileName = $"{old.VersionInfo.VersionNumber}_{GetDateString(old.VersionInfo.DateTimeStamp)}_{reason}.bite";
                    if (!_file.Exists(_filePath.Combine(versionFolder, fileName)))
                    {
                        var sourceFile = _filePath.Combine(GetFolderFromResource(old.GetResourcePath(workSpaceId)), old.ResourceName) + ".bite";
                        if (_file.Exists(sourceFile))
                        {
                            _directory.CreateIfNotExists(versionFolder);
                            _file.Copy(sourceFile, _filePath.Combine(versionFolder, fileName));
                        }
                    }

                    resource.VersionInfo = _versionStrategy.GetNextVersion(resource, old, _userName, reason);
                }
            }
        }