public void ConvertTo_DataUri() { //arrange var value = "data:image/jpeg;base64,QUJDREVGRw=="; var expected_DataUri = new DataUri("image/jpeg", new byte[] { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 }); //act var typeconverter = Create_DataUriTypeConverter(); var actual_DataUri = (DataUri)typeconverter.ConvertFrom(value); //assert Assert.That(actual_DataUri, Is.Not.Null); Assert.That(actual_DataUri, Is.TypeOf<System.DataUri>()); //Assert.That(actual_DataUri.MediaType, Is.EqualTo("image/jpeg")); //Assert.That(actual_DataUri.Bytes, Is.EqualTo(expected_DataUri.Bytes)); }
public void Null_Value_throws_ArgumentNullException() { //assert //act //assert Assert.Throws <ArgumentNullException>(() => { DataUri.Parse((string)null); }); }
public void Must_start_with_data_throws_ArgumentException(string input) { //assert //act //assert Assert.Throws <ArgumentException>(() => { DataUri.Parse(input); }); }
public void Tolerates_whitespace_within_base64(string input, string expectedBytesStr) { //arrange byte[] expectedBytes = HexStringToByteArray(expectedBytesStr); //act var datauri = DataUri.Parse(input); //assert Assert.That(datauri, Is.Not.Null); Assert.That(datauri.Bytes, Is.EqualTo(expectedBytes)); Assert.That(datauri.MediaType, Is.EqualTo((string)null)); }
public void Parse_Base64_Specified_MediaType(string input, string expectedBytesStr) { //arrange byte[] expectedBytes = HexStringToByteArray(expectedBytesStr); string expected_MediaType = "image/jpeg"; //if not specified, media type is assumed to be text/plain //act var datauri = DataUri.Parse(input); //assert Assert.That(datauri, Is.Not.Null); Assert.That(datauri.Bytes, Is.EqualTo(expectedBytes)); Assert.That(datauri.MediaType, Is.EqualTo(expected_MediaType)); }
public override object ConvertFrom(ComponentModel.ITypeDescriptorContext context, Globalization.CultureInfo culture, object value) { if (value is string) { string valstr = value as string; if (string.IsNullOrEmpty(valstr) == false && valstr.StartsWith("data:")) { return(DataUri.Parse(valstr)); } else { return(null); } } return(base.ConvertFrom(context, culture, value)); }
/// <summary> /// Loads the Current Item /// </summary> private void LoadCurrentItem() { if (CurrentItem == null) { return; } examGridPanel.Visible = true; ValidateItem(); //set selected on menu DataUri[] dataUris = new DataUri[1]; dataUris[0] = new DataUri(CurrentItem.ID); TreeviewDataContext.DefaultItem = CurrentItem.ID.ToString(); TreeviewDataContext.Folder = CurrentItem.Paths.FullPath; TreeviewDataContext.Selected = dataUris; TreeviewDataContext.AddSelected(new DataUri(CurrentItem.ID)); TreeviewDataContext.Refresh(); //reset form SetDisplay(); //make sure we are on a velir image IFieldSuiteImage fieldSuiteImage = FieldSuiteImageFactory.GetFieldSuiteImage(CurrentItem); if (fieldSuiteImage != null) { CreateContentEditor(CurrentItem); } }
public virtual IItem GetItem(DataUri uri) { return ItemFactory.BuildItem(_database.GetItem(uri)); }
/// <summary> /// Displays the state. /// </summary> /// <param name="workflow"> /// The workflow. /// </param> /// <param name="state"> /// The state. /// </param> /// <param name="items"> /// The items. /// </param> /// <param name="control"> /// The control. /// </param> /// <param name="offset"> /// The offset. /// </param> /// <param name="pageSize"> /// Size of the page. /// </param> protected virtual void DisplayState(IWorkflow workflow, WorkflowState state, DataUri[] items, System.Web.UI.Control control, int offset, int pageSize) { Assert.ArgumentNotNull(workflow, "workflow"); Assert.ArgumentNotNull(state, "state"); Assert.ArgumentNotNull(items, "items"); Assert.ArgumentNotNull(control, "control"); if ((int)items.Length > 0) { int length = offset + pageSize; if (length > (int)items.Length) { length = (int)items.Length; } for (int i = offset; i < length; i++) { DataUri dataUri = items[i]; Item item = Context.ContentDatabase.Items[dataUri]; if (item != null) { this.CreateItem(workflow, item, control); } } Border border = new Border(); border.Background = "#e9e9e9"; Border border1 = border; control.Controls.Add(border1); border1.Margin = "0px 4px 0px 16px"; border1.Padding = "2px 8px 2px 8px"; border1.Border = "1px solid #999999"; WorkflowCommand[] workflowCommandArray = WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(state.StateID)); for (int j = 0; j < (int)workflowCommandArray.Length; j++) { WorkflowCommand workflowCommand = workflowCommandArray[j]; XmlControl webControl = Resource.GetWebControl("WorkboxCommand") as XmlControl; Assert.IsNotNull(webControl, "workboxCommand is null"); webControl["Header"] = string.Concat(workflowCommand.DisplayName, " ", Translate.Text("(selected)")); webControl["Icon"] = workflowCommand.Icon; string[] commandID = new string[] { "workflow:sendselected(command=", workflowCommand.CommandID, ",ws=", state.StateID, ",wf=", workflow.WorkflowID, ")" }; webControl["Command"] = string.Concat(commandID); border1.Controls.Add(webControl); webControl = Resource.GetWebControl("WorkboxCommand") as XmlControl; Assert.IsNotNull(webControl, "workboxCommand is null"); webControl["Header"] = string.Concat(workflowCommand.DisplayName, " ", Translate.Text("(all)")); webControl["Icon"] = workflowCommand.Icon; string[] strArrays = new string[] { "workflow:sendall(command=", workflowCommand.CommandID, ",ws=", state.StateID, ",wf=", workflow.WorkflowID, ")" }; webControl["Command"] = string.Concat(strArrays); border1.Controls.Add(webControl); } } }
/// <summary> /// Jumps the specified sender. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="message"> /// The message. /// </param> /// <param name="offset"> /// The offset. /// </param> private void Jump(object sender, Message message, int offset) { Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(message, "message"); string control = Context.ClientPage.ClientRequest.Control; string str = ShortID.Decode(control.Substring(0, 32)); string str1 = ShortID.Decode(control.Substring(33, 32)); control = control.Substring(0, 65); IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider; Assert.IsNotNull(workflowProvider, string.Concat("Workflow provider for database \"", Context.ContentDatabase.Name, "\" not found.")); IWorkflow workflow = workflowProvider.GetWorkflow(str); Error.Assert(workflow != null, string.Concat("Workflow \"", str, "\" not found.")); Assert.IsNotNull(workflow, "workflow"); WorkflowState state = workflow.GetState(str1); Assert.IsNotNull(state, string.Concat("Workflow state \"", str1, "\" not found.")); Border border = new Border(); border.ID = string.Concat(control, "_content"); Border border1 = border; DataUri[] items = this.GetItems(state, workflow); WorkboxForm workboxForm = this; IWorkflow workflow1 = workflow; WorkflowState workflowState = state; DataUri[] dataUriArray = items; DataUri[] dataUriArray1 = dataUriArray; if (dataUriArray == null) { dataUriArray1 = new DataUri[0]; } workboxForm.DisplayState(workflow1, workflowState, dataUriArray1, border1, offset, this.PageSize); Context.ClientPage.ClientResponse.SetOuterHtml(string.Concat(control, "_content"), border1); }
/// <summary> /// Load Treepicker datacontext /// </summary> private void LoadDataContext() { if (SourceItem == null || Context.ClientPage.IsPostBack) { return; } DataUri[] dataUris = new DataUri[1]; dataUris[0] = new DataUri(SourceItem.ID); addItemDataContext.Root = SourceItem.Paths.FullPath; addItemDataContext.DefaultItem = SourceItem.ID.ToString(); addItemDataContext.Folder = SourceItem.Paths.FullPath; addItemDataContext.Selected = dataUris; addItemDataContext.AddSelected(new DataUri(SourceItem.ID)); addItemDataContext.Refresh(); }
/// <summary> /// Decrypt the given DataUri. /// </summary> public void DownloadData(DataUri dataUri) { if (dataUri != null) { ImagePartType type; if (knownContentType.TryGetValue(dataUri.Mime, out type)) imageInfo.Type = type; imageInfo.RawData = dataUri.Data; } }
protected virtual void DisplayState(IWorkflow workflow, WorkflowState state, DataUri[] items, Control control, int offset, int pageSize) { if (items.Length > 0) { int length = offset + pageSize; if (length > items.Length) { length = items.Length; } for (int i = offset; i < length; i++) { DataUri uri = items[i]; Item item = Context.ContentDatabase.Items[uri]; if (item != null) { this.CreateItem(workflow, item, control); } } Border child = new Border { Background = "#e9e9e9" }; control.Controls.Add(child); child.Margin = "0px 4px 0px 16px"; child.Padding = "2px 8px 2px 8px"; child.Border = "1px solid #999999"; foreach (WorkflowCommand command in WorkflowFilterer.FilterVisibleCommands(workflow.GetCommands(state.StateID))) { XmlControl webControl = Resource.GetWebControl("WorkboxCommand") as XmlControl; webControl["Header"] = command.DisplayName + " " + Translate.Text("(selected)"); webControl["Icon"] = command.Icon; webControl["Command"] = "workflow:sendselected(command=" + command.CommandID + ",ws=" + state.StateID + ",wf=" + workflow.WorkflowID + ")"; child.Controls.Add(webControl); webControl = Resource.GetWebControl("WorkboxCommand") as XmlControl; webControl["Header"] = command.DisplayName + " " + Translate.Text("(all)"); webControl["Icon"] = command.Icon; webControl["Command"] = "workflow:sendall(command=" + command.CommandID + ",ws=" + state.StateID + ",wf=" + workflow.WorkflowID + ")"; child.Controls.Add(webControl); } } }