Example #1
0
        public async Task JsonBatchSequencingSingeChangeSetTest()
        {
            DefaultContainer context = this.CreateWrappedContext <DefaultContainer>().Context;
            Customer         c1      = new Customer {
                CustomerId = 1, Name = "customerOne"
            };
            Customer c2 = new Customer {
                CustomerId = 2, Name = "customerTwo"
            };
            Customer c3 = new Customer {
                CustomerId = 3, Name = "customerThree"
            };

            context.AddToCustomer(c1);
            context.AddToCustomer(c2);
            context.AddToCustomer(c3);
            await context.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset);

            c1.Name = "customerOne updated name";
            c2.Name = "customerTwo updated name";

            context.UpdateObject(c1);
            context.UpdateObject(c2, c1);
            context.DeleteObject(c3, c2);

            var response = await context.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset | SaveChangesOptions.UseJsonBatch);

            Assert.Equal(204, (response.First() as ChangeOperationResponse).StatusCode);

            this.EnqueueTestComplete();
        }
Example #2
0
        /*[Fact, Asynchronous] */ // Activate this after solving error handling
        public async Task BatchSequencingTestFailsWithMultiPartMixed()
        {
            DefaultContainer context = this.CreateWrappedContext <DefaultContainer>().Context;
            Customer         c1      = new Customer {
                CustomerId = 1, Name = "customerOne"
            };
            Customer c2 = new Customer {
                CustomerId = 2, Name = "customerTwo"
            };

            context.AddToCustomer(c1);
            context.AddToCustomer(c2);
            await context.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset);

            c1.Name = "customerOne updated name";
            c2.Name = "customerTwo updated name";

            context.UpdateObject(c1);
            context.UpdateObject(c2, c1);

            Task response() => context.SaveChangesAsync(SaveChangesOptions.BatchWithIndependentOperations);

            var exception = await Assert.ThrowsAsync <ODataException>(response);

            Assert.Contains("The dependsOn Id in request is not matching any of the request Id and atomic group Id seen so far", exception.Message);

            this.EnqueueTestComplete();
        }
Example #3
0
 private void delete_Click(object sender, RoutedEventArgs e)
 {
     ExceptionFriendly(() =>
     {
         var airlines = WaitForResult(_context.Airlines.ExecuteAsync());
         var airline  = airlines.Single(a => a.AirlineCode == "AA");
         _context.DeleteObject(airline);
         _context.SaveChangesAsync();
         SetText("Deleted Airlines('AA').");
     });
 }
Example #4
0
    public async Task <HttpStatusCode> ConfirmAliveAsync(int processId, DateTime now, ControllableProcessStatus status)
    {
        using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(ConfirmAliveAsync)))) {
            var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames();
            _SimpleLogger.LogInformationWithCallStack($"Confirm that process with id={processId} is alive", methodNamesFromStack);
            var context       = new DefaultContainer(new Uri(BaseUrl));
            var processExists = await ProcessExists(context, processId);

            if (processExists.Inconclusive)
            {
                _SimpleLogger.LogInformationWithCallStack($"Could not determine if process with id={processId} exists", methodNamesFromStack);
                return(HttpStatusCode.InternalServerError);
            }

            if (!processExists.YesNo)
            {
                _SimpleLogger.LogInformationWithCallStack($"No process exists with id={processId}", methodNamesFromStack);
                return(HttpStatusCode.NotFound);
            }

            _SimpleLogger.LogInformationWithCallStack($"Update process with id={processId}", methodNamesFromStack);
            var controllableProcess = await context.ControllableProcesses.ByKey(processId).GetValueAsync();

            controllableProcess.ConfirmedAt = now;
            controllableProcess.Status      = status;
            context.UpdateObject(controllableProcess);
            var response = await context.SaveChangesAsync(SaveChangesOptions.None);

            var statusCode = response.Select(r => (HttpStatusCode)r.StatusCode).FirstOrDefault();
            return(statusCode);
        }
    }
Example #5
0
    public async Task <HttpStatusCode> ConfirmStatusAsync(Guid taskId, ControllableProcessTaskStatus status, string text, string errorMessage)
    {
        using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(ConfirmStatusAsync)))) {
            var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames();
            _SimpleLogger.LogInformationWithCallStack($"Confirm status {Enum.GetName(typeof(ControllableProcessStatus), status)} for task id={taskId}", methodNamesFromStack);

            DefaultContainer        context;
            ControllableProcessTask controllableProcessTask = null;
            bool wasExceptionThrown;
            do
            {
                wasExceptionThrown = false;
                context            = new DefaultContainer(new Uri(BaseUrl));
                try {
                    if (!await ProcessTaskExists(context, taskId))
                    {
                        return(HttpStatusCode.NotFound);
                    }
                    _SimpleLogger.LogInformationWithCallStack($"Select task with id={taskId} for update", methodNamesFromStack);
                    controllableProcessTask = await context.ControllableProcessTasks.ByKey(taskId).GetValueAsync();
                } catch {
                    _SimpleLogger.LogErrorWithCallStack($"Could not select task with id={taskId} for update, trying again", methodNamesFromStack);
                    wasExceptionThrown = true;
                }
            } while (wasExceptionThrown);

            if (controllableProcessTask == null)
            {
                _SimpleLogger.LogInformationWithCallStack($"No task found with id={taskId}", methodNamesFromStack);
                return(HttpStatusCode.NotFound);
            }

            _SimpleLogger.LogInformationWithCallStack($"Update task with id={taskId}", methodNamesFromStack);
            controllableProcessTask.Status       = status;
            controllableProcessTask.Text         = text;
            controllableProcessTask.ErrorMessage = errorMessage;
            context.UpdateObject(controllableProcessTask);
            var response = await context.SaveChangesAsync(SaveChangesOptions.None);

            var statusCode = response.Select(r => (HttpStatusCode)r.StatusCode).FirstOrDefault();
            return(statusCode);
        }
    }
Example #6
0
    public async Task <HttpStatusCode> PutControllableProcessTaskAsync(ControllableProcessTask processTask)
    {
        using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(PutControllableProcessTaskAsync)))) {
            var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames();
            _SimpleLogger.LogInformationWithCallStack($"Put controllable process task with id={processTask.Id}", methodNamesFromStack);
            var context = new DefaultContainer(new Uri(BaseUrl));
            ControllableProcessTask controllableProcessTask;
            if (await ProcessTaskExists(context, processTask.Id))
            {
                _SimpleLogger.LogInformationWithCallStack($"Update controllable process task with id={processTask.Id}", methodNamesFromStack);
                controllableProcessTask = await context.ControllableProcessTasks.ByKey(processTask.Id).GetValueAsync();

                controllableProcessTask.ProcessId   = processTask.ProcessId;
                controllableProcessTask.Type        = processTask.Type;
                controllableProcessTask.ControlName = processTask.ControlName;
                controllableProcessTask.Text        = processTask.Text;
                controllableProcessTask.Status      = processTask.Status;
                context.UpdateObject(controllableProcessTask);
            }
            else
            {
                _SimpleLogger.LogInformationWithCallStack($"Insert controllable process task with id={processTask.Id}", methodNamesFromStack);
                controllableProcessTask = new ControllableProcessTask {
                    Id          = processTask.Id,
                    ProcessId   = processTask.ProcessId,
                    Type        = processTask.Type,
                    ControlName = processTask.ControlName,
                    Text        = processTask.Text,
                    Status      = processTask.Status
                };
                context.AddToControllableProcessTasks(controllableProcessTask);
            }

            var response = await context.SaveChangesAsync(SaveChangesOptions.ReplaceOnUpdate);

            var statusCode = response.Select(r => (HttpStatusCode)r.StatusCode).FirstOrDefault();
            return(statusCode);
        }
    }
Example #7
0
    public async Task <HttpStatusCode> PutControllableProcessAsync(Process process)
    {
        using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(PutControllableProcessAsync)))) {
            var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames();
            _SimpleLogger.LogInformationWithCallStack($"Put controllable process with id={process.Id}", methodNamesFromStack);
            var context = new DefaultContainer(new Uri(BaseUrl));
            ControllableProcess controllableProcess;
            if ((await ProcessExists(context, process.Id)).YesNo)
            {
                _SimpleLogger.LogInformationWithCallStack($"Update controllable process with id={process.Id}", methodNamesFromStack);
                controllableProcess = await context.ControllableProcesses.ByKey(process.Id).GetValueAsync();

                controllableProcess.Title         = process.ProcessName;
                controllableProcess.Status        = ControllableProcessStatus.Idle;
                controllableProcess.ConfirmedAt   = DateTimeOffset.Now;
                controllableProcess.LaunchCommand = process.MainModule?.FileName;
                context.UpdateObject(controllableProcess);
            }
            else
            {
                _SimpleLogger.LogInformationWithCallStack($"Insert controllable process with id={process.Id}", methodNamesFromStack);
                controllableProcess = new ControllableProcess {
                    ProcessId     = process.Id,
                    Title         = process.ProcessName,
                    Status        = ControllableProcessStatus.Idle,
                    ConfirmedAt   = DateTimeOffset.Now,
                    LaunchCommand = process.MainModule?.FileName
                };
                context.AddToControllableProcesses(controllableProcess);
            }

            var response = await context.SaveChangesAsync(SaveChangesOptions.ReplaceOnUpdate);

            var statusCode = response.Select(r => (HttpStatusCode)r.StatusCode).FirstOrDefault();
            return(statusCode);
        }
    }
 static async Task AddOriginal_ConcreteStrainTableEntity(DefaultContainer container, Original_ConcreteStrainTable entity)
 {
     container.AddToOriginal_ConcreteStrains(entity);
     await container.SaveChangesAsync();
 }
 static async Task AddOriginal_WindLoadTableEntity(DefaultContainer container, Original_WindLoadTable entity)
 {
     container.AddToOriginal_WindLoads(entity);
     await container.SaveChangesAsync();
 }
 static async Task AddOriginal_TemperatureTableEntity(DefaultContainer container, Original_TemperatureTable entity)
 {
     container.AddToOriginal_Temperatures(entity);
     await container.SaveChangesAsync();
 }
 static async Task AddOriginal_DisplacementTableEntity(DefaultContainer container, Original_DisplacementTable entity)
 {
     container.AddToOriginal_Displacements(entity);
     await container.SaveChangesAsync();
 }