public static Task <IEnumerable <T> > EnumerateAsync <T>(this ISDataClient client, string path = null, SDataEnumerateOptions options = null, CancellationToken cancel = default(CancellationToken)) { var parms = GetEnumerateParameters(client, GetPath <T>(path), options); var items = new List <T>(); Func <Task <ISDataResults <SDataCollection <T> > > > loop = null; loop = () => client.ExecuteAsync <SDataCollection <T> >(parms, cancel) .ContinueWith( task => { var collection = task.Result.Content; if (collection.Count == 0) { return(task); } items.AddRange(collection); parms.StartIndex = (parms.StartIndex ?? 1) + collection.Count; if (collection.TotalResults != null && parms.StartIndex > collection.TotalResults) { return(task); } return(loop()); }, cancel) .Unwrap(); return(loop().ContinueWith(task => (IEnumerable <T>)items, cancel)); }
private static T GetServiceResult <T>(ISDataClient client, Expression bodyExpr, SDataResource content) { var value = content["response"]; var response = (SDataResource)value; var attr = ((MethodCallExpression)bodyExpr).Method.GetCustomAttribute <SDataServiceOperationAttribute>(); if (attr != null && !string.IsNullOrEmpty(attr.ResultPropertyName)) { value = response[attr.ResultPropertyName]; } else if (response.Count == 1) { var firstValue = response.Values.First(); var type = typeof(T); type = Nullable.GetUnderlyingType(type) ?? type; if (ContentHelper.IsObject(type) == ContentHelper.IsObject(firstValue)) { value = firstValue; } } var result = ContentHelper.Deserialize <T>(value, client.NamingScheme); var tracking = result as IChangeTracking; if (tracking != null) { tracking.AcceptChanges(); } return(result); }
private static SDataParameters GetPostParameters <T>(ISDataClient client, T content, string path, SDataPayloadOptions options) { Guard.ArgumentNotNull(client, "client"); Guard.ArgumentNotNull(content, "content"); Guard.ArgumentNotNullOrEmptyString(path, "path"); if (options == null) { options = new SDataPayloadOptions(); } var resource = ContentHelper.Serialize(content, client.NamingScheme) as SDataResource; if (resource == null) { throw new SDataClientException("Only resources can be posted"); } resource.HttpMethod = HttpMethod.Post; return(new SDataParameters { Method = HttpMethod.Post, Path = path, Content = resource, Include = options.Include, Select = options.Select, Precedence = options.Precedence }); }
private LibraryDirectoryInfo(ISDataClient client, bool formMode, IDirectoryInfo parent, LibraryDirectory directory) { _client = client; _formMode = formMode; _parent = parent; _directory = directory; }
public static T Get <T>(this ISDataClient client, T content, string path = null, SDataPayloadOptions options = null) { Guard.ArgumentNotNull(content, "content"); var results = client.Execute <T>(GetGetParameters(client, GetKey(content), GetETag(content), GetPath <T>(path), options)); return(!Equals(results.Content, default(T)) ? results.Content : content); }
public LibraryFileInfo(ISDataClient client, bool formMode, IDirectoryInfo directory, LibraryDocument document) : base(directory) { _client = client; _formMode = formMode; _document = document; }
public AttachmentFileInfo(ISDataClient client, bool formMode, IDirectoryInfo directory, Attachment attachment) : base(directory) { _client = client; _formMode = formMode; _attachment = attachment; }
internal static IList <IDirectoryInfo> GetDirectories(ISDataClient client, bool formMode, IDirectoryInfo parent, string id) { return(client.Query <LibraryDirectory>() .Where(x => x.ParentId == id) .OrderBy(x => x.DirectoryName) .Select(directory => (IDirectoryInfo) new LibraryDirectoryInfo(client, formMode, parent, directory)) .ToList()); }
private static SDataParameters GetDeleteParameters <T>(ISDataClient client, T content, string path) { Guard.ArgumentNotNull(client, "client"); Guard.ArgumentNotNull(content, "content"); Guard.ArgumentNotNullOrEmptyString(path, "path"); return(new SDataParameters { Method = HttpMethod.Delete, Path = string.Format("{0}({1})", path, SDataUri.FormatConstant(GetKey(content))), ETag = GetETag(content) }); }
private static SDataParameters GetEnumerateParameters(ISDataClient client, string path, SDataEnumerateOptions options) { Guard.ArgumentNotNull(client, "client"); if (options == null) { options = new SDataEnumerateOptions(); } return(new SDataParameters { Path = path, Where = options.Where, OrderBy = options.OrderBy, Include = options.Include, Select = options.Select, Precedence = options.Precedence }); }
private void Initialize() { _client = new SDataClient(_serverUrlText.Text) { Credentials = _credentials, NamingScheme = NamingScheme.CamelCase, Trace = { Switch = { Level = SourceLevels.Information }, Listeners = { new TextBoxTraceListener(_logText, _serverUrlText.Text.Length) { Filter = new EventTypeFilter(SourceLevels.All) } } } }; Settings.Default.Save(); _jobsGrid.AutoGenerateColumns = true; _triggersGrid.AutoGenerateColumns = true; _executionsGrid.AutoGenerateColumns = true; _jobsGrid.DataSource = new Job[0]; _jobParametersGrid.DataSource = new JobParameter[0]; _jobStateGrid.DataSource = new State[0]; _triggersGrid.DataSource = new Trigger[0]; _triggerParametersGrid.DataSource = new TriggerParameter[0]; _executionsGrid.DataSource = new Execution[0]; _executionStateGrid.DataSource = new State[0]; _jobsGrid.Columns.Remove("Parameters"); _jobsGrid.Columns.Remove("State"); _jobsGrid.AutoGenerateColumns = false; _triggersGrid.Columns.Remove("Parameters"); _triggersGrid.AutoGenerateColumns = false; _executionsGrid.Columns.Remove("State"); _executionsGrid.AutoGenerateColumns = false; _jobsGrid.AutoResizeColumns(); _jobParametersGrid.AutoResizeColumns(); _jobStateGrid.AutoResizeColumns(); _triggersGrid.AutoResizeColumns(); _triggerParametersGrid.AutoResizeColumns(); _executionsGrid.AutoResizeColumns(); _executionStateGrid.AutoResizeColumns(); }
private static SDataParameters GetGetParameters(ISDataClient client, string key, string etag, string path, SDataPayloadOptions options) { Guard.ArgumentNotNull(client, "client"); Guard.ArgumentNotNullOrEmptyString(key, "key"); Guard.ArgumentNotNullOrEmptyString(path, "path"); if (options == null) { options = new SDataPayloadOptions(); } return(new SDataParameters { Path = string.Format("{0}({1})", path, SDataUri.FormatConstant(key)), ETag = etag, Include = options.Include, Select = options.Select, Precedence = options.Precedence }); }
private static SDataParameters GetPutParameters <T>(ISDataClient client, T content, string path, SDataPayloadOptions options) { Guard.ArgumentNotNull(client, "client"); Guard.ArgumentNotNull(content, "content"); Guard.ArgumentNotNullOrEmptyString(path, "path"); if (options == null) { options = new SDataPayloadOptions(); } return(new SDataParameters { Method = HttpMethod.Put, Path = string.Format("{0}({1})", path, SDataUri.FormatConstant(GetKey(content))), Content = content, ETag = GetETag(content), Include = options.Include, Select = options.Select, Precedence = options.Precedence }); }
public static IEnumerable <T> Enumerate <T>(this ISDataClient client, string path = null, SDataEnumerateOptions options = null) { var parms = GetEnumerateParameters(client, GetPath <T>(path), options); while (true) { var collection = client.Execute <SDataCollection <T> >(parms).Content; if (collection.Count == 0) { break; } foreach (var item in collection) { yield return(item); } parms.StartIndex = (parms.StartIndex ?? 1) + collection.Count; if (collection.TotalResults != null && parms.StartIndex > collection.TotalResults) { break; } } }
public SDataQueryable(ISDataClient client, string path, INamingScheme namingScheme) : this(QueryParser.CreateDefault(), client, path, namingScheme) { }
public static void Delete <T>(this ISDataClient client, T content, string path = null) { client.Execute(GetDeleteParameters(client, content, GetPath <T>(path))); }
public static Task DeleteAsync <T>(this ISDataClient client, T content, string path = null, CancellationToken cancel = default(CancellationToken)) { return(client.ExecuteAsync(GetDeleteParameters(client, content, GetPath <T>(path)), cancel)); }
private SDataQueryable(QueryParser queryParser, ISDataClient client, string path, INamingScheme namingScheme) : base(queryParser, new SDataQueryExecutor(client, path, queryParser.NodeTypeProvider, namingScheme)) { }
public SDataDriveInfo(ISDataClient client, bool formMode) { _client = client; _formMode = formMode; _directory = new SDataDirectoryInfo(_client, _formMode, this); }
public static IEnumerable <T> Enumerate <T>(this ISDataClient client, string path, T prototype, SDataEnumerateOptions options = null) { return(Enumerate <T>(client, path, options)); }
public static Task <IEnumerable <T> > EnumerateAsync <T>(this ISDataClient client, string path, T prototype, SDataEnumerateOptions options = null, CancellationToken cancel = default(CancellationToken)) { return(EnumerateAsync <T>(client, path, options, cancel)); }
public static void CallService(this ISDataClient client, Expression <Action> methodCall, string path = null) { client.Execute(GetServiceParameters(client, methodCall.Body, path)); }
public static ISDataBatch <T> CreateBatch <T>(this ISDataClient client, string path = null, SDataPayloadOptions options = null) { Guard.ArgumentNotNull(client, "client"); return(new SDataBatch <T>(client, GetPath <T>(path), options)); }
public static Task <IEnumerable <SDataResource> > EnumerateAsync(this ISDataClient client, string path = null, SDataEnumerateOptions options = null, CancellationToken cancel = default(CancellationToken)) { return(EnumerateAsync <SDataResource>(client, path, options, cancel)); }
private static SDataParameters GetServiceParameters(ISDataClient client, Expression bodyExpr, string path) { Guard.ArgumentNotNull(client, "client"); var callExpr = bodyExpr as MethodCallExpression; if (callExpr == null) { throw new SDataClientException("Expression must be a method call"); } var attr = callExpr.Method.GetCustomAttribute <SDataServiceOperationAttribute>(); var namingScheme = client.NamingScheme ?? NamingScheme.Default; var request = new SDataResource(); var instance = callExpr.Object != null?Expression.Lambda(callExpr.Object).Compile().DynamicInvoke() : null; if (path == null) { path = SDataPathAttribute.GetPath(instance != null ? instance.GetType() : callExpr.Method.DeclaringType); } if (instance != null) { if (attr == null || attr.PassInstanceBy == InstancePassingConvention.Selector || (attr.PassInstanceBy == InstancePassingConvention.Default && string.IsNullOrEmpty(attr.InstancePropertyName))) { if (path == null) { throw new SDataClientException("Path must be specified when passing instance context by selector"); } var key = ContentHelper.GetProtocolValue <string>(instance, SDataProtocolProperty.Key); if (string.IsNullOrEmpty(key)) { throw new SDataClientException("Unable to extract resource key from instance"); } path += string.Format("({0})", SDataUri.FormatConstant(key)); } else if (attr.PassInstanceBy == InstancePassingConvention.Default) { var key = ContentHelper.GetProtocolValue <string>(instance, SDataProtocolProperty.Key); request[attr.InstancePropertyName] = !string.IsNullOrEmpty(key) ? key : instance; } else { if (string.IsNullOrEmpty(attr.InstancePropertyName)) { throw new SDataClientException("Instance property name must be specified when passing instance context by key property or object property"); } if (attr.PassInstanceBy == InstancePassingConvention.KeyProperty) { var key = ContentHelper.GetProtocolValue <string>(instance, SDataProtocolProperty.Key); if (string.IsNullOrEmpty(key)) { throw new SDataClientException("Unable to extract resource key from instance"); } request[attr.InstancePropertyName] = key; } else if (attr.PassInstanceBy == InstancePassingConvention.ObjectProperty) { request[attr.InstancePropertyName] = instance; } } } if (path != null) { path += "/"; } path += "$service/" + namingScheme.GetName(callExpr.Method); foreach (var pair in callExpr.Method.GetParameters().Zip(callExpr.Arguments, (param, arg) => new { param, arg })) { request[namingScheme.GetName(pair.param)] = Expression.Lambda(pair.arg).Compile().DynamicInvoke(); } var xmlLocalName = attr != null ? attr.XmlLocalName : null; var xmlNamespace = attr != null ? attr.XmlNamespace : null; var content = new SDataResource(xmlLocalName, xmlNamespace) { { "request", request } }; return(new SDataParameters { Method = HttpMethod.Post, Path = path, Content = content }); }
public static Task <T> CallServiceAsync <T>(this ISDataClient client, Expression <Func <T> > methodCall, string path = null, CancellationToken cancel = default(CancellationToken)) { return(client.ExecuteAsync <SDataResource>(GetServiceParameters(client, methodCall.Body, path), cancel) .ContinueWith(task => GetServiceResult <T>(client, methodCall.Body, task.Result.Content), cancel)); }
public static Task CallServiceAsync(this ISDataClient client, Expression <Action> methodCall, string path = null, CancellationToken cancel = default(CancellationToken)) { return(client.ExecuteAsync(GetServiceParameters(client, methodCall.Body, path), cancel)); }
public SDataDirectoryInfo(ISDataClient client, bool formMode, IDriveInfo drive) { _client = client; _formMode = formMode; _drive = drive; }
public static ISDataBatch <SDataResource> CreateBatch(this ISDataClient client, string path, SDataPayloadOptions options = null) { return(CreateBatch <SDataResource>(client, path, options)); }
public static T CallService <T>(this ISDataClient client, Expression <Func <T> > methodCall, string path = null) { var content = client.Execute <SDataResource>(GetServiceParameters(client, methodCall.Body, path)).Content; return(GetServiceResult <T>(client, methodCall.Body, content)); }
public SDataBatch(ISDataClient client, string path, SDataPayloadOptions options) { _client = client; _path = path; _options = options ?? new SDataPayloadOptions(); }
public AttachmentDirectoryInfo(ISDataClient client, bool formMode, IDirectoryInfo parent) { _client = client; _formMode = formMode; _parent = parent; }