public static IBoundClient <CrmSolution.Shared.Dto.CustomerDto> Sum(this IBoundClient <CrmSolution.Shared.Dto.CustomerDto> customersController, int n1, int n2)
 {
     return(customersController.Function("Sum").Set(new
     {
         n1, n2
     }));
 }
Exemplo n.º 2
0
        protected virtual async Task BuildRetrieveDataTask(DtoSyncConfigSyncFromInformation dtoSyncConfigSyncFromInformation, CancellationToken cancellationToken)
        {
            if (dtoSyncConfigSyncFromInformation == null)
            {
                throw new ArgumentNullException(nameof(dtoSyncConfigSyncFromInformation));
            }

            try
            {
                IBoundClient <IDictionary <string, object> > query = (dtoSyncConfigSyncFromInformation.DtoSetSyncConfig.OnlineDtoSetForGet ?? dtoSyncConfigSyncFromInformation.DtoSetSyncConfig.OnlineDtoSet)(ODataClient);

                if (dtoSyncConfigSyncFromInformation.MaxVersion == 0)
                {
                    query = query.Where($"{nameof(ISyncableDto.IsArchived)} eq false");
                }
                else
                {
                    query = query.Where($"{nameof(ISyncableDto.Version)} gt {dtoSyncConfigSyncFromInformation.MaxVersion}");
                }

                string oDataGetAndVersionFilter = await query
                                                  .GetCommandTextAsync(cancellationToken)
                                                  .ConfigureAwait(false);

                string oDataUri = $"{ClientAppProfile.ODataRoute}{oDataGetAndVersionFilter}";

                using (HttpResponseMessage response = await HttpClient.GetAsync(oDataUri, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false))
                {
                    response.EnsureSuccessStatusCode();

#if DotNetStandard2_0 || UWP
                    using Stream stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
#elif Android || iOS || DotNetStandard2_1
                    await using Stream stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
#else
                    await using Stream stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
#endif
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            using (JsonReader jsonReader = new JsonTextReader(reader))
                            {
                                JToken jToken = await JToken.LoadAsync(jsonReader, new JsonLoadSettings
                                {
                                    CommentHandling  = CommentHandling.Ignore,
                                    LineInfoHandling = LineInfoHandling.Ignore
                                }, cancellationToken).ConfigureAwait(false);

                                dtoSyncConfigSyncFromInformation.RecentlyChangedOnlineDtos = ((IEnumerable)(jToken)["value"] !.ToObject(typeof(List <>).MakeGenericType(dtoSyncConfigSyncFromInformation.DtoType)) !).Cast <ISyncableDto>().ToArray();
                            }
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                dtoSyncConfigSyncFromInformation.RecentlyChangedOnlineDtos = Array.Empty <ISyncableDto>();
                ExceptionHandler.OnExceptionReceived(exp);
            }
        }
        public static async Task <IEnumerable <T> > FindEntriesWithLogsAsync <T>(this IBoundClient <T> boundClient, ILogger logger, bool resultRequired = true) where T : class, IDynamicsEntity
        {
            logger.LogInformation($"Executing Dynamics Query: {await boundClient.GetCommandTextAsync()}");
            var result = await boundClient.FindEntriesAsync(resultRequired);

            return(result);
        }
        public static async Task <T> FindEntryWithLogsAsync <T>(this IBoundClient <T> boundClient, ILogger logger) where T : class, IDynamicsEntity
        {
            logger.LogInformation($"Executing Dynamics Query: {await boundClient.GetCommandTextAsync()}");
            var result = await boundClient.FindEntryAsync();

            return(result);
        }
 public static IBoundClient <Ntt_breathingspacedebt> ExpandDebt(this IBoundClient <Ntt_breathingspacedebt> debtQuery)
 {
     return(debtQuery
            .Expand(x => x.ntt_BreathingSpaceMoratoriumId)
            .Expand(x => x.ntt_debttypeid)
            .Expand(x => x.ntt_creditorid)
            .Expand(x => x.ntt_SoldToCreditorId)
            .Expand(x => x.ntt_breathingspacedebt_ntt_debteligibilityreview_DebtId));
 }
Exemplo n.º 6
0
        public async Task <int> Count(Expression <Func <T, bool> > expression)
        {
            //bounder = bounder.Count();
            bounder = bounder.Filter(expression);
            var count = await bounder.Count().FindScalarAsync <int>();

            Dispose();
            return(count);
        }
Exemplo n.º 7
0
        private static void RemoveFilterExpression(IBoundClient <IDictionary <string, object> > client)
        {
            var    cmdprop              = client.GetType().GetProperty("Command", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            object fluentcmd            = cmdprop.GetValue(client);
            var    detailsProp          = fluentcmd.GetType().GetProperty("Details", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var    cmdDetails           = detailsProp.GetValue(fluentcmd);
            var    filterExpressionProp = cmdDetails.GetType().GetProperty("FilterExpression", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

            filterExpressionProp.SetValue(cmdDetails, null);
        }
        public static async Task <T1> UpdateEntryWithLogsAsync <T1>(this IBoundClient <T1> boundClient, ILogger logger, bool resultRequired = true) where T1 : class, IDynamicsEntity
        {
            logger.LogDebug($"Executing update entry {Environment.NewLine} {Environment.StackTrace}");
            logger.LogInformation($"Updating type: {typeof(T1)}");
            logger.LogInformation($"Executing Dynamics Query: {await boundClient.GetCommandTextAsync()}");
            var result = await boundClient.UpdateEntryAsync(resultRequired);

            logger.LogInformation($"Updated entry with Id: {result.GetId()}");
            return(result);
        }
Exemplo n.º 9
0
        public static IBoundClient <T> Include <T>(this IBoundClient <T> client, params ODataExpression[] associations)
            where T : class
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(client.Expand(associations: associations));
        }
        public static Task <T> CreateEntryAsync <T>(this IBoundClient <T> client, CancellationToken cancellationToken)
            where T : class
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(client.InsertEntryAsync(cancellationToken));
        }
Exemplo n.º 11
0
        public static IBoundClient <T> Where <T>(this IBoundClient <T> client, string where)
            where T : class
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(client.Filter(filter: where));
        }
Exemplo n.º 12
0
        public static IBoundClient <T> Include <T>(this IBoundClient <T> client, IEnumerable <string> associations)
            where T : class
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(client.Expand(associations: associations));
        }
        public static Task <T> CreateEntryAsync <T>(this IBoundClient <T> client, bool resultRequired)
            where T : class
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(client.InsertEntryAsync(resultRequired));
        }
Exemplo n.º 14
0
        public static IBoundClient <T> Take <T>(this IBoundClient <T> client, int count)
            where T : class
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(client.Top(count: count));
        }
Exemplo n.º 15
0
        public static IBoundClient <T> Include <T>(this IBoundClient <T> client, ODataExpandOptions includeOptions, params string[] associations)
            where T : class
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(client.Expand(expandOptions: includeOptions, associations: associations));
        }
Exemplo n.º 16
0
        public static IBoundClient <T> Include <T>(this IBoundClient <T> client, Expression <Func <T, object> > expression)
            where T : class
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(client.Expand(expression: expression));
        }
Exemplo n.º 17
0
        public static IBoundClient <T> Where <T>(this IBoundClient <T> client, ODataExpression expression)
            where T : class
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(client.Filter(expression: expression));
        }
        public static async Task LinkEntryWithLogsAsync <T1, T2>(this IBoundClient <T1> boundClient, ILogger logger, T2 linkedEntryKey, string linkName)
            where T1 : class, IDynamicsEntity
            where T2 : class, IDynamicsEntity
        {
            logger.LogDebug($"Linking entry {Environment.NewLine} {Environment.StackTrace}");
            logger.LogInformation($"Linking type: {typeof(T1)} to type: {typeof(T2)} with Id: {linkedEntryKey.GetId()}");
            logger.LogInformation($"Executing Dynamics Query: {await boundClient.GetCommandTextAsync()}");
            await boundClient.LinkEntryAsync <T2>(linkedEntryKey, linkName);

            logger.LogInformation($"Link completed successfully.");
        }
Exemplo n.º 19
0
        /// <summary>
        /// Filters a sequence of values based on a <paramref name="predicate"/> only <paramref name="when"/> <c>true</c>.
        /// </summary>
        /// <typeparam name="TElement">The element <see cref="Type"/>.</typeparam>
        /// <param name="query">The query.</param>
        /// <param name="when">Indicates to perform an underlying <see cref="IFluentClient{TElement, FT}.Filter(Expression{Func{TElement, bool}})"/> only when <c>true</c>;
        /// otherwise, no <b>Where</b> is invoked.</param>
        /// <param name="predicate">A function to test each element for a condition.</param>
        /// <returns>The resulting query.</returns>
        public static IBoundClient <TElement> FilterWhen <TElement>(this IBoundClient <TElement> query, bool when, Expression <Func <TElement, bool> > predicate) where TElement : class
        {
            var q = Check.NotNull(query, nameof(query));

            if (when)
            {
                return(q.Filter(predicate));
            }
            else
            {
                return(q);
            }
        }
Exemplo n.º 20
0
        public async Task <IEnumerable <T> > ResultAsync(Expression <Func <T, bool> > expression)
        {
            try
            {
                bounder = bounder.Filter(expression);
                var result = await bounder.FindEntriesAsync();

                Dispose();
                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Exemplo n.º 21
0
        protected virtual async Task <IEnumerable <T> > GetAllRecordsAsync <T>(IBoundClient <T> query) where T : class
        {
            var annotations = new ODataFeedAnnotations();
            var entities    = await query.FindEntriesAsync(annotations);

            var result = entities.ToList();

            while (annotations.NextPageLink != null)
            {
                entities = await query.FindEntriesAsync(annotations.NextPageLink, annotations);

                result.AddRange(entities);
            }

            return(result);
        }
Exemplo n.º 22
0
        public async Task <T> FirstAsync(Expression <Func <T, bool> > expression)
        {
            try
            {
                bounder = bounder.Filter(expression);
                string command = await bounder.GetCommandTextAsync();

                var result = await bounder.FindEntryAsync();

                Dispose();
                return(result);
            }
            catch (Exception ex)
            {
                //configuration.ExceptionTrace?.Invoke(new ExceptionObject() { Exception = ex, ODataCommand = await bounder.GetCommandTextAsync() });
                return(null);
            }
        }
Exemplo n.º 23
0
        public ODataSet(ODataConfiguration config)
        {
            this.Configuration                = config;
            settings                          = new ODataClientSettings();
            settings.PreferredUpdateMethod    = ODataUpdateMethod.Put;
            settings.IgnoreUnmappedProperties = true;
            settings.BaseUri                  = new Uri(config.BaseUrl);

            settings.BeforeRequest = (request) =>
            {
                //if (config.AccessToken != null)
                //{
                //    request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", config.AccessToken);
                //}
            };
            if (config.OnTrance != null)
            {
                settings.OnTrace = config.OnTrance;
            }


            bounder = new ODataClient(settings).For <T>();
        }
Exemplo n.º 24
0
        /// <summary>
        /// Filters a sequence of values based on a <paramref name="predicate"/> only when the <paramref name="with"/> is not the default value for the <see cref="Type"/>.
        /// </summary>
        /// <typeparam name="TElement">The element <see cref="Type"/>.</typeparam>
        /// <typeparam name="T">The with value <see cref="Type"/>.</typeparam>
        /// <param name="query">The query.</param>
        /// <param name="with">Indicates to perform an underlying <see cref="IFluentClient{TElement, FT}.Filter(Expression{Func{TElement, bool}})"/> only when the with is not the default
        /// value; otherwise, no <b>Where</b> is invoked.</param>
        /// <param name="predicate">A function to test each element for a condition.</param>
        /// <returns>The resulting query.</returns>
        public static IBoundClient <TElement> FilterWith <TElement, T>(this IBoundClient <TElement> query, T with, Expression <Func <TElement, bool> > predicate) where TElement : class
        {
            var q = Check.NotNull(query, nameof(query));

            if (Comparer <T> .Default.Compare(with, default !) != 0 && Comparer <T> .Default.Compare(with, default !) != 0)
Exemplo n.º 25
0
 public static BoundClient <T> AsBoundClient <T>(this IBoundClient <T> client) where T : class
 {
     return(client as BoundClient <T>);
 }
Exemplo n.º 26
0
 public Pageable(IBoundClient <T> client)
 {
     _client = client;
 }
Exemplo n.º 27
0
 public static Task <T> CreateEntryAsync <T>(this IBoundClient <T> client)
     where T : class
 {
     return(client.InsertEntryAsync());
 }
Exemplo n.º 28
0
 public static Task <T> CreateEntryAsync <T>(this IBoundClient <T> client, bool resultRequired)
     where T : class
 {
     return(client.InsertEntryAsync(resultRequired));
 }
Exemplo n.º 29
0
        public virtual async Task CallSyncFrom(DtoSetSyncConfig[] fromServerDtoSetSyncMaterials, CancellationToken cancellationToken)
        {
            if (fromServerDtoSetSyncMaterials == null)
            {
                throw new ArgumentNullException(nameof(fromServerDtoSetSyncMaterials));
            }

            if (fromServerDtoSetSyncMaterials.Any())
            {
                await GetMetadataIfNotRetrievedAlready(cancellationToken).ConfigureAwait(false);

                await using (EfCoreDbContextBase offlineContextForSyncFrom = Container.Resolve <EfCoreDbContextBase>())
                {
                    ((IsSyncDbContext)offlineContextForSyncFrom).IsSyncDbContext = true;

                    List <DtoSyncConfigSyncFromInformation> dtoSyncConfigSyncFromInformationList = new List <DtoSyncConfigSyncFromInformation>();

                    int id = 0;

                    foreach (DtoSetSyncConfig fromServerSyncConfig in fromServerDtoSetSyncMaterials)
                    {
                        IQueryable <ISyncableDto> offlineSet = fromServerSyncConfig.OfflineDtoSet(offlineContextForSyncFrom);

                        var mostRecentOfflineDto = await offlineSet
                                                   .IgnoreQueryFilters()
                                                   .AsNoTracking()
                                                   .Select(e => new { e.Version })
                                                   .OrderByDescending(e => e.Version)
                                                   .FirstOrDefaultAsync(cancellationToken)
                                                   .ConfigureAwait(false);

                        long maxVersion = mostRecentOfflineDto?.Version ?? 0;

                        DtoSyncConfigSyncFromInformation dtoSyncConfigSyncFromInformation = new DtoSyncConfigSyncFromInformation
                        {
                            Id = id++,
                            DtoSetSyncConfig    = fromServerSyncConfig,
                            DtoType             = offlineSet.ElementType.GetTypeInfo(),
                            HadOfflineDtoBefore = mostRecentOfflineDto != null,
                            MaxVersion          = maxVersion
                        };

                        IBoundClient <IDictionary <string, object> > query = (dtoSyncConfigSyncFromInformation.DtoSetSyncConfig.OnlineDtoSetForGet ?? dtoSyncConfigSyncFromInformation.DtoSetSyncConfig.OnlineDtoSet)(ODataClient);

                        if (dtoSyncConfigSyncFromInformation.MaxVersion == 0)
                        {
                            query = query.Where($"{nameof(ISyncableDto.IsArchived)} eq false");
                        }
                        else
                        {
                            query = query.Where($"{nameof(ISyncableDto.Version)} gt {dtoSyncConfigSyncFromInformation.MaxVersion}");
                        }

                        string oDataGetAndVersionFilter = await query
                                                          .GetCommandTextAsync(cancellationToken)
                                                          .ConfigureAwait(false);

                        dtoSyncConfigSyncFromInformation.ODataGetUri = $"{ClientAppProfile.HostUri}{ClientAppProfile.ODataRoute}{oDataGetAndVersionFilter}";

                        dtoSyncConfigSyncFromInformationList.Add(dtoSyncConfigSyncFromInformation);
                    }

                    StringBuilder batchRequests = new StringBuilder();

                    batchRequests.AppendLine(@"
{
    ""requests"": [");

                    foreach (DtoSyncConfigSyncFromInformation?dtoSyncConfigSyncFromInformation in dtoSyncConfigSyncFromInformationList)
                    {
                        batchRequests.AppendLine(@$ "
        {{
            " "id" ": " "{dtoSyncConfigSyncFromInformation.Id}" ",
            " "method" ": " "GET" ",
            " "url" ": " "{dtoSyncConfigSyncFromInformation.ODataGetUri}" "
        }}{(dtoSyncConfigSyncFromInformation != dtoSyncConfigSyncFromInformationList.Last() ? ", " : " ")}");
                    }

                    batchRequests.AppendLine(@"
                  ]
}");

                    using (HttpResponseMessage batchResponbse = await HttpClient.PostAsync($"{ClientAppProfile.ODataRoute}$batch", new StringContent(batchRequests.ToString(), Encoding.UTF8, "application/json"), cancellationToken).ConfigureAwait(false))
                    {
                        batchResponbse.EnsureSuccessStatusCode();

                        if (batchResponbse.Content.Headers.ContentType.MediaType != "application/json")
                        {
                            throw new InvalidOperationException($"{batchResponbse.Content.Headers.ContentType.MediaType} content type is not supported.");
                        }

#if UWP || DotNetStandard2_0
                        using (Stream stream = await batchResponbse.Content.ReadAsStreamAsync().ConfigureAwait(false))
#else
                        await using (Stream stream = await batchResponbse.Content.ReadAsStreamAsync().ConfigureAwait(false))
#endif
                        {
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                using (JsonReader jsonReader = new JsonTextReader(reader))
                                {
                                    JToken jToken = await JToken.LoadAsync(jsonReader, new JsonLoadSettings
                                    {
                                        CommentHandling  = CommentHandling.Ignore,
                                        LineInfoHandling = LineInfoHandling.Ignore
                                    }, cancellationToken).ConfigureAwait(false);

                                    foreach (JToken response in jToken["responses"] !)
                                    {
                                        int responseId = response.Value <int>("id");

                                        DtoSyncConfigSyncFromInformation?dtoSyncConfigSyncFromInformation = dtoSyncConfigSyncFromInformationList.ExtendedSingle($"Getting dtoSyncConfigSyncFromInformation with id {responseId}", item => item.Id == responseId);

                                        dtoSyncConfigSyncFromInformation.RecentlyChangedOnlineDtos = ((IEnumerable)response["body"] !["value"] !.ToObject(typeof(List <>).MakeGenericType(dtoSyncConfigSyncFromInformation.DtoType)) !).Cast <ISyncableDto>().ToArray();
Exemplo n.º 30
0
 public static Task <T> CreateEntryAsync <T>(this IBoundClient <T> client, CancellationToken cancellationToken)
     where T : class
 {
     return(client.InsertEntryAsync(cancellationToken));
 }