/// <summary> /// 本函数为Form添加FormClosingEvent,关闭窗口时关闭rs实例。构造函数依据Stream.***Option来使用 /// </summary> /// <param name="so"></param> public Stream(Form f, StreamOption so = StreamOption.None, AlgoOption ao = AlgoOption.Face, RecordOption ro = RecordOption.Record, Label lb = null) { m_algoOption = ao; m_streamOption = so; m_recordOption = ro; m_label = lb; f.FormClosing += new System.Windows.Forms.FormClosingEventHandler(FormClosingHandler); InitPowerState(); }
/// <summary> /// 构造函数依据Stream.***Option来使用 /// </summary> /// <param name="so"></param> public Stream(StreamOption so = StreamOption.None, AlgoOption ao = AlgoOption.Face, RecordOption ro = RecordOption.Record) { m_algoOption = ao; m_streamOption = so; m_recordOption = ro; if (session == null) { session = PXCMSession.CreateInstance(); } InitPowerState(); }
/// <summary> /// Insert or update all entities on database /// </summary> /// <param name="entities">Entity list model</param> /// <param name="recordOption">Insert, update or upsert operation</param> /// <param name="cancellationToken">Token</param> /// <typeparam name="TEntity">Entity type</typeparam> /// <returns></returns> public async Task SaveAllAsync <TEntity> (IEnumerable <TEntity> entities, RecordOption recordOption = RecordOption.Upsert, CancellationToken cancellationToken = default) where TEntity : Entity { try { var collection = GetCollection <TEntity> (); if (recordOption == RecordOption.Insert) { await collection.InsertManyAsync(entities, new InsertManyOptions() { IsOrdered = true }, cancellationToken); } #region RecordOption.Update //else if (recordOption == RecordOption.Update) //{ // var updates = new List<WriteModel<TEntity>>(); // var filterBuilder = Builders<TEntity>.Filter; // foreach (var doc in entities) // { // var filter = filterBuilder.Where(x => x.Id == doc.Id); // updates.Add(new ReplaceOneModel<TEntity>(filter, doc)); // } // await collection.BulkWriteAsync(updates, cancellationToken: cancellationToken); //} #endregion else { var bulkOps = entities .Select(entity => new ReplaceOneModel <TEntity> (Builders <TEntity> .Filter.Where(x => x.Id == entity.Id), entity) { IsUpsert = true }) .Cast <WriteModel <TEntity> > () .ToList(); await collection.BulkWriteAsync(bulkOps, cancellationToken : cancellationToken); } } catch (TimeoutException ex) { _logger?.LogError($"Timeout Exception in SaveAsync method. Source: {ex.Source}"); } catch (MongoAuthenticationException ex) { _logger?.LogError($"Mongo Authentication Exception in SaveAsync method. Source: {ex.Source}"); } catch (Exception ex) { _logger?.LogError(ex, $"These records cannot be saved"); } }
public async Task SaveAllAsync(IEnumerable <Bookmark> entities, RecordOption recordOption, CancellationToken cancellationToken = default) { await _context.SaveAllAsync <Bookmark> (entities, recordOption, cancellationToken); }