protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (localContext == null) { throw new ArgumentNullException(nameof(localContext)); } EntityReference noteWithAttachment = NoteWithAttachment.Get(context); if (noteWithAttachment == null) { throw new ArgumentNullException("Note cannot be null"); } string fileName = FileName.Get(context); bool appendNotice = AppendNotice.Get(context); Entity note = GetNote(localContext.OrganizationService, noteWithAttachment.Id); if (!CheckForAttachment(note)) { return; } StringBuilder notice = new StringBuilder(); int numberOfAttachmentsDeleted = 0; if (String.Equals(note.GetAttributeValue <string>("filename"), fileName, StringComparison.CurrentCultureIgnoreCase)) { numberOfAttachmentsDeleted++; if (appendNotice) { notice.AppendLine("Deleted Attachment: " + note.GetAttributeValue <string>("filename") + " " + DateTime.Now.ToShortDateString()); } UpdateNote(localContext.OrganizationService, note, notice.ToString()); } NumberOfAttachmentsDeleted.Set(context, numberOfAttachmentsDeleted); }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracer = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); try { EntityReference noteWithAttachment = NoteWithAttachment.Get(executionContext); string fileName = FileName.Get(executionContext); bool appendNotice = AppendNotice.Get(executionContext); Entity note = GetNote(service, noteWithAttachment.Id); if (!CheckForAttachment(note)) { return; } StringBuilder notice = new StringBuilder(); int numberOfAttachmentsDeleted = 0; if (String.Equals(note.GetAttributeValue <string>("filename"), fileName, StringComparison.CurrentCultureIgnoreCase)) { numberOfAttachmentsDeleted++; if (appendNotice) { notice.AppendLine("Deleted Attachment: " + note.GetAttributeValue <string>("filename") + " " + DateTime.Now.ToShortDateString()); } UpdateNote(service, note, notice.ToString()); } NumberOfAttachmentsDeleted.Set(executionContext, numberOfAttachmentsDeleted); } catch (Exception ex) { tracer.Trace("Exception: {0}", ex.ToString()); } }
private void MoveFromSlot(Employee employee, string attachmentId) { var slot = employee.AttachmentsBySlot.Where(x => x.SlotId == SlotId && x.Attachment != null && x.Attachment.Id == attachmentId).First(); var note = new NoteWithAttachment() { Note = DownNoteText, Attachment = slot.Attachment, RealDate = slot.Date, RegisterDate = slot.Date }; if (employee.Notes == null) { employee.Notes = new List <NoteWithAttachment>(); } employee.Notes.Add(note); employee.AttachmentsBySlot.Remove(slot); }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracer = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); try { EntityReference noteWithAttachment = NoteWithAttachment.Get(executionContext); int deleteSizeMax = DeleteSizeMax.Get(executionContext); int deleteSizeMin = DeleteSizeMin.Get(executionContext); string extensions = Extensions.Get(executionContext); bool appendNotice = AppendNotice.Get(executionContext); if (deleteSizeMax == 0) { deleteSizeMax = int.MaxValue; } if (deleteSizeMin > deleteSizeMax) { tracer.Trace("Exception: {0}", "Min:" + deleteSizeMin + " Max:" + deleteSizeMax); throw new InvalidPluginExecutionException("Minimum Size Cannot Be Greater Than Maximum Size"); } Entity note = GetNote(service, noteWithAttachment.Id); if (!CheckForAttachment(note)) { return; } string[] filetypes = new string[0]; if (!string.IsNullOrEmpty(extensions)) { filetypes = extensions.Replace(".", string.Empty).Split(','); } StringBuilder notice = new StringBuilder(); int numberOfAttachmentsDeleted = 0; bool delete = false; if (note.GetAttributeValue <int>("filesize") >= deleteSizeMax) { delete = true; } if (note.GetAttributeValue <int>("filesize") <= deleteSizeMin) { delete = true; } if (filetypes.Length > 0 && delete) { delete = ExtensionMatch(filetypes, note.GetAttributeValue <string>("filename")); } if (delete) { numberOfAttachmentsDeleted++; if (appendNotice) { notice.AppendLine("Deleted Attachment: " + note.GetAttributeValue <string>("filename") + " " + DateTime.Now.ToShortDateString()); } UpdateNote(service, note, notice.ToString()); } NumberOfAttachmentsDeleted.Set(executionContext, numberOfAttachmentsDeleted); } catch (Exception ex) { tracer.Trace("Exception: {0}", ex.ToString()); } }
protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (localContext == null) { throw new ArgumentNullException(nameof(localContext)); } EntityReference noteWithAttachment = NoteWithAttachment.Get(context); int deleteSizeMax = DeleteSizeMax.Get(context); int deleteSizeMin = DeleteSizeMin.Get(context); string extensions = Extensions.Get(context); bool appendNotice = AppendNotice.Get(context); if (deleteSizeMax == 0) { deleteSizeMax = int.MaxValue; } if (deleteSizeMin > deleteSizeMax) { localContext.TracingService.Trace("Exception: {0}", "Min:" + deleteSizeMin + " Max:" + deleteSizeMax); throw new InvalidPluginExecutionException("Minimum Size Cannot Be Greater Than Maximum Size"); } Entity note = GetNote(localContext.OrganizationService, noteWithAttachment.Id); if (!CheckForAttachment(note)) { return; } string[] filetypes = new string[0]; if (!string.IsNullOrEmpty(extensions)) { filetypes = extensions.Replace(".", string.Empty).Split(','); } StringBuilder notice = new StringBuilder(); int numberOfAttachmentsDeleted = 0; bool delete = note.GetAttributeValue <int>("filesize") >= deleteSizeMax; if (note.GetAttributeValue <int>("filesize") <= deleteSizeMin) { delete = true; } if (filetypes.Length > 0 && delete) { delete = ExtensionMatch(filetypes, note.GetAttributeValue <string>("filename")); } if (delete) { numberOfAttachmentsDeleted++; if (appendNotice) { notice.AppendLine("Deleted Attachment: " + note.GetAttributeValue <string>("filename") + " " + DateTime.Now.ToShortDateString()); } UpdateNote(localContext.OrganizationService, note, notice.ToString()); } NumberOfAttachmentsDeleted.Set(context, numberOfAttachmentsDeleted); }