예제 #1
0
        private void DeleteAllCmd(DeleteAll cmd)
        {
            // aggregator
            var agg = Context.ActorOf(Props.Create(() => new AggregateActor()), AggregateActor.GetUniqueName());

            // active ids
            agg.Tell(new AggregateActor.GetAll(Sender, cmd, State.IdsActive.Count, typeof(DeleteById_Success), 10, false));
            foreach (var activeId in State.IdsActive)
            {
                var child = Context.Child(activeId);
                if (child != ActorRefs.Nobody)
                {
                    agg.Tell(new AggregateActor.GetAllAdd(child, new DeleteById(activeId)));
                }
                else
                {
                    agg.Tell(new AggregateActor.ReduceTargetCount());
                }
            }
            // inactive ids
            agg.Tell(new AggregateActor.GetAll(Sender, cmd, State.IdsInactive.Count, typeof(DeleteById_Success), 10, false));
            foreach (var inactiveId in State.IdsInactive)
            {
                var child = Context.Child(inactiveId);
                if (child == ActorRefs.Nobody)
                {
                    child = CreateEntity(inactiveId);
                }

                // get inactive data and deactivate child once it replies
                agg.Tell(new AggregateActor.GetAllAdd(child, new EntityActor.DeactivateAfter <DeleteById>(new DeleteById(inactiveId))));
            }
        }
예제 #2
0
        public static SuccessFailCode Execute(IServiceProvider services, Options opts)
        {
            var logger = services.GetService <ILogger <CleanCosmos> >();

            try
            {
                var configuration = services.GetService <IConfiguration>();
                configuration.Bind(opts);

                var client = new DocumentClient(new Uri(opts.Cosmos.Endpoint), opts.Cosmos.Key);

                DeleteAll <UserSession>(logger, client, opts.Cosmos.DatabaseName, "UserSessions", a => (a.UserSessionId, a.PartitionKey)).GetAwaiter().GetResult();
                DeleteAll <Question>(logger, client, opts.Cosmos.DatabaseName, "Questions", a => (a.QuestionId, a.PartitionKey)).GetAwaiter().GetResult();
                DeleteAll <QuestionSet>(logger, client, opts.Cosmos.DatabaseName, "QuestionSets", a => (a.QuestionSetVersion, a.PartitionKey)).GetAwaiter().GetResult();

                return(SuccessFailCode.Succeed);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "An error occured ");
                return(SuccessFailCode.Fail);
            }
        }
            protected override async Task <FlowElementResult> OnExecuteAsync(object args, FlowState state)
            {
                object result = _delete switch
                {
                    DeleteById byId => await Db.DeleteByIdAsync <TTable>(byId.MapId(args)),
                    DeleteByIds byIds => await Db.DeleteByIdsAsync <TTable>(byIds.MapIds(args)),
                    DeleteAll _ => await Db.DeleteAllAsync <TTable>(),
                    DeleteAll <TTable> all => await Db.DeleteAsync(all.ExpressionBuilder(args)),
                    _ => new NotImplementedException("Delete action not implemented")
                };

                return(new FlowSuccessResult
                {
                    Result = result
                });
            }
        }
예제 #4
0
        public static void TryDelete(this IDocumentSession session, string indexname, string tag)
        {
            Exception ex        = null;
            bool      retry     = false;
            var       startTime = DateTime.UtcNow;

            //attempt to do the delete every n seconds for n minutes
            do
            {
                if (retry)
                {
                    Thread.Sleep(DefaultWaitForRetryOnStaleIndexes);
                }

                ex    = DeleteAll.Invoke(session, indexname, tag);
                retry = true;
            } while (ex?.Message.Contains("index is stale") == true && (DateTime.UtcNow - startTime < DefaultWaitTimeoutForNonStaleIndexes));

            if (ex != null)
            {
                throw ex;
            }
        }
예제 #5
0
        public void ShowExample_Click(object sender, EventArgs e)
        {
            Form form = null;

            switch (((Button)sender).Name)
            {
            // Dapper - API | Query
            case "uiExecute":
                form = new Execute();
                break;

            case "uiQuery":
                form = new Query();
                break;

            case "uiQueryFirst":
                form = new QueryFirst();
                break;

            case "uiQueryFirstOrDefault":
                form = new QueryFirstOrDefault();
                break;

            case "uiQuerySingle":
                form = new QuerySingle();
                break;

            case "uiQuerySingleOrDefault":
                form = new QuerySingleOrDefault();
                break;

            case "uiQueryMultiple":
                form = new QueryMultiple();
                break;

            // Dapper - API | Parameter
            case "uiParameter_Anonymous":
                form = new Anonymous();
                break;

            case "uiParameter_Dynamic":
                form = new Dynamic();
                break;

            case "uiParameter_List":
                form = new List();
                break;

            case "uiParameter_String":
                form = new String();
                break;

            // Dapper - API | Result Type
            case "uiResult_Anonymous":
                form = new Result.Anonymous();
                break;

            case "uiResult_Strongly_Typed":
                form = new Strongly_Typed();
                break;

            case "uiResult_Multi_Mapping":
                form = new Multi_Mapping();
                break;

            case "uiResult_Multi_Result":
                form = new Multi_Result();
                break;

            case "uiResult_Multi_Type":
                form = new Multi_Type();
                break;

            // Dapper - API | Utilities
            case "uiAsync":
                form = new Async();
                break;

            case "uiBuffered":
                form = new Buffered();
                break;

            case "uiTransaction":
                form = new Transaction();
                break;

            case "uiStored_Procedure":
                form = new Stored_Procedure();
                break;

            // Dapper Plus - API | Methods
            case "uiBulk_Insert":
                form = new Bulk_Insert();
                break;

            case "uiBulk_Update":
                form = new Bulk_Update();
                break;

            case "uiBulk_Delete":
                form = new Bulk_Delete();
                break;

            case "uiBulk_Merge":
                form = new Bulk_Merge();
                break;

            // Dapper Contrib - API | Methods
            case "uiGet":
                form = new Get();
                break;

            case "uiGetAll":
                form = new GetAll();
                break;

            case "uiInsert":
                form = new Insert();
                break;

            case "uiUpdate":
                form = new Update();
                break;

            case "uiDelete":
                form = new Delete();
                break;

            case "uiDeleteAll":
                form = new DeleteAll();
                break;

            // Dapper Contrib - API | Data Annotations
            case "uiData_Annotation_Key":
                form = new Key();
                break;

            case "uiData_Annotation_ExplicitKey":
                form = new ExplicitKey();
                break;

            case "uiData_Annotation_Table":
                form = new Table();
                break;

            case "uiData_Annotation_Write":
                form = new Write();
                break;

            case "uiData_Annotation_Computed":
                form = new Computed();
                break;

            // Performance Comparison
            case "uiDapper_vs_EF_Query":
                form = new Performance_Comparison.Dapper_vs_EF6.Query();
                break;

            case "uiDapper_vs_EF_Insert":
                form = new Performance_Comparison.Dapper_vs_EF6.Insert();
                break;

            case "uiDapper_vs_EF_Update":
                form = new Performance_Comparison.Dapper_vs_EF6.Update();
                break;

            case "uiDapper_vs_EF_Delete":
                form = new Performance_Comparison.Dapper_vs_EF6.Delete();
                break;

            default:
                throw new Exception("Invalid Button Name");
            }

            form.StartPosition = FormStartPosition.CenterParent;
            form.ShowDialog();
        }
예제 #6
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                if (CollectAllButton != null)
                {
                    if (!CollectAllButton.IsDisposed)
                    {
                        CollectAllButton.Dispose();
                    }

                    CollectAllButton = null;
                }

                if (DeleteAll != null)
                {
                    if (!DeleteAll.IsDisposed)
                    {
                        DeleteAll.Dispose();
                    }

                    DeleteAll = null;
                }

                if (NewButton != null)
                {
                    if (!NewButton.IsDisposed)
                    {
                        NewButton.Dispose();
                    }

                    NewButton = null;
                }

                if (Header != null)
                {
                    if (!Header.IsDisposed)
                    {
                        Header.Dispose();
                    }

                    Header = null;
                }

                if (ScrollBar != null)
                {
                    if (!ScrollBar.IsDisposed)
                    {
                        ScrollBar.Dispose();
                    }

                    ScrollBar = null;
                }

                if (NewButton != null)
                {
                    if (!NewButton.IsDisposed)
                    {
                        NewButton.Dispose();
                    }

                    NewButton = null;
                }

                if (Rows != null)
                {
                    for (int i = 0; i < Rows.Length; i++)
                    {
                        if (Rows[i] != null)
                        {
                            if (!Rows[i].IsDisposed)
                            {
                                Rows[i].Dispose();
                            }

                            Rows[i] = null;
                        }
                    }

                    Rows = null;
                }

                MailList.Clear();
                MailList = null;
            }
        }
예제 #7
0
        public IHttpActionResult Post(string operation, string tabKey, string intervalString, [FromBody] CycleDtc record)
        {
            var operationInfo = GetOperationInfo(operation);

            var tabInfo = VwRfProductionDataEntryTab.Find(operationInfo.Operation, tabKey);

            if (tabInfo == null)
            {
                throw new ArgumentException();
            }

            // Only shift interval supported at the moment.
            if (!tabInfo.IntervalType.Equals("Shift", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new ArgumentException();
            }

            // Maximum # of loads exceeded
            if (record.Loads > MAX_LOADS)
            {
                throw new Exception("$Too many loads entered.Maximum { maxLoads } loads per record.");
            }

            var intervalType  = tabInfo.IntervalType.ToUpper();
            var shiftInterval = (ShiftInterval)_entryIntervalProvider.GetInterval(intervalType, intervalString);

            var productionEntryIntervalFactory = new ProductionEntryIntervalFactory(_operationInfoProvider, _timezoneInfoProvider, _productionEntryUtility);

            var productionEntryIntervalType = (ProductionEntryIntervalType)Enum.Parse(typeof(ProductionEntryIntervalType), tabInfo.IntervalType);
            var entryIntervalProvider       = productionEntryIntervalFactory.GetProvider(productionEntryIntervalType);

            //var intervals = entryIntervalProvider.GetIntervals(operationInfo.Operation, shiftInterval.DateOp, shiftInterval.Shift);

            //if (!bool.TryParse(showAll, out bool finalShowAll)) finalShowAll = false;

            //ViewData["ShowAllIntervals"] = finalShowAll;

            //Process the interval
            //int finalIntervalId;
            //if (string.IsNullOrEmpty(intervalId) || !int.TryParse(intervalId, out finalIntervalId))
            //    finalIntervalId = 0;

            ////if the show all box is checked, then we ignore the passed interval id
            //if (finalShowAll) finalIntervalId = -1;

            //get the related interval
            var productionEntryInterval = entryIntervalProvider.GetInterval(
                operationInfo.Operation,
                shiftInterval.DateOp,
                shiftInterval.Shift,
                0);

            //if (!finalShowAll)
            //{
            //try
            //{
            //    productionEntryInterval = entryIntervalProvider.GetInterval(
            //        operationInfo.Operation,
            //        shiftInstance.DateOp,
            //        shiftInstance.Shift,
            //        record.IntervalId);
            //}
            //catch (Exception)
            //{
            //    //if a bad interval id is passed in, then default to the first interval for the shift.
            //    productionEntryInterval = entryIntervalProvider.GetInterval(
            //        operationInfo.Operation,
            //        shiftInstance.DateOp,
            //        shiftInstance.Shift, 0);
            //}

            //ViewData["IntervalId"] = finalIntervalId;

            //}

            //ViewData["IntervalSelect"] = new SelectList(intervals, "IntervalId", "Label", finalIntervalId);

            //Data for shift selector view
            //ViewData["Operation"] = operationInfo.Operation;
            //if (operationsContext.Length > 1) ViewData["OperationSelect"] = new SelectList(operationsContext, "Operation", "Description", operationInfo.Description);
            //ViewData["ShiftSelect"] = new SelectList(shiftInfos, "Shift", "Label", finalShift.Shift);

            //ViewData["Shift"] = finalShift.Shift;
            //ViewData["DateOp"] = finalDateOp.ToShortDateString();

            //var includedFleetTypes = new[]
            //{
            //    FleetTypeValidator.HaulerFleetType, FleetTypeValidator.LoaderFleetType,
            //    FleetTypeValidator.ExcavatorFleetType, FleetTypeValidator.ShovelFleetType
            //};

            //var fleetTypes = Request.QueryString.GetValues("FleetType");
            ////Validate fleettypes, prepare select list
            //var fleetTypeRecords = Array.FindAll(RfFleetType.SelectAll(),
            //                                     f =>
            //                                     Array.Find(includedFleetTypes, i => Utility.CompareSqlStrings(i, f.FleetType)) != null);

            //var selectedFleetTypeRecords = fleetTypes != null && fleetTypes.Length != 0
            //                                   ? Array.FindAll(fleetTypeRecords, ur => Array.Find(fleetTypes, u => Utility.CompareSqlStrings(u, ur.FleetType)) != null) : fleetTypeRecords;

            //var fleetTypeSelect = new BetterCheckBoxList<RfFleetType>(fleetTypeRecords, "FleetType", "Description", selectedFleetTypeRecords);

            //ViewData["FleetTypeSelect"] = fleetTypeSelect;
            //ViewData["SelectedFleetTypes"] = Array.ConvertAll(selectedFleetTypeRecords, u => u.FleetType);

            //var fleetTypeUrl = "&FleetType=" + String.Join("&FleetType=", Array.ConvertAll(selectedFleetTypeRecords, u => u.FleetType));

            ////Next and previous shift links
            //if (Request.Url != null)
            //{
            //    var url = Request.Url.AbsolutePath;
            //    var nextShift = operationInfo.GetNextShift(shiftInstance);
            //    var prevShift = operationInfo.GetPrevShift(shiftInstance);

            //    ViewData["Url"] = url;

            //    var urlTail = string.Format("{0}&ShowAllIntervals={1}&tabKey={2}", fleetTypeUrl, finalShowAll, tabKey);

            //    if (intervalType == ProductionEntryIntervalType.Hourly && !finalShowAll && entryInterval != null)
            //    {
            //        var nextInterval = entryIntervalProvider.GetNextInterval(shiftInstance.Operation, shiftInstance.DateOp, shiftInstance.Shift, finalIntervalId);
            //        var prevInterval = entryIntervalProvider.GetPrevInterval(shiftInstance.Operation, shiftInstance.DateOp, shiftInstance.Shift, finalIntervalId);

            //        ViewData["NextIntervalUrl"] =
            //            string.Format("{0}?operation={1}&dateOp={2}&shift={3}&intervalId={4}{5}", url,
            //                          operationInfo.Operation, nextInterval.IntervalShift.DateOp.ToShortDateString(),
            //                          nextInterval.IntervalShift.Shift, nextInterval.IntervalId, urlTail);
            //        ViewData["PrevIntervalUrl"] =
            //            string.Format("{0}?operation={1}&dateOp={2}&shift={3}&intervalId={4}{5}", url,
            //                          operationInfo.Operation, prevInterval.IntervalShift.DateOp.ToShortDateString(),
            //                          prevInterval.IntervalShift.Shift, prevInterval.IntervalId, urlTail);
            //    }

            //    var defaultIntervalId = finalShowAll ? -1 : 0;

            //    ViewData["NextShiftUrl"] = string.Format("{0}?operation={1}&dateOp={2}&shift={3}&intervalId={4}{5}", url,
            //                                             operationInfo.Operation, nextShift.DateOp.ToShortDateString(),
            //                                             nextShift.Shift, defaultIntervalId, urlTail);
            //    ViewData["PrevShiftUrl"] = string.Format("{0}?operation={1}&dateOp={2}&shift={3}&intervalId={4}{5}", url,
            //                                             operationInfo.Operation, prevShift.DateOp.ToShortDateString(),
            //                                             prevShift.Shift, defaultIntervalId, urlTail);

            //    ViewData["NextDayUrl"] = string.Format("{0}?operation={1}&dateOp={2}&shift={3}&intervalId={4}{5}", url,
            //                             operationInfo.Operation, shiftInstance.DateOp.AddDays(1).ToShortDateString(),
            //                             shiftInstance.Shift, defaultIntervalId, urlTail);
            //    ViewData["PrevDayUrl"] = string.Format("{0}?operation={1}&dateOp={2}&shift={3}&intervalId={4}{5}", url,
            //                                             operationInfo.Operation, shiftInstance.DateOp.AddDays(-1).ToShortDateString(),
            //                                             shiftInstance.Shift, defaultIntervalId, urlTail);
            //}

            //const int maxLoads = 1000;

            //IOperationInfo operationInfo;
            //ShiftInstance shiftInstance;
            //IProductionEntryIntervalProvider entryIntervalProvider;
            //ProductionEntryInterval entryInterval;
            //ValidateArguments(out operationInfo, out shiftInstance, out entryIntervalProvider, out entryInterval);

            var gradeItems = RfProductionDataEntryGrade.SelectAll(operation, tabKey).Select(g => g.GradeItem).ToArray();

            //var newValues = ObjectBinder.BindDictionary<FlexibleRowObject, int>(Request.Form, "NewValues");
            //var oldValues = ObjectBinder.BindDictionary<FlexibleRowObject, int>(Request.Form, "OldValues");

            using (var connection = Utility.GetConnection <Cycle> ()) {
                using (var transaction = connection.BeginTransaction()) {
                    // Get movement rows
                    var rows = entryIntervalProvider.ConvertToMovementRows(shiftInterval, productionEntryInterval, tabKey, newValues, oldValues);

                    var row = rows.Where(r => r.Id == rowIndex).FirstOrDefault();

                    result.AddValidationErrors(rowIndex, entryIntervalProvider.ValidateMovementRow(connection, transaction, row));

                    if (!result.IsErrorFree() || result.RowResults.Exists(row => row.ValidationErrors.Count > 0))
                    {
                        return(result);
                    }

                    foreach (var row in rows)
                    {
                        try {
                            var deleteRow = row.OldValue != null ? row.OldValue : row;

                            var deleteGrades = new DeleteAll <CycleGrade> ()
                                               .WherePropertyEquals("Operation", deleteRow.Operation)
                                               .WherePropertyEquals("Loader", deleteRow.Loader)
                                               .WherePropertyEquals("Hauler", deleteRow.Hauler)
                                               .WherePropertyEquals("LoaderOperatorId", deleteRow.LoaderOperatorId)
                                               .WherePropertyEquals("HaulerOperatorId", deleteRow.HaulerOperatorId)
                                               .WherePropertyEquals("Origin", deleteRow.Origin)
                                               .WherePropertyEquals("Destination", deleteRow.Destination)
                                               .WherePropertyEquals("Material", deleteRow.Material)
                                               .WherePropertyEquals("DateOp", deleteRow.DateOp)
                                               .WherePropertyEquals("Shift", deleteRow.Shift)
                                               .WherePropertyEquals("Datasource", deleteRow.Datasource)
                                               .WherePropertyIn("GradeItem", gradeItems);

                            if (deleteRow.DateTimeStart.HasValue)
                            {
                                deleteGrades.WherePropertyEquals("DateTimeStart", deleteRow.DateTimeStart.Value);
                            }

                            deleteGrades.Execute(connection, transaction);

                            var deleteCycles = new DeleteAll <Cycle> ()
                                               .WherePropertyEquals("Operation", deleteRow.Operation)
                                               .WherePropertyEquals("Loader", deleteRow.Loader)
                                               .WherePropertyEquals("Hauler", deleteRow.Hauler)
                                               .WherePropertyEquals("LoaderOperatorId", deleteRow.LoaderOperatorId)
                                               .WherePropertyEquals("HaulerOperatorId", deleteRow.HaulerOperatorId)
                                               .WherePropertyEquals("Origin", deleteRow.Origin)
                                               .WherePropertyEquals("Destination", deleteRow.Destination)
                                               .WherePropertyEquals("Material", deleteRow.Material)
                                               .WherePropertyEquals("DateOp", deleteRow.DateOp)
                                               .WherePropertyEquals("Shift", deleteRow.Shift)
                                               .WherePropertyEquals("Datasource", deleteRow.Datasource);

                            if (deleteRow.DateTimeStart.HasValue)
                            {
                                deleteCycles.WherePropertyEquals("DateTimeStart", deleteRow.DateTimeStart.Value);
                            }

                            deleteCycles.Execute(connection, transaction);

                            int cycleCount = 0;

                            foreach (var cycle in row.Cycles)
                            {
                                cycleCount++;
                                Utility.SaveSafe(connection, transaction, cycle);

                                foreach (var gradeItem in cycle.GradeValues)
                                {
                                    Utility.SaveSafe(connection, transaction, CreateCycleGrade(cycle, gradeItem.Key, gradeItem.Value));
                                    if (cycleCount.Equals(row.Cycles.Count()) && !string.IsNullOrEmpty(tab.SourceGradeType))
                                    {
                                        var grade = new SelectAll <VwProductionDataEntryGrade> ()
                                                    .WherePropertyEquals("Operation", cycle.Operation)
                                                    .WherePropertyEquals("DateOp", cycle.DateOp)
                                                    .WherePropertyEquals("Origin", cycle.Origin)
                                                    .WherePropertyEquals("Material", cycle.Material)
                                                    .WherePropertyEquals("GradeItem", gradeItem.Key)
                                                    .First(connection, transaction);

                                        Utility.SaveSafe(connection, transaction, CreateGrade(cycle, tab.SourceGradeType, grade));
                                    }
                                }
                            }

                            result.AddRowSaved(row.Id);
                            result.AddRowUpdated(row.Id, new FlexibleRowObject(row));

                            ManualDataEntryLog.Log(transaction,
                                                   row.IsNew ? ManualDataEntryLog.AdditionLogType : ManualDataEntryLog.UpdateLogType, shiftInstance.Operation,
                                                   LoadAndHaulManualEntryLog.LogArea, LoadAndHaulManualEntryLog.LogGroup, "Production Entry", shiftInstance.DateOp, shiftInstance.Shift, null, "Data edited.");
                        } catch (Exception ex) {
                            result.AddRowError(row.Id, GridRowError.Make(ex));
                        }
                    }

                    if (!result.IsErrorFree() || result.RowResults.Exists(row => row.ValidationErrors.Count > 0))
                    {
                        return(result);
                    }

                    // Add record to ManualDataEntryProcesQueue to recalculate the grades
                    Utility.SaveSafe(connection, transaction, new ManualDataEntryProcessQueue()
                    {
                        Operation = shiftInstance.Operation, DateOp = shiftInstance.DateOp, DateTimeAdded = DateTime.UtcNow
                    });

                    transaction.Commit();
                }
            }

            return(result);
        }
예제 #8
0
 private void DeleteAllCmd(DeleteAll cmd)
 {
     CreateRequest(cmd, new EntityTypeActor.DeleteAll());
 }