/// <summary> /// 保存图片 /// </summary> /// <param name="files"></param> /// <param name="imageType"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> internal static string Save(HttpFileCollectionBase files, ImageTypeEnum imageType, int width = 1366, int height = 768) { string locaAbsPath = string.Format("{0}/{1}/", Static.FileDirPath, Util.Enum.GetDescriptionString(imageType)); Util.IO.Directory.Create(locaAbsPath); StringBuilder result = new StringBuilder(); for (int i = 0; i < files.Count; i++) { var file = files[i]; if (file.ContentLength <= 0) { continue; } string filename = Util.Utility.MD5.GetMD5_32(string.Format("{0}{1}{2}{3}", DateTime.Now.ToString(), Static.ImageFileOrg, i, Guid.NewGuid())); string fileAbsPath = string.Format("{0}{1}{2}", locaAbsPath, filename, ".jpg"); string newfileAbsPath = EncryptImageNameAndPath(fileAbsPath); file.SaveAs(fileAbsPath); Util.IO.StreamUtil.ResizeImage(fileAbsPath, width, height); result.Append(string.Format("{0},", newfileAbsPath)); } if (result.Length > 0) { result.Length--; } return(result.ToString()); }
private string GetDataUrl(ImageTypeEnum imageType) { if (imageType == ImageTypeEnum.Attachment) { var url = Url.Action(new UrlActionContext { Action = "Upload", Controller = "AttachmentImageUploader", Values = new { pageId = pageDataContextRetriever.Retrieve <TreeNode>().Page.DocumentID } }); return(Url.Kentico().AuthenticateUrlRaw(url, false)); } if (imageType == ImageTypeEnum.MediaFile) { var url = Url.Action(new UrlActionContext { Action = "Upload", Controller = "MediaFileImageUploader", Values = new { libraryName = MEDIA_LIBRARY_NAME }, }); return(Url.Kentico().AuthenticateUrlRaw(url, false)); } return(null); }
public bool Equals(ImageTypeEnum obj) { if ((object)obj == null) { return(false); } return(StringComparer.OrdinalIgnoreCase.Equals(this.Value, obj.Value)); }
public Task <String> UploadImage(ImageTypeEnum type, UploadImageRequest req) { var newfileName = RandomName() + Path.GetExtension(req.Image.FileName); var path = GetPath(type, newfileName); var imagePath = UploadImageToServer(req.Image, path); return(Task.FromResult(GetRelativePath(type, newfileName))); }
public void SetData(int recordid, ImageTypeEnum type) { _recordId = recordid; _type = type; _image1 = _image2 = _image3 = null; _t_imgs1 = _t_imgs2 = _t_imgs3 = null; //pictureBox1.Image = pictureBox2.Image = pictureBox3.Image = _noImage; GetImages(); }
private String GetDefaultPath(ImageTypeEnum type) { var path = ""; switch (type) { case ImageTypeEnum.PROFILE_PICTURE: { path = Path.Combine(AVATAR_ROOT, "default.png"); break; } case ImageTypeEnum.BACKGROUND_PICTURE: { path = Path.Combine(BACKGROUND_ROOT, "default.png"); break; } } return(path); }
/// <summary> /// Retrieves image as byte array by its id. /// </summary> /// <param name="id">The ID of the media library element.</param> /// <param name="imageId">The ID of the image.</param> /// <returns></returns> public async Task <byte[]> GetImage(string id, string imageId, ImageTypeEnum imageType) { if (string.IsNullOrEmpty(id)) { return(null); } if (string.IsNullOrEmpty(imageId)) { return(null); } ImageCacheItem cacheItem = new ImageCacheItem { Id = imageId, ImageType = imageType.ToString(), MediaElementId = id }; if (isCacheEnabled) { ImageCacheItem retrievedItem = await _localCacheService.Get <ImageCacheItem>(cacheItem.GetFileName()); if (retrievedItem != null) { return(retrievedItem.Image); } } string imageEndpoint = string.Format(GetImageEndpoint, id, imageType, imageId); using (HttpClient cli = new HttpClient()) { cli.AddAuthorizationHeaders(); HttpResponseMessage result = await cli.GetAsync(imageEndpoint); byte[] retrievedImage = await result.Content.ReadAsByteArrayAsync(); if (isCacheEnabled) { cacheItem.Image = retrievedImage; #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed _localCacheService.Set(cacheItem.GetFileName(), cacheItem); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } return(retrievedImage); } }
private String GetRelativePath(ImageTypeEnum type, String name) { var path = ""; switch (type) { case ImageTypeEnum.PROFILE_PICTURE: { path = Path.Combine("images", "avatars", name); break; } case ImageTypeEnum.BACKGROUND_PICTURE: { path = Path.Combine("images", "backgrounds", name); break; } case ImageTypeEnum.POST_PICTURE: { path = Path.Combine("images", "posts", name); break; } } return(path); }
public async Task <List <string> > UploadImages(ImageTypeEnum type, ICollection <IFormFile> images) { var result = new List <String>(); foreach (IFormFile image in images) { var newfileName = RandomName() + Path.GetExtension(image.FileName); var path = GetPath(type, newfileName); var pathAbs = await UploadImageToServer(image, path); var relPath = GetRelativePath(type, newfileName); result.Add(relPath); } return(await Task.FromResult(result)); }
public IViewComponentResult Invoke(string propertyName, bool hasImage, ImageTypeEnum imageType, bool useAbsolutePosition, PanelPositionEnum messagePosition) { var model = new ImageUploaderEditorViewModel { PropertyName = propertyName, HasImage = hasImage, UseAbsolutePosition = useAbsolutePosition, MessagePosition = messagePosition, ImageType = imageType, DataUrl = GetDataUrl(imageType) }; return(View("~/Views/Shared/Components/ImageUploaderEditor/_ImageUploaderEditor.cshtml", model)); }
private String GetPath(ImageTypeEnum type, String name) { var path = ""; switch (type) { case ImageTypeEnum.PROFILE_PICTURE: { path = Path.Combine(AVATAR_ROOT, name); break; } case ImageTypeEnum.BACKGROUND_PICTURE: { path = Path.Combine(BACKGROUND_ROOT, name); break; } case ImageTypeEnum.POST_PICTURE: { path = Path.Combine(POST_ROOT, name); break; } } return(path); }
public Person AddImage(int personId, HttpPostedFileBase uploadedFile, ImageTypeEnum imageType) { Person editPerson; var dateCreated = DateTime.Now; const string createdBy = "jhendrikse"; using (var dbContext = new SDIIS_DatabaseEntities()) { try { editPerson = (from p in dbContext.Persons where p.Person_Id.Equals(personId) select p).FirstOrDefault(); if (editPerson == null) { return(null); } var profilePhoto = new Person_Image() { Person_Id = editPerson.Person_Id, Image_Filename = Path.GetFileName(uploadedFile.FileName), Image_Content_Type = uploadedFile.ContentType, Image_Type_Id = (int)imageType, Date_Created = dateCreated, Created_By = createdBy }; using (var reader = new BinaryReader(uploadedFile.InputStream)) { profilePhoto.Image_Content = reader.ReadBytes(uploadedFile.ContentLength); } editPerson.Images.Add(profilePhoto); dbContext.SaveChanges(); } catch (Exception) { return(null); } } return(editPerson); }
private void RegisterImage(string message, string imageName, ImageTypeEnum imageType, string imageAttributes, Guid sdkMessageProcessingStepId) { var image = new Entity("sdkmessageprocessingstepimage"); image["name"] = imageName; image["imagetype"] = new OptionSetValue((int)imageType); image["sdkmessageprocessingstepid"] = new EntityReference("sdkmessageprocessingstep", sdkMessageProcessingStepId); image["attributes"] = imageAttributes.Replace(" ", ""); image["entityalias"] = imageName; image["messagepropertyname"] = message == "Create" ? "Id" : "Target"; var fetchData = new { sdkmessageprocessingstepid = sdkMessageProcessingStepId, entityalias = imageName, imagetype = (int)imageType }; var fetchXml = $@" <fetch> <entity name='sdkmessageprocessingstepimage'> <attribute name='sdkmessageprocessingstepimageid' /> <filter type='and'> <condition attribute='sdkmessageprocessingstepid' operator='eq' value='{fetchData.sdkmessageprocessingstepid}'/> <condition attribute='entityalias' operator='eq' value='{fetchData.entityalias}'/> <condition attribute='imagetype' operator='eq' value='{fetchData.imagetype}'/> </filter> </entity> </fetch>"; var rows = CrmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml)); if (rows.Entities.Count == 0) { CliLog.WriteLine(CliLog.COLOR_GREEN, "\t\t\tRegistering Image: ", CliLog.COLOR_CYAN, $"{imageName}"); CrmServiceClient.Create(image); } else { image["sdkmessageprocessingstepimageid"] = rows.Entities[0].Id; CliLog.WriteLine(CliLog.COLOR_BLUE, "\t\t\tUpdating Image: ", CliLog.COLOR_CYAN, $"{imageName}"); CrmServiceClient.Update(image); } }
public Task <ImageResponse> GetImage(ImageTypeEnum type, UserProfileModel mod) { var path = GetPath(type, mod.ProfilePicturePath); if (mod == null) { return(Task.FromResult(new ImageResponse { ImageAdress = GetDefaultPath(type) })); } if (!File.Exists(Path.Combine(_environment.WebRootPath, path))) { return(Task.FromResult(new ImageResponse { ImageAdress = GetDefaultPath(type) })); } return(Task.FromResult(new ImageResponse { ImageAdress = path })); }
public FormImage(int recordId, ImageTypeEnum type) { InitializeComponent(); menuStrip1.Visible = false; _noImage = Properties.Resources.img_bkg_normal; pictureBox1.Image = _noImage; pictureBox2.Image = _noImage; pictureBox3.Image = _noImage; SetButtomImage(btnSelect1); SetButtomImage(btnselect2); SetButtomImage(btnselect3); SetButtomImage(btnZoom1); SetButtomImage(btnZoom2); SetButtomImage(btnZoom3); SetButtomImage(btnDelete1); SetButtomImage(btndelete2); SetButtomImage(btndelete3); }
protected bool AddImage(HttpPostedFile file, ImageTypeEnum imageType, string remoteUrl) { if ((file != null) && !string.IsNullOrEmpty(file.FileName)) { byte[] buffer = new byte[file.InputStream.Length]; BCImage image = new BCImage(); RPCResponse <BCImage> result = null; file.InputStream.Read(buffer, 0, buffer.Length); image.type = imageType; image.remoteUrl = remoteUrl; image.id = this.video.id; image.displayName = Path.GetFileName(file.FileName);; result = this.bcApi.AddImage(image, image.displayName, buffer, this.video.id, true); if ((result.error.code != null) || (result.error.message != null)) { return(false); } } return(true); }
private void RegisterImage(string message, string imageName, string imageAliasName, ImageTypeEnum imageType, string imageAttributes, Guid sdkMessageProcessingStepId) { if (imageAliasName.Length == 0) { imageAliasName = imageName; } var image = new Entity("sdkmessageprocessingstepimage") { ["name"] = imageName, ["imagetype"] = new OptionSetValue((int)imageType), ["sdkmessageprocessingstepid"] = new EntityReference("sdkmessageprocessingstep", sdkMessageProcessingStepId), ["attributes"] = imageAttributes.Replace(" ", ""), ["entityalias"] = imageAliasName, ["messagepropertyname"] = message == "Create" ? "Id" : "Target" }; var fetchData = new { name = imageName, sdkmessageprocessingstepid = sdkMessageProcessingStepId, imagetype = (int)imageType }; var fetchXml = $@" <fetch> <entity name='sdkmessageprocessingstepimage'> <attribute name='sdkmessageprocessingstepimageid' /> <attribute name='name' /> <attribute name='entityalias' /> <attribute name='attributes' /> <attribute name='imagetype' /> <filter type='and'> <condition attribute='sdkmessageprocessingstepid' operator='eq' value='{fetchData.sdkmessageprocessingstepid}'/> <condition attribute='imagetype' operator='eq' value='{fetchData.imagetype}'/> <condition attribute='name' operator='eq' value='{fetchData.name}'/> </filter> </entity> </fetch>"; var rows = CrmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml)); if (rows.Entities.Count == 0) { if (imageAttributes.Replace(" ", "").Length > 0) { CliLog.WriteLine(CliLog.ColorRed, "\t\t\tRegistering", CliLog.ColorGreen, " Image: ", CliLog.ColorCyan, $"{imageName}"); CrmServiceClient.Create(image); } } else { var row = rows.Entities[0]; var name = row.GetAttributeValue <string>("name"); var entityalias = row.GetAttributeValue <string>("entityalias"); var attributes = row.GetAttributeValue <string>("attributes"); var imagetype = row.GetAttributeValue <OptionSetValue>("imagetype").Value; if (name == imageName && entityalias == imageAliasName && attributes == imageAttributes.Replace(" ", "") && imagetype == (int)imageType) { CliLog.WriteLine(CliLog.ColorRed, "\t\t\tNo Change", CliLog.ColorGreen, " Image: ", CliLog.ColorCyan, $"{imageName}"); } else { if (attributes != imageAttributes.Replace(" ", "") && imageAttributes.Replace(" ", "").Length != 0) { image["sdkmessageprocessingstepimageid"] = rows.Entities[0].Id; CliLog.WriteLine(CliLog.ColorRed, "\t\t\tUpdating", CliLog.ColorGreen, " Image: ", CliLog.ColorCyan, $"{imageName}"); CrmServiceClient.Update(image); } else if (imageAttributes.Replace(" ", "").Length == 0) { CliLog.WriteLine(CliLog.ColorRed, "\t\t\tDeleting", CliLog.ColorGreen, " Image: ", CliLog.ColorCyan, $"{imageName}"); CrmServiceClient.Delete("sdkmessageprocessingstepimage", rows.Entities[0].Id); } } } }
/// <summary> /// 保存图片 多图片之间用","隔开 /// </summary> /// <param name="files"></param> /// <param name="imageType"></param> /// <returns></returns> public static string SaveImage(HttpFileCollectionBase files, ImageTypeEnum imageType) { return(ImageDao.Save(files, imageType)); }
private Dictionary <string, string> CheckOrSaveExperienceReportImg(Boolean isSave = false, Boolean notcheck = false) { #region 图片上传与检测 Dictionary <string, string> result = new Dictionary <string, string>(); result["success"] = ""; result["error"] = ""; HttpFileCollection Files = System.Web.HttpContext.Current.Request.Files; int fileCount = 0; if (Files != null && Files.Count > 0)// && Files[0].ContentLength > 0) { List <string> indexes = new List <string>(); string types = null;// AppSettingManager.AppSettings["InputUserCommentImgType"]; string[] allowTypes = string.IsNullOrEmpty(types) ? (new string[] { ".jpg", ".gif", ".png", ".jpeg" }) : (types.Split('/')); //允许上传的大小 , 以字节为单位 , 稍后读取配置文件 int allowSize = 4 * 1024 * 1024; for (int i = 0; i < Files.Count; i++) { if (indexes.Contains(i.ToString()) || Files[i].ContentLength == 0) { continue; } string fileFullName = Files[i].FileName; string fileType = System.IO.Path.GetExtension(fileFullName).ToLower(); string fileName = Path.GetFileName(fileFullName); ImageTypeEnum[] allowType = new ImageTypeEnum[] { ImageTypeEnum.JPG, ImageTypeEnum.PNG, ImageTypeEnum.GIF }; if (notcheck || allowTypes.Contains(fileType) && (allowType.Contains(ImageTypeCheck.CheckImageType(Files[i].InputStream, false)))) { int conLen = Files[i].ContentLength; if (conLen <= allowSize && conLen > 0)//需要保存时 { if (fileCount == 3) { result["error"] = "上传图片数量最多为3张"; return(result); } fileCount++; if (!isSave) { continue; } UserPictureFile model = new UserPictureFile(); //读取文件为 二进制流 , 保存到 图片表 , 返回 图片编号 model = productCommentService.SavePostedFile(Files[i]); result["success"] = result["success"] + "|" + model.PictureFileNo; } else if (conLen > allowSize) { result["error"] = "上传文件长度超过4MB"; return(result); } } else { result["error"] = "上传文件类型错误"; return(result); } } } else { result["success"] = ""; } if (fileCount == 0) { result["success"] = ""; result.Add("noimg", "noimg"); } else { if (result["success"].Length == 0) { result["success"] = "1"; } } return(result); #endregion }
private SdkMessageProcessingStepImage RegisterImage(CrmPluginRegistrationAttribute stepAttribute, SdkMessageProcessingStep step, SdkMessageProcessingStepImage[] existingImages, string imageName, ImageTypeEnum imagetype, string attributes) { if (String.IsNullOrWhiteSpace(imageName)) { return(null); } var image = existingImages.Where(a => a.SdkMessageProcessingStepId.Id == step.Id && a.EntityAlias == imageName && a.ImageType.Value == (int)imagetype).FirstOrDefault(); if (image == null) { image = new SdkMessageProcessingStepImage(); } image.Name = imageName; image.ImageType = new OptionSetValue((int)imagetype); image.SdkMessageProcessingStepId = new EntityReference(SdkMessageProcessingStep.EntityLogicalName, step.Id); image.Attributes1 = attributes; image.EntityAlias = imageName; image.MessagePropertyName = stepAttribute.Message == "Create" ? "Id" : "Target"; if (image.Id == Guid.Empty) { _trace.WriteLine("Registering Image '{0}'", image.Name); image.Id = _service.Create(image); } else { _trace.WriteLine("Updating Image '{0}'", image.Name); _ctx.UpdateObject(image); } return(image); }
/// <summary> /// 抓拍图像 /// </summary> /// <param name="FileName">图片保存的路径</param> /// <param name="ImageType">保存图像的类型</param> /// <param name="ImageSize">保存图像的大小</param> /// <param name="ImageQuality">图像的质量</param> /// <returns>true表示成功,false表示失败</returns> public bool SnapsortFromDevice(string FileName, ImageTypeEnum ImageType, ImageSizeEnum ImageSize, ImageQualityEnum ImageQuality) { if (!InitializedForDevice) throw new InvalidOperationException(); string RealFileName = new System.IO.FileInfo(FileName).FullName; switch (ImageType) { case ImageTypeEnum.Bitmap: if (DvcPlayHandle < 0) throw new InvalidOperationException(); return HCSDK.HCNetSDK.NET_DVR_CapturePicture(DvcPlayHandle, RealFileName+".bmp"); case ImageTypeEnum.Jpeg: if (DvcUserID < 0) throw new InvalidOperationException(); HCSDK.HCNetSDK.NET_DVR_JPEGPARA JPEGPARA = new HCSDK.HCNetSDK.NET_DVR_JPEGPARA(); JPEGPARA.wPicSize = (ushort)ImageSize; JPEGPARA.wPicQuality = (ushort)ImageQuality; return HCSDK.HCNetSDK.NET_DVR_CaptureJPEGPicture(DvcUserID, VideoChannel, JPEGPARA, RealFileName+".jpg"); default: throw new ArgumentException(); } }
public ProviderPhoto CreateThumbnailFromOriginal(ImageTypeEnum imageType) { if (this.IsThumbnail) { throw new Exception("warning: attempting to create thumbnail from non-original image"); } ProviderPhoto thumbnail = new ProviderPhoto(); thumbnail.Copy(this); thumbnail.OriginalId = this.Id; thumbnail.AdjustToDimensions(imageType); thumbnail.IsThumbnail = true; thumbnail.PhotoImageType = imageType; return thumbnail; }
public bool Snap(ImageTypeEnum ImageType, ImageSizeEnum ImageSize, ImageQualityEnum ImageQuality) { if (DeviceArea == null || DeviceName == null) throw new InvalidOperationException(); string path = FileManager.FileManager.GetSnapFileName(DeviceArea, DeviceName); this.SnapsortFromDevice(path, ImageType, ImageSize, ImageQuality); return true; }
/// <summary> /// Initializes a new instance of the <see cref="ImageManagementAssetUpdateSpec" /> class. /// </summary> /// <param name="additionalDetails">Additional details about image management asset..</param> /// <param name="cloneType">Image management asset clone type. * FULL_CLONE: Image management asset to be used in full clone automated desktop pool. * INSTANT_CLONE: Image management asset to be used in instant clone desktop pool/farm. (required).</param> /// <param name="imageType">Image management asset image type. * RDSH_APPS: Image management asset to be used for farm creation which is be used in application. * RDSH_DESKTOP: Image management asset is for farm creation to be created. * VDI_DESKTOP: Image management asset is available for desktops/farms to be created. (required).</param> /// <param name="status">Image management asset status. * AVAILABLE: Image management asset is available for desktop pools/farms to be created. * DEPLOYING_VM: Image management asset is deploying VM on the virtual center. * DEPLOYMENT_DONE: Image management asset VM deployed on the virtual center. * DELETED: Image management asset has been deleted. * DISABLED: Image management asset has been disabled and no further pool/farm operation can be done using the same. * FAILED: Image management asset creation has failed. * REPLICATING: Copying the specialized images across all virtual centers. * RETRY_PENDING: When image management asset creation has failed, retry action is pending for asset to be created. * SPECIALIZING_VM: Image management asset is being published and specialized internally like installing agents etc. (required).</param> public ImageManagementAssetUpdateSpec(Dictionary <string, string> additionalDetails = default(Dictionary <string, string>), CloneTypeEnum cloneType = default(CloneTypeEnum), ImageTypeEnum imageType = default(ImageTypeEnum), StatusEnum status = default(StatusEnum)) { // to ensure "cloneType" is required (not null) if (cloneType == null) { throw new InvalidDataException("cloneType is a required property for ImageManagementAssetUpdateSpec and cannot be null"); } else { this.CloneType = cloneType; } // to ensure "imageType" is required (not null) if (imageType == null) { throw new InvalidDataException("imageType is a required property for ImageManagementAssetUpdateSpec and cannot be null"); } else { this.ImageType = imageType; } // to ensure "status" is required (not null) if (status == null) { throw new InvalidDataException("status is a required property for ImageManagementAssetUpdateSpec and cannot be null"); } else { this.Status = status; } this.AdditionalDetails = additionalDetails; }
/// <summary> /// Initializes a new instance of the <see cref="ImageManagementAssetCreateSpec" /> class. /// </summary> /// <param name="additionalDetails">Additional details about image management asset..</param> /// <param name="baseSnapshotId">Virtual machine snapshot. Must be set if vm_template_id is unset..</param> /// <param name="baseVmId">Virtual machine ID. Must be set if vm_template_id is unset..</param> /// <param name="cloneType">Image management asset clone type. * FULL_CLONE: Image management asset to be used in full clone automated desktop pool. * INSTANT_CLONE: Image management asset to be used in instant clone desktop pool/farm. (required).</param> /// <param name="imStreamId">Image management stream to which this asset belongs to. (required).</param> /// <param name="imVersionId">Image management version to which this asset belongs to. (required).</param> /// <param name="imageType">Image management asset image type. * RDSH_APPS: Image management asset to be used for farm creation which is be used in application. * RDSH_DESKTOP: Image management asset is for farm creation to be created. * VDI_DESKTOP: Image management asset is available for desktops/farms to be created. (required).</param> /// <param name="status">Image management asset status. * AVAILABLE: Image management asset is available for desktop pools/farms to be created. * DEPLOYING_VM: Image management asset is deploying VM on the virtual center. * DEPLOYMENT_DONE: Image management asset VM deployed on the virtual center. * DELETED: Image management asset has been deleted. * DISABLED: Image management asset has been disabled and no further pool/farm operation can be done using the same. * FAILED: Image management asset creation has failed. * REPLICATING: Copying the specialized images across all virtual centers. * RETRY_PENDING: When image management asset creation has failed, retry action is pending for asset to be created. * SPECIALIZING_VM: Image management asset is being published and specialized internally like installing agents etc. (required).</param> /// <param name="vcenterId">Virtual Center where this asset is created. (required).</param> /// <param name="vmTemplateId">Virtual machine template ID..</param> public ImageManagementAssetCreateSpec(Dictionary <string, string> additionalDetails = default(Dictionary <string, string>), string baseSnapshotId = default(string), string baseVmId = default(string), CloneTypeEnum cloneType = default(CloneTypeEnum), string imStreamId = default(string), string imVersionId = default(string), ImageTypeEnum imageType = default(ImageTypeEnum), StatusEnum status = default(StatusEnum), string vcenterId = default(string), string vmTemplateId = default(string)) { // to ensure "cloneType" is required (not null) if (cloneType == null) { throw new InvalidDataException("cloneType is a required property for ImageManagementAssetCreateSpec and cannot be null"); } else { this.CloneType = cloneType; } // to ensure "imStreamId" is required (not null) if (imStreamId == null) { throw new InvalidDataException("imStreamId is a required property for ImageManagementAssetCreateSpec and cannot be null"); } else { this.ImStreamId = imStreamId; } // to ensure "imVersionId" is required (not null) if (imVersionId == null) { throw new InvalidDataException("imVersionId is a required property for ImageManagementAssetCreateSpec and cannot be null"); } else { this.ImVersionId = imVersionId; } // to ensure "imageType" is required (not null) if (imageType == null) { throw new InvalidDataException("imageType is a required property for ImageManagementAssetCreateSpec and cannot be null"); } else { this.ImageType = imageType; } // to ensure "status" is required (not null) if (status == null) { throw new InvalidDataException("status is a required property for ImageManagementAssetCreateSpec and cannot be null"); } else { this.Status = status; } // to ensure "vcenterId" is required (not null) if (vcenterId == null) { throw new InvalidDataException("vcenterId is a required property for ImageManagementAssetCreateSpec and cannot be null"); } else { this.VcenterId = vcenterId; } this.AdditionalDetails = additionalDetails; this.BaseSnapshotId = baseSnapshotId; this.BaseVmId = baseVmId; this.VmTemplateId = vmTemplateId; }
private void RegisterImage(string message, string imageName, string imageAliasName, ImageTypeEnum imageType, string imageAttributes, Guid sdkMessageProcessingStepId, string pluginType) { if (imageAliasName.Length == 0) { imageAliasName = imageName; } if (imageAttributes.Length == 0) { CliLog.WriteLine(); CliLog.WriteLine(); CliLog.WriteLine(ConsoleColor.Red, "!!! Plugin Type: ", ConsoleColor.Green, pluginType, ConsoleColor.Red, " register ", ConsoleColor.Green, "Image", ConsoleColor.Red, " need provide ", ConsoleColor.Green, "ImageAttributes", ConsoleColor.Red, " value !!!"); CliLog.WriteLine(); CliLog.WriteLine(); CliLog.WriteLine(ConsoleColor.Red, "!!! DEPLOY [PLUGIN] FAILED !!!"); throw new Exception(); } var image = new Entity("sdkmessageprocessingstepimage") { ["name"] = imageName, ["imagetype"] = new OptionSetValue((int)imageType), ["sdkmessageprocessingstepid"] = new EntityReference("sdkmessageprocessingstep", sdkMessageProcessingStepId), ["attributes"] = imageAttributes.Replace(" ", ""), ["entityalias"] = imageAliasName, ["messagepropertyname"] = message == "Create" ? "Id" : "Target" }; var fetchData = new { name = imageName, sdkmessageprocessingstepid = sdkMessageProcessingStepId, imagetype = (int)imageType }; var fetchXml = $@" <fetch> <entity name='sdkmessageprocessingstepimage'> <attribute name='sdkmessageprocessingstepimageid' /> <attribute name='name' /> <attribute name='entityalias' /> <attribute name='attributes' /> <attribute name='imagetype' /> <filter type='and'> <condition attribute='sdkmessageprocessingstepid' operator='eq' value='{fetchData.sdkmessageprocessingstepid}'/> <condition attribute='imagetype' operator='eq' value='{fetchData.imagetype}'/> <condition attribute='name' operator='eq' value='{fetchData.name}'/> </filter> </entity> </fetch>"; var rows = crmServiceClient.RetrieveMultiple(new FetchExpression(fetchXml)); if (rows.Entities.Count == 0) { if (imageAttributes.Replace(" ", "").Length > 0) { CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorRed, " Registering", CliLog.ColorGreen, " Image: ", CliLog.ColorCyan, $"{imageName}"); try { crmServiceClient.Create(image); } catch { CliLog.WriteLine(); CliLog.WriteLine(); CliLog.WriteLine(ConsoleColor.Red, "!!! Plugin Type: ", ConsoleColor.Green, pluginType, ConsoleColor.Red, " does not support: ", ConsoleColor.Green, imageType.ToString()); CliLog.WriteLine(); CliLog.WriteLine(); CliLog.WriteLine(ConsoleColor.Red, "!!! DEPLOY [PLUGIN] FAILED !!!"); throw; } } } else { var row = rows.Entities[0]; var name = row.GetAttributeValue <string>("name"); var entityalias = row.GetAttributeValue <string>("entityalias"); var attributes = row.GetAttributeValue <string>("attributes"); var imagetype = row.GetAttributeValue <OptionSetValue>("imagetype").Value; if (name == imageName && entityalias == imageAliasName && attributes == imageAttributes.Replace(" ", "") && imagetype == (int)imageType) { CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorGreen, " Image: ", CliLog.ColorCyan, $"{imageName}"); } else { if (attributes != imageAttributes.Replace(" ", "") && imageAttributes.Replace(" ", "").Length != 0) { image["sdkmessageprocessingstepimageid"] = rows.Entities[0].Id; CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorRed, " Updating", CliLog.ColorGreen, " Image: ", CliLog.ColorCyan, $"{imageName}"); crmServiceClient.Update(image); } else if (imageAttributes.Replace(" ", "").Length == 0) { CliLog.WriteLine(CliLog.ColorWhite, "|", CliLog.ColorRed, " Deleting", CliLog.ColorGreen, " Image: ", CliLog.ColorCyan, $"{imageName}"); crmServiceClient.Delete("sdkmessageprocessingstepimage", rows.Entities[0].Id); } } } }
private SdkMessageProcessingStepImage RegisterImage(CrmPluginRegistrationAttribute stepAttribute, SdkMessageProcessingStep step, List <SdkMessageProcessingStepImage> existingImages, string imageName, ImageTypeEnum imagetype, string attributes) { if (String.IsNullOrWhiteSpace(imageName)) { return(null); } var image = existingImages.FirstOrDefault( a => a.SdkMessageProcessingStepId.Id == step.Id && a.EntityAlias == imageName && a.ImageType == (sdkmessageprocessingstepimage_imagetype)imagetype) ?? new SdkMessageProcessingStepImage(); image.Name = imageName; image.ImageType = (sdkmessageprocessingstepimage_imagetype)imagetype; image.SdkMessageProcessingStepId = new EntityReference(SdkMessageProcessingStep.EntityLogicalName, step.Id); image.Attributes1 = attributes; image.EntityAlias = imageName; switch (stepAttribute.Message) { case "Create": image.MessagePropertyName = "Id"; break; case "SetState": case "SetStateDynamicEntity": image.MessagePropertyName = "EntityMoniker"; break; case "Send": case "DeliverIncoming": case "DeliverPromote": image.MessagePropertyName = "EmailId"; break; default: image.MessagePropertyName = "Target"; break; } if (image.Id == Guid.Empty) { _trace.WriteLine("Registering Image '{0}'", image.Name); image.Id = _service.Create(image); } else { _trace.WriteLine("Updating Image '{0}'", image.Name); _service.Update(image); existingImages.Remove(image); } return(image); }
private void ParseData() { FileInfo fi = null; try { fi = new FileInfo(this._filePath); } catch //(Exception ex) { fi = null; } if ((fi != null) && (fi.Exists == true)) { FileStream fs = null; try { fs = fi.OpenRead(); if (fs.Length > 0) { ITCFILE_HEADER hdr = new ITCFILE_HEADER(); ITCFILE_HEADER2 data = new ITCFILE_HEADER2(); try { hdr.Read(fs); data.Read(fs); this._downloaded = (bool)(data.downloadIndicator == "down"); this._libraryPersistentId = data.libraryPersistentId; this._trackPersistentId = data.trackPersistentId; this._width = data.width; this._height = data.height; int l = (int)(fs.Length - fs.Position); this.m_imageData = new byte[l]; fs.Read(this.m_imageData, 0, l); //Quick read for image signature this._imageType = CheckSignature(this.m_imageData); } catch (EndOfStreamException ex) { Debug.WriteLine(ex); } } } finally { if (fs != null) fs.Close(); } } }
/// <summary> /// Auto-resize width and height to fit within max dimensions given by ImageTypeAttributes for the given ImageType /// </summary> /// <param name="imageType"></param> /// <returns></returns> public bool AdjustToDimensions(ImageTypeEnum imageType) { return AdjustToDimensions(ProviderPhotoRecord.ImageTypeAttributes[imageType].Item1, ProviderPhotoRecord.ImageTypeAttributes[imageType].Item2); }
protected bool AddImage(HttpPostedFile file, ImageTypeEnum imageType, string remoteUrl) { if ((file != null) && !string.IsNullOrEmpty(file.FileName)) { byte[] buffer = new byte[file.InputStream.Length]; BCImage image = new BCImage(); RPCResponse<BCImage> result = null; file.InputStream.Read(buffer, 0, buffer.Length); image.type = imageType; image.remoteUrl = remoteUrl; image.id = this.video.id; image.displayName = Path.GetFileName(file.FileName);; result = this.bcApi.AddImage(image, image.displayName, buffer, this.video.id, true); if ((result.error.code != null) || (result.error.message != null)) { return false; } } return true; }