Ejemplo n.º 1
0
 IEnumerable <Event> IDomainEventProvider.GetUncommittedChanges()
 {
     lock (_locker.GetLock(Id.ToString()))
     {
         return(_changes);
     }
 }
Ejemplo n.º 2
0
        public string Get(string project, string submission, string supplement, string study, string report)
        {
            DeleteReportZipPackage(project, submission, supplement, study, report);

            var userName   = Users.GetCurrentUserName();
            var reportPath = string.Format(@"\\{0}\Output Files\PKView\{1}\{2}\{3}\{4}\{5}\{6}",
                                           iPortalApp.AppServerName, userName, project, submission, supplement, study, report);

            // If report folder exists, zip the contents and return them
            if (Directory.Exists(reportPath))
            {
                lock (zipLocks.GetLock(reportPath))
                {
                    // Create a memory stream for the zip file
                    using (var memoryStream = new MemoryStream())
                    {
                        // Create a zip archive in the memory stream
                        using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                        {
                            // Add the report folder to the archive
                            archive.CreateEntriesFromDirectory(reportPath);
                        }

                        using (var fileStream = new FileStream(reportPath + ".zip", FileMode.Create))
                        {
                            memoryStream.Seek(0, SeekOrigin.Begin);
                            memoryStream.CopyTo(fileStream);
                        }

                        //// Set the read cursor at the beginning of the memory stream
                        //memoryStream.Seek(0, SeekOrigin.Begin);

                        //// Set the memory stream as the content for the response
                        //var result = new HttpResponseMessage(HttpStatusCode.OK);
                        //result.Content = new ByteArrayContent(memoryStream.GetBuffer());
                        ////result.Content = new StreamContent(memoryStream);

                        ////specify the content type
                        //result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");

                        ////we used attachment to force download
                        //result.Content.Headers.ContentDisposition =
                        //    new ContentDispositionHeaderValue("attachment") { FileName = report + ".zip" };
                        //return result;
                        return("yes");
                    }
                }
            }

            return("Report not exist,please generate it.");
        }
Ejemplo n.º 3
0
        public HttpResponseMessage Get(string repository, string filename, string subfolder = "")
        {
            try
            {
                var result = new HttpResponseMessage(HttpStatusCode.OK);

                // Create a memory stream to dump the file to
                MemoryStream virtualStream = null;

                // Replace [USER] by the user folder in repository path if present
                string repositoryPath = this.GetRepositoryPath(repository);

                // Use a lock to control mutual exclusion on file access
                lock (filelocks.GetLock(repository + subfolder + filename))
                {
                    // Copy the file to the virtual stream
                    using (var fileStream = new FileStream(
                               String.Format("{0}\\{1}\\{2}", repositoryPath,
                                             subfolder, filename), FileMode.Open, FileAccess.Read))
                    {
                        virtualStream = new MemoryStream((int)fileStream.Length);
                        fileStream.CopyTo(virtualStream);
                    }
                }

                // Set the read cursor at the beginning of the memory stream
                virtualStream.Seek(0, SeekOrigin.Begin);

                // Set the memory stream as the content for the response
                result.Content = new StreamContent(virtualStream);

                //a text file is actually an octet-stream (pdf, etc)
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                //we used attachment to force download
                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = filename
                };
                return(result);
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }
Ejemplo n.º 4
0
        public void Save(AggregateRoot aggregate, int expectedVersion)
        {
            if (aggregate.GetUncommittedChanges().Any())
            {
                lock (_locker.GetLock(aggregate.Id.ToString()))
                {
                    var item = new T();

                    if (expectedVersion != -1)
                    {
                        item = GetById(aggregate.Id).Result;

                        if (item.Version != expectedVersion)
                        {
                            throw new ConcurrencyException(string.Format("Aggregate {0} has been previously modified", item.Id));
                        }
                    }

                    _storage.Save(aggregate).Wait();
                }
            }
        }
Ejemplo n.º 5
0
        public void Save(T aggregate, int?expectedVersion = null)
        {
            lock (_locker.GetLock(aggregate.Id.ToString()))
            {
                IDomainEventProvider domainEventProvider = (IDomainEventProvider)aggregate;
                var eventList = domainEventProvider.GetUncommittedChanges().ToList();
                eventList.ForEach(e =>
                {
                    if (e.Id == Guid.Empty)
                    {
                        e.Id = aggregate.Id;
                    }
                    if (e.Id == Guid.Empty)
                    {
                        throw new AggregateOrEventMissingIdException(
                            aggregate.GetType(), e.GetType());
                    }
                });

                _eventStore.Save(aggregate.Id, eventList);
                domainEventProvider.MarkChangesAsCommitted();
            }
        }