Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many Fixes and Improvements #9

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions RetsConnector/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public async Task Execute()

// We can also download photos
// This will return all photos for property with the primarykey 1234
IEnumerable<FileObject> files = await Client.GetObject("Property", "Photo", new PhotoId(1234), false);
IEnumerable<FileObject> files = await Client.GetObject("Property", "Photo", new PhotoId("1234"), false);

// Here is how we can iterate over the fields
foreach (FileObject file in files)
Expand All @@ -120,11 +120,11 @@ public async Task Execute()
}

// you can get a specific image for a given primary key like so
IEnumerable<FileObject> files2 = await Client.GetObject("Property", "Photo", new PhotoId(1234, 1), false);
IEnumerable<FileObject> files2 = await Client.GetObject("Property", "Photo", new PhotoId("1234", 1), false);


// you can get also get images for multiple primary keys at the same time like this
List<PhotoId> photoIds = new List<PhotoId>() { new PhotoId(1234), new PhotoId(5678), new PhotoId(2255) };
List<PhotoId> photoIds = new List<PhotoId>() { new PhotoId("1234"), new PhotoId("5678"), new PhotoId("2255") };

IEnumerable<FileObject> files3 = await Client.GetObject("Property", "Photo", photoIds, false);

Expand Down
14 changes: 7 additions & 7 deletions RetsConnector/RetsConnector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand All @@ -15,12 +15,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions RetsSdk/Contracts/IMetadataCollection.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Linq;

namespace CrestApps.RetsSdk.Contracts
{
public interface IMetadataCollection<T> where T : class
public interface IMetadataCollection<T> : IEnumerable<T> where T : class
{
void Add(T resource);
void Remove(T resource);
Expand All @@ -14,11 +15,10 @@ public interface IMetadataCollection<T> where T : class
Type GetGenericType();
}

public interface IMetadataCollection
public interface IMetadataCollection : IEnumerable
{
string Version { get; set; }
DateTime Date { get; set; }

}

public interface IMetadataCollectionLoad
Expand Down
3 changes: 2 additions & 1 deletion RetsSdk/Models/Enums/RetsDataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum RetsDataType
Small,
Int,
Long,
Decimal
Decimal,
@object
}
}
3 changes: 2 additions & 1 deletion RetsSdk/Models/Enums/SupportedRetsVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum SupportedRetsVersion
Version_1_7,
Version_1_7_1,
Version_1_7_2,
Version_1_8
Version_1_8,
Version_1_9,
}
}
3 changes: 2 additions & 1 deletion RetsSdk/Models/FileObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ public class FileObject : IDisposable
public string ContentDescription { get; set; }
public string ContentSubDescription { get; set; }
public Uri ContentLocation { get; set; }
public string MemeVersion { get; set; }
public string MimeVersion { get; set; }
public bool IsPreferred { get; set; }
public string Extension { get; set; }
public Stream Content { get; set; }

private bool IsDisposed;

public bool IsImage => ContentType?.MediaType.StartsWith("image", StringComparison.CurrentCultureIgnoreCase) ?? false;
Expand Down
4 changes: 2 additions & 2 deletions RetsSdk/Models/PhotoId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
{
public class PhotoId
{
public long Id { get; set; }
public string Id { get; set; }
public int? ObjectId { get; set; }

public PhotoId()
{

}

public PhotoId(long id, int? objectId = null)
public PhotoId(string id, int? objectId = null)
{
Id = id;
ObjectId = objectId;
Expand Down
20 changes: 15 additions & 5 deletions RetsSdk/Models/RetsCollection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CrestApps.RetsSdk.Contracts;
using CrestApps.RetsSdk.Helpers.Extensions;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand All @@ -14,8 +15,8 @@ namespace CrestApps.RetsSdk.Models
public string Version { get; set; }
public DateTime Date { get; set; }

private List<T> Items = new List<T>();
private Type _Type;
private readonly List<T> Items = new List<T>();
private Type Type;

public void Add(T item)
{
Expand All @@ -34,12 +35,12 @@ public IEnumerable<T> Get()

public Type GetGenericType()
{
if (_Type == null)
if (Type == null)
{
_Type = typeof(T);
Type = typeof(T);
}

return _Type;
return Type;
}

public void Remove(T item)
Expand Down Expand Up @@ -182,5 +183,14 @@ private static void SetValueSafely(object entity, PropertyInfo property, string
public abstract void Load(XElement xElement);
public abstract T Get(object value);

public IEnumerator<T> GetEnumerator()
{
return Items.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return Items.GetEnumerator();
}
}
}
2 changes: 1 addition & 1 deletion RetsSdk/Models/RetsField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class RetsField
public string LongName { get; set; }
public string DbName { get; set; }
public string ShortName { get; set; }
public int MaximumLength { get; set; }
public decimal MaximumLength { get; set; }
public RetsDataType? DataType { get; set; }
public int? Precision { get; set; }
public bool Searchable { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion RetsSdk/Models/RetsVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static SupportedRetsVersion Make(string version)

var castable = Str.PrependOnce(v, "Version_");

return Enum.Parse<SupportedRetsVersion>(castable);
return (SupportedRetsVersion) Enum.Parse(typeof(SupportedRetsVersion), castable);
}

}
Expand Down
51 changes: 39 additions & 12 deletions RetsSdk/Models/SearchRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -9,11 +10,17 @@ public class SearchRequest
public string SearchType { get; set; }
public string Class { get; set; }
public string QueryType { get; set; } = "DMQL2";
public int Count { get; set; } = 0;
public CountType Count { get; set; } = CountType.NoCount;
public string Format { get; set; } = "COMPACT-DECODED"; // COMPACT-DECODED
public string RestrictedIndicator { get; set; } = "****";
public int Limit { get; set; } = int.MaxValue;
public int Offset { get; set; } = 1;

public int StandardNames { get; set; } = 0;

[CanBeNull]
public string RawQuery { get; set; } = null;

public QueryParameterGroup ParameterGroup { get; set; }
private List<string> Columns = new List<string>();

Expand Down Expand Up @@ -62,22 +69,42 @@ public void RemoveColumns(IEnumerable<string> columnNames)
Columns = Columns.Where(x => !columnNames.Contains(x)).ToList();
}

public bool HasColumns()
{
return Columns.Any();
}


public bool HasColumns() => Columns.Any();

public bool HasColumn(string columnName)
{
bool exists = Columns.Any(x => x.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));

var exists = Columns.Any(x => x.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
return exists;
}

public IEnumerable<string> GetColumns()
public IEnumerable<string> GetColumns() => Columns.Distinct();

public SearchRequest Clone()
{
return Columns.Distinct();
var newSr = new SearchRequest()
{
SearchType = this.SearchType,
Class = this.Class,
QueryType = this.QueryType,
Count = this.Count,
Format = this.Format,
RestrictedIndicator = this.RestrictedIndicator,
Limit = this.Limit,
Offset = this.Offset,
StandardNames = this.StandardNames,
RawQuery = this.RawQuery,
ParameterGroup = this.ParameterGroup,
};
newSr.AddColumns(this.Columns);
return newSr;
}
}

public enum CountType
{
NoCount = 0,
CountWithData = 1,
OnlyCount = 2
}

}
23 changes: 15 additions & 8 deletions RetsSdk/Models/SearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ namespace CrestApps.RetsSdk.Models
{
public class SearchResult
{
public RetsResource Resource { get; private set; }
public string ClassName { get; private set; }
public RetsResource Resource { get; }
public string ClassName { get; }

private string RestrictedValue;
private string[] Columns { get; set; }
private Dictionary<string, SearchResultRow> Rows { get; set; }
private Dictionary<string, SearchResultRow> Rows { get; }
public bool HasMoreRows { get; internal set; }
public int? ServerCount { get; internal set; }

public SearchResult(RetsResource resource, string className, string restrictedValue)
{
Expand Down Expand Up @@ -38,7 +41,15 @@ public bool AddRow(SearchResultRow row)
throw new ArgumentNullException($"{nameof(row)} cannot be null.");
}

return Rows.TryAdd(row.PrimaryKeyValue, row);
if (Rows.ContainsKey(row.PrimaryKeyValue))
{
return false;
}
else
{
Rows.Add(row.PrimaryKeyValue, row);
return true;
}
}

public bool RemoveRow(string primaryKeyValue)
Expand Down Expand Up @@ -68,23 +79,20 @@ public bool RemoveRow(SearchResultRow row)
public IEnumerable<SearchResultCellValue> Pluck(string columnName)
{
var values = Rows.Select(x => x.Value.Get(columnName));

return values;
}

public IEnumerable<T> Pluck<T>(string columnName)
where T : struct
{
IEnumerable<T> values = Rows.Select(x => x.Value.Get(columnName).Get<T>());

return values;
}

public IEnumerable<T?> PluckNullable<T>(string columnName)
where T : struct
{
IEnumerable<T?> values = Rows.Select(x => x.Value.Get(columnName).GetNullable<T>());

return values;
}

Expand All @@ -103,7 +111,6 @@ public void SetColumns(string[] columns)
Columns = columns ?? throw new ArgumentNullException($"{nameof(columns)} cannot be null.");
}


public void SetColumns(IEnumerable<string> columns)
{
SetColumns(columns?.AsEnumerable());
Expand Down
5 changes: 4 additions & 1 deletion RetsSdk/Models/SearchResultRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public SearchResultRow(string[] columns, string[] values, string primaryKeyColum
value.SetIsPrimaryKeyValue(keyIndex == index);
value.SetIsRestricted(RestrictedValue);

Values.TryAdd(columns[index].ToLower(), value);
if (!Values.ContainsKey(columns[index].ToLower()))
{
Values.Add(columns[index].ToLower(), value);
}
}

}
Expand Down
7 changes: 5 additions & 2 deletions RetsSdk/Models/SessionResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public void AddCapability(Capability name, string url)
{
return;
}

Capabilities.TryAdd(name, uri);

if (!Capabilities.ContainsKey(name))
{
Capabilities.Add(name, uri);
}
}

public Uri GetCapability(Capability name)
Expand Down
13 changes: 7 additions & 6 deletions RetsSdk/RetsSdk.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Authors>CrestApps</Authors>
Expand All @@ -16,14 +16,15 @@
<RepositoryUrl>https://github.com/CrestApps/RetsConnector</RepositoryUrl>
<PackageIconUrl>https://avatars1.githubusercontent.com/u/24724371?s=460&amp;v=4</PackageIconUrl>
<Version>1.0.1</Version>
<Platforms>AnyCPU;x86</Platforms>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.4" />
<PackageReference Include="MimeKit" Version="2.8.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="MimeKit" Version="3.4.1" />
<PackageReference Include="MimeTypeMap.Core" Version="1.0.0" />
<PackageReference Include="X.PagedList" Version="8.0.7" />
<PackageReference Include="X.PagedList" Version="8.4.3" />
</ItemGroup>

</Project>
Loading