public object Compile(Shader shader, ShaderType type, SourceDescription source) { // HLSL design is kinda screwed up, it only allows us to use one // shared source, so we pass through the source and build a // merged sourcecode at linktime return(new Tuple <ShaderType, SourceDescription>(type, source)); }
private void ClearBuffers(SourceDescription source, int count) { if (_context == null) { return; } int[] freedbuffers; if (count == 0) { int buffersProcessed; AL.GetSource(source.Id, ALGetSourcei.BuffersProcessed, out buffersProcessed); if (buffersProcessed == 0) { return; } freedbuffers = AL.SourceUnqueueBuffers(source.Id, buffersProcessed); } else { freedbuffers = AL.SourceUnqueueBuffers(source.Id, count); } AL.DeleteBuffers(freedbuffers); }
//TODO: Create FamilysearchSourceReferencesQueryState class, add it to FamilySearchStateFactory when link is created /* * public FamilySearchSourceReferencesQueryState ReadSourceReferencesQuery() * { * Link link = GetLink( //TODO: Put Rel here when added ); * if (link == null || link.Href = null) * { * return null; * } * * IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(link.Href, Method.GET); * return ((FamilySearchStateFactory)this.stateFactory).NewFamilySearchSourceReferencesQueryState(request, Invoke(request), this.Client, this.CurrentAccessToken); * } */ /// <summary> /// Moves the current source description to the specified collection. /// </summary> /// <param name="collection">The target collection to contain this source description.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="FamilySearchSourceDescriptionState"/> instance containing the REST API response. /// </returns> public FamilySearchSourceDescriptionState MoveToCollection(CollectionState collection, params IStateTransitionOption[] options) { Link link = collection.GetLink(Rel.SOURCE_DESCRIPTIONS); if (link == null || link.Href == null) { return(null); } SourceDescription me = SourceDescription; if (me == null || me.Id == null) { return(null); } Gx.Gedcomx gx = new Gx.Gedcomx(); gx.AddSourceDescription(new SourceDescription() { Id = me.Id }); IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).SetEntity(gx).Build(link.Href, Method.POST); return((FamilySearchSourceDescriptionState)((FamilySearchStateFactory)this.stateFactory).NewSourceDescriptionStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
public void TestDeleteMemoryPersona() { var converter = new ImageConverter(); var bytes = (Byte[])converter.ConvertTo(TestBacking.GetCreatePhoto(), typeof(Byte[])); var dataSource = new BasicDataSource(Guid.NewGuid().ToString("n") + ".jpg", "image/jpeg", bytes); var description = new SourceDescription().SetTitle("PersonImage").SetCitation("Citation for PersonImage").SetDescription("Description"); var image = (SourceDescriptionState)tree.AddArtifact(description, dataSource).Get(); cleanup.Add(image); var person = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(person); var persona = (PersonState)image.AddPersona(new Person().SetName("John Smith")).Get(); person.AddPersonaReference(persona); // Confirm it is there. var personas = tree.ReadPerson(new Uri(person.GetSelfUri())); Assert.Greater(personas.Person.Evidence.Count, 0); var state = personas.DeletePersonaReference(personas.GetPersonaReference()); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.NoContent, state.Response.StatusCode); }
public virtual void VisitSourceDescription(SourceDescription sourceDescription) { this.contextStack.Push(sourceDescription); List <SourceReference> sources = sourceDescription.Sources; if (sources != null) { foreach (SourceReference source in sources) { source.Accept(this); } } List <Note> notes = sourceDescription.Notes; if (notes != null) { foreach (Note note in notes) { note.Accept(this); } } List <SourceCitation> citations = sourceDescription.Citations; if (citations != null) { foreach (SourceCitation citation in citations) { citation.Accept(this); } } this.contextStack.Pop(); }
/// <summary> /// Visits the source description. /// </summary> /// <param name="sourceDescription">The source description to visit.</param> public virtual void VisitSourceDescription(SourceDescription sourceDescription) { this.contextStack.Push(sourceDescription); if (sourceDescription.Sources != null) { foreach (SourceReference source in sourceDescription.Sources) { VisitSourceReference(source); } } if (sourceDescription.Notes != null) { foreach (Note note in sourceDescription.Notes) { VisitNote(note); } } if (sourceDescription.Citations != null) { foreach (SourceCitation citation in sourceDescription.Citations) { VisitSourceCitation(citation); } } this.contextStack.Pop(); }
protected void SetSourceDescription(SourceDescription source) { if (this.description.Source != null) { throw new BindingException("You cannot set the source path of a Fluent binding more than once"); } this.description.Source = source; }
public virtual bool IsSupported(SourceDescription description) { if (!(description is T)) { return(false); } return(true); }
public void TestUploadMultiplePhotoMemories() { var converter = new ImageConverter(); var bytes1 = (Byte[])converter.ConvertTo(TestBacking.GetCreatePhoto(), typeof(Byte[])); var bytes2 = (Byte[])converter.ConvertTo(TestBacking.GetCreatePhoto(), typeof(Byte[])); var dataSource1 = new BasicDataSource(Guid.NewGuid().ToString("n") + ".jpg", "image/jpeg", bytes1); var dataSource2 = new BasicDataSource(Guid.NewGuid().ToString("n") + ".jpg", "image/jpeg", bytes2); var description = new SourceDescription().SetTitle(new TextValue().SetValue("PersonImage")).SetCitation("Citation for PersonImage"); var artifacts = new List <IDataSource>(); artifacts.Add(dataSource1); artifacts.Add(dataSource2); IRestRequest request = new RestRequest() .AddHeader("Authorization", "Bearer " + tree.CurrentAccessToken) .Accept(MediaTypes.GEDCOMX_JSON_MEDIA_TYPE) .ContentType(MediaTypes.MULTIPART_FORM_DATA_TYPE) .Build("https://sandbox.familysearch.org/platform/memories/memories", Method.POST); foreach (var artifact in artifacts) { String mediaType = artifact.ContentType; foreach (TextValue value in description.Titles) { request.AddFile("title", Encoding.UTF8.GetBytes(value.Value), null, MediaTypes.TEXT_PLAIN_TYPE); } foreach (SourceCitation citation in description.Citations) { request.AddFile("citation", Encoding.UTF8.GetBytes(citation.Value), null, MediaTypes.TEXT_PLAIN_TYPE); } if (artifact.Name != null) { request.Files.Add(new FileParameter() { Name = "artifact", FileName = artifact.Name, ContentType = artifact.ContentType, Writer = new Action <Stream>(s => { artifact.InputStream.Seek(0, SeekOrigin.Begin); using (var ms = new MemoryStream(artifact.InputStream.ReadAsBytes())) using (var reader = new StreamReader(ms)) { reader.BaseStream.CopyTo(s); } }) }); } } var state = tree.Client.Handle(request); Assert.IsNotNull(state); Assert.AreEqual(HttpStatusCode.Created, state.StatusCode); }
/// <summary> /// Adds a source description the current collection of source descriptions. /// </summary> /// <param name="source">The source description to add.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="SourceDescriptionState"/> instance containing the REST API response. /// </returns> public SourceDescriptionState AddSourceDescription(SourceDescription source, params IStateTransitionOption[] options) { Gedcomx entity = new Gedcomx(); entity.AddSourceDescription(source); IRestRequest request = CreateAuthenticatedGedcomxRequest().SetEntity(entity).Build(GetSelfUri(), Method.POST); return(this.stateFactory.NewSourceDescriptionState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
private void Stop(SourceDescription source) { int count; AL.GetSource(source.Id, ALGetSourcei.BuffersQueued, out count); ClearBuffers(source, count); AL.DeleteSource(source.Id); }
public BindingDescription(string targetName, Path path, IConverter converter = null, BindingMode mode = BindingMode.Default) { this.TargetName = targetName; this.Mode = mode; this.Converter = converter; this.Source = new ObjectSourceDescription { Path = path }; }
protected void CreateSourceProxy(object source, SourceDescription description) { Debug.LogError("CreateSourceProxy"); this.sourceProxy = this.sourceProxyFactory.CreateProxy(source, description); if (this.sourceProxy is INotifiable) { this.sourceValueChangedHandler = (sender, args) => this.UpdateTargetFromSource(); (this.sourceProxy as INotifiable).ValueChanged += this.sourceValueChangedHandler; } }
public override void VisitSourceDescription(SourceDescription sourceDescription) { if ((sourceDescription.KnownResourceType == ResourceType.DigitalArtifact) && (sourceDescription.About != null)) { _columnNames.Add("IMAGE_URI"); _currentRecord["IMAGE_URI"] = sourceDescription.About; } base.VisitSourceDescription(sourceDescription); }
/// <summary> /// Add a source description to the data set. /// </summary> /// <param name="sourceDescription">The source description to be added.</param> public void AddSourceDescription(SourceDescription sourceDescription) { if (sourceDescription != null) { if (SourceDescriptions == null) { SourceDescriptions = new List <SourceDescription>(); } SourceDescriptions.Add(sourceDescription); } }
protected void CreateSourceProxy(object source, SourceDescription description) { this.DisposeSourceProxy(); this.sourceProxy = this.sourceProxyFactory.CreateProxy(description.IsStatic ? null : source, description); if (this.IsSubscribeSourceValueChanged(this.BindingMode) && this.sourceProxy is INotifiable) { this.sourceValueChangedHandler = (sender, args) => this.UpdateTargetFromSource(); (this.sourceProxy as INotifiable).ValueChanged += this.sourceValueChangedHandler; } }
public void TestCreateMemoryPersona() { var converter = new ImageConverter(); var bytes = (Byte[])converter.ConvertTo(TestBacking.GetCreatePhoto(), typeof(Byte[])); var dataSource = new BasicDataSource(Guid.NewGuid().ToString("n") + ".jpg", "image/jpeg", bytes); var description = new SourceDescription().SetTitle("PersonImage").SetCitation("Citation for PersonImage").SetDescription("Description"); var image = (SourceDescriptionState)tree.AddArtifact(description, dataSource).Get(); cleanup.Add(image); var state = image.AddPersona(new Person().SetName("John Smith")); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.Created, state.Response.StatusCode); }
/// <summary> /// Adds a <see cref="SourceDescription"/> to the current collection. /// </summary> /// <param name="source">The source description to add.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="SourceDescriptionState" /> instance containing the REST API response. /// </returns> /// <exception cref="Gx.Rs.Api.GedcomxApplicationException">Thrown if this collection does not have a link to the resource.</exception> public SourceDescriptionState AddSourceDescription(SourceDescription source, params IStateTransitionOption[] options) { Link link = this.GetLink(Rel.SOURCE_DESCRIPTIONS); if (link == null || link.Href == null) { throw new GedcomxApplicationException(String.Format("Collection at {0} doesn't support adding source descriptions.", GetUri())); } Gedcomx entity = new Gedcomx(); entity.AddSourceDescription(source); IRestRequest request = CreateAuthenticatedGedcomxRequest().SetEntity(entity).Build(link.Href, Method.POST); return(this.stateFactory.NewSourceDescriptionState(request, Invoke(request, options), this.Client, this.CurrentAccessToken)); }
public static string ToHlslFx(this SourceDescription desc) { var s = new StringBuilder(desc.ToHlsl()); s.AppendLine(@" technique t0 { pass p0 { VertexShader = compile vs_2_0 SLSharp_VertexMain(); PixelShader = compile ps_2_0 SLSharp_FragmentMain(); } } "); return(s.ToString()); }
public ISourceProxy CreateProxy(object source, SourceDescription description) { if (!IsSupported(description)) { return(null); } ISourceProxy proxy = null; if (TryCreateProxy(source, (T)description, out proxy)) { return(proxy); } return(proxy); }
public override void VisitSourceDescription(SourceDescription sourceDescription) { if ((sourceDescription.KnownResourceType == ResourceType.DigitalArtifact) && (sourceDescription.About != null)) { _columnNames.Add("IMAGE_URI"); _currentRecord["IMAGE_URI"] = sourceDescription.About; } if (sourceDescription.KnownResourceType == ResourceType.Record) { var identifyer = sourceDescription.Identifiers.Where(p => p.KnownType == IdentifierType.Persistent).FirstOrDefault(); _columnNames.Add("RECORD_IDENTIFER"); _currentRecord["RECORD_IDENTIFER"] = identifyer != null ? identifyer.Value : ""; } base.VisitSourceDescription(sourceDescription); }
public object Compile(Shader s, ShaderType type, SourceDescription source) { var src = source.ToGlsl(type); int shader; switch (type) { case ShaderType.FragmentShader: shader = GL.CreateShader(global::OpenTK.Graphics.OpenGL.ShaderType.FragmentShader); break; case ShaderType.VertexShader: shader = GL.CreateShader(global::OpenTK.Graphics.OpenGL.ShaderType.VertexShader); break; default: throw new SLSharpException("Binding does not support " + type); } Utilities.CheckGL(); GL.ShaderSource(shader, src); GL.CompileShader(shader); int compileResult; GL.GetShader(shader, ShaderParameter.CompileStatus, out compileResult); string info; GL.GetShaderInfoLog(shader, out info); if (compileResult != 1) { //Dump(type, src); throw new SLSharpException("Shader compilation failed: " + info); } if (info != string.Empty) { Console.WriteLine(info); } return(new Tuple <int, SourceDescription>(shader, source)); }
public void Enqueue(string id, long packNumber, SoundPack pack) { if (string.IsNullOrEmpty(id)) { throw new ArgumentException("id"); } if (!IsInited) { return; } lock (_syncObject) { SourceDescription source; if (!_sources.TryGetValue(id, out source)) { int sourceId = AL.GenSource(); source = new SourceDescription(sourceId); _sources.Add(id, source); } if (source.LastPlayedNumber > packNumber) { return; } source.LastPlayedNumber = packNumber; int bufferId = AL.GenBuffer(); AL.BufferData(bufferId, source.GetFormat(pack), pack.Data, pack.Data.Length, pack.Frequency); AL.SourceQueueBuffer(source.Id, bufferId); if (AL.GetSourceState(source.Id) != ALSourceState.Playing) { AL.SourcePlay(source.Id); } ClearBuffers(source, 0); } }
public void TestExample() { Agent contributor = (Agent) new Agent().SetName("Jane Doe").SetEmail("*****@*****.**").SetId("A-1"); Agent repository = (Agent) new Agent().SetName("General Registry Office, Southport").SetId("A-2"); Attribution attribution = new Attribution().SetContributor(contributor).SetModified(DateTime.Parse("2014-03-07")); SourceDescription sourceDescription = (SourceDescription) new SourceDescription() .SetTitle("Birth Certificate of Emma Bocock, 23 July 1843, General Registry Office") .SetCitation(new SourceCitation().SetValue("England, birth certificate for Emma Bocock, born 23 July 1843; citing 1843 Birth in District and Sub-district of Ecclesall-Bierlow in the County of York, 303; General Registry Office, Southport.")) .SetResourceType(ResourceType.PhysicalArtifact) .SetCreated(DateTime.Parse("1843-07-27")) .SetRepository(repository) .SetId("S-1"); Fact birth = new Fact() .SetType(FactType.Birth) .SetDate(new DateInfo().SetOriginal("23 June 1843")) .SetPlace(new PlaceReference().SetOriginal("Broadfield Bar, Abbeydale Road, Ecclesall-Bierlow, York, England, United Kingdom")); Person emma = (Person) new Person().SetName("Emma Bocock").SetGender(GenderType.Female).SetFact(birth).SetExtracted(true).SetSource(sourceDescription).SetId("P-1"); Person father = (Person) new Person().SetName("William Bocock").SetFact(new Fact().SetType(FactType.Occupation).SetValue("Toll Collector")).SetExtracted(true).SetSource(sourceDescription).SetId("P-2"); Person mother = (Person) new Person().SetName("Sarah Bocock formerly Brough").SetExtracted(true).SetSource(sourceDescription).SetId("P-3"); Relationship fatherRelationship = new Relationship().SetType(RelationshipType.ParentChild).SetPerson1(father).SetPerson2(emma); Relationship motherRelationship = new Relationship().SetType(RelationshipType.ParentChild).SetPerson1(mother).SetPerson2(emma); Document analysis = (Document) new Document().SetText("...Jane Doe's analysis document...").SetId("D-1"); Person emmaConclusion = (Person) new Person().SetEvidence(emma).SetAnalysis(analysis).SetId("C-1"); Gx.Gedcomx gx = new Gx.Gedcomx() .SetAgent(contributor) .SetAgent(repository) .SetAttribution(attribution) .SetSourceDescription(sourceDescription) .SetPerson(emma) .SetPerson(father) .SetPerson(mother) .SetRelationship(fatherRelationship) .SetRelationship(motherRelationship) .SetDocument(analysis) .SetPerson(emmaConclusion); xmlSerializer.Deserialize <Gx.Gedcomx>(xmlSerializer.Serialize(gx)); jsonSerializer.Deserialize <Gx.Gedcomx>(jsonSerializer.Serialize(gx)); }
/// <summary> /// Compiles the shader as GLSL shader. /// </summary> /// <param name="type">The shader type to construct and compile.</param> private void CompileShader(ShaderType type) { ShaderContext.UnitContext unit; switch (type) { case ShaderType.VertexShader: if (_vsCompiled) { return; } _vsCompiled = true; unit = _context.VertexUnit; break; case ShaderType.FragmentShader: if (_fsCompiled) { return; } _fsCompiled = true; unit = _context.FragmentUnit; break; default: throw new NotImplementedException(); } var desc = new SourceDescription(unit.Functions, _context.Uniforms, _context.Attribs, _context.Varyings, _context.Ins, _context.Outs, unit.ForwardDeclarations); var shader = Binding.Active.Compile(this, type, desc); _dependencies = _dependencies.Union(unit.Dependencies).ToList(); _objects.Add(shader); }
private List <SourceDescription> CiteGeorgeMarthaAndMarriage(Person george, Person martha, Relationship relationship) { SourceDescription georgeSource = new SourceDescription(); georgeSource.SetId("EEE-EEEE"); georgeSource.SetAbout("http://en.wikipedia.org/wiki/George_washington"); SourceCitation georgeCitation = new SourceCitation(); georgeCitation.SetValue("\"George Washington.\" Wikipedia, The Free Encyclopedia. Wikimedia Foundation, Inc. 24 October 2012."); georgeSource.SetCitation(georgeCitation); SourceDescription marthaSource = new SourceDescription(); marthaSource.SetId("FFF-FFFF"); marthaSource.SetAbout("http://en.wikipedia.org/wiki/Martha_washington"); SourceCitation marthaCitation = new SourceCitation(); marthaCitation.SetValue("\"Martha Washington.\" Wikipedia, The Free Encyclopedia. Wikimedia Foundation, Inc. 24 October 2012."); marthaSource.SetCitation(marthaCitation); SourceReference reference = new SourceReference(); reference.SetDescriptionRef("#" + georgeSource.Id); george.SetSource(reference); reference = new SourceReference(); reference.SetDescriptionRef("#" + marthaSource.Id); martha.SetSource(reference); relationship.SetSource(reference); return(new List <SourceDescription>() { georgeSource, marthaSource }); }
private static void GenerateVaryingStruct(StringBuilder s, SourceDescription desc) { var usedSemantics = new HashSet <UsageSemantic>(); foreach (var x in desc.Varyings.Where(x => x.Semantic != UsageSemantic.Unknown)) { s.AppendFormat(" {0} {1}: {2};", x.Type.ToHlsl(), x.Name, x.Semantic.ToHlsl()).AppendLine(); if (!usedSemantics.Add(x.Semantic)) { throw new SLSharpException(String.Format("Semantic {0} redefined with {1}", x.Semantic, x.Name)); } } foreach (var x in desc.Varyings.Where(x => x.Semantic == UsageSemantic.Unknown)) { var t0 = UsageSemantic.Texcoord0; while (usedSemantics.Contains(t0)) { switch (t0) { case UsageSemantic.Texcoord15: t0 = UsageSemantic.Color0; break; case UsageSemantic.Color15: throw new SLSharpException("SLSharp does not support that many varyings for hlsl at the moment."); default: t0++; break; } t0++; } s.AppendFormat(" {0} {1}: {2};", x.Type.ToHlsl(), x.Name, t0.ToHlsl()).AppendLine(); usedSemantics.Add(t0); } }
private void ClearBuffers(SourceDescription source, int count) { if (context == null) return; int[] freedbuffers; if (count == 0) { int buffersProcessed; AL.GetSource(source.Id, ALGetSourcei.BuffersProcessed, out buffersProcessed); if (buffersProcessed == 0) return; freedbuffers = AL.SourceUnqueueBuffers(source.Id, buffersProcessed); } else freedbuffers = AL.SourceUnqueueBuffers(source.Id, count); AL.DeleteBuffers(freedbuffers); }
public void Enqueue(string id, long packNumber, SoundPack pack) { if (string.IsNullOrEmpty(id)) throw new ArgumentException("id"); if (!IsInited) return; lock (syncObject) { SourceDescription source; if (!sources.TryGetValue(id, out source)) { int sourceId = AL.GenSource(); source = new SourceDescription(sourceId); sources.Add(id, source); } if (source.LastPlayedNumber > packNumber) return; source.LastPlayedNumber = packNumber; int bufferId = AL.GenBuffer(); AL.BufferData(bufferId, source.GetFormat(pack), pack.Data, pack.Data.Length, pack.Frequency); AL.SourceQueueBuffer(source.Id, bufferId); if (AL.GetSourceState(source.Id) != ALSourceState.Playing) AL.SourcePlay(source.Id); ClearBuffers(source, 0); } }
private static void GenerateVaryingStruct(StringBuilder s, SourceDescription desc) { var usedSemantics = new HashSet<UsageSemantic>(); foreach (var x in desc.Varyings.Where(x => x.Semantic != UsageSemantic.Unknown)) { s.AppendFormat(" {0} {1}: {2};", x.Type.ToHlsl(), x.Name, x.Semantic.ToHlsl()).AppendLine(); if (!usedSemantics.Add(x.Semantic)) throw new SLSharpException(String.Format("Semantic {0} redefined with {1}", x.Semantic, x.Name)); } foreach (var x in desc.Varyings.Where(x => x.Semantic == UsageSemantic.Unknown)) { var t0 = UsageSemantic.Texcoord0; while (usedSemantics.Contains(t0)) { switch (t0) { case UsageSemantic.Texcoord15: t0 = UsageSemantic.Color0; break; case UsageSemantic.Color15: throw new SLSharpException("SLSharp does not support that many varyings for hlsl at the moment."); default: t0++; break; } t0++; } s.AppendFormat(" {0} {1}: {2};", x.Type.ToHlsl(), x.Name, t0.ToHlsl()).AppendLine(); usedSemantics.Add(t0); } }
/// <summary> /// Adds an artifact to the specified state, using the specified <see cref="SourceDescription"/>. /// </summary> /// <param name="state">The state instance to which the artifact will be added.</param> /// <param name="description">The <see cref="SourceDescription"/> to apply to the artifact.</param> /// <param name="artifact">The artifact to add to the state.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="SourceDescriptionState" /> instance containing the REST API response. /// </returns> /// <exception cref="Gx.Rs.Api.GedcomxApplicationException">Thrown if this collection does not have a link to the resource.</exception> internal static SourceDescriptionState AddArtifact(GedcomxApplicationState <Gedcomx> state, SourceDescription description, IDataSource artifact, params IStateTransitionOption[] options) { Link link = state.GetLink(Rel.ARTIFACTS); if (link == null || link.Href == null) { throw new GedcomxApplicationException(String.Format("Resource at {0} doesn't support adding artifacts.", state.GetUri())); } String mediaType = artifact.ContentType; IRestRequest request = state.CreateAuthenticatedGedcomxRequest() .ContentType(MediaTypes.MULTIPART_FORM_DATA_TYPE) .Build(link.Href, Method.POST); if (description != null) { if (description.Titles != null) { foreach (TextValue value in description.Titles) { request.AddFile("title", Encoding.UTF8.GetBytes(value.Value), null, MediaTypes.TEXT_PLAIN_TYPE); } } if (description.Descriptions != null) { foreach (TextValue value in description.Descriptions) { request.AddFile("description", Encoding.UTF8.GetBytes(value.Value), null, MediaTypes.TEXT_PLAIN_TYPE); } } if (description.Citations != null) { foreach (SourceCitation citation in description.Citations) { request.AddFile("citation", Encoding.UTF8.GetBytes(citation.Value), null, MediaTypes.TEXT_PLAIN_TYPE); } } if (description.MediaType != null) { mediaType = description.MediaType; } } if (mediaType == null) { mediaType = MediaTypes.APPLICATION_OCTET_STREAM;//default to octet stream? } Byte[] inputBytes = GetBytes(artifact.InputStream); if (artifact.Name != null) { request.Files.Add(new FileParameter() { Name = "artifact", FileName = artifact.Name, ContentType = artifact.ContentType, Writer = new Action <Stream>(s => { using (var ms = new MemoryStream(inputBytes)) using (var reader = new StreamReader(ms)) { reader.BaseStream.CopyTo(s); } }) }); } return(state.stateFactory.NewSourceDescriptionState(request, state.Invoke(request, options), state.Client, state.CurrentAccessToken)); }
/// <summary> /// Adds an artifact to the collection using the specified <see cref="SourceDescription"/>. /// </summary> /// <param name="description">The <see cref="SourceDescription"/> to apply to the artifact.</param> /// <param name="artifact">The artifact to add to the collection.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="SourceDescriptionState"/> instance containing the REST API response. /// </returns> public SourceDescriptionState AddArtifact(SourceDescription description, IDataSource artifact, params IStateTransitionOption[] options) { return(AddArtifact(this, description, artifact, options)); }
/** * Build this out with a source description. * @param sourceDescription The source description. * @return this. */ public Gedcomx SetSourceDescription(SourceDescription sourceDescription) { AddSourceDescription(sourceDescription); return(this); }