Beispiel #1
0
        public async Task <Guid> Start(string friendlyName, BatchType batchType, CancellationToken token)
        {
            var batchId = Guid.NewGuid();

            _hub.ConfigureScope(s => s.SetTag("batchId", batchId.ToString()));

            var body = new { BatchFriendlyName = friendlyName, BatchType = batchType };

            var content = new ByteArrayContent(JsonSerializer.SerializeToUtf8Bytes(body));

            content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

            var url = $"{_options.BaseAddress.AbsoluteUri}symbol/batch/{batchId}/start";

            try
            {
                var request = new HttpRequestMessage(HttpMethod.Post, url)
                {
                    Version = _httpVersion, Content = content
                };
                var response = await _httpClient.SendAsync(request, token);
                await ThrowOnUnsuccessfulResponse("Could not start batch.", response);
            }
            catch (Exception e)
            {
                e.Data["URL"] = url;
                throw;
            }

            return(batchId);
        }
        public long CreateBatch(string batchName,
                                BatchType batchType,
                                IList <long> orderIds,
                                DateTime?when,
                                long?by)
        {
            var batch = new OrderBatch
            {
                Name       = batchName,
                Type       = (int)batchType,
                CreateDate = when,
                CreatedBy  = by
            };

            Add(batch);
            unitOfWork.Commit();
            if (orderIds != null)
            {
                var orders = unitOfWork.Orders.GetFiltered(o => orderIds.Contains(o.Id));
                foreach (var order in orders)
                {
                    order.BatchId = batch.Id;
                }
            }
            unitOfWork.Commit();
            return(batch.Id);
        }
Beispiel #3
0
        public void Delete_BatchType(BatchType batchType)
        {
            var table = new Table <AllDataTypesEntity>(Session, new MappingConfiguration());
            AllDataTypesEntity entityToDelete  = _entityList[0];
            AllDataTypesEntity entityToDelete2 = _entityList[1];

            var selectQuery  = table.Select(m => m).Where(m => m.StringType == entityToDelete.StringType);
            var deleteQuery  = selectQuery.Delete();
            var selectQuery2 = table.Select(m => m).Where(m => m.StringType == entityToDelete2.StringType);
            var deleteQuery2 = selectQuery2.Delete();

            var batch = table.GetSession().CreateBatch(batchType);

            batch.Append(deleteQuery);
            batch.Append(deleteQuery2);
            batch.Execute();

            VerifyBatchStatement(
                1,
                new []
            {
                $"DELETE FROM \"{AllDataTypesEntity.TableName}\" WHERE \"string_type\" = ?",
                $"DELETE FROM \"{AllDataTypesEntity.TableName}\" WHERE \"string_type\" = ?"
            },
                new[] { new object [] { entityToDelete.StringType }, new object [] { entityToDelete2.StringType } });
        }
        public SymbolUploadBatch(Guid batchId, string friendlyName, BatchType batchType)
        {
            if (batchId == default)
            {
                throw new ArgumentException("Empty Batch Id.");
            }

            if (string.IsNullOrWhiteSpace(friendlyName))
            {
                throw new ArgumentException("Friendly name is required.");
            }

            if (batchType == BatchType.Unknown)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(batchType),
                          batchType,
                          "A batch type is required.");
            }

            BatchId      = batchId;
            FriendlyName = friendlyName;
            BatchType    = batchType;
            StartTime    = DateTimeOffset.UtcNow;
        }
Beispiel #5
0
 public BatchGroup(int toCreate, int willCreate)
     : base(toCreate, willCreate)
 {
     name = BatchType.Null;
     index = Index.Index_Null;
     willDraw = true;
 }
Beispiel #6
0
        public BatchRequest(ProtocolVersion protocolVersion, BatchStatement statement, ConsistencyLevel consistency, Configuration config)
        {
            if (!protocolVersion.SupportsBatch())
            {
                throw new NotSupportedException("Batch request is supported in C* >= 2.0.x");
            }
            _type     = statement.BatchType;
            _requests = statement.Queries
                        .Select(q => q.CreateBatchRequest(protocolVersion))
                        .ToArray();
            Consistency = consistency;
            if (statement.IsTracing)
            {
                _headerFlags = FrameHeader.HeaderFlag.Tracing;
            }

            _serialConsistency = config.QueryOptions.GetSerialConsistencyLevelOrDefault(statement);
            _batchFlags       |= QueryProtocolOptions.QueryFlags.WithSerialConsistency;

            _timestamp = GetRequestTimestamp(protocolVersion, statement, config.Policies);
            if (_timestamp != null)
            {
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp;
            }
        }
Beispiel #7
0
        public BatchRequest(ProtocolVersion protocolVersion, BatchStatement statement, ConsistencyLevel consistency, IRequestOptions requestOptions)
        {
            if (!protocolVersion.SupportsBatch())
            {
                throw new NotSupportedException("Batch request is supported in C* >= 2.0.x");
            }
            _type     = statement.BatchType;
            _requests = statement.Queries
                        .Select(q => q.CreateBatchRequest(protocolVersion))
                        .ToArray();
            Consistency = consistency;
            if (statement.IsTracing)
            {
                _headerFlags = FrameHeader.HeaderFlag.Tracing;
            }

            SerialConsistency = requestOptions.GetSerialConsistencyLevelOrDefault(statement);
            _batchFlags      |= QueryProtocolOptions.QueryFlags.WithSerialConsistency;

            _timestamp = BatchRequest.GetRequestTimestamp(protocolVersion, statement, requestOptions.TimestampGenerator);
            if (_timestamp != null)
            {
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp;
            }

            if (protocolVersion.SupportsKeyspaceInRequest() && statement.Keyspace != null)
            {
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithKeyspace;
                _keyspace    = statement.Keyspace;
            }
        }
Beispiel #8
0
        public void Delete_BatchType(BatchType batchType)
        {
            var table = new Table <AllDataTypesEntity>(_session, new MappingConfiguration());
            var count = table.Count().Execute();

            Assert.AreEqual(_entityList.Count, count);
            AllDataTypesEntity entityToDelete  = _entityList[0];
            AllDataTypesEntity entityToDelete2 = _entityList[1];

            var selectQuery  = table.Select(m => m).Where(m => m.StringType == entityToDelete.StringType);
            var deleteQuery  = selectQuery.Delete();
            var selectQuery2 = table.Select(m => m).Where(m => m.StringType == entityToDelete2.StringType);
            var deleteQuery2 = selectQuery2.Delete();


            var batch = table.GetSession().CreateBatch(batchType);

            batch.Append(deleteQuery);
            batch.Append(deleteQuery2);
            batch.Execute();

            count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count - 2, count);
            Assert.AreEqual(0, selectQuery.Execute().ToList().Count);
            Assert.AreEqual(0, selectQuery2.Execute().ToList().Count);
        }
Beispiel #9
0
        public IAsyncResult BeginBatch(int streamId, BatchType batchType, List <Statement> queries,
                                       AsyncCallback callback, object state, object owner,
                                       ConsistencyLevel consistency, bool isTracing)
        {
            AsyncResult <IOutput> jar = SetupJob(streamId, callback, state, owner, "BATCH");


            BeginJob(jar, SetupKeyspace(jar, SetupPreparedQueries(jar, GetIdsFromListOfQueries(queries), () =>
            {
                Evaluate(new BatchRequest(jar.StreamId, batchType, GetRequestsFromListOfQueries(queries), consistency, isTracing), jar.StreamId,
                         frame2 =>
                {
                    AbstractResponse response = FrameParser.Parse(frame2);
                    if (response is ResultResponse)
                    {
                        JobFinished(jar, (response as ResultResponse).Output);
                    }
                    else
                    {
                        _protocolErrorHandlerAction(new ErrorActionParam
                        {
                            AbstractResponse = response,
                            Jar = jar
                        });
                    }
                });
            })));

            return(jar);
        }
Beispiel #10
0
        public Facturae() : base()
        {
            var fileHeader = new FileHeaderType();

            fileHeader.SchemaVersion     = SchemaVersionType.Item32;
            fileHeader.Modality          = ModalityType.I;
            fileHeader.InvoiceIssuerType = InvoiceIssuerTypeType.EM;

            var batch = new BatchType();

            fileHeader.Batch = batch;

            batch.InvoicesCount       = 0;
            batch.BatchIdentifier     = string.Empty;
            batch.TotalInvoicesAmount = new AmountType()
            {
                TotalAmount = new DoubleTwoDecimalType()
            };
            batch.TotalOutstandingAmount = new AmountType()
            {
                TotalAmount = new DoubleTwoDecimalType()
            };
            batch.TotalExecutableAmount = new AmountType()
            {
                TotalAmount = new DoubleTwoDecimalType()
            };
            batch.InvoiceCurrencyCode = CurrencyCodeType.EUR;

            this.FileHeader = fileHeader;
            this.Parties    = new PartiesType();
            this.Invoices   = new InvoiceType[] { };
        }
Beispiel #11
0
 public BatchRequest(ProtocolVersion protocolVersion, BatchStatement statement, ConsistencyLevel consistency,
                     Policies policies)
 {
     if (!protocolVersion.SupportsBatch())
     {
         throw new NotSupportedException("Batch request is supported in C* >= 2.0.x");
     }
     _type     = statement.BatchType;
     _requests = statement.Queries
                 .Select(q => q.CreateBatchRequest(protocolVersion))
                 .ToArray();
     Consistency = consistency;
     if (statement.IsTracing)
     {
         _headerFlags = FrameHeader.HeaderFlag.Tracing;
     }
     if (statement.SerialConsistencyLevel != ConsistencyLevel.Any)
     {
         if (!protocolVersion.SupportsTimestamp())
         {
             throw new NotSupportedException("Serial consistency level for BATCH request is supported in Cassandra 2.1 or above.");
         }
         if (statement.SerialConsistencyLevel < ConsistencyLevel.Serial)
         {
             throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
         }
         _batchFlags       |= QueryProtocolOptions.QueryFlags.WithSerialConsistency;
         _serialConsistency = statement.SerialConsistencyLevel;
     }
     _timestamp = GetRequestTimestamp(protocolVersion, statement, policies);
     if (_timestamp != null)
     {
         _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp;
     }
 }
        public async Task Start_BatchType_TestCase(BatchType batchType, bool validationError)
        {
            var model = new BatchStartRequestModel {
                BatchType = batchType
            };

            var client = _fixture.GetClient();
            var resp   = await client.SendAsync(
                new HttpRequestMessage(HttpMethod.Post, SymbolsController.Route + $"/batch/{Guid.NewGuid()}/start")
            {
                Content = new JsonContent(model)
            });

            resp.AssertStatusCode(HttpStatusCode.BadRequest);
            var responseModel = await resp.Content.ToJsonElement();

            if (validationError)
            {
                Assert.Equal("The field BatchType must be between 1 and 5.",
                             responseModel.GetProperty("BatchType")[0].GetString());
            }
            else
            {
                Assert.False(responseModel.TryGetProperty("BatchType", out _));
            }
        }
Beispiel #13
0
        public async Task <string> GetFormattedPreferences()
        {
            int       migrationCount = MigrationCount;
            int       lastPullKeysBatchNumberNotSubmitted          = LastPullKeysBatchNumberNotSubmitted;
            int       lastPullKeysBatchNumberSuccessfullySubmitted = LastPullKeysBatchNumberSuccessfullySubmitted;
            BatchType lastPulledBatchType = LastPulledBatchType;

            bool     isOnboardingCompleted           = IsOnboardingCompleted;
            bool     isOnboardingCountriesCompleted  = IsOnboardingCountriesCompleted;
            bool     isDownloadWithMobileDataEnabled = GetIsDownloadWithMobileDataEnabled();
            DateTime updatedDateTime = GetUpdatedDateTime();
            DateTime lastPullKeysSucceededDateTime = GetLastPullKeysSucceededDateTime();
            string   appLanguage = GetAppLanguage();

            string formattedString =
                $"EXPOSURE_TIME_THRESHOLD: {ExposureTimeThreshold}\n" +
                $"LOW_ATTENUATION_DURATION_MULTIPLIER: {LowAttenuationDurationMultiplier}\n" +
                $"MIDDLE_ATTENUATION_DURATION_MULTIPLIER: {MiddleAttenuationDurationMultiplier}\n" +
                $"HIGH_ATTENUATION_DURATION_MULTIPLIER: {HighAttenuationDurationMultiplier}\n\n" +
                $"MIGRATION_COUNT: {migrationCount}\n " +
                $"LAST_PULLED_BATCH_NUMBER_NOT_SUBMITTED: {lastPullKeysBatchNumberNotSubmitted}\n " +
                $"LAST_PULLED_BATCH_NUMBER_SUBMITTED: {lastPullKeysBatchNumberSuccessfullySubmitted}\n " +
                $"LAST_PULLED_BATCH_TYPE: {lastPulledBatchType}\n " +
                $"IS_ONBOARDING_COMPLETED_PREF: {isOnboardingCompleted}\n " +
                $"IS_ONBOARDING_COUNTRIES_COMPLETED_PREF: {isOnboardingCountriesCompleted}\n" +
                $"USE_MOBILE_DATA_PREF: {isDownloadWithMobileDataEnabled}\n" +
                $"MESSAGES_LAST_UPDATED_PREF: {updatedDateTime}\n" +
                $"LAST_PULL_KEYS_SUCCEEDED_DATE_TIME: {lastPullKeysSucceededDateTime}\n" +
                $"TERMS_NOTIFICATION_WAS_SENT: {TermsNotificationWasShown}\n" +
                $"APP_LANGUAGE: {appLanguage}\n\n";

            await _clipboard.SetTextAsync(formattedString);

            return(formattedString);
        }
        private void RunBatch(BatchType batchType, string workingDirectory, string batch, bool isBeingDebugged)
        {
            string batchTypeString = (batchType == BatchType.TestSetup) ? Resources.TestSetupBatchFile : Resources.TestTeardownBatchFile;

            int batchExitCode;

            if (_settings.UseNewTestExecutionFramework)
            {
                var executor = new ProcessExecutor(null, _logger);
                batchExitCode = executor.ExecuteBatchFileBlocking(batch, "", workingDirectory, "", s => { });
            }
            else
            {
                new TestProcessLauncher(_logger, _settings, isBeingDebugged).GetOutputOfCommand(
                    workingDirectory, null, batch, "", false, false, null, out batchExitCode);
            }

            if (batchExitCode == 0)
            {
                _logger.DebugInfo(String.Format(Resources.SuccessfullyRun, _threadName, batchTypeString, batch));
            }
            else
            {
                _logger.LogWarning(String.Format(Resources.BatchReturnedExitCode, _threadName, batchTypeString, batchExitCode, batch));
            }
        }
Beispiel #15
0
 public void Init()
 {
     type1 = new BatchType("Test1", 12.34, 56.7, 123, null, 65, 142424);
     type2 = new BatchType("Test2", 442.2, 2521.11, 1223, 473, 765, 1212424);
     type3 = new BatchType("Test3", 675.43, 3900.03444, 123, 43, 65, 5787878);
     type4 = new BatchType("Test4", 49.03, 98.48, 123, 43, 65, null);
 }
        /// <summary>
        /// Handles the SelectionChanged event of the cboBatchTypes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
        private void cboBatchTypes_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            BatchType type = cboBatchTypes.SelectedItem as BatchType;

            if (type != null)
            {
                txtVariableA.Text = type.VariableA.ToString();
                txtVariableB.Text = type.VariableB.ToString();

                txtViscosityRequirement.Text   = string.Empty;
                txtSpeedRequirement.Text       = string.Empty;
                txtTemperatureRequirement.Text = string.Empty;
                txtTimeRequirement.Text        = string.Empty;

                if (type.SpeedRequirement.HasValue)
                {
                    txtSpeedRequirement.Text = type.SpeedRequirement.Value.ToString();
                }
                if (type.TimeRequirement.HasValue)
                {
                    txtTimeRequirement.Text = type.TimeRequirement.Value.ToString();
                }
                if (type.TemperatureRequirement.HasValue)
                {
                    txtTemperatureRequirement.Text = type.TemperatureRequirement.Value.ToString();
                }
                if (type.ViscosityRequirement.HasValue)
                {
                    txtViscosityRequirement.Text = type.ViscosityRequirement.Value.ToString();
                }
            }
        }
Beispiel #17
0
        private int ValidateBatchArgs(CommandLineArgs cmdLine, BatchType batchType)
        {
            int tmpReturn;

            string[] errorMessages;
            if (batchType == BatchType.Run)
            {
                log.LogInformation("Validating general command parameters");

                tmpReturn = Validation.ValidateCommonCommandLineArgs(cmdLine, out errorMessages);
                if (tmpReturn != 0)
                {
                    foreach (var msg in errorMessages)
                    {
                        log.LogError(msg);
                    }
                    return(tmpReturn);
                }
            }

            log.LogInformation("Validating batch command parameters");
            tmpReturn = Validation.ValidateBatchArguments(cmdLine, out errorMessages);
            if (tmpReturn != 0)
            {
                foreach (var msg in errorMessages)
                {
                    log.LogError(msg);
                }
                return(tmpReturn);
            }

            return(0);
        }
Beispiel #18
0
 internal Batch(ISession session, BatchType batchType)
 {
     _session          = session;
     _metricsManager   = (session as IInternalSession)?.MetricsManager;
     _batchType        = batchType;
     QueryAbortTimeout = session.Cluster.Configuration.DefaultRequestOptions.QueryAbortTimeout;
 }
Beispiel #19
0
 /// <summary>
 /// The app will request a file with the following format.
 /// </summary>
 /// <returns>"[date]_[batchnumber]_[no/all].zip", e.g. "2020-08-13_1_no.zip"</returns>
 public string ToBatchFileRequest()
 {
     return($"{Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}" +
            $"_{BatchNumber}" +
            $"_{BatchType.ToTypeString()}" +
            $".zip");
 }
Beispiel #20
0
        public void Ctor_ValidBatchType_BatchTypeSet(string batchType, BatchType expectedType)
        {
            //Act
            var arg = _fixture.NewArgsWithBatchType(batchType);

            //Assert
            Assert.Equal(expectedType, arg.BatchType);
        }
Beispiel #21
0
 public static Batch CreateBatch(this ISession session, BatchType batchType)
 {
     if (session == null || session.BinaryProtocolVersion > 1)
     {
         return(new BatchV2(session, batchType));
     }
     return(new BatchV1(session, batchType));
 }
Beispiel #22
0
 public CqlBatch(MapperFactory mapperFactory, CqlGenerator cqlGenerator, BatchType type)
 {
     _mapperFactory = mapperFactory ?? throw new ArgumentNullException(nameof(mapperFactory));
     _cqlGenerator  = cqlGenerator ?? throw new ArgumentNullException(nameof(cqlGenerator));
     _statements    = new List <Cql>();
     BatchType      = type;
     Options        = new CqlQueryOptions();
 }
Beispiel #23
0
        public void TestGetBachType()
        {
            TestAddBatchType();

            BatchType test = BatchTypeDAL.GetBatchType(type1.Name);

            Assert.IsTrue(test.Equals(test, type1));
        }
Beispiel #24
0
 /// Choose active batch and flush if needed.
 private void Flush(BatchType switchto)
 {
     if (activeBatch != switchto)
     {
         Flush();
         activeBatch = switchto;
     }
 }
 public BatchStatement GetBatchStatement(ISession session, IEnumerable<Cql> cqlToBatch, BatchType batchType)
 {
     var batch = new BatchStatement().SetBatchType(batchType);
     foreach (var cql in cqlToBatch)
     {
         batch.Add(GetStatement(session, cql));
     }
     return batch;
 }
Beispiel #26
0
        public void SetUp()
        {
            _type1 = new BatchType("Test1", 12.34, 56.7, 123, null, 65, 142424);
            _type2 = new BatchType("Test2", 442.2, 2521.11, 1223, 473, 765, 1212424);

            _batch1 = new Batch("machine1", Convert.ToDateTime("2001-01-01"), _type1, true);
            _batch2 = new Batch("machine2", Convert.ToDateTime("2001-01-01"), _type2, false);
            _batch3 = new Batch("machine1", Convert.ToDateTime("2001-01-01"), _type1, true);
        }
Beispiel #27
0
 string GetRequest(DateTime date, int batchNum, BatchType batchType = BatchType.NO)
 {
     return(new PullKeysParams
     {
         Date = date,
         BatchNumber = batchNum,
         BatchType = batchType
     }.ToBatchFileRequest());
 }
Beispiel #28
0
        public void LoadInvoiceBatchesFor(int clientId, BatchType batchType)
        {
            ArgumentChecker.ThrowIfNull(batchType, "batchType");
            if (batchType.IsDateRangeDependant)
            {
                throw new InvalidOperationException("Batch type is date range dependent");
            }

            view.DisplayInvoiceBatches(repository.LoadInvoiceBatchesFor(clientId, batchType), false);
        }
Beispiel #29
0
 public Batch(XElement data)
 {
     MerchantId = int.Parse(data.Element("merchant_id").Value);
     Date       = DateTime.Parse(data.Element("date").Value);
     Reference  = data.Element("reference").Value.Trim();
     Net        = decimal.Parse(data.Element("net").Value);
     Count      = int.Parse(data.Element("count").Value);
     File       = data.Element("file").Value;
     Type       = GetBatchType(data.Element("type").Value);
 }
Beispiel #30
0
 public Batch(XElement data)
 {
     MerchantId = int.Parse(data.Element("merchant_id").Value);
     Date = DateTime.Parse(data.Element("date").Value);
     Reference = data.Element("reference").Value.Trim();
     Net = decimal.Parse(data.Element("net").Value);
     Count = int.Parse(data.Element("count").Value);
     File = data.Element("file").Value;
     Type = GetBatchType(data.Element("type").Value);
 }
Beispiel #31
0
        private static BatchType ConvertBatchType(BatchTypeView batchTypeView)
        {
            var batchtype = new BatchType
            {
                BatchTypeid   = batchTypeView.BatchTypeid,
                BatchTypeDesc = batchTypeView.BatchTypeDesc
            };

            return(batchtype);
        }
Beispiel #32
0
        public void TestGetBachType()
        {
            TestAddBatchType();

            BatchType test      = BatchTypeController.GetBatchType(type1.Name);
            BatchType emptyTest = BatchTypeController.GetBatchType("");

            Assert.IsTrue(test.Equals(test, type1));
            Assert.AreEqual(null, emptyTest);
        }
Beispiel #33
0
        /// <summary>
        /// Handles the Click event of the btnStart control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            _type = cboBatchTypes.SelectedItem as BatchType;

            //_worker.RunWorkerAsync();

            _task = Task <Batch> .Factory.StartNew(() => TaskStuff());

            Task.Factory.StartNew(() => BatchDone());
        }
Beispiel #34
0
        public static Batch createBatch(String name, BatchType type, UserProfile owner)
        {
            BrewersBuddyContext db = new BrewersBuddyContext();

            Batch batch = new Batch();
            batch.Name = name;
            batch.Type = type;
            batch.OwnerId = owner.UserId;
            batch.StartDate = DateTime.Now;

            db.Batches.Add(batch);

            db.SaveChanges();

            return batch;
        }
 public Task<BatchStatement> GetBatchStatementAsync(ISession session, IEnumerable<Cql> cqlToBatch, BatchType batchType)
 {
     // Get all the statements async in parallel, then add to batch
     return Task.Factory.ContinueWhenAll(cqlToBatch.Select(cql => GetStatementAsync(session, cql)).ToArray(), (tasks) =>
     {
         var batch = new BatchStatement().SetBatchType(batchType);
         foreach (var t in tasks)
         {
             if (t.Exception != null)
             {
                 throw t.Exception;
             }
             batch.Add(t.Result);
         }
         return batch;
     }, TaskContinuationOptions.ExecuteSynchronously);
 }
Beispiel #36
0
        public BatchRequest(int protocolVersion, BatchStatement statement, ConsistencyLevel consistency)
        {
            ProtocolVersion = protocolVersion;
            if (ProtocolVersion < 2)
            {
                throw new NotSupportedException("Batch request is supported in C* >= 2.0.x");
            }

            var subRequests = new List<IQueryRequest>();
            foreach (var q in statement.Queries)
            {
                subRequests.Add(q.CreateBatchRequest(ProtocolVersion));
            }
            _type = statement.BatchType;
            _requests = subRequests;
            Consistency = consistency;
            _timestamp = statement.Timestamp;
            if (statement.IsTracing)
            {
                _headerFlags = 0x02;
            }
            if (statement.SerialConsistencyLevel != ConsistencyLevel.Any)
            {
                if (protocolVersion < 3)
                {
                    throw new NotSupportedException("Serial consistency level for BATCH request is supported in Cassandra 2.1 or above.");
                }
                if (statement.SerialConsistencyLevel < ConsistencyLevel.Serial)
                {
                    throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
                }
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithSerialConsistency;
                _serialConsistency = statement.SerialConsistencyLevel;
            }
            if (_timestamp != null)
            {
                if (protocolVersion < 3)
                {
                    throw new NotSupportedException("Timestamp for BATCH request is supported in Cassandra 2.1 or above.");
                }
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp;
            }
        }
Beispiel #37
0
 public BatchRequest(int protocolVersion, BatchStatement statement, ConsistencyLevel consistency)
 {
     if (protocolVersion < 2)
     {
         throw new NotSupportedException("Batch request is supported in C* >= 2.0.x");
     }
     _type = statement.BatchType;
     _requests = statement.Queries
         .Select(q => q.CreateBatchRequest(protocolVersion))
         .ToArray();
     Consistency = consistency;
     _timestamp = statement.Timestamp;
     if (statement.IsTracing)
     {
         _headerFlags = FrameHeader.HeaderFlag.Tracing;
     }
     if (statement.SerialConsistencyLevel != ConsistencyLevel.Any)
     {
         if (protocolVersion < 3)
         {
             throw new NotSupportedException("Serial consistency level for BATCH request is supported in Cassandra 2.1 or above.");
         }
         if (statement.SerialConsistencyLevel < ConsistencyLevel.Serial)
         {
             throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
         }
         _batchFlags |= QueryProtocolOptions.QueryFlags.WithSerialConsistency;
         _serialConsistency = statement.SerialConsistencyLevel;
     }
     if (_timestamp != null)
     {
         if (protocolVersion < 3)
         {
             throw new NotSupportedException("Timestamp for BATCH request is supported in Cassandra 2.1 or above.");
         }
         _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp;
     }
 }
Beispiel #38
0
        public void LoadImageSet(string path, string[] fileNames, BatchType batchType)
        {
            //Get a list of images from source
            List<BitmapImage>  imageBatch = il.Load(path, fileNames);

            //Create a dictionary of subjects from the list of images
            if( imageBatch != null )
            {
                SubjectBatch subjects = new SubjectBatch();
                subjects.Name = DEFAULT_BATCH_PREFIX + assignBatchNum++;

                for (int i = 0; i < imageBatch.Count; i++)
                {
                    Subject subject = new Subject();
                    subject.BaseImage = imageBatch.ElementAt(i);
                    subject.Path = path;
                    subject.Name = fileNames[i];
                    subject.Gender = GenderType.UNKNOWN;
                    subjects.Add(subject);
                }

                //Add the collection of new subjects to the batch list
                subjectBatches.Add(subjects.Name, subjects);
                focusBatchName = subjects.Name;
                if(!FocusSubjects.Keys.Contains(subjects.Name))
                {
                    focusSubjects.Add(focusBatchName, subjects.Subjects.Values.Last());
                }
                else
                {
                    focusSubjects[focusBatchName] = subjects.Subjects.Values.Last();
                }

            }
        }
Beispiel #39
0
 public void LoadImageSet(string[] fullPathFileNames, BatchType batchType)
 {
     int slashPos = 0;
     string[] fileNames = new string[fullPathFileNames.Count()];
     slashPos = fullPathFileNames[0].LastIndexOf("\\");
     string path = fullPathFileNames[0].Substring(0, slashPos+1);
     for(int i = 0; i < fullPathFileNames.Count(); i++)
     {
         fileNames[i] = fullPathFileNames[i].Substring(slashPos+1);
     }
     LoadImageSet(path, fileNames, batchType);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BatchInformation"/> class.
 /// INSTACED CONSTRUCTOR
 /// </summary>
 /// <param name="BaseVertex">The base vertex.</param>
 /// <param name="NumVertices">The num vertices.</param>
 /// <param name="PrimitiveCount">The primitive count.</param>
 /// <param name="StartIndex">The start index.</param>
 /// <param name="StreamOffset">The stream offset.</param>
 /// <param name="VertexDeclaration">The vertex declaration.</param>
 /// <param name="VertexStride">The vertex stride.</param>
 /// <param name="instanceCount">The instance count.</param>
 /// <param name="PrimitiveType">Type of the primitive.</param>
 public BatchInformation(int BaseVertex, int NumVertices, int PrimitiveCount, int StartIndex, int StreamOffset, VertexDeclaration VertexDeclaration, int VertexStride, int instanceCount ,PrimitiveType PrimitiveType = ANX.Framework.Graphics.PrimitiveType.TriangleList)
 {
     this.BaseVertex = BaseVertex;
     this.NumVertices = NumVertices;
     this.PrimitiveCount = PrimitiveCount;
     this.StartIndex = StartIndex;
     this.StreamOffset = StreamOffset;
     this.VertexDeclaration = VertexDeclaration;
     this.VertexStride = VertexStride;
     this.PrimitiveType = PrimitiveType;
     this.InstanceCount = instanceCount;
     this.BatchType = BatchType.INSTANCED;
 }
Beispiel #41
0
 public SubjectBatch()
 {
     subjects = new Dictionary<string, Subject>();
     type = BatchType.TESTING;
 }
Beispiel #42
0
 public void set(BatchType name, Index index, bool draw = true)
 {
     this.name = name;
     this.index = index;
     this.willDraw = draw;
 }
Beispiel #43
0
 /// <summary>
 /// Sets the <see cref="BatchType"/>
 /// </summary>
 /// <returns></returns>
 public BatchStatement SetBatchType(BatchType batchType)
 {
     _batchType = batchType;
     return this;
 }
Beispiel #44
0
 public ChunkBatch(List<Chunk> chunks, BatchType batchType )
 {
     m_Chunks = chunks;
     m_BatchType = batchType;
 }
        public void UpdateDisplayStatsSavedFlag(int captureBatchId, BatchType batchType, bool saveData)
        {
            using (var context = new PacketAnalysisEntity())
            {
                var captureBatch = (from b in context.CaptureBatches
                                    where b.CaptureBatchId == captureBatchId
                                    select b).Single();

                if (batchType == BatchType.Single)
                {
                    captureBatch.SingleStatistics = saveData;
                }
                else if(batchType == BatchType.Cumulative)
                {
                    captureBatch.CumulativeStatistics = saveData;
                }
                else
                {
                    // no op - unknown batch type
                }

                context.SaveChanges();
            }
        }
Beispiel #46
0
 public void SaveDisplayStatistics(BatchStatistics batchStatistics, int captureBatchId, CaptureState captureState, BatchType batchType, bool saveData)
 {
     // Save the statistics to the database for display on the Analysis tab (save to DisplayStatistics table)
     // Replace cumulative data with new data
     DisplayStatisticsData dsd = new DisplayStatisticsData();
     switch (captureState)
     {
         case CaptureState.Marked:
             switch (batchType)
             {
                 case BatchType.Single:
                     //dsd.DeleteSingleMarkedDisplayStatitics();
                     dsd.InsertSingleMarkedDisplayStatitics(batchStatistics);
                     dsd.UpdateDisplayStatsSavedFlag(captureBatchId, BatchType.Single, true);
                     break;
                 case BatchType.Cumulative:
                     dsd.DeleteCumulativeMarkedDisplayStatitics();
                     dsd.InsertCumulativeMarkedDisplayStatitics(batchStatistics);
                     dsd.UpdateDisplayStatsSavedFlag(captureBatchId, BatchType.Cumulative, true);
                     break;
             }
             break;
         case CaptureState.Unmarked:
             switch (batchType)
             {
                 case BatchType.Single:
                     //dsd.DeleteSingleUnmarkedDisplayStatitics();
                     dsd.InsertSingleUnarkedDisplayStatitics(batchStatistics);
                     dsd.UpdateDisplayStatsSavedFlag(captureBatchId, BatchType.Single, true);
                     break;
                 case BatchType.Cumulative:
                     dsd.DeleteCumulativeUnmarkedDisplayStatitics();
                     dsd.InsertCumulativeUnarkedDisplayStatitics(batchStatistics);
                     dsd.UpdateDisplayStatsSavedFlag(captureBatchId, BatchType.Cumulative, true);
                     break;
             }
             break;
     }
 }
Beispiel #47
0
        public BatchStatistics CalculateBatchStatistics(BindingList<BatchIntervalMarked> batchIntervals, CaptureState captureState, BatchType batchType)
        {
            decimal batchIntervalsMean = 0;
            decimal batchIntervalsTrimmedMean = 0;

            // Trim zero packets from the batch interval
            BindingList<BatchIntervalMarked> batchIntervalsTrimmed = new BindingList<BatchIntervalMarked>();
            foreach (BatchIntervalMarked bim in batchIntervals)
            {
                if (bim.PacketCount > AnalysisConfiguration.HistogramBinSize)
                {
                    batchIntervalsTrimmed.Add(bim);
                }
            }

            // Calculate statistics for the batch
            BatchStatistics bs = new BatchStatistics();

            if (AnalysisConfiguration.TrimSmallPackets)
            {
                BaseStatistics stats = new BaseStatistics(batchIntervalsTrimmed);
                bs.IntervalCountTrimmed = stats.Count;
                bs.PacketCountMaximum = stats.Maximum;
                bs.PacketCountMinimum = stats.Minimum;
                bs.PacketCountMean = stats.Mean;
                bs.PacketCountStandardDeviation = stats.StdDev;

                // Calculate both means for updating the capture batch intervals
                batchIntervalsTrimmedMean = stats.Mean;
                batchIntervalsMean = Convert.ToDecimal((from t in batchIntervals select t.PacketCount).Average());

                // Get both counts for the batch
                bs.IntervalCountTrimmed = stats.Count < 0 ? 0 : stats.Count;
                bs.IntervalCount = batchIntervals.Count < 0 ? 0 : batchIntervals.Count;
            }
            else
            {
                BaseStatistics stats = new BaseStatistics(batchIntervals);
                bs.IntervalCount = stats.Count;
                bs.PacketCountMaximum = stats.Maximum;
                bs.PacketCountMinimum = stats.Minimum;
                bs.PacketCountMean = stats.Mean;
                bs.PacketCountStandardDeviation = stats.StdDev;

                // Calculate both means for updating the capture batch intervals
                batchIntervalsMean = bs.PacketCountMean;
                batchIntervalsTrimmedMean = Convert.ToDecimal((from t in batchIntervalsTrimmed select t.PacketCount).Average());

                // Get both counts for the batch
                bs.IntervalCount = stats.Count < 0 ? 0 : stats.Count;
                bs.IntervalCountTrimmed = batchIntervalsTrimmed.Count < 0 ? 0 : batchIntervalsTrimmed.Count;
            }

            // Update the batch mean - only for single batches, not cumulative batches
            CurrentCaptureFile captureFile = new CurrentCaptureFile();
            ProcessCapturePackets pcp = new ProcessCapturePackets();
            captureFile = pcp.GetCurrentCaptureFile(_CaptureFileName);
            int captureBatchId = captureFile.CaptureBatchId;

            if (batchType == BatchType.Single && captureBatchId != 0)
            {
                try
                {
                    //ProcessCapturePackets pcp = new ProcessCapturePackets();
                    //if (!pcp.UpdateBatchMean(Convert.ToInt32(captureBatchId), bs.PacketCountMean))
                    if (!pcp.UpdateBatchMean(Convert.ToInt32(captureBatchId), batchIntervalsMean, batchIntervalsTrimmedMean))
                    {
                        throw new Exception("Error updating batch mean for CaptureBatchId " + captureBatchId);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Error updating batch mean for CaptureBatchId " + captureBatchId + ": " + ex.Message);
                }
            }

            // Save the statistics to the database for display on the Analysis tab (save to DisplayStatistics table)
            SaveDisplayStatistics(bs, captureBatchId, captureState, batchType, true);

            return bs;
        }
Beispiel #48
0
        private void CalculateSingleHistogramProbability(BindingList<BatchIntervalMarked> batchIntervalsCollection, BatchType batchType, CurrentCaptureFile captureFile)
        {
            BindingList<BatchIntervalMarked> batchIntervals = new BindingList<BatchIntervalMarked>();
            batchIntervals = batchIntervalsCollection;

            SortedDictionary<int, decimal> histogramProbabilities = new SortedDictionary<int, decimal>();

            int histogramBinSize = AnalysisConfiguration.HistogramBinSize;
            histogramProbabilities = new CalculateProbability(batchIntervals).GetProbabilityByPacketRange(_TrimZeroPacketIntervals, histogramBinSize);

            // Convert histogram probabilities to Histogram type collection
            BindingList<SingleHistogram> singleHistogramProbabilityData = new BindingList<SingleHistogram>();
            foreach (KeyValuePair<int, decimal> data in histogramProbabilities)
            {
                SingleHistogram h = new SingleHistogram();
                h.CaptureBatchId = captureFile.CaptureBatchId;
                h.Interval = data.Key;
                h.Probability = data.Value;
                h.BatchType = Convert.ToInt32(batchType);
                h.CaptureState = Convert.ToInt32(captureFile.CaptureState);
                singleHistogramProbabilityData.Add(h);
            }

            // Save histogram data
            SingleHistogramData shd = new SingleHistogramData(singleHistogramProbabilityData);
            shd.InsertSingleHistogramData();
        }
Beispiel #49
0
        private void CalculateCumulativeHistogramProbability(BindingList<BatchIntervalMarked> batchIntervalsCollection, BatchType batchType, CaptureState captureState)
        {
            BindingList<BatchIntervalMarked> batchIntervals = new BindingList<BatchIntervalMarked>();
            batchIntervals = batchIntervalsCollection;

            SortedDictionary<int, decimal> histogramProbabilities = new SortedDictionary<int, decimal>();

            int histogramBinSize = AnalysisConfiguration.HistogramBinSize;
            histogramProbabilities = new CalculateProbability(batchIntervals).GetProbabilityByPacketRange(_TrimZeroPacketIntervals, histogramBinSize);

            // Update the cumulative intervals for calculating cumulative probability distributions
            switch(captureState)
            {
                case CaptureState.Marked:
                    _CumulativeMarkedProbabilities = histogramProbabilities;
                    break;

                case CaptureState.Unmarked:
                    _CumulativeUnmarkedProbabilities = histogramProbabilities;
                    break;
            }

            // Convert histogram probabilities to Histogram type collection
            BindingList<CumulativeHistogram> cumulativeHistogramProbabilityData = new BindingList<CumulativeHistogram>();
            foreach (KeyValuePair<int, decimal> data in histogramProbabilities)
            {
                CumulativeHistogram h = new CumulativeHistogram();
                h.Interval = data.Key;
                h.Probability = data.Value;
                h.BatchType = Convert.ToInt32(batchType);
                h.CaptureState = Convert.ToInt32(captureState);
                cumulativeHistogramProbabilityData.Add(h);
            }

            // Save histogram data
            CumulativeHistogramData chd = new CumulativeHistogramData(cumulativeHistogramProbabilityData);
            chd.InsertCumulativeHistogramData();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BatchInformation"/> class.
        /// Indexed or Normal
        /// Use OTHER constructor to created INSTANCED
        /// </summary>
        /// <param name="BaseVertex">The base vertex.</param>
        /// <param name="NumVertices">The num vertices.</param>
        /// <param name="PrimitiveCount">The primitive count.</param>
        /// <param name="StartIndexOrVertex">The start index or vertex.</param>
        /// <param name="StreamOffset">The stream offset.</param>
        /// <param name="VertexDeclaration">The vertex declaration.</param>
        /// <param name="VertexStride">The vertex stride.</param>
        /// <param name="BatchType">Type of the batch.</param>
        /// <param name="PrimitiveType">Type of the primitive.</param>
        public BatchInformation(int BaseVertex, int NumVertices, int PrimitiveCount, int StartIndexOrVertex, int StreamOffset, VertexDeclaration VertexDeclaration, int VertexStride, BatchType BatchType,PrimitiveType PrimitiveType = PrimitiveType.TriangleList)
        {
            if (BatchType == BatchType.INSTANCED)
                throw new Exception("This constructor cannot be used to creat instanced BatchInformation, use the other one");

            this.BaseVertex = BaseVertex;
            this.NumVertices = NumVertices;
            this.PrimitiveCount = PrimitiveCount;
            this.StreamOffset = StreamOffset;
            this.VertexDeclaration = VertexDeclaration;
            this.VertexStride = VertexStride;
            this.BatchType = BatchType;
            if (BatchType == BatchType.INDEXED)
            {
                this.StartIndex = StartIndexOrVertex;
            }
            else
            {
                this.StartVertex = StartIndexOrVertex;
            }
            this.PrimitiveType = PrimitiveType;
        }
 public void AddBatchOfChunks(List<Chunk> chunks, BatchType batchType)
 {
     m_ChunkBatches.Enqueue(new ChunkBatch(chunks, batchType));
 }