Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #66 from speckleworks/api-upgrade
Browse files Browse the repository at this point in the history
Api upgrade
  • Loading branch information
didimitrie committed Apr 1, 2018
2 parents fcfffa8 + 9d18a4e commit 30a8e53
Show file tree
Hide file tree
Showing 15 changed files with 5,962 additions and 7,940 deletions.
1,067 changes: 0 additions & 1,067 deletions SpeckleCore/BaseObjects.cs

This file was deleted.

567 changes: 0 additions & 567 deletions SpeckleCore/BaseObjectsExtensions.cs

This file was deleted.

19 changes: 10 additions & 9 deletions SpeckleCore/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public static List<SpeckleObject> Serialise( IEnumerable<object> objectList )
/// <returns>A native type, a SpeckleAbstract if no explicit conversion found, or null.</returns>
public static List<object> Deserialise( IEnumerable<SpeckleObject> objectList )
{
return objectList.Select( obj => Deserialise( obj ) ).ToList();
var copy = objectList.ToArray();
return copy.Select( obj => Deserialise( obj ) ).ToList();
}

/// <summary>
Expand Down Expand Up @@ -153,15 +154,15 @@ public static object Deserialise( SpeckleObject obj, object root = null )
// we have a speckle abstract object
SpeckleAbstract absObj = obj as SpeckleAbstract;

if ( absObj._Type == "ref" )
if ( absObj._type == "ref" )
return null;

var assembly = System.AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault( a => a.FullName == absObj._Assembly );
var assembly = System.AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault( a => a.FullName == absObj._assembly );

if ( assembly == null ) // we can't deserialise for sure
return Converter.ShallowConvert( absObj );

var type = assembly.GetTypes().FirstOrDefault( t => t.Name == absObj._Type );
var type = assembly.GetTypes().FirstOrDefault( t => t.Name == absObj._type );
if ( type == null ) // type not present in the assembly
return Converter.ShallowConvert( absObj );

Expand Down Expand Up @@ -343,8 +344,8 @@ private static void ResolveRefs( object original, object root, string currentPat
if ( original is SpeckleAbstract )
{
SpeckleAbstract myObj = ( SpeckleAbstract ) original;
if ( myObj._Type == "ref" )
Converter.LinkRef( root, myObj._Ref, currentPath );
if ( myObj._type == "ref" )
Converter.LinkRef( root, myObj._ref, currentPath );
else
foreach ( var key in myObj.Properties.Keys )
Converter.ResolveRefs( myObj.Properties[ key ], root, currentPath + "/" + key );
Expand Down Expand Up @@ -502,7 +503,7 @@ public static SpeckleObject Serialise( object source, int recursionDepth = 0, Di

// check references
if ( traversed.ContainsKey( source.GetHashCode() ) )
return new SpeckleAbstract() { _Type = "ref", _Ref = traversed[ source.GetHashCode() ] };
return new SpeckleAbstract() { _type = "ref", _ref = traversed[ source.GetHashCode() ] };
else
traversed.Add( source.GetHashCode(), path );

Expand All @@ -527,8 +528,8 @@ public static SpeckleObject Serialise( object source, int recursionDepth = 0, Di

// else just continue with the to abstract part
SpeckleAbstract result = new SpeckleAbstract();
result._Type = source.GetType().Name;
result._Assembly = source.GetType().Assembly.FullName;
result._type = source.GetType().Name;
result._assembly = source.GetType().Assembly.FullName;

Dictionary<string, object> dict = new Dictionary<string, object>();

Expand Down
74 changes: 39 additions & 35 deletions SpeckleCore/GzipContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,50 @@

namespace SpeckleCore
{
/// <summary>
/// https://cymbeline.ch/2014/03/16/gzip-encoding-an-http-post-request-body/
/// </summary>
internal sealed class GzipContent : HttpContent
{
private readonly HttpContent content;

public GzipContent(HttpContent content)
{
this.content = content;

/// <summary>
/// https://cymbeline.ch/2014/03/16/gzip-encoding-an-http-post-request-body/
/// </summary>
internal sealed class GzipContent : HttpContent
{
private readonly HttpContent content;

// Keep the original content's headers ...
if (content != null)
foreach (KeyValuePair<string, IEnumerable<string>> header in content.Headers)
{
Headers.TryAddWithoutValidation(header.Key, header.Value);
}
public GzipContent( HttpContent content )
{
if(content == null)
{
return;
}

// ... and let the server know we've Gzip-compressed the body of this request.
Headers.ContentEncoding.Add("gzip");
}
this.content = content;

protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
// Keep the original content's headers ...
if ( content != null )
foreach ( KeyValuePair<string, IEnumerable<string>> header in content.Headers )
{
// Open a GZipStream that writes to the specified output stream.
using (GZipStream gzip = new GZipStream(stream, CompressionMode.Compress, true))
{
// Copy all the input content to the GZip stream.
if (content != null)
await content.CopyToAsync(gzip);
else
await (new System.Net.Http.StringContent(string.Empty)).CopyToAsync(gzip);
}
Headers.TryAddWithoutValidation( header.Key, header.Value );
}

protected override bool TryComputeLength(out long length)
{
length = -1;
return false;
}
// ... and let the server know we've Gzip-compressed the body of this request.
Headers.ContentEncoding.Add( "gzip" );
}

protected override async Task SerializeToStreamAsync( Stream stream, TransportContext context )
{
// Open a GZipStream that writes to the specified output stream.
using ( GZipStream gzip = new GZipStream( stream, CompressionMode.Compress, true ) )
{
// Copy all the input content to the GZip stream.
if ( content != null )
await content.CopyToAsync( gzip );
else
await ( new System.Net.Http.StringContent( string.Empty ) ).CopyToAsync( gzip );
}
}

protected override bool TryComputeLength( out long length )
{
length = -1;
return false;
}
}
}
Loading

0 comments on commit 30a8e53

Please sign in to comment.