Merge with 6.0.0
This commit is contained in:
@@ -91,7 +91,6 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
var sqlClause = GetBaseQuery(false);
|
||||
var translator = new SqlTranslator<IContent>(sqlClause, query);
|
||||
var sql = translator.Translate();
|
||||
//sql.OrderBy("[cmsContentVersion].[VersionDate] DESC");
|
||||
|
||||
//NOTE: This doesn't allow properties to be part of the query
|
||||
var dtos = Database.Fetch<DocumentDto, ContentVersionDto, ContentDto, NodeDto>(sql);
|
||||
@@ -112,11 +111,14 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From("cmsDocument")
|
||||
.InnerJoin("cmsContentVersion").On("cmsDocument.versionId = cmsContentVersion.VersionId")
|
||||
.InnerJoin("cmsContent").On("cmsContentVersion.ContentId = cmsContent.nodeId")
|
||||
.InnerJoin("umbracoNode").On("cmsContent.nodeId = umbracoNode.id")
|
||||
.Where("umbracoNode.nodeObjectType = @NodeObjectType", new { NodeObjectType = NodeObjectTypeId });
|
||||
.From<DocumentDto>()
|
||||
.InnerJoin<ContentVersionDto>()
|
||||
.On<DocumentDto, ContentVersionDto>(left => left.VersionId, right => right.VersionId)
|
||||
.InnerJoin<ContentDto>()
|
||||
.On<ContentVersionDto, ContentDto>(left => left.NodeId, right => right.NodeId)
|
||||
.InnerJoin<NodeDto>()
|
||||
.On<ContentDto, NodeDto>(left => left.NodeId, right => right.NodeId)
|
||||
.Where<NodeDto>(x => x.NodeObjectType == NodeObjectTypeId );
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -408,7 +410,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
var sql = GetBaseQuery(false);
|
||||
sql.Where(GetBaseWhereClause(), new { Id = id });
|
||||
sql.Where("cmsContentVersion.LanguageLocale = @Language", new { Language = language });
|
||||
sql.Where<ContentVersionDto>(x => x.Language == language);
|
||||
sql.OrderByDescending<ContentVersionDto>(x => x.VersionDate);
|
||||
|
||||
var dto = Database.Query<DocumentDto, ContentVersionDto, ContentDto, NodeDto>(sql).FirstOrDefault();
|
||||
@@ -423,14 +425,15 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
private PropertyCollection GetPropertyCollection(int id, Guid versionId, IContentType contentType)
|
||||
{
|
||||
var propertySql = new Sql();
|
||||
propertySql.Select("*");
|
||||
propertySql.From("cmsPropertyData");
|
||||
propertySql.InnerJoin("cmsPropertyType ON (cmsPropertyData.propertytypeid = cmsPropertyType.id)");
|
||||
propertySql.Where("cmsPropertyData.contentNodeId = @Id", new { Id = id });
|
||||
propertySql.Where("cmsPropertyData.versionId = @VersionId", new { VersionId = versionId });
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<PropertyDataDto>()
|
||||
.InnerJoin<PropertyTypeDto>()
|
||||
.On<PropertyDataDto, PropertyTypeDto>(left => left.PropertyTypeId, right => right.Id)
|
||||
.Where<PropertyDataDto>(x => x.NodeId == id)
|
||||
.Where<PropertyDataDto>(x => x.VersionId == versionId);
|
||||
|
||||
var propertyDataDtos = Database.Fetch<PropertyDataDto, PropertyTypeDto>(propertySql);
|
||||
var propertyDataDtos = Database.Fetch<PropertyDataDto, PropertyTypeDto>(sql);
|
||||
var propertyFactory = new PropertyFactory(contentType, versionId, id);
|
||||
var properties = propertyFactory.BuildEntity(propertyDataDtos);
|
||||
return new PropertyCollection(properties);
|
||||
|
||||
@@ -35,10 +35,12 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
protected IEnumerable<int> PerformGetByQuery(IQuery<PropertyType> query)
|
||||
{
|
||||
var sqlClause = new Sql();
|
||||
sqlClause.Select("*");
|
||||
sqlClause.From("cmsPropertyTypeGroup");
|
||||
sqlClause.RightJoin("cmsPropertyType ON cmsPropertyTypeGroup.id = cmsPropertyType.propertyTypeGroupId");
|
||||
sqlClause.InnerJoin("cmsDataType ON cmsPropertyType.dataTypeId = cmsDataType.nodeId");
|
||||
sqlClause.Select("*")
|
||||
.From<PropertyTypeGroupDto>()
|
||||
.RightJoin<PropertyTypeDto>()
|
||||
.On<PropertyTypeGroupDto, PropertyTypeDto>(left => left.Id, right => right.PropertyTypeGroupId)
|
||||
.InnerJoin<DataTypeDto>()
|
||||
.On<PropertyTypeDto, DataTypeDto>(left => left.DataTypeId, right => right.DataTypeId);
|
||||
|
||||
var translator = new SqlTranslator<PropertyType>(sqlClause, query);
|
||||
var sql = translator.Translate();
|
||||
@@ -210,25 +212,27 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
protected IEnumerable<ContentTypeSort> GetAllowedContentTypeIds(int id)
|
||||
{
|
||||
var allowedContentTypesSql = new Sql();
|
||||
allowedContentTypesSql.Select("*");
|
||||
allowedContentTypesSql.From("cmsContentTypeAllowedContentType");
|
||||
allowedContentTypesSql.Where("cmsContentTypeAllowedContentType.Id = @Id", new { Id = id });
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<ContentTypeAllowedContentTypeDto>()
|
||||
.Where<ContentTypeAllowedContentTypeDto>(x => x.Id == id);
|
||||
|
||||
var allowedContentTypeDtos = Database.Fetch<ContentTypeAllowedContentTypeDto>(allowedContentTypesSql);
|
||||
var allowedContentTypeDtos = Database.Fetch<ContentTypeAllowedContentTypeDto>(sql);
|
||||
return allowedContentTypeDtos.Select(x => new ContentTypeSort { Id = new Lazy<int>(() => x.AllowedId), SortOrder = x.SortOrder }).ToList();
|
||||
}
|
||||
|
||||
protected PropertyGroupCollection GetPropertyGroupCollection(int id)
|
||||
{
|
||||
var propertySql = new Sql();
|
||||
propertySql.Select("*");
|
||||
propertySql.From("cmsPropertyTypeGroup");
|
||||
propertySql.RightJoin("cmsPropertyType ON cmsPropertyTypeGroup.id = cmsPropertyType.propertyTypeGroupId");
|
||||
propertySql.InnerJoin("cmsDataType ON cmsPropertyType.dataTypeId = cmsDataType.nodeId");
|
||||
propertySql.Where("cmsPropertyType.contentTypeId = @Id", new { Id = id });
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<PropertyTypeGroupDto>()
|
||||
.RightJoin<PropertyTypeDto>()
|
||||
.On<PropertyTypeGroupDto, PropertyTypeDto>(left => left.Id, right => right.PropertyTypeGroupId)
|
||||
.InnerJoin<DataTypeDto>()
|
||||
.On<PropertyTypeDto, DataTypeDto>(left => left.DataTypeId, right => right.DataTypeId)
|
||||
.Where<PropertyTypeDto>(x => x.ContentTypeId == id);
|
||||
|
||||
var dtos = Database.Fetch<PropertyTypeGroupDto, PropertyTypeDto, DataTypeDto, PropertyTypeGroupDto>(new GroupPropertyTypeRelator().Map, propertySql);
|
||||
var dtos = Database.Fetch<PropertyTypeGroupDto, PropertyTypeDto, DataTypeDto, PropertyTypeGroupDto>(new GroupPropertyTypeRelator().Map, sql);
|
||||
|
||||
var propertyFactory = new PropertyGroupFactory(id);
|
||||
var propertyGroups = propertyFactory.BuildEntity(dtos);
|
||||
|
||||
@@ -114,14 +114,17 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
protected override Sql GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = new Sql();
|
||||
//TODO Investigate the proper usage of IsDefault on cmsDocumentType
|
||||
sql.Select(isCount ? "COUNT(*)" : "*");
|
||||
sql.From("cmsDocumentType");
|
||||
sql.RightJoin("cmsContentType ON (cmsContentType.nodeId = cmsDocumentType.contentTypeNodeId)");
|
||||
sql.InnerJoin("umbracoNode ON (cmsContentType.nodeId = umbracoNode.id)");
|
||||
sql.Where("umbracoNode.nodeObjectType = @NodeObjectType", new { NodeObjectType = NodeObjectTypeId });
|
||||
sql.Where("cmsDocumentType.IsDefault = @IsDefault", new { IsDefault = true });
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From<DocumentTypeDto>()
|
||||
.RightJoin<ContentTypeDto>()
|
||||
.On<ContentTypeDto, DocumentTypeDto>(left => left.NodeId, right => right.ContentTypeNodeId)
|
||||
.InnerJoin<NodeDto>()
|
||||
.On<ContentTypeDto, NodeDto>(left => left.NodeId, right => right.NodeId)
|
||||
.Where<NodeDto>(x => x.NodeObjectType == NodeObjectTypeId)
|
||||
.Where<DocumentTypeDto>(x => x.IsDefault == true);
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -134,18 +137,18 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
var list = new List<string>
|
||||
{
|
||||
string.Format("DELETE FROM umbracoUser2NodeNotify WHERE nodeId = @Id"),
|
||||
string.Format("DELETE FROM umbracoUser2NodePermission WHERE nodeId = @Id"),
|
||||
string.Format("DELETE FROM cmsTagRelationship WHERE nodeId = @Id"),
|
||||
string.Format("DELETE FROM cmsContentTypeAllowedContentType WHERE Id = @Id"),
|
||||
string.Format("DELETE FROM cmsContentTypeAllowedContentType WHERE AllowedId = @Id"),
|
||||
string.Format("DELETE FROM cmsContentType2ContentType WHERE parentContentTypeId = @Id"),
|
||||
string.Format("DELETE FROM cmsContentType2ContentType WHERE childContentTypeId = @Id"),
|
||||
string.Format("DELETE FROM cmsPropertyType WHERE contentTypeId = @Id"),
|
||||
string.Format("DELETE FROM cmsPropertyTypeGroup WHERE contenttypeNodeId = @Id"),
|
||||
string.Format("DELETE FROM cmsDocumentType WHERE contentTypeNodeId = @Id"),
|
||||
string.Format("DELETE FROM cmsContentType WHERE NodeId = @Id"),
|
||||
string.Format("DELETE FROM umbracoNode WHERE id = @Id")
|
||||
"DELETE FROM umbracoUser2NodeNotify WHERE nodeId = @Id",
|
||||
"DELETE FROM umbracoUser2NodePermission WHERE nodeId = @Id",
|
||||
"DELETE FROM cmsTagRelationship WHERE nodeId = @Id",
|
||||
"DELETE FROM cmsContentTypeAllowedContentType WHERE Id = @Id",
|
||||
"DELETE FROM cmsContentTypeAllowedContentType WHERE AllowedId = @Id",
|
||||
"DELETE FROM cmsContentType2ContentType WHERE parentContentTypeId = @Id",
|
||||
"DELETE FROM cmsContentType2ContentType WHERE childContentTypeId = @Id",
|
||||
"DELETE FROM cmsPropertyType WHERE contentTypeId = @Id",
|
||||
"DELETE FROM cmsPropertyTypeGroup WHERE contenttypeNodeId = @Id",
|
||||
"DELETE FROM cmsDocumentType WHERE contentTypeNodeId = @Id",
|
||||
"DELETE FROM cmsContentType WHERE NodeId = @Id",
|
||||
"DELETE FROM umbracoNode WHERE id = @Id"
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -85,10 +85,11 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
protected override Sql GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*");
|
||||
sql.From("cmsDataType");
|
||||
sql.InnerJoin("umbracoNode ON (cmsDataType.nodeId = umbracoNode.id)");
|
||||
sql.Where("umbracoNode.nodeObjectType = @NodeObjectType", new { NodeObjectType = NodeObjectTypeId });
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From<DataTypeDto>()
|
||||
.InnerJoin<NodeDto>()
|
||||
.On<DataTypeDto, NodeDto>(left => left.DataTypeId, right => right.NodeId)
|
||||
.Where<NodeDto>(x => x.NodeObjectType == NodeObjectTypeId);
|
||||
return sql;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,14 +101,15 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
var sql = new Sql();
|
||||
if(isCount)
|
||||
{
|
||||
sql.Select("COUNT(*)");
|
||||
sql.From("cmsDictionary");
|
||||
sql.Select("COUNT(*)")
|
||||
.From<DictionaryDto>();
|
||||
}
|
||||
else
|
||||
{
|
||||
sql.Select("*");
|
||||
sql.From("cmsDictionary");
|
||||
sql.InnerJoin("cmsLanguageText ON (cmsDictionary.id = cmsLanguageText.UniqueId)");
|
||||
sql.Select("*")
|
||||
.From<DictionaryDto>()
|
||||
.InnerJoin<LanguageTextDto>()
|
||||
.On<DictionaryDto, LanguageTextDto>(left => left.UniqueId, right => right.UniqueId);
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
protected override Sql GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*");
|
||||
sql.From("umbracoLanguage");
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From<LanguageDto>();
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
//NOTE: There is no constraint between the Language and cmsDictionary/cmsLanguageText tables (?)
|
||||
var list = new List<string>
|
||||
{
|
||||
string.Format("DELETE FROM umbracoLanguage WHERE id = @Id")
|
||||
"DELETE FROM umbracoLanguage WHERE id = @Id"
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -97,11 +97,13 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
protected override Sql GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*");
|
||||
sql.From("cmsContentVersion");
|
||||
sql.InnerJoin("cmsContent ON (cmsContentVersion.ContentId = cmsContent.nodeId)");
|
||||
sql.InnerJoin("umbracoNode ON (cmsContent.nodeId = umbracoNode.id)");
|
||||
sql.Where("umbracoNode.nodeObjectType = @NodeObjectType", new { NodeObjectType = NodeObjectTypeId });
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From<ContentVersionDto>()
|
||||
.InnerJoin<ContentDto>()
|
||||
.On<ContentVersionDto, ContentDto>(left => left.NodeId, right => right.NodeId)
|
||||
.InnerJoin<NodeDto>()
|
||||
.On<ContentDto, NodeDto>(left => left.NodeId, right => right.NodeId)
|
||||
.Where<NodeDto>(x => x.NodeObjectType == NodeObjectTypeId);
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -332,14 +334,15 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
private PropertyCollection GetPropertyCollection(int id, Guid versionId, IMediaType contentType)
|
||||
{
|
||||
var propertySql = new Sql();
|
||||
propertySql.Select("*");
|
||||
propertySql.From("cmsPropertyData");
|
||||
propertySql.InnerJoin("cmsPropertyType ON (cmsPropertyData.propertytypeid = cmsPropertyType.id)");
|
||||
propertySql.Where("cmsPropertyData.contentNodeId = @Id", new { Id = id });
|
||||
propertySql.Where("cmsPropertyData.versionId = @VersionId", new { VersionId = versionId });
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<PropertyDataDto>()
|
||||
.InnerJoin<PropertyTypeDto>()
|
||||
.On<PropertyDataDto, PropertyTypeDto>(left => left.PropertyTypeId, right => right.Id)
|
||||
.Where<PropertyDataDto>(x => x.NodeId == id)
|
||||
.Where<PropertyDataDto>(x => x.VersionId == versionId);
|
||||
|
||||
var propertyDataDtos = Database.Fetch<PropertyDataDto, PropertyTypeDto>(propertySql);
|
||||
var propertyDataDtos = Database.Fetch<PropertyDataDto, PropertyTypeDto>(sql);
|
||||
var propertyFactory = new PropertyFactory(contentType, versionId, id);
|
||||
var properties = propertyFactory.BuildMediaEntity(propertyDataDtos);
|
||||
return new PropertyCollection(properties);
|
||||
|
||||
@@ -104,10 +104,11 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
protected override Sql GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*");
|
||||
sql.From("cmsContentType");
|
||||
sql.InnerJoin("umbracoNode ON (cmsContentType.nodeId = umbracoNode.id)");
|
||||
sql.Where("umbracoNode.nodeObjectType = @NodeObjectType", new { NodeObjectType = NodeObjectTypeId });
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From<ContentTypeDto>()
|
||||
.InnerJoin<NodeDto>()
|
||||
.On<ContentTypeDto, NodeDto>(left => left.NodeId, right => right.NodeId)
|
||||
.Where<NodeDto>(x => x.NodeObjectType == NodeObjectTypeId);
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -120,17 +121,17 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
var list = new List<string>
|
||||
{
|
||||
string.Format("DELETE FROM umbracoUser2NodeNotify WHERE nodeId = @Id"),
|
||||
string.Format("DELETE FROM umbracoUser2NodePermission WHERE nodeId = @Id"),
|
||||
string.Format("DELETE FROM cmsTagRelationship WHERE nodeId = @Id"),
|
||||
string.Format("DELETE FROM cmsContentTypeAllowedContentType WHERE Id = @Id"),
|
||||
string.Format("DELETE FROM cmsContentTypeAllowedContentType WHERE AllowedId = @Id"),
|
||||
string.Format("DELETE FROM cmsContentType2ContentType WHERE parentContentTypeId = @Id"),
|
||||
string.Format("DELETE FROM cmsContentType2ContentType WHERE childContentTypeId = @Id"),
|
||||
string.Format("DELETE FROM cmsPropertyType WHERE contentTypeId = @Id"),
|
||||
string.Format("DELETE FROM cmsPropertyTypeGroup WHERE contenttypeNodeId = @Id"),
|
||||
string.Format("DELETE FROM cmsContentType WHERE NodeId = @Id"),
|
||||
string.Format("DELETE FROM umbracoNode WHERE id = @Id")
|
||||
"DELETE FROM umbracoUser2NodeNotify WHERE nodeId = @Id",
|
||||
"DELETE FROM umbracoUser2NodePermission WHERE nodeId = @Id",
|
||||
"DELETE FROM cmsTagRelationship WHERE nodeId = @Id",
|
||||
"DELETE FROM cmsContentTypeAllowedContentType WHERE Id = @Id",
|
||||
"DELETE FROM cmsContentTypeAllowedContentType WHERE AllowedId = @Id",
|
||||
"DELETE FROM cmsContentType2ContentType WHERE parentContentTypeId = @Id",
|
||||
"DELETE FROM cmsContentType2ContentType WHERE childContentTypeId = @Id",
|
||||
"DELETE FROM cmsPropertyType WHERE contentTypeId = @Id",
|
||||
"DELETE FROM cmsPropertyTypeGroup WHERE contenttypeNodeId = @Id",
|
||||
"DELETE FROM cmsContentType WHERE NodeId = @Id",
|
||||
"DELETE FROM umbracoNode WHERE id = @Id"
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence.Caching;
|
||||
using Umbraco.Core.Persistence.Factories;
|
||||
@@ -93,8 +92,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
protected override Sql GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*");
|
||||
sql.From("umbracoRelation");
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From<RelationDto>();
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -107,7 +106,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
var list = new List<string>
|
||||
{
|
||||
string.Format("DELETE FROM umbracoRelation WHERE id = @Id")
|
||||
"DELETE FROM umbracoRelation WHERE id = @Id"
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -84,8 +84,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
protected override Sql GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*");
|
||||
sql.From("umbracoRelationType");
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From<RelationTypeDto>();
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -98,8 +98,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
var list = new List<string>
|
||||
{
|
||||
string.Format("DELETE FROM umbracoRelation WHERE relType = @Id"),
|
||||
string.Format("DELETE FROM umbracoRelationType WHERE id = @Id")
|
||||
"DELETE FROM umbracoRelation WHERE relType = @Id",
|
||||
"DELETE FROM umbracoRelationType WHERE id = @Id"
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -130,10 +130,11 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
protected override Sql GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*");
|
||||
sql.From("cmsTemplate");
|
||||
sql.InnerJoin("umbracoNode").On("cmsTemplate.nodeId = umbracoNode.id");
|
||||
sql.Where("umbracoNode.nodeObjectType = @NodeObjectType", new { NodeObjectType = NodeObjectTypeId });
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From<TemplateDto>()
|
||||
.InnerJoin<NodeDto>()
|
||||
.On<TemplateDto, NodeDto>(left => left.NodeId, right => right.NodeId)
|
||||
.Where<NodeDto>(x => x.NodeObjectType == NodeObjectTypeId);
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -147,11 +148,11 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
//TODO check for references in DocumentDto and remove value (nullable)
|
||||
var list = new List<string>
|
||||
{
|
||||
string.Format("DELETE FROM umbracoUser2NodeNotify WHERE nodeId = @Id"),
|
||||
string.Format("DELETE FROM umbracoUser2NodePermission WHERE nodeId = @Id"),
|
||||
string.Format("DELETE FROM cmsDocumentType WHERE templateNodeId = @Id"),
|
||||
string.Format("DELETE FROM cmsTemplate WHERE nodeId = @Id"),
|
||||
string.Format("DELETE FROM umbracoNode WHERE id = @Id")
|
||||
"DELETE FROM umbracoUser2NodeNotify WHERE nodeId = @Id",
|
||||
"DELETE FROM umbracoUser2NodePermission WHERE nodeId = @Id",
|
||||
"DELETE FROM cmsDocumentType WHERE templateNodeId = @Id",
|
||||
"DELETE FROM cmsTemplate WHERE nodeId = @Id",
|
||||
"DELETE FROM umbracoNode WHERE id = @Id"
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -88,8 +88,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
protected override Sql GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*");
|
||||
sql.From("umbracoUser");
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From<UserDto>();
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
var list = new List<string>
|
||||
{
|
||||
string.Format("DELETE FROM umbracoUser WHERE id = @Id")
|
||||
"DELETE FROM umbracoUser WHERE id = @Id"
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
protected override Sql GetBaseQuery(bool isCount)
|
||||
{
|
||||
var sql = new Sql();
|
||||
sql.Select(isCount ? "COUNT(*)" : "*");
|
||||
sql.From("umbracoUserType");
|
||||
sql.Select(isCount ? "COUNT(*)" : "*")
|
||||
.From<UserTypeDto>();
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -97,8 +97,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
var list = new List<string>
|
||||
{
|
||||
string.Format("DELETE FROM umbracoUser WHERE userType = @Id"),
|
||||
string.Format("DELETE FROM umbracoUserType WHERE id = @Id")
|
||||
"DELETE FROM umbracoUser WHERE userType = @Id",
|
||||
"DELETE FROM umbracoUserType WHERE id = @Id"
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -104,5 +104,31 @@ namespace Umbraco.Tests.Persistence.Querying
|
||||
|
||||
Console.WriteLine(sql.SQL);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Verify_Property_Collection_Query()
|
||||
{
|
||||
var versionId = new Guid("2b543516-a944-4ee6-88c6-8813da7aaa07");
|
||||
var id = 1050;
|
||||
|
||||
var expected = new Sql();
|
||||
expected.Select("*");
|
||||
expected.From("[cmsPropertyData]");
|
||||
expected.InnerJoin("[cmsPropertyType]").On("[cmsPropertyData].[propertytypeid] = [cmsPropertyType].[id]");
|
||||
expected.Where("[cmsPropertyData].[contentNodeId] = 1050");
|
||||
expected.Where("[cmsPropertyData].[versionId] = '2b543516-a944-4ee6-88c6-8813da7aaa07'");
|
||||
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<PropertyDataDto>()
|
||||
.InnerJoin<PropertyTypeDto>()
|
||||
.On<PropertyDataDto, PropertyTypeDto>(left => left.PropertyTypeId, right => right.Id)
|
||||
.Where<PropertyDataDto>(x => x.NodeId == id)
|
||||
.Where<PropertyDataDto>(x => x.VersionId == versionId);
|
||||
|
||||
Assert.That(sql.SQL, Is.EqualTo(expected.SQL));
|
||||
|
||||
Console.WriteLine(sql.SQL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,5 +70,69 @@ namespace Umbraco.Tests.Persistence.Querying
|
||||
|
||||
Console.WriteLine(sql.SQL);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Verify_PerformQuery_Clause()
|
||||
{
|
||||
var expected = new Sql();
|
||||
expected.Select("*")
|
||||
.From("[cmsPropertyTypeGroup]")
|
||||
.RightJoin("[cmsPropertyType]").On("[cmsPropertyTypeGroup].[id] = [cmsPropertyType].[propertyTypeGroupId]")
|
||||
.InnerJoin("[cmsDataType]").On("[cmsPropertyType].[dataTypeId] = [cmsDataType].[nodeId]");
|
||||
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<PropertyTypeGroupDto>()
|
||||
.RightJoin<PropertyTypeDto>()
|
||||
.On<PropertyTypeGroupDto, PropertyTypeDto>(left => left.Id, right => right.PropertyTypeGroupId)
|
||||
.InnerJoin<DataTypeDto>()
|
||||
.On<PropertyTypeDto, DataTypeDto>(left => left.DataTypeId, right => right.DataTypeId);
|
||||
|
||||
Assert.That(sql.SQL, Is.EqualTo(expected.SQL));
|
||||
|
||||
Console.WriteLine(sql.SQL);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Verify_AllowedContentTypeIds_Clause()
|
||||
{
|
||||
var expected = new Sql();
|
||||
expected.Select("*")
|
||||
.From("[cmsContentTypeAllowedContentType]")
|
||||
.Where("[cmsContentTypeAllowedContentType].[Id] = 1050");
|
||||
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<ContentTypeAllowedContentTypeDto>()
|
||||
.Where<ContentTypeAllowedContentTypeDto>(x => x.Id == 1050);
|
||||
|
||||
Assert.That(sql.SQL, Is.EqualTo(expected.SQL));
|
||||
|
||||
Console.WriteLine(sql.SQL);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Verify_PropertyGroupCollection_Clause()
|
||||
{
|
||||
var expected = new Sql();
|
||||
expected.Select("*")
|
||||
.From("[cmsPropertyTypeGroup]")
|
||||
.RightJoin("[cmsPropertyType]").On("[cmsPropertyTypeGroup].[id] = [cmsPropertyType].[propertyTypeGroupId]")
|
||||
.InnerJoin("[cmsDataType]").On("[cmsPropertyType].[dataTypeId] = [cmsDataType].[nodeId]")
|
||||
.Where("[cmsPropertyType].[contentTypeId] = 1050");
|
||||
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<PropertyTypeGroupDto>()
|
||||
.RightJoin<PropertyTypeDto>()
|
||||
.On<PropertyTypeGroupDto, PropertyTypeDto>(left => left.Id, right => right.PropertyTypeGroupId)
|
||||
.InnerJoin<DataTypeDto>()
|
||||
.On<PropertyTypeDto, DataTypeDto>(left => left.DataTypeId, right => right.DataTypeId)
|
||||
.Where<PropertyTypeDto>(x => x.ContentTypeId == 1050);
|
||||
|
||||
Assert.That(sql.SQL, Is.EqualTo(expected.SQL));
|
||||
|
||||
Console.WriteLine(sql.SQL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
|
||||
namespace Umbraco.Tests.Persistence.Querying
|
||||
{
|
||||
[TestFixture]
|
||||
public class DataTypeDefinitionRepositorySqlClausesTest : BaseUsingSqlCeSyntax
|
||||
{
|
||||
[Test]
|
||||
public void Can_Verify_Base_Clause()
|
||||
{
|
||||
var NodeObjectTypeId = new Guid("30a2a501-1978-4ddb-a57b-f7efed43ba3c");
|
||||
|
||||
var expected = new Sql();
|
||||
expected.Select("*")
|
||||
.From("[cmsDataType]")
|
||||
.InnerJoin("[umbracoNode]").On("[cmsDataType].[nodeId] = [umbracoNode].[id]")
|
||||
.Where("[umbracoNode].[nodeObjectType] = '30a2a501-1978-4ddb-a57b-f7efed43ba3c'");
|
||||
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<DataTypeDto>()
|
||||
.InnerJoin<NodeDto>()
|
||||
.On<DataTypeDto, NodeDto>(left => left.DataTypeId, right => right.NodeId)
|
||||
.Where<NodeDto>(x => x.NodeObjectType == NodeObjectTypeId);
|
||||
|
||||
Assert.That(sql.SQL, Is.EqualTo(expected.SQL));
|
||||
|
||||
Console.WriteLine(sql.SQL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
|
||||
namespace Umbraco.Tests.Persistence.Querying
|
||||
{
|
||||
[TestFixture]
|
||||
public class MediaRepositorySqlClausesTest : BaseUsingSqlCeSyntax
|
||||
{
|
||||
[Test]
|
||||
public void Can_Verify_Base_Clause()
|
||||
{
|
||||
var NodeObjectTypeId = new Guid("b796f64c-1f99-4ffb-b886-4bf4bc011a9c");
|
||||
|
||||
var expected = new Sql();
|
||||
expected.Select("*")
|
||||
.From("[cmsContentVersion]")
|
||||
.InnerJoin("[cmsContent]").On("[cmsContentVersion].[ContentId] = [cmsContent].[nodeId]")
|
||||
.InnerJoin("[umbracoNode]").On("[cmsContent].[nodeId] = [umbracoNode].[id]")
|
||||
.Where("[umbracoNode].[nodeObjectType] = 'b796f64c-1f99-4ffb-b886-4bf4bc011a9c'");
|
||||
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<ContentVersionDto>()
|
||||
.InnerJoin<ContentDto>()
|
||||
.On<ContentVersionDto, ContentDto>(left => left.NodeId, right => right.NodeId)
|
||||
.InnerJoin<NodeDto>()
|
||||
.On<ContentDto, NodeDto>(left => left.NodeId, right => right.NodeId)
|
||||
.Where<NodeDto>(x => x.NodeObjectType == NodeObjectTypeId);
|
||||
|
||||
Assert.That(sql.SQL, Is.EqualTo(expected.SQL));
|
||||
|
||||
Console.WriteLine(sql.SQL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
|
||||
namespace Umbraco.Tests.Persistence.Querying
|
||||
{
|
||||
[TestFixture]
|
||||
public class MediaTypeRepositorySqlClausesTest : BaseUsingSqlCeSyntax
|
||||
{
|
||||
[Test]
|
||||
public void Can_Verify_Base_Clause()
|
||||
{
|
||||
var NodeObjectTypeId = new Guid("4ea4382b-2f5a-4c2b-9587-ae9b3cf3602e");
|
||||
|
||||
var expected = new Sql();
|
||||
expected.Select("*")
|
||||
.From("[cmsContentType]")
|
||||
.InnerJoin("[umbracoNode]").On("[cmsContentType].[nodeId] = [umbracoNode].[id]")
|
||||
.Where("[umbracoNode].[nodeObjectType] = '4ea4382b-2f5a-4c2b-9587-ae9b3cf3602e'");
|
||||
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<ContentTypeDto>()
|
||||
.InnerJoin<NodeDto>()
|
||||
.On<ContentTypeDto, NodeDto>(left => left.NodeId, right => right.NodeId)
|
||||
.Where<NodeDto>(x => x.NodeObjectType == NodeObjectTypeId);
|
||||
|
||||
Assert.That(sql.SQL, Is.EqualTo(expected.SQL));
|
||||
|
||||
Console.WriteLine(sql.SQL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,58 +10,42 @@ namespace Umbraco.Tests.PropertyEditors
|
||||
[TestFixture]
|
||||
public class PropertyEditorValueConverterTests
|
||||
{
|
||||
[Test]
|
||||
public void CanConvertDatePickerPropertyEditor()
|
||||
[TestCase("2012-11-10", true)]
|
||||
[TestCase("2012/11/10", true)]
|
||||
[TestCase("10/11/2012", true)]
|
||||
[TestCase("11/10/2012", false)]
|
||||
[TestCase("Sat 10, Nov 2012", true)]
|
||||
[TestCase("Saturday 10, Nov 2012", true)]
|
||||
[TestCase("Sat 10, November 2012", true)]
|
||||
[TestCase("Saturday 10, November 2012", true)]
|
||||
[TestCase("2012-11-10 13:14:15", true)]
|
||||
[TestCase("", false)]
|
||||
public void CanConvertDatePickerPropertyEditor(string date, bool expected)
|
||||
{
|
||||
var converter = new DatePickerPropertyEditorValueConverter();
|
||||
var dateTime = new DateTime(2012, 11, 10, 13, 14, 15);
|
||||
var testCases = new Dictionary<string, bool>
|
||||
{
|
||||
{"2012-11-10", true},
|
||||
{"2012/11/10", true},
|
||||
{"10/11/2012", true},
|
||||
{"11/10/2012", false},
|
||||
{"Sat 10, Nov 2012", true},
|
||||
{"Saturday 10, Nov 2012", true},
|
||||
{"Sat 10, November 2012", true},
|
||||
{"Saturday 10, November 2012", true},
|
||||
{"2012-11-10 13:14:15", true},
|
||||
{"", false}
|
||||
};
|
||||
var result = converter.ConvertPropertyValue(date);
|
||||
|
||||
foreach (var testCase in testCases)
|
||||
{
|
||||
var result = converter.ConvertPropertyValue(testCase.Key);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(DateTime.Equals(dateTime.Date, ((DateTime)result.Result).Date), testCase.Value);
|
||||
}
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(DateTime.Equals(dateTime.Date, ((DateTime) result.Result).Date), expected);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanConvertYesNoPropertyEditor()
|
||||
[TestCase("TRUE", true)]
|
||||
[TestCase("True", true)]
|
||||
[TestCase("true", true)]
|
||||
[TestCase("1", true)]
|
||||
[TestCase("FALSE", false)]
|
||||
[TestCase("False", false)]
|
||||
[TestCase("false", false)]
|
||||
[TestCase("0", false)]
|
||||
[TestCase("", false)]
|
||||
public void CanConvertYesNoPropertyEditor(string value, bool expected)
|
||||
{
|
||||
var converter = new YesNoPropertyEditorValueConverter();
|
||||
var testCases = new Dictionary<string, bool>
|
||||
{
|
||||
{"TRUE", true},
|
||||
{"True", true},
|
||||
{"true", true},
|
||||
{"1", true},
|
||||
{"FALSE", false},
|
||||
{"False", false},
|
||||
{"false", false},
|
||||
{"0", false},
|
||||
{"", false}
|
||||
};
|
||||
var result = converter.ConvertPropertyValue(value);
|
||||
|
||||
foreach (var testCase in testCases)
|
||||
{
|
||||
var result = converter.ConvertPropertyValue(testCase.Key);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(testCase.Value, result.Result);
|
||||
}
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(expected, result.Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,10 @@
|
||||
<Compile Include="Persistence\Mappers\MappingResolverTests.cs" />
|
||||
<Compile Include="Persistence\Querying\ContentRepositorySqlClausesTest.cs" />
|
||||
<Compile Include="Persistence\Querying\ContentTypeRepositorySqlClausesTest.cs" />
|
||||
<Compile Include="Persistence\Querying\DataTypeDefinitionRepositorySqlClausesTest.cs" />
|
||||
<Compile Include="Persistence\Querying\ExpressionTests.cs" />
|
||||
<Compile Include="Persistence\Querying\MediaRepositorySqlClausesTest.cs" />
|
||||
<Compile Include="Persistence\Querying\MediaTypeRepositorySqlClausesTest.cs" />
|
||||
<Compile Include="Persistence\SyntaxProvider\SqlSyntaxProviderTests.cs" />
|
||||
<Compile Include="PublishedContent\DynamicXmlTests.cs" />
|
||||
<Compile Include="PublishedContent\PublishedContentDataTableTests.cs" />
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using System.Web.UI;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Services;
|
||||
@@ -68,5 +71,17 @@ namespace Umbraco.Web
|
||||
{
|
||||
get { return ApplicationContext.DatabaseContext; }
|
||||
}
|
||||
|
||||
private UrlHelper _url;
|
||||
/// <summary>
|
||||
/// Returns a UrlHelper
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This URL helper is created without any route data and an empty request context
|
||||
/// </remarks>
|
||||
public UrlHelper Url
|
||||
{
|
||||
get { return _url ?? (_url = new UrlHelper(new RequestContext(new HttpContextWrapper(Context), new RouteData()))); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Web;
|
||||
using System.Xml.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using umbraco.DataLayer;
|
||||
using umbraco.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -78,24 +79,29 @@ namespace umbraco.BusinessLogic
|
||||
{
|
||||
if (_sqlHelper == null)
|
||||
{
|
||||
var connectionString = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
const string umbracoDsn = Umbraco.Core.Configuration.GlobalSettings.UmbracoConnectionName;
|
||||
|
||||
var connectionString = string.Empty;
|
||||
|
||||
|
||||
var databaseSettings = ConfigurationManager.ConnectionStrings[umbracoDsn];
|
||||
if(databaseSettings != null)
|
||||
if (databaseSettings != null)
|
||||
connectionString = databaseSettings.ConnectionString;
|
||||
|
||||
|
||||
// During upgrades we might still have the old appSettings connectionstring, and not the new one, so get that one instead
|
||||
if (string.IsNullOrWhiteSpace(connectionString) && ConfigurationManager.AppSettings.ContainsKey(umbracoDsn))
|
||||
if (string.IsNullOrWhiteSpace(connectionString) &&
|
||||
ConfigurationManager.AppSettings.ContainsKey(umbracoDsn))
|
||||
connectionString = ConfigurationManager.AppSettings[umbracoDsn];
|
||||
|
||||
_sqlHelper = DataLayerHelper.CreateSqlHelper(connectionString);
|
||||
}
|
||||
catch { }
|
||||
catch(Exception ex)
|
||||
{
|
||||
LogHelper.Error<Application>(string.Format("Can't instantiate SQLHelper with connectionstring \"{0}\"", connectionString), ex);
|
||||
}
|
||||
}
|
||||
|
||||
return _sqlHelper;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,62 +31,25 @@ namespace umbraco.editorControls.imagecropper
|
||||
DirectoryInfo di = new DirectoryInfo(path);
|
||||
if (!di.Exists) di.Create();
|
||||
|
||||
using(Image croppedImage = cropImage(image, new Rectangle(cropX, cropY, cropWidth, cropHeight)))
|
||||
using(Image croppedImage = CropImage(image, new Rectangle(cropX, cropY, cropWidth, cropHeight)))
|
||||
{
|
||||
using(Image resizedImage = resizeImage(croppedImage, new Size(sizeWidth, sizeHeight)))
|
||||
using(Image resizedImage = ResizeImage(croppedImage, new Size(sizeWidth, sizeHeight)))
|
||||
{
|
||||
using (Bitmap b = new Bitmap(resizedImage))
|
||||
{
|
||||
saveJpeg(String.Format("{0}/{1}.jpg", path, name), b, quality);
|
||||
SaveJpeg(String.Format("{0}/{1}.jpg", path, name), b, quality);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//saveJpeg(
|
||||
// String.Format("{0}/{1}.jpg", path, name),
|
||||
// new Bitmap(
|
||||
// resizeImage(cropImage(image, new Rectangle(cropX, cropY, cropWidth, cropHeight)), new Size(sizeWidth, sizeHeight))),
|
||||
// quality
|
||||
// );
|
||||
|
||||
//using (FileStream stm = new FileStream(sourceFile, FileMode.Open, FileAccess.Read))
|
||||
//{
|
||||
//using (Image image = Image.FromStream(stm))
|
||||
//{
|
||||
|
||||
//}
|
||||
//stm.Close();
|
||||
//}
|
||||
|
||||
|
||||
//using (Image image = Image.FromFile(sourceFile))
|
||||
//{
|
||||
// //image = cropImage(image, new Rectangle(cropX, cropY, cropWidth, cropHeight));
|
||||
// //cropImage(image, new Rectangle(cropX, cropY, cropWidth, cropHeight));
|
||||
// //image = resizeImage(image, new Size(sizeWidth, sizeHeight));
|
||||
// //resizeImage(image, new Size(sizeWidth, sizeHeight));
|
||||
// string path = sourceFile.Substring(0, sourceFile.LastIndexOf('\\') + 1) + "Crops";
|
||||
// DirectoryInfo di = new DirectoryInfo(path);
|
||||
// if (!di.Exists) di.Create();
|
||||
// saveJpeg(
|
||||
// String.Format("{0}/{1}.jpg", path, name),
|
||||
// new Bitmap(
|
||||
// resizeImage(cropImage(image, new Rectangle(cropX, cropY, cropWidth, cropHeight)), new Size(sizeWidth, sizeHeight))),
|
||||
// quality
|
||||
// );
|
||||
|
||||
// image.Dispose();
|
||||
//}
|
||||
}
|
||||
|
||||
private static void saveJpeg(string path, Bitmap img, long quality)
|
||||
private static void SaveJpeg(string path, Bitmap img, long quality)
|
||||
{
|
||||
// Encoder parameter for image quality
|
||||
EncoderParameter qualityParam = new EncoderParameter(Encoder.Quality, quality);
|
||||
|
||||
// Jpeg image codec
|
||||
ImageCodecInfo jpegCodec = getEncoderInfo("image/jpeg");
|
||||
ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
|
||||
|
||||
if (jpegCodec == null)
|
||||
return;
|
||||
@@ -97,7 +60,7 @@ namespace umbraco.editorControls.imagecropper
|
||||
img.Save(path, jpegCodec, encoderParams);
|
||||
}
|
||||
|
||||
private static ImageCodecInfo getEncoderInfo(string mimeType)
|
||||
private static ImageCodecInfo GetEncoderInfo(string mimeType)
|
||||
{
|
||||
// Get image codecs for all image formats
|
||||
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
|
||||
@@ -109,39 +72,22 @@ namespace umbraco.editorControls.imagecropper
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Image cropImage(Image img, Rectangle cropArea)
|
||||
private static Image CropImage(Image img, Rectangle cropArea)
|
||||
{
|
||||
Bitmap bmpImage = new Bitmap(img);
|
||||
Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
|
||||
return (Image)(bmpCrop);
|
||||
var bmpImage = new Bitmap(img);
|
||||
|
||||
if (cropArea.Right > img.Width)
|
||||
cropArea.Width -= (cropArea.Right - img.Width);
|
||||
|
||||
if (cropArea.Bottom > img.Height)
|
||||
cropArea.Height -= (cropArea.Bottom - img.Height);
|
||||
|
||||
var bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
|
||||
return bmpCrop;
|
||||
}
|
||||
|
||||
private static Image resizeImage(Image imgToResize, Size size)
|
||||
private static Image ResizeImage(Image imgToResize, Size size)
|
||||
{
|
||||
//int sourceWidth = imgToResize.Width;
|
||||
//int sourceHeight = imgToResize.Height;
|
||||
|
||||
//float nPercent = 0;
|
||||
//float nPercentW = 0;
|
||||
//float nPercentH = 0;
|
||||
|
||||
//nPercentW = ((float)size.Width / (float)sourceWidth);
|
||||
//nPercentH = ((float)size.Height / (float)sourceHeight);
|
||||
|
||||
//if (nPercentH < nPercentW)
|
||||
// nPercent = nPercentH;
|
||||
//else
|
||||
// nPercent = nPercentW;
|
||||
|
||||
//int destWidth = (int)(sourceWidth * nPercent);
|
||||
//int destHeight = (int)(sourceHeight * nPercent);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int destWidth = size.Width;
|
||||
int destHeight = size.Height;
|
||||
|
||||
@@ -163,50 +109,6 @@ namespace umbraco.editorControls.imagecropper
|
||||
g.Dispose();
|
||||
|
||||
return b;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if false
|
||||
|
||||
int destWidth = size.Width;
|
||||
int destHeight = size.Height;
|
||||
|
||||
using (Bitmap b = new Bitmap(destWidth, destHeight))
|
||||
{
|
||||
using (Graphics g = Graphics.FromImage(b))
|
||||
{
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
using (ImageAttributes ia = new ImageAttributes())
|
||||
{
|
||||
ia.SetWrapMode(WrapMode.TileFlipXY);
|
||||
g.Clear(Color.White);
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
g.CompositingQuality = CompositingQuality.HighQuality;
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.DrawImage(imgToResize, new Rectangle(0, 0, destWidth, destHeight), 0, 0, imgToResize.Width,
|
||||
imgToResize.Height, GraphicsUnit.Pixel, ia);
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if false
|
||||
int destWidth = size.Width;
|
||||
int destHeight = size.Height;
|
||||
|
||||
Bitmap b = new Bitmap(destWidth, destHeight);
|
||||
Graphics g = Graphics.FromImage((Image)b);
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
|
||||
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
|
||||
g.Dispose();
|
||||
|
||||
return (Image)b;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user