コード例 #1
0
        public async Task <string> AddSharedFile(IFormFile file, string organizationID)
        {
            var expirationDate = DateTimeOffset.Now.AddDays(-AppConfig.DataRetentionInDays);
            var expiredFiles   = RemotelyContext.SharedFiles.Where(x => x.Timestamp < expirationDate);

            RemotelyContext.RemoveRange(expiredFiles);

            byte[] fileContents;
            using (var stream = file.OpenReadStream())
            {
                using var ms = new MemoryStream();
                await stream.CopyToAsync(ms);

                fileContents = ms.ToArray();
            }
            var newEntity = RemotelyContext.Add(new SharedFile()
            {
                FileContents   = fileContents,
                FileName       = file.FileName,
                ContentType    = file.ContentType,
                OrganizationID = organizationID
            });
            await RemotelyContext.SaveChangesAsync();

            return(newEntity.Entity.ID);
        }
コード例 #2
0
ファイル: DataService.cs プロジェクト: remote3993/remotely
        public void CleanupOldRecords()
        {
            if (AppConfig.DataRetentionInDays > 0)
            {

                var expirationDate = DateTimeOffset.Now - TimeSpan.FromDays(AppConfig.DataRetentionInDays);

                var eventLogs = RemotelyContext.EventLogs
                                    .Where(x => x.TimeStamp < expirationDate);

                RemotelyContext.RemoveRange(eventLogs);

                var commandResults = RemotelyContext.CommandResults
                                        .Where(x => x.TimeStamp < expirationDate);

                RemotelyContext.RemoveRange(commandResults);

                var sharedFiles = RemotelyContext.SharedFiles
                                        .Where(x => x.Timestamp < expirationDate);

                RemotelyContext.RemoveRange(sharedFiles);

                RemotelyContext.SaveChanges();
            }
        }