本文整理汇总了C#中System.Guid.HasDefaultValue方法的典型用法代码示例。如果您正苦于以下问题:C# Guid.HasDefaultValue方法的具体用法?C# Guid.HasDefaultValue怎么用?C# Guid.HasDefaultValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Guid
的用法示例。
在下文中一共展示了Guid.HasDefaultValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveSubscriber
/// <summary>
/// Saves the newsletter subscriber.
/// </summary>
/// <param name="email">The subscriber email.</param>
/// <param name="id">The subscriber id.</param>
/// <param name="version">The version.</param>
/// <param name="ignoreUniqueSubscriberException">if set to <c>true</c> ignore unique subscriber exception.</param>
/// <returns>
/// Saved entity
/// </returns>
public Subscriber SaveSubscriber(string email, Guid id, int version, bool ignoreUniqueSubscriberException = false)
{
var isNew = id.HasDefaultValue();
Subscriber subscriber;
// Validate
if (!ValidateSubscriber(id, email, out subscriber))
{
var logMessage = string.Format("Subscriber with entered Email {0} already is subscribed.", email);
if (!ignoreUniqueSubscriberException)
{
var message = string.Format(NewsletterGlobalization.SaveSubscriberCommand_EmailAlreadyExists_Message, email);
throw new UniqueSubscriberException(() => message, logMessage);
}
Logger.Info(logMessage);
return subscriber;
}
if (isNew)
{
subscriber = new Subscriber();
}
else
{
subscriber = repository.AsQueryable<Subscriber>(w => w.Id == id).FirstOne();
}
subscriber.Email = email;
subscriber.Version = version;
repository.Save(subscriber);
unitOfWork.Commit();
if (isNew)
{
Events.NewsletterEvents.Instance.OnSubscriberCreated(subscriber);
}
else
{
Events.NewsletterEvents.Instance.OnSubscriberUpdated(subscriber);
}
return subscriber;
}
示例2: ValidateSubscriber
/// <summary>
/// Validates the subscriber.
/// </summary>
/// <param name="id">The id.</param>
/// <param name="email">The email.</param>
/// <param name="subscriber">The subscriber.</param>
/// <returns></returns>
private bool ValidateSubscriber(Guid id, string email, out Subscriber subscriber)
{
var query = repository.AsQueryable<Subscriber>(s => s.Email == email);
if (!id.HasDefaultValue())
{
query = query.Where(s => s.Id != id);
}
subscriber = query.FirstOrDefault();
return subscriber == null;
}
示例3: UploadImage
/// <summary>
/// Uploads the image.
/// </summary>
/// <param name="rootFolderId">The root folder id.</param>
/// <param name="fileName">Name of the file.</param>
/// <param name="fileLength">Length of the file.</param>
/// <param name="fileStream">The file stream.</param>
/// <param name="reuploadMediaId">The reupload media identifier.</param>
/// <param name="overrideUrl">if set to <c>true</c> override URL.</param>
/// <returns>
/// Image entity.
/// </returns>
public MediaImage UploadImage(Guid rootFolderId, string fileName, long fileLength, Stream fileStream, Guid reuploadMediaId, bool overrideUrl = true)
{
overrideUrl = false; // TODO: temporary disabling feature #1055.
using (var thumbnailFileStream = new MemoryStream())
{
MediaImage originalImage;
string folderName;
string publicFileName;
fileStream = RotateImage(fileStream);
var size = GetSize(fileStream);
CreatePngThumbnail(fileStream, thumbnailFileStream, ThumbnailSize);
if (!reuploadMediaId.HasDefaultValue())
{
// Re-uploading image: Get original image, folder name, file extension, file name
originalImage = repository.First<MediaImage>(image => image.Id == reuploadMediaId);
folderName = Path.GetFileName(Path.GetDirectoryName(originalImage.FileUri.OriginalString));
MediaImage clonedOriginalImage = (MediaImage)originalImage.Clone();
clonedOriginalImage.Original = originalImage;
// Get original file stream
using (var originalFileStream = DownloadFileStream(originalImage.PublicUrl))
{
// Get thumbnail file stream
using (var originalThumbnailFileStream = DownloadFileStream(originalImage.PublicThumbnailUrl))
{
// Check is re-uploaded image has the same extension as original
var reuploadedFileExtension = Path.GetExtension(fileName);
if (reuploadedFileExtension != null && !reuploadedFileExtension.Equals(originalImage.OriginalFileExtension))
{
fileStream = UpdateCodec(fileStream, originalFileStream);
}
// Create version file name for current original image
var historicalUrl = MediaImageHelper.CreateHistoricalVersionedFileName(
clonedOriginalImage.OriginalFileName,
clonedOriginalImage.OriginalFileExtension);
// Update urls with version file name
mediaImageVersionPathService.SetPathForArchive(clonedOriginalImage, folderName, historicalUrl);
unitOfWork.BeginTransaction();
repository.Save(clonedOriginalImage);
unitOfWork.Commit();
// Re-upload original and thumbnail images to version urls
StartTasksForImage(clonedOriginalImage, originalFileStream, originalThumbnailFileStream, originalImage.IsEdited());
}
}
UpdateImageProperties(originalImage, rootFolderId, originalImage.OriginalFileName, originalImage.OriginalFileExtension, originalImage.Title, size, fileLength,
thumbnailFileStream.Length);
if (!overrideUrl)
{
publicFileName = MediaImageHelper.CreateVersionedFileName(originalImage.OriginalFileName, GetVersion(originalImage));
mediaImageVersionPathService.SetPathForNewOriginal(originalImage, folderName, publicFileName);
}
}
else
{
// Uploading new image
folderName = mediaFileService.CreateRandomFolderName();
publicFileName = MediaImageHelper.CreatePublicFileName(fileName, Path.GetExtension(fileName));
// Create new original image and upload file stream to the storage
originalImage = CreateImage( rootFolderId, fileName, Path.GetExtension(fileName), fileName, size, fileLength, thumbnailFileStream.Length);
mediaImageVersionPathService.SetPathForNewOriginal(originalImage, folderName, publicFileName);
}
unitOfWork.BeginTransaction();
repository.Save(originalImage);
unitOfWork.Commit();
StartTasksForImage(originalImage, fileStream, thumbnailFileStream, false);
return originalImage;
}
}
示例4: ValidateRoleName
/// <summary>
/// Validates the name of the role.
/// </summary>
/// <param name="id">The id.</param>
/// <param name="name">The name.</param>
private void ValidateRoleName(Guid id, string name)
{
var query = repository
.AsQueryable<Role>(r => r.Name == name.Trim());
if (!id.HasDefaultValue())
{
query = query.Where(r => r.Id != id);
}
var existIngId = query
.Select(r => r.Id)
.FirstOrDefault();
if (!existIngId.HasDefaultValue())
{
var message = string.Format(UsersGlobalization.SaveRole_RoleExists_Message, name);
var logMessage = string.Format("Role already exists. Role name: {0}, Id: {1}", name, id);
throw new ValidationException(() => message, logMessage);
}
}
示例5: SaveNode
/// <summary>
/// Saves the node.
/// </summary>
/// <param name="id">The id.</param>
/// <param name="version">The version.</param>
/// <param name="url">The URL.</param>
/// <param name="title">The title.</param>
/// <param name="displayOrder">The display order.</param>
/// <param name="parentId">The parent id.</param>
/// <param name="isDeleted">if set to <c>true</c> [is deleted].</param>
/// <param name="parentNode">The parent node.</param>
/// <returns>
/// Updated or newly created sitemap node.
/// </returns>
public SitemapNode SaveNode(Guid id, int version, string url, string title, int displayOrder, Guid parentId, bool isDeleted = false, SitemapNode parentNode = null)
{
var node = id.HasDefaultValue()
? new SitemapNode()
: repository.First<SitemapNode>(id);
var oldUrl = node.Url;
if (isDeleted)
{
if (!node.Id.HasDefaultValue())
{
repository.Delete(node);
UpdatedPageProperties(id.HasDefaultValue(), node.IsDeleted, oldUrl, url);
}
}
else
{
node.Version = version;
node.Title = title;
node.Url = url;
node.DisplayOrder = displayOrder;
if (parentNode != null && !parentNode.Id.HasDefaultValue())
{
node.ParentNode = parentNode;
}
else
{
node.ParentNode = parentId.HasDefaultValue()
? null
: repository.First<SitemapNode>(parentId);
}
repository.Save(node);
UpdatedPageProperties(id.HasDefaultValue(), node.IsDeleted, oldUrl, url);
}
return node;
}
示例6: SaveRole
/// <summary>
/// Saves the role.
/// </summary>
/// <param name="id">The id.</param>
/// <param name="version">The version.</param>
/// <param name="name">The name.</param>
/// <param name="description">The description.</param>
/// <param name="newEntityCreated">if set to <c>true</c> new entity was created.</param>
/// <param name="createIfNotExists">if set to <c>true</c> create entity if not exists.</param>
/// <returns>
/// Saved role entity
/// </returns>
/// <exception cref="EntityNotFoundException"></exception>
/// <exception cref="System.ComponentModel.DataAnnotations.ValidationException"></exception>
public Role SaveRole(Guid id, int version, string name, string description, out bool newEntityCreated, bool createIfNotExists = false)
{
// Check if such role doesn't exist
ValidateRoleName(id, name);
Role role = null;
newEntityCreated = id.HasDefaultValue();
if (!newEntityCreated)
{
role = repository.AsQueryable<Role>(f => f.Id == id).FirstOrDefault();
newEntityCreated = role == null;
if (newEntityCreated && !createIfNotExists)
{
throw new EntityNotFoundException(typeof(Role), id);
}
}
if (newEntityCreated)
{
role = new Role { Id = id };
}
if (role.IsSystematic)
{
var logMessage = string.Format("Cannot save systematic role: {0} {1}", role.Name, role.Description);
var message = string.Format(UsersGlobalization.SaveRole_Cannot_Save_Systematic_Role, role.Description ?? role.Name);
throw new ValidationException(() => message, logMessage);
}
if (version > 0)
{
role.Version = version;
}
role.Name = name;
role.Description = description;
repository.Save(role);
return role;
}
示例7: UploadImage
/// <summary>
/// Uploads the image.
/// </summary>
/// <param name="rootFolderId">The root folder id.</param>
/// <param name="fileName">Name of the file.</param>
/// <param name="fileLength">Length of the file.</param>
/// <param name="fileStream">The file stream.</param>
/// <returns>Image entity.</returns>
public MediaImage UploadImage(Guid rootFolderId, string fileName, long fileLength, Stream fileStream)
{
string folderName = mediaFileService.CreateRandomFolderName();
Size size = GetImageSize(fileStream);
using (var thumbnailImage = new MemoryStream())
{
ResizeImageAndCropToFit(fileStream, thumbnailImage, ThumbnailSize);
MediaImage image = new MediaImage();
if (!rootFolderId.HasDefaultValue())
{
image.Folder = repository.AsProxy<MediaFolder>(rootFolderId);
}
image.Title = Path.GetFileName(fileName);
image.Caption = null;
image.FileName = fileName;
image.FileExtension = Path.GetExtension(fileName);
image.Type = MediaType.Image;
image.Width = size.Width;
image.Height = size.Height;
image.Size = fileLength;
image.FileUri = mediaFileService.GetFileUri(MediaType.Image, folderName, fileName);
image.PublicUrl = mediaFileService.GetPublicFileUrl(MediaType.Image, folderName, fileName);
image.CropCoordX1 = null;
image.CropCoordY1 = null;
image.CropCoordX2 = null;
image.CropCoordY2 = null;
image.OriginalWidth = size.Width;
image.OriginalHeight = size.Height;
image.OriginalSize = fileLength;
image.OriginalUri = mediaFileService.GetFileUri(MediaType.Image, folderName, OriginalImageFilePrefix + fileName);
image.PublicOriginallUrl = mediaFileService.GetPublicFileUrl(MediaType.Image, folderName, OriginalImageFilePrefix + fileName);
image.ThumbnailWidth = ThumbnailSize.Width;
image.ThumbnailHeight = ThumbnailSize.Height;
image.ThumbnailSize = thumbnailImage.Length;
image.ThumbnailUri = mediaFileService.GetFileUri(MediaType.Image, folderName, ThumbnailImageFilePrefix + Path.GetFileNameWithoutExtension(fileName) + ".png");
image.PublicThumbnailUrl = mediaFileService.GetPublicFileUrl(MediaType.Image, folderName, ThumbnailImageFilePrefix + Path.GetFileNameWithoutExtension(fileName) + ".png");
image.ImageAlign = null;
image.IsTemporary = true;
image.IsUploaded = false;
image.IsThumbnailUploaded = false;
image.IsOriginalUploaded = false;
unitOfWork.BeginTransaction();
repository.Save(image);
unitOfWork.Commit();
Task imageUpload = mediaFileService.UploadMediaFileToStorage<MediaImage>(fileStream, image.FileUri, image.Id, img => { img.IsUploaded = true; });
Task originalUpload = mediaFileService.UploadMediaFileToStorage<MediaImage>(fileStream, image.OriginalUri, image.Id, img => { img.IsOriginalUploaded = true; });
Task thumbnailUpload = mediaFileService.UploadMediaFileToStorage<MediaImage>(thumbnailImage, image.ThumbnailUri, image.Id, img => { img.IsThumbnailUploaded = true; });
Task.Factory.ContinueWhenAll(
new[]
{
imageUpload,
originalUpload,
thumbnailUpload
},
result =>
{
// During uploading progress Cancel action can by executed. Need to remove uploaded images from the storage.
ExecuteActionOnThreadSeparatedSessionWithNoConcurrencyTracking(session =>
{
var media = session.Get<MediaImage>(image.Id);
if (media.IsCanceled && (media.IsUploaded || media.IsThumbnailUploaded || media.IsOriginalUploaded))
{
RemoveImageWithFiles(media.Id, media.Version);
}
});
});
imageUpload.Start();
originalUpload.Start();
thumbnailUpload.Start();
return image;
}
}
示例8: UploadImage
/// <summary>
/// Uploads the image.
/// </summary>
/// <param name="rootFolderId">The root folder id.</param>
/// <param name="fileName">Name of the file.</param>
/// <param name="fileLength">Length of the file.</param>
/// <param name="fileStream">The file stream.</param>
/// <param name="reuploadMediaId">The reupload media identifier.</param>
/// <param name="overrideUrl">if set to <c>true</c> override URL.</param>
/// <returns>
/// Image entity.
/// </returns>
public MediaImage UploadImage(Guid rootFolderId, string fileName, long fileLength, Stream fileStream, Guid reuploadMediaId, bool overrideUrl = true)
{
overrideUrl = false; // TODO: temporary disabling feature #1055.
using (var thumbnailFileStream = new MemoryStream())
{
var folderName = mediaFileService.CreateRandomFolderName();
fileStream = RotateImage(fileStream);
var size = GetSize(fileStream);
CreatePngThumbnail(fileStream, thumbnailFileStream, ThumbnailSize);
if (!reuploadMediaId.HasDefaultValue())
{
// Re-uploading image: Get original image, folder name, file extension, file name
MediaImage reuploadImage = (MediaImage)repository.First<MediaImage>(image => image.Id == reuploadMediaId).Clone();
reuploadImage.IsTemporary = true;
var publicFileName = RemoveInvalidHtmlSymbols(MediaImageHelper.CreatePublicFileName(fileName, Path.GetExtension(fileName)));
// Create new original image and upload file stream to the storage
reuploadImage = CreateImage(rootFolderId, fileName, Path.GetExtension(fileName), fileName, size, fileLength, thumbnailFileStream.Length);
mediaImageVersionPathService.SetPathForNewOriginal(reuploadImage, folderName, publicFileName);
unitOfWork.BeginTransaction();
repository.Save(reuploadImage);
unitOfWork.Commit();
StartTasksForImage(reuploadImage, fileStream, thumbnailFileStream, false);
return reuploadImage;
}
else
{
// Uploading new image
var publicFileName = RemoveInvalidHtmlSymbols(MediaImageHelper.CreatePublicFileName(fileName, Path.GetExtension(fileName)));
// Create new original image and upload file stream to the storage
MediaImage originalImage = CreateImage(rootFolderId, fileName, Path.GetExtension(fileName), fileName, size, fileLength, thumbnailFileStream.Length);
mediaImageVersionPathService.SetPathForNewOriginal(originalImage, folderName, publicFileName);
unitOfWork.BeginTransaction();
repository.Save(originalImage);
unitOfWork.Commit();
StartTasksForImage(originalImage, fileStream, thumbnailFileStream, false);
return originalImage;
}
}
}
示例9: UploadImage
/// <summary>
/// Uploads the image.
/// </summary>
/// <param name="rootFolderId">The root folder id.</param>
/// <param name="fileName">Name of the file.</param>
/// <param name="fileLength">Length of the file.</param>
/// <param name="fileStream">The file stream.</param>
/// <param name="reuploadMediaId">The reupload media identifier.</param>
/// <param name="overrideUrl">if set to <c>true</c> override URL.</param>
/// <returns>
/// Image entity.
/// </returns>
public MediaImage UploadImage(Guid rootFolderId, string fileName, long fileLength, Stream fileStream, Guid reuploadMediaId, bool overrideUrl = true)
{
overrideUrl = false; // TODO: temporary disabling feature #1055.
var folderName = mediaFileService.CreateRandomFolderName();
var publicFileName = MediaHelper.RemoveInvalidPathSymbols(MediaImageHelper.CreatePublicFileName(fileName, Path.GetExtension(fileName)));
var fileExtension = Path.GetExtension(fileName);
var imageType = ImageHelper.GetImageType(fileExtension);
MediaImage uploadImage = null;
var thumbnailFileStream = new MemoryStream();
Size size;
Size thumbnailSize = ThumbnailSize;
long thumbnailImageLength;
/* Upload standard raster type images */
if (imageType == ImageType.Raster)
{
fileStream = RotateImage(fileStream);
size = GetSize(fileStream);
CreatePngThumbnail(fileStream, thumbnailFileStream, ThumbnailSize);
thumbnailImageLength = thumbnailFileStream.Length;
}
/* Upload vector graphics images */
else
{
size = Size.Empty;
ReadParametersFormVectorImage(fileStream, ref size);
thumbnailImageLength = fileStream.Length;
CreateSvgThumbnail(fileStream, thumbnailFileStream, ThumbnailSize);
}
try
{
if (!reuploadMediaId.HasDefaultValue())
{
// Re-uploading image: Get original image, folder name, file extension, file name
uploadImage = (MediaImage)repository.First<MediaImage>(image => image.Id == reuploadMediaId).Clone();
uploadImage.IsTemporary = true;
// Create new original image and upload file stream to the storage
uploadImage = CreateImage(rootFolderId, fileName, fileExtension, Path.GetFileName(fileName), size, fileLength);
}
else
{
// Uploading new image
// Create new original image and upload file stream to the storage
uploadImage = CreateImage(
rootFolderId,
fileName,
fileExtension,
Path.GetFileName(fileName),
size,
fileLength);
}
SetThumbnailParameters(uploadImage, thumbnailSize, thumbnailImageLength);
mediaImageVersionPathService.SetPathForNewOriginal(uploadImage, folderName, publicFileName, imageType);
unitOfWork.BeginTransaction();
repository.Save(uploadImage);
unitOfWork.Commit();
StartTasksForImage(uploadImage, fileStream, thumbnailFileStream, false);
}
finally
{
if (thumbnailFileStream != null)
{
thumbnailFileStream.Dispose();
}
}
return uploadImage;
}
示例10: SaveRole
/// <summary>
/// Saves the role.
/// </summary>
/// <param name="id">The id.</param>
/// <param name="version">The version.</param>
/// <param name="name">The name.</param>
/// <param name="description">The description.</param>
/// <returns>
/// Saved role entity
/// </returns>
private Role SaveRole(Guid id, int version, string name, string description)
{
// Check if such role doesn't exist
ValidateRoleName(id, name);
Role role;
if (!id.HasDefaultValue())
{
role = repository.AsQueryable<Role>(f => f.Id == id).FirstOne();
if (role.IsSystematic)
{
var logMessage = string.Format("Cannot save systematic role: {0} {1}", role.Name, role.Description);
var message = string.Format(UsersGlobalization.SaveRole_Cannot_Save_Systematic_Role, role.Description ?? role.Name);
throw new ValidationException(() => message, logMessage);
}
role.Version = version;
}
else
{
role = new Role();
}
role.Name = name;
role.Description = description;
repository.Save(role);
return role;
}