Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "soonjoo"

Hello, I had managed to do it, I needed to inherit IXamarinView inside my BarcodeSearchView class.. now the page loads properly.

Thanks!

hello, here is the httpResponse.. if i continue the code, it dies after this line

var response = await httpResponse.GetJsonAsync<AjaxResponse<T>>();

Hello again,

I didnt know i could step inside that call. So i had debug it, and found it had caught this exception message:

{Flurl.Http.FlurlHttpException: GET <a class="postlink" href="http://myprojectdev.azurewebsites.net/api/services/app/Session/GetCurrentLoginInformations">http://myprojectdev.azurewebsites.net/a ... formations</a> failed. Unexpected character encountered while parsing value: . Path '', line 0, position 0. ---> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: . Path '', line 0, position 0. at Newtonsoft.Json.JsonTextReader.ParseValue () [0x002b3] in <c19705166c7c4a608e182e859c4de6d2>:0 at Newtonsoft.Json.JsonTextReader.Read () [0x0004c] in <c19705166c7c4a608e182e859c4de6d2>:0 at Newtonsoft.Json.JsonReader.ReadAndMoveToContent () [0x00000] in <c19705166c7c4a608e182e859c4de6d2>:0 at Newtonsoft.Json.JsonReader.ReadForType (Newtonsoft.Json.Serialization.JsonContract contract, System.Boolean hasConverter) [0x00043] in <c19705166c7c4a608e182e859c4de6d2>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <c19705166c7c4a608e182e859c4de6d2>:0 at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00053] in <c19705166c7c4a608e182e859c4de6d2>:0 at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <c19705166c7c4a608e182e859c4de6d2>:0 at Newtonsoft.Json.JsonSerializer.Deserialize[T] (Newtonsoft.Json.JsonReader reader) [0x00000] in <c19705166c7c4a608e182e859c4de6d2>:0 at Flurl.Http.Configuration.NewtonsoftJsonSerializer.Deserialize[T] (System.IO.Stream stream) [0x00019] in <f0b4fb8d1d61489486317325ace33652>:0 at Flurl.Http.HttpResponseMessageExtensions+<ReceiveJson>d__01[T].MoveNext () [0x00121] in <f0b4fb8d1d61489486317325ace33652>:0 --- End of inner exception stack trace --- at Flurl.Http.HttpResponseMessageExtensions+<ReceiveJson>d__01[T].MoveNext () [0x00157] in <f0b4fb8d1d61489486317325ace33652>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at MyCompany.MyProject.ApiClient.AbpApiClient+<GetAsync>d__251[T].MoveNext () [0x0007e] in C:\Users\Justin\Source\Repos\MyProject\src\MyCompany.MyProject.Application.Client\ApiClient\AbpApiClient.cs:183 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at MyCompany.MyProject.ApiClient.AbpApiClient+<GetAsync>d__241[T].MoveNext () [0x000c6] in C:\Users\Justin\Source\Repos\MyProject\src\MyCompany.MyProject.Application.Client\ApiClient\AbpApiClient.cs:172 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at MyCompany.MyProject.ApiClient.AbpApiClient+<GetAsync>d__221[T].MoveNext () [0x00027] in C:\Users\Justin\Source\Repos\MyProject\src\MyCompany.MyProject.Application.Client\ApiClient\AbpApiClient.cs:156 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at MyCompany.MyProject.Sessions.ProxySessionAppService+<GetCurrentLoginInformations>d__0.MoveNext () [0x00035] in C:\Users\Justin\Source\Repos\MyProject\src\MyCompany.MyProject.Application.Client\Sessions\ProxySessionAppService.cs:10 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at MyCompany.MyProject.ViewModels.LoginViewModel+<<SetCurrentUserInfoAsync>b__48_0>d.MoveNext () [0x00024] in C:\Users\Justin\Source\Repos\MyProject\src\MyCompany.MyProject.Mobile.Shared\ViewModels\LoginViewModel.cs:256 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at MyCompany.MyProject.Core.Threading.WebRequestExecuter+<Execute>d__01[TResult].MoveNext () [0x002a1] in C:\Users\Justin\Source\Repos\MyProject\src\MyCompany.MyProject.Mobile.Shared\Core\Threading\WebRequestExecuter.cs:52 }

hello again, i forgot to mention previously i directly pointed to the development api service (online not localhost). And it manages to call GetAll for User configurations and Authenticate, then keeps dying at GetCurrentLoginInformations...

so i tried localhost, but running the start-host.bat provided, and it manages to run successfully, for everything

on the development api service online, the url is formed correctly when i look inside httpResponse variable, and paste the url into my browser it works, but it immediately dies on the await httpResponse.GetJsonAsync<AjaxResponse<T>>(); line

thank you.

Thank you for your help, I will try the first method, the second method seems hard, I'm not sure how to store the next code in cache, because the next code is not always in a sequence as it might be under a different parent

Hello aaron, thank you for your reply,

my entity is Sample, this is my application service to create a new Sample

public async Task<SampleDto> CreateNewSample(CreateNewSampleInput input)
        {
            var sample = ObjectMapper.Map<Sample>(input);
            var insertedSample = await _sampleManager.CreateNewSample(sample);

            return ObjectMapper.Map<SampleDto>(insertedSample);
        }

This is the sample manager (i left out some unrelated business logic) Sample's Line is similar to the Organization Unit's Code

public async Task<Sample> CreateNewSample(Sample sample)
        {
     
            ....

            sample.Line = await GetNextChildCodeAsync(sample.ParentSampleId);

            ....

            var insertedSample = await _sampleRepository.InsertAsync(sample);
            await CurrentUnitOfWork.SaveChangesAsync();

            return insertedSample;
        }

This is taken from organization unit manager's codes

public virtual async Task<string> GetNextChildCodeAsync(long? parentId)
        {
            var lastChild = await GetLastChildOrNullAsync(parentId);
            if (lastChild == null)
            {
                var parentCode = parentId != null ? await GetCodeAsync(parentId.Value) : null;
                return Sample.AppendCode(parentCode, Sample.CreateCode(1));
            }

            return Sample.CalculateNextCode(lastChild.Line);
        }

        public virtual async Task<Sample> GetLastChildOrNullAsync(long? parentId)
        {
            var children = await _sampleRepository.GetAllListAsync(ou => ou.ParentSampleId == parentId);
            return children.OrderBy(c => c.Line).LastOrDefault();
        }

        public virtual async Task<string> GetCodeAsync(long id)
        {
            return (await _sampleRepository.GetAsync(id)).Line;
        }

this is my sample entity model, most of it taken from organization unit

public class Sample : FullAuditedEntity<long>, IMustHaveTenant
    {

        /// <summary>
        /// Maximum depth of an UO hierarchy.
        /// </summary>
        public const int MaxDepth = 16;

        /// <summary>
        /// Length of a code unit between dots.
        /// </summary>
        public const int CodeUnitLength = 6;

        /// <summary>
        /// Maximum length of the <see cref="Line"/> property.
        /// </summary>
        public const int MaxCodeLength = MaxDepth * (CodeUnitLength + 1) - 1;


        public Sample()
        {
            this.ChildSamples = new HashSet<Sample>();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Sample"/> class.
        /// </summary>
        /// <param name="tenantId">Tenant's Id or null for host.</param>
        /// <param name="sampleDefinitionId">Sample Definition Id.</param>
        /// <param name="parentId">Parent's Id or null if OU is a root.</param>
        public Sample(int tenantId, long? sampleDefinitionId, long? parentId = null)
        {
            TenantId = tenantId;
            SampleDefinitionId = sampleDefinitionId;
            ParentSampleId = parentId;
        }

         .....

        [ForeignKey("ParentSampleId")]
        public Sample ParentSample { get; set; }
        public long? ParentSampleId { get; set; }

       .....

        /// <summary>
        /// Hierarchical Lineage of this sample.
        /// Example: "00001.00042.00005".
        /// It's changeable if OU hierarch is changed.
        /// </summary>
        [StringLength(MaxCodeLength)]
        public string Line { get; set; }

       .....

        public virtual ICollection<Sample> ChildSamples { get; set; }

        public int TenantId { get; set; }


        /// <summary>
        /// Gets user friendly code to be displayed.
        /// Example: if code = "00019.00055.00001" then returns "19.55.1".
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="parentCode">The parent code.</param>
        public static string GetUserFriendlyCode(string code)
        {
            List<string> friendlyCodeList = new List<string>();

            var codeList = code.Split(".");
            foreach (var codePart in codeList)
            {
                friendlyCodeList.Add(codePart.TrimStart('0'));
            }

            return String.Join(".", friendlyCodeList);
        }

        /// <summary>
        /// Creates code for given numbers.
        /// Example: if numbers are 4,2 then returns "00004.00002";
        /// </summary>
        /// <param name="numbers">Numbers</param>
        public static string CreateCode(params int[] numbers)
        {
            if (numbers.IsNullOrEmpty())
            {
                return null;
            }

            return numbers.Select(number => number.ToString(new string('0', CodeUnitLength))).JoinAsString(".");
        }

        /// <summary>
        /// Appends a child code to a parent code. 
        /// Example: if parentCode = "00001", childCode = "00042" then returns "00001.00042".
        /// </summary>
        /// <param name="parentCode">Parent code. Can be null or empty if parent is a root.</param>
        /// <param name="childCode">Child code.</param>
        public static string AppendCode(string parentCode, string childCode)
        {
            if (childCode.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(childCode), "childCode can not be null or empty.");
            }

            if (parentCode.IsNullOrEmpty())
            {
                return childCode;
            }

            return parentCode + "." + childCode;
        }

        /// <summary>
        /// Gets relative code to the parent.
        /// Example: if code = "00019.00055.00001" and parentCode = "00019" then returns "00055.00001".
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="parentCode">The parent code.</param>
        public static string GetRelativeCode(string code, string parentCode)
        {
            if (code.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(code), "code can not be null or empty.");
            }

            if (parentCode.IsNullOrEmpty())
            {
                return code;
            }

            if (code.Length == parentCode.Length)
            {
                return null;
            }

            return code.Substring(parentCode.Length + 1);
        }

        /// <summary>
        /// Calculates next code for given code.
        /// Example: if code = "00019.00055.00001" returns "00019.00055.00002".
        /// </summary>
        /// <param name="code">The code.</param>
        public static string CalculateNextCode(string code)
        {
            if (code.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(code), "code can not be null or empty.");
            }

            var parentCode = GetParentCode(code);
            var lastUnitCode = GetLastUnitCode(code);

            return AppendCode(parentCode, CreateCode(Convert.ToInt32(lastUnitCode) + 1));
        }

        /// <summary>
        /// Gets the last unit code.
        /// Example: if code = "00019.00055.00001" returns "00001".
        /// </summary>
        /// <param name="code">The code.</param>
        public static string GetLastUnitCode(string code)
        {
            if (code.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(code), "code can not be null or empty.");
            }

            var splittedCode = code.Split('.');
            return splittedCode[splittedCode.Length - 1];
        }

        /// <summary>
        /// Gets parent code.
        /// Example: if code = "00019.00055.00001" returns "00019.00055".
        /// </summary>
        /// <param name="code">The code.</param>
        public static string GetParentCode(string code)
        {
            if (code.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(code), "code can not be null or empty.");
            }

            var splittedCode = code.Split('.');
            if (splittedCode.Length == 1)
            {
                return null;
            }

            return splittedCode.Take(splittedCode.Length - 1).JoinAsString(".");
        }
    }

I notice that whenever the CreateNewSample api is called multiple times with the same parent id, the Line doesn't set correctly..

Answer

Thank you for your help @aaron

Thank you

I have found the issue, its because I wasn't awaiting an async call.. sorry for the inconvenience.

I get this error too occasionally

Mvc.ExceptionHandling.AbpExceptionFilter - A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe. System.InvalidOperationException: A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe.

I have a suspicion that its because my entity has a self referencing relationship... I think self referencing relationship doesn't play too well with domain events?

Showing 11 to 20 of 38 entries