public void Test_CreateUpdateDeleteContentFile() { IUserBasic userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager); CMSSection section = Test_CMSSections.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, null, this.Random); CMSThread thread = Test_CMSThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, section, this.Random); CMSContent content = Test_CMSContents.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic.UserId, thread, this.Random); CMSFileManager manager = new CMSFileManager(this.DataStore); CMSFile record = CreateContentFile(this.DataStore, this.Application.ApplicationId, userBasic, content, this.Random); CMSFile recordToCompare; for (int i = 0; i < this.DefaultUpdateTestIterations; i++) { PopulateWithRandomValues(record, this.DummyDataManager, this.Random); recordToCompare = record; manager.Update(record); record = manager.GetFile(record.CMSFileId); string errors = string.Empty; // TODO (Roman): relax datetime comparisons Assert.IsTrue(DebugUtility.ArePropertyValuesEqual(record, recordToCompare, out errors), errors); Trace.WriteLine("Update test successfull."); } Test_CMSSections.Delete(this.DataStore, section); // deleting the section should also delete the file Assert.IsNull(manager.GetFile(record.CMSFileId)); }
public void Test_CreateTempFileAndMove() { IUserBasic userBasic = Test_WorkmateMembershipProvider.CreateUser(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, this.DummyDataManager); CMSSection section = Test_CMSSections.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, null, this.Random); CMSThread thread = Test_CMSThreads.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, section, this.Random); CMSContent content = Test_CMSContents.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application, userBasic.UserId, thread, this.Random); CMSFileManager manager = new CMSFileManager(this.DataStore); ASCIIEncoding encoding = new ASCIIEncoding(); string contentString = "Some String " + this.Random.Next(1000000, 10000000); CMSFile tempFile = CreateTemporaryFile(this.DataStore, this.Application.ApplicationId, userBasic, encoding.GetBytes(contentString), this.Random); int fileId; manager.MoveTemporaryFileToFiles(tempFile.CMSFileId, content.CMSContentId, "FileName", "FriendlyFileName", null, out fileId); CMSFile file = manager.GetFile(fileId); Assert.IsNotNull(file); // TODO (Roman): do all the value asserts Assert.AreEqual(contentString, encoding.GetString(file.Content)); // TODO (Roman): check that tempFile doesn't exist any more Test_CMSSections.Delete(this.DataStore, section); // deleting the section should also delete the file Assert.IsNull(manager.GetFile(file.CMSFileId)); }
internal static CMSFile CreateContentFile(IDataStore dataStore, int applicationId, IUserBasic fileOwner, CMSContent content, Random random) { CMSFileManager manager = new CMSFileManager(dataStore); CMSFile file = new CMSFile(applicationId, fileOwner, FileType.PostAttachment); file.ContentId = content.CMSContentId; ASCIIEncoding encoding = new ASCIIEncoding(); string contentString = "Some String " + random.Next(1000000, 10000000); file.CMSHeight = random.Next(10, 1000); file.CMSWidth = random.Next(10, 1000); file.Content = encoding.GetBytes(contentString); file.ContentSize = file.Content.Length; file.ContentType = "TEXT " + random.Next(1000, 10000); file.FileName = "Some Name " + random.Next(1000000, 10000000); file.FriendlyFileName = "Some Name " + random.Next(1000000, 10000000); file.IsTemporary = false; BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Create(file); Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status); CMSFile dsFile = manager.GetFile(file.CMSFileId); Assert.IsNotNull(dsFile); Assert.AreEqual(contentString, encoding.GetString(dsFile.Content)); Assert.AreEqual(file.ContentId, content.CMSContentId); return(dsFile); }
public ArticleImage(int applicationId, UserBasic owner) { this._CMSFile = new CMSFile(applicationId, owner, FileType.ArticleImage); this.OwnerUserId = owner.UserId; this.Tags = new List <string>(); }
internal static void Delete(IDataStore dataStore, CMSFile file) { CMSFileManager manager = new CMSFileManager(dataStore); BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Delete(file); Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status); Assert.IsNull(manager.GetFile(file.CMSFileId)); Trace.WriteLine("Successfully deleted file " + file.FileName); }
internal static void PopulateWithRandomValues(CMSFile record, DummyDataManager dtm, Random random) { ASCIIEncoding encoding = new ASCIIEncoding(); string contentString = "Some String " + random.Next(1000000, 10000000); record.CMSHeight = random.Next(10, 1000); record.CMSWidth = random.Next(10, 1000); record.Content = encoding.GetBytes(contentString); record.ContentSize = record.Content.Length; record.ContentType = "TEXT " + random.Next(1000, 10000); record.FileName = "Some Name " + random.Next(1000000, 10000000); record.FriendlyFileName = "Some Name " + random.Next(1000000, 10000000); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Create(CMSFile cmsFile, string[] tags) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsFile); if (businessObjectActionReport.ValidationResult.IsValid) { int num = -1; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_Files_Insert(cmsFile.ApplicationId, cmsFile.CMSUserId, cmsFile.CMSFileType, cmsFile.FileName, cmsFile.Content, cmsFile.ContentType, cmsFile.ContentSize, cmsFile.FriendlyFileName, cmsFile.CMSHeight, cmsFile.CMSWidth, cmsFile.ContentId, tags); } } catch (Exception ex) { _Log.Error("Error at cms_Files_Insert", ex); throw new DataStoreException(ex, true); } if (num > 0) { cmsFile.CMSFileId = num; cmsFile.DateCreatedUtc = DateTime.UtcNow; } else if (num == -501) {// this is a special condition for system profile images to ensure thread safety on inserts businessObjectActionReport.Status = DataRepositoryActionStatus.UniqueKeyConstraint; } else { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.ErrorFormat("CMSFile was not inserted at the database (ErrorCode: {0}).", num); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSFile {0} was not inserted at the database because the validation failed.\nReport: {1}", cmsFile.CMSFileId , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
public ArticleImage GetArticleImage(int imageId) { ArticleImage articleImage = null; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { CMSFile file = dataStoreContext.cms_Files_Get(imageId, Contracts.CMS.FileType.ArticleImage); if (file != null) { articleImage = new ArticleImage(file, dataStoreContext.cms_Tags_GetByFileId(imageId).ToList()); } } } catch (SqlException ex) { _Log.Error("Error at cms_Files_Get", ex); throw new DataStoreException(ex, true); } return(articleImage); }
public ArticleImage GetTemporaryArticleImage(int imageId) { ArticleImage articleImage = null; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { CMSFile file = dataStoreContext.cms_FilesTemp_Get(imageId, FileType.ArticleImage); if (file != null) { articleImage = new ArticleImage(file); } } } catch (SqlException ex) { _Log.Error("Error at cms_FilesTemp_Get", ex); throw new DataStoreException(ex, true); } return(articleImage); }
internal static CMSFile CreateTemporaryFile(IDataStore dataStore, int applicationId, IUserBasic fileOwner, byte[] content, Random random) { CMSFileManager manager = new CMSFileManager(dataStore); CMSFile file = new CMSFile(applicationId, fileOwner, FileType.PostAttachment); file.IsTemporary = true; file.CMSHeight = random.Next(10, 1000); file.CMSWidth = random.Next(10, 1000); file.Content = content; file.ContentSize = file.Content.Length; file.ContentType = "TEXT " + random.Next(1000, 10000); file.FileName = "Some Name " + random.Next(1000000, 10000000); file.FriendlyFileName = "Some Name " + random.Next(1000000, 10000000); file.IsTemporary = false; BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.CreateTemporaryFile(file); Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status); return(file); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Update(CMSFile cmsFile, string[] tags) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsFile); if (businessObjectActionReport.ValidationResult.IsValid) { int num = 0; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_Files_Update(cmsFile.CMSFileId, cmsFile.CMSUserId, cmsFile.CMSFileType, cmsFile.FileName , cmsFile.Content, cmsFile.ContentType, cmsFile.ContentSize, cmsFile.FriendlyFileName, cmsFile.CMSHeight , cmsFile.CMSWidth, cmsFile.ContentId, tags); } } catch (Exception ex) { _Log.Error("Error at cms_Files_Update", ex); throw new DataStoreException(ex, true); } if (num != 0) { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.ErrorFormat("CMSFile {0} was not updated from the database (ErrorCode: {1}).", cmsFile.CMSFileId, num); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSFile {0} was not updated at the database because the validation failed.\nReport: {1}", cmsFile.CMSFileId , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
public ArticleAttachment(int applicationId, IUserBasic user) { this._CMSFile = new CMSFile(applicationId, user, Contracts.CMS.FileType.ArticleAttachment); this.IsTemporary = true; }
internal ArticleAttachment(CMSFile cmsFile) { this._CMSFile = cmsFile; }
protected SystemProfileImage(int applicationId, IUserBasic user, FileType fileType) { this._CMSFile = new CMSFile(applicationId, user, fileType); this.IsTemporary = true; }
internal SystemProfileImage(CMSFile cmsFile) { this._CMSFile = cmsFile; }
public SystemProfileImage(int applicationId) { this._CMSFile = new CMSFile(applicationId, null, Contracts.CMS.FileType.SystemProfileImage); this.IsTemporary = true; }
protected internal ArticleImage(CMSFile cmsFile, List <string> tags) { this._CMSFile = cmsFile; this.Tags = (tags ?? new List <string>()); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Delete(CMSFile cmsFile) { return(Delete(cmsFile.CMSFileId)); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> CreateTemporaryFile(CMSFile cmsFile) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsFile); if (businessObjectActionReport.ValidationResult.IsValid) { DateTime utcNow = DateTime.UtcNow; int num = -1; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_FilesTemp_Insert(cmsFile.ApplicationId, cmsFile.CMSUserId, cmsFile.CMSFileType, cmsFile.FileName, cmsFile.Content , cmsFile.ContentType, cmsFile.ContentSize, cmsFile.FriendlyFileName, cmsFile.CMSHeight, cmsFile.CMSWidth); } } catch (Exception ex) { _Log.Error("Error at cms_FilesTemp_Insert", ex); throw new DataStoreException(ex, true); } if (num > 0) { cmsFile.CMSFileId = num; cmsFile.IsTemporary = true; cmsFile.DateCreatedUtc = DateTime.UtcNow; } else { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.ErrorFormat("Temporary CMSFile {0} was not inserted at the database (ErrorCode: {1}).", cmsFile.CMSFileId, num); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("Temporary CMSFile {0} was not inserted at the database because the validation failed.\nReport: {1}", cmsFile.CMSFileId, businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Create(CMSFile cmsFile) { return(this.Create(cmsFile, null)); }
public ProfileImage(CMSFile cmsFile) : base(cmsFile) { }
protected internal ArticleImage(CMSFile cmsFile) : this(cmsFile, new List <string>()) { }