public void ParseCommand() { var bytes = ArrayHelper.ToByteArray("782E72753A68656C6C6F20776F726C64CA410000"); var command = DeserializedCommand.Parse(bytes); }
public void UncommitPingUrls() { PingUrlsPending = ArrayHelper.Union(PingUrlsSent, PingUrlsPending); PingUrlsSent = new string[0]; }
/// <summary>Computations that depend on the observed value of vVector__208 and vdouble__624</summary> private void Changed_vVector__208_vdouble__624() { if (this.Changed_vVector__208_vdouble__624_iterationsDone == 1) { return; } this.vVector__208_marginal = new PointMass <Vector[]>(this.VVector__208); this.vdouble__624_marginal = new DistributionStructArray <Gaussian, double>(5622, delegate(int index208) { return(Gaussian.Uniform()); }); this.vdouble__624_marginal = Distribution.SetPoint <DistributionStructArray <Gaussian, double>, double[]>(this.vdouble__624_marginal, this.Vdouble__624); // The constant 'vVectorGaussian208' VectorGaussian vVectorGaussian208 = VectorGaussian.FromNatural(DenseVector.FromArray(new double[3] { 0.0, 0.0, 0.0 }), new PositiveDefiniteMatrix(new double[3, 3] { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 } })); this.vVector625_marginal_F = ArrayHelper.MakeUniform <VectorGaussian>(vVectorGaussian208); // Message from use of 'vdouble__625' DistributionStructArray <Gaussian, double> vdouble__625_use_B = default(DistributionStructArray <Gaussian, double>); // Create array for 'vdouble__625_use' Backwards messages. vdouble__625_use_B = new DistributionStructArray <Gaussian, double>(5622); for (int index208 = 0; index208 < 5622; index208++) { vdouble__625_use_B[index208] = Gaussian.Uniform(); // Message to 'vdouble__625_use' from GaussianFromMeanAndVariance factor vdouble__625_use_B[index208] = GaussianFromMeanAndVarianceOp.MeanAverageConditional(this.Vdouble__624[index208], 0.1); } DistributionRefArray <VectorGaussian, Vector> vVector625_rep_B = default(DistributionRefArray <VectorGaussian, Vector>); // Create array for 'vVector625_rep' Backwards messages. vVector625_rep_B = new DistributionRefArray <VectorGaussian, Vector>(5622); for (int index208 = 0; index208 < 5622; index208++) { vVector625_rep_B[index208] = ArrayHelper.MakeUniform <VectorGaussian>(vVectorGaussian208); // Message to 'vVector625_rep' from InnerProduct factor vVector625_rep_B[index208] = InnerProductOp.AAverageConditional(vdouble__625_use_B[index208], this.VVector__208[index208], vVector625_rep_B[index208]); } // Buffer for ReplicateOp_Divide.Marginal<VectorGaussian> VectorGaussian vVector625_rep_B_toDef = default(VectorGaussian); // Message to 'vVector625_rep' from Replicate factor vVector625_rep_B_toDef = ReplicateOp_Divide.ToDefInit <VectorGaussian>(vVectorGaussian208); // Message to 'vVector625_rep' from Replicate factor vVector625_rep_B_toDef = ReplicateOp_Divide.ToDef <VectorGaussian>(vVector625_rep_B, vVector625_rep_B_toDef); // Message to 'vVector625_marginal' from Variable factor this.vVector625_marginal_F = VariableOp.MarginalAverageConditional <VectorGaussian>(vVector625_rep_B_toDef, vVectorGaussian208, this.vVector625_marginal_F); DistributionStructArray <Gaussian, double> vdouble__625_F = default(DistributionStructArray <Gaussian, double>); // Create array for 'vdouble__625' Forwards messages. vdouble__625_F = new DistributionStructArray <Gaussian, double>(5622); for (int index208 = 0; index208 < 5622; index208++) { vdouble__625_F[index208] = Gaussian.Uniform(); } DistributionRefArray <VectorGaussian, Vector> vVector625_rep_F = default(DistributionRefArray <VectorGaussian, Vector>); // Create array for 'vVector625_rep' Forwards messages. vVector625_rep_F = new DistributionRefArray <VectorGaussian, Vector>(5622); for (int index208 = 0; index208 < 5622; index208++) { vVector625_rep_F[index208] = ArrayHelper.MakeUniform <VectorGaussian>(vVectorGaussian208); } // Buffer for ReplicateOp_Divide.UsesAverageConditional<VectorGaussian> VectorGaussian vVector625_rep_F_marginal = default(VectorGaussian); // Message to 'vVector625_rep' from Replicate factor vVector625_rep_F_marginal = ReplicateOp_Divide.MarginalInit <VectorGaussian>(vVectorGaussian208); // Message to 'vVector625_rep' from Replicate factor vVector625_rep_F_marginal = ReplicateOp_Divide.Marginal <VectorGaussian>(vVector625_rep_B_toDef, vVectorGaussian208, vVector625_rep_F_marginal); // Buffer for InnerProductOp.InnerProductAverageConditional // Create array for replicates of 'vVector625_rep_F_index208__AMean' Vector[] vVector625_rep_F_index208__AMean = new Vector[5622]; for (int index208 = 0; index208 < 5622; index208++) { // Message to 'vdouble__625' from InnerProduct factor vVector625_rep_F_index208__AMean[index208] = InnerProductOp.AMeanInit(vVector625_rep_F[index208]); } // Buffer for InnerProductOp.AMean // Create array for replicates of 'vVector625_rep_F_index208__AVariance' PositiveDefiniteMatrix[] vVector625_rep_F_index208__AVariance = new PositiveDefiniteMatrix[5622]; for (int index208 = 0; index208 < 5622; index208++) { // Message to 'vdouble__625' from InnerProduct factor vVector625_rep_F_index208__AVariance[index208] = InnerProductOp.AVarianceInit(vVector625_rep_F[index208]); // Message to 'vVector625_rep' from Replicate factor vVector625_rep_F[index208] = ReplicateOp_Divide.UsesAverageConditional <VectorGaussian>(vVector625_rep_B[index208], vVector625_rep_F_marginal, index208, vVector625_rep_F[index208]); } // Create array for 'vdouble__625_marginal' Forwards messages. this.vdouble__625_marginal_F = new DistributionStructArray <Gaussian, double>(5622); for (int index208 = 0; index208 < 5622; index208++) { this.vdouble__625_marginal_F[index208] = Gaussian.Uniform(); // Message to 'vdouble__625' from InnerProduct factor vVector625_rep_F_index208__AVariance[index208] = InnerProductOp.AVariance(vVector625_rep_F[index208], vVector625_rep_F_index208__AVariance[index208]); // Message to 'vdouble__625' from InnerProduct factor vVector625_rep_F_index208__AMean[index208] = InnerProductOp.AMean(vVector625_rep_F[index208], vVector625_rep_F_index208__AVariance[index208], vVector625_rep_F_index208__AMean[index208]); // Message to 'vdouble__625' from InnerProduct factor vdouble__625_F[index208] = InnerProductOp.InnerProductAverageConditional(vVector625_rep_F_index208__AMean[index208], vVector625_rep_F_index208__AVariance[index208], this.VVector__208[index208]); // Message to 'vdouble__625_marginal' from DerivedVariable factor this.vdouble__625_marginal_F[index208] = DerivedVariableOp.MarginalAverageConditional <Gaussian>(vdouble__625_use_B[index208], vdouble__625_F[index208], this.vdouble__625_marginal_F[index208]); } this.Changed_vVector__208_vdouble__624_iterationsDone = 1; }
private IEnumerable <Security> GetSubscribers(MarketDataTypes type) { return(_subscribers.TryGetValue(type)?.Cache ?? ArrayHelper.Empty <Security>()); }
protected override int DoUpdateRows(object id, IPersistentCollection collection, ISessionImplementor session) { if (ArrayHelper.IsAllFalse(elementColumnIsSettable)) { return(0); } try { IDbCommand st = null; IExpectation expectation = Expectations.AppropriateExpectation(UpdateCheckStyle); //bool callable = UpdateCallable; bool useBatch = expectation.CanBeBatched; IEnumerable entries = collection.Entries(this); int i = 0; int count = 0; foreach (object entry in entries) { if (collection.NeedsUpdating(entry, i, ElementType)) { int offset = 0; if (useBatch) { if (st == null) { st = session.Batcher.PrepareBatchCommand(SqlUpdateRowString.CommandType, SqlUpdateRowString.Text, SqlUpdateRowString.ParameterTypes); } } else { st = session.Batcher.PrepareCommand(SqlUpdateRowString.CommandType, SqlUpdateRowString.Text, SqlUpdateRowString.ParameterTypes); } try { //offset += expectation.Prepare(st, Factory.ConnectionProvider.Driver); int loc = WriteElement(st, collection.GetElement(entry), offset, session); if (hasIdentifier) { WriteIdentifier(st, collection.GetIdentifier(entry, i), loc, session); } else { loc = WriteKey(st, id, loc, session); if (HasIndex && !indexContainsFormula) { WriteIndexToWhere(st, collection.GetIndex(entry, i, this), loc, session); } else { WriteElementToWhere(st, collection.GetSnapshotElement(entry, i), loc, session); } } if (useBatch) { session.Batcher.AddToBatch(expectation); } else { expectation.VerifyOutcomeNonBatched(session.Batcher.ExecuteNonQuery(st), st); } } catch (Exception e) { if (useBatch) { session.Batcher.AbortBatch(e); } throw; } finally { if (!useBatch) { session.Batcher.CloseCommand(st, null); } } count++; } i++; } return(count); } catch (DbException sqle) { throw ADOExceptionHelper.Convert(SQLExceptionConverter, sqle, "could not update collection rows: " + MessageHelper.CollectionInfoString(this, collection, id, session), SqlUpdateRowString.Text); } }
private void Parse(Stream stream, Encoding encoding) { this.Success = false; // Read the stream into a byte array byte[] data = ArrayHelper.ToByteArray(stream); // Copy to a string for header parsing string content = encoding.GetString(data); // The first line should contain the delimiter int delimiterEndIndex = content.IndexOf("\r\n"); if (delimiterEndIndex > -1) { string delimiter = content.Substring(0, content.IndexOf("\r\n")); string[] sections = content.Split(new string[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in sections) { if (s.Contains("Content-Disposition")) { // If we find "Content-Disposition", this is a valid multi-part section // Now, look for the "name" parameter Match nameMatch = new Regex(@"(?<=name\=\"")(.*?)(?=\"")").Match(s); string name = nameMatch.Value.Trim().ToLower(); if (name == FilePartName.ToLower()) { // Look for Content-Type Regex re = new Regex(@"(?<=Content\-Type:)(.*?)(?=\r\n\r\n)"); Match contentTypeMatch = re.Match(content); // Look for filename re = new Regex(@"(?<=filename\=\"")(.*?)(?=\"")"); Match filenameMatch = re.Match(content); // Did we find the required values? if (contentTypeMatch.Success && filenameMatch.Success) { // Set properties this.ContentType = contentTypeMatch.Value.Trim(); this.FileName = filenameMatch.Value.Trim(); // Get the start & end indexes of the file contents int startIndex = contentTypeMatch.Index + contentTypeMatch.Length + "\r\n\r\n".Length; byte[] delimiterBytes = encoding.GetBytes("\r\n" + delimiter); int endIndex = ArrayHelper.IndexOf(data, delimiterBytes, startIndex); int contentLength = endIndex - startIndex; // Extract the file contents from the byte array byte[] fileData = new byte[contentLength]; Buffer.BlockCopy(data, startIndex, fileData, 0, contentLength); this.FileContents = fileData; } } else if (!string.IsNullOrWhiteSpace(name)) { // Get the start & end indexes of the file contents int startIndex = nameMatch.Index + nameMatch.Length + "\r\n\r\n".Length; Parameters.Add(name, s.Substring(startIndex).TrimEnd(new char[] { '\r', '\n' }).Trim()); } } } // If some data has been successfully received, set success to true if (FileContents != null || Parameters.Count != 0) { this.Success = true; } } }
/// <summary> /// 반복 제거. /// </summary> public void RemoveLoop(int index) { this.checkTime = ArrayHelper.Remove(index, this.checkTime); this.setTime = ArrayHelper.Remove(index, this.setTime); }
public NLogXmlElement(XmlReader reader, bool nestedElement) { Parse(reader, nestedElement, out var attributes, out var children); AttributeValues = attributes ?? ArrayHelper.Empty <KeyValuePair <string, string> >(); Children = children ?? ArrayHelper.Empty <NLogXmlElement>(); }
public object[,] ToArray() { object[,] values = ArrayHelper.ConvertDictionaryTo2DArray(ToDict()); return(values); }
public static void Fill <T> (this T[] array, T[] values) { ArrayHelper.ArrayFill(array, values); }
public static object CreateProxyWithTarget(this IProxyFactory proxyFactory, Type serviceType, object target) { return(proxyFactory.CreateProxyWithTarget(serviceType, target, ArrayHelper.Empty <object>())); }
public VehiclePool(VehiclePool other) { Cars = ArrayHelper.DeepClone(other.Cars); Boats = ArrayHelper.DeepClone(other.Boats); }
public void NullArraysShouldBeEqual() { bool[] a = null, b = null; Assert.That(ArrayHelper.ArrayEquals(a, b), Is.True); }
public void ParseCommand2() { var bytes = ArrayHelper.ToByteArray("000B01E8DFB81EB400000293BD00000000000000"); var command = DeserializedCommand.Parse(bytes); }
public void SubselectFetchNamedParam() { ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); Parent p = new Parent("foo"); p.Children.Add(new Child("foo1")); p.Children.Add(new Child("foo2")); Parent q = new Parent("bar"); q.Children.Add(new Child("bar1")); q.Children.Add(new Child("bar2")); ArrayHelper.AddAll(q.MoreChildren, p.Children); s.Save(p); s.Save(q); t.Commit(); s.Close(); s = OpenSession(); t = s.BeginTransaction(); Sfi.Statistics.Clear(); IList parents = s.CreateQuery("from Parent where name between :bar and :foo order by name desc") .SetParameter("bar", "bar") .SetParameter("foo", "foo") .List(); p = (Parent)parents[0]; q = (Parent)parents[1]; Assert.IsFalse(NHibernateUtil.IsInitialized(p.Children)); Assert.IsFalse(NHibernateUtil.IsInitialized(q.Children)); Assert.AreEqual(p.Children.Count, 2); Assert.IsTrue(NHibernateUtil.IsInitialized(p.Children[0])); Assert.IsTrue(NHibernateUtil.IsInitialized(q.Children)); Assert.AreEqual(q.Children.Count, 2); Assert.IsTrue(NHibernateUtil.IsInitialized(q.Children[0])); Assert.IsFalse(NHibernateUtil.IsInitialized(p.MoreChildren)); Assert.IsFalse(NHibernateUtil.IsInitialized(q.MoreChildren)); Assert.AreEqual(p.MoreChildren.Count, 0); Assert.IsTrue(NHibernateUtil.IsInitialized(q.MoreChildren)); Assert.AreEqual(q.MoreChildren.Count, 2); Assert.IsTrue(NHibernateUtil.IsInitialized(q.MoreChildren[0])); Assert.AreEqual(3, Sfi.Statistics.PrepareStatementCount); Child c = (Child)p.Children[0]; NHibernateUtil.Initialize(c.Friends); s.Delete(p); s.Delete(q); t.Commit(); s.Close(); }
/// <summary> /// Toes the array. /// </summary> /// <param name="assembly">The assembly.</param> /// <returns></returns> public object[,] ToArray(Assembly assembly) { return(ArrayHelper.ConvertDictionaryTo2DArray(ToDict(assembly))); }
public static void ParseFiles(Stream stream, string[] filenames, Encoding encoding, MultiPartFileHandler multiPartHandler) { List <string> lowerCasedFileNames = new List <string>(); foreach (string fname in filenames) { lowerCasedFileNames.Add(fname.ToLower()); } // Read the stream into a byte array byte[] data = ArrayHelper.ToByteArray(stream); // Copy to a string for header parsing string content = encoding.GetString(data); System.IO.File.WriteAllText(@"C:\debug.txt", content); // The first line should contain the delimiter int delimiterEndIndex = content.IndexOf("\r\n"); if (delimiterEndIndex > -1) { string delimiter = content.Substring(0, content.IndexOf("\r\n")); string[] sections = content.Split(new string[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); foreach (string currentSection in sections) { if (currentSection.Contains("Content-Disposition")) { // If we find "Content-Disposition", this is a valid multi-part section // Now, look for the "name" parameter Match nameMatch = new Regex(@"(?<=name\=\"")(.*?)(?=\"")").Match(currentSection); string name = nameMatch.Value.Trim(); int idx = lowerCasedFileNames.IndexOf(name.ToLower()); if (idx >= 0) { // Look for Content-Type Regex re = new Regex(@"(?<=Content\-Type:)(.*?)(?=\r\n\r\n)"); Match contentTypeMatch = re.Match(currentSection); // Look for filename re = new Regex(@"(?<=filename\=\"")(.*?)(?=\"")"); Match filenameMatch = re.Match(currentSection); // Did we find the required values? if (contentTypeMatch.Success && filenameMatch.Success) { // Set properties string contentType = contentTypeMatch.Value.Trim(); string fileName = filenameMatch.Value.Trim(); System.IO.File.WriteAllText(@"C:\debug2.txt", fileName); if (multiPartHandler != null) { // Get the start & end indexes of the file contents int startIndex = contentTypeMatch.Index + contentTypeMatch.Length + "\r\n\r\n".Length; byte[] delimiterBytes = encoding.GetBytes("\r\n" + delimiter); int endIndex = ArrayHelper.IndexOf(data, delimiterBytes, startIndex); int contentLength = endIndex - startIndex; // Extract the file contents from the byte array byte[] fileData = new byte[contentLength]; Buffer.BlockCopy(data, startIndex, fileData, 0, contentLength); multiPartHandler(fileName, contentType, fileData); } } } //else if (!string.IsNullOrWhiteSpace(name)) //{ // // Get the start & end indexes of the file contents // int startIndex = nameMatch.Index + nameMatch.Length + "\r\n\r\n".Length; // Parameters.Add(name, s.Substring(startIndex).TrimEnd(new char[] { '\r', '\n' }).Trim()); //} } } } }
public override string ToString() { return("CollectionCacheEntry" + ArrayHelper.ToString(State)); }
/// <summary> /// 반복 추가. /// </summary> public void AddLoop() { this.checkTime = ArrayHelper.Add(0.0f, this.checkTime); this.setTime = ArrayHelper.Add(0.0f, this.setTime); }
public Streaming() { ModelFlags = ArrayHelper.CreateArray <StreamingFlags>(NumModels); }
public static IPPacket.IPVersions ExtractVersion(int lLen, byte[] packetBytes) { return((IPPacket.IPVersions)((ArrayHelper.extractInteger(packetBytes, lLen + IPv4Fields_Fields.IP_VER_POS, IPv4Fields_Fields.IP_VER_LEN) >> 4) & 0xF)); }
public Streaming(Streaming other) { ModelFlags = ArrayHelper.DeepClone(other.ModelFlags); }
public async Task PerformListAsync(QueryParameters queryParameters, ISessionImplementor session, IList results, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (Log.IsDebugEnabled()) { Log.Debug("find: {0}", _sourceQuery); queryParameters.LogParameters(session.Factory); } bool hasLimit = queryParameters.RowSelection != null && queryParameters.RowSelection.DefinesLimits; bool needsLimit = hasLimit && Translators.Length > 1; QueryParameters queryParametersToUse; if (needsLimit) { Log.Warn("firstResult/maxResults specified on polymorphic query; applying in memory!"); RowSelection selection = new RowSelection(); selection.FetchSize = queryParameters.RowSelection.FetchSize; selection.Timeout = queryParameters.RowSelection.Timeout; queryParametersToUse = queryParameters.CreateCopyUsing(selection); } else { queryParametersToUse = queryParameters; } IList combinedResults = results ?? new List <object>(); var distinction = new HashSet <object>(ReferenceComparer <object> .Instance); int includedCount = -1; for (int i = 0; i < Translators.Length; i++) { IList tmp = await(Translators[i].ListAsync(session, queryParametersToUse, cancellationToken)).ConfigureAwait(false); if (needsLimit) { // NOTE : firstRow is zero-based int first = queryParameters.RowSelection.FirstRow == RowSelection.NoValue ? 0 : queryParameters.RowSelection.FirstRow; int max = queryParameters.RowSelection.MaxRows == RowSelection.NoValue ? RowSelection.NoValue : queryParameters.RowSelection.MaxRows; int size = tmp.Count; for (int x = 0; x < size; x++) { object result = tmp[x]; if (!distinction.Add(result)) { continue; } includedCount++; if (includedCount < first) { continue; } combinedResults.Add(result); if (max >= 0 && includedCount > max) { // break the outer loop !!! return; } } } else { ArrayHelper.AddAll(combinedResults, tmp); } } }
public async Task <ushort[, ]> TakeImage( TakeParams acquireParams, CancellationToken ct, IProgress <TakeProgressEventArgs> progress = null) { if (!IsAttached) { throw new Exception("The camera has been disconnected"); } try { //Pixel format var rez = await _cameraHelper.SetConfigRegisterAsync(0x30024, 5); //set gain await CorrectGainAsync(acquireParams); //Get SBRM register var sbrm = await _cameraHelper.GetRegisterValueAsync(0x001D8); //Read SIRM register var sirm = await _cameraHelper.GetRegisterValueAsync(sbrm + 0x0020); //Get leader size. var leaderSize = await _cameraHelper.GetBlocksSizeAsync(sirm + 0x10); //Get trailer size var trailerSize = await _cameraHelper.GetBlocksSizeAsync(sirm + 0x14); //image width and height, registers from props.txt var width = await _cameraHelper.GetBlocksSizeAsync(0x30204); var height = await _cameraHelper.GetBlocksSizeAsync(0x30224); //trigger_mode_off (on = 1), registers from props.txt rez = await _cameraHelper.SetConfigRegisterAsync(0x40104, 0); //unknown register from WireShark dump rez = await _cameraHelper.SetConfigRegisterAsync(0x40204, 0); //acquisition mode, 0-single, 2-continue rez = await _cameraHelper.SetConfigRegisterAsync(0x40004, 0); //disable exposure rez = await _cameraHelper.SetConfigRegisterAsync(sirm + 0x0004, 0); //single payload size rez = await _cameraHelper.SetConfigRegisterAsync(sirm + 0x001C, width *height); //count of payload transmitions rez = await _cameraHelper.SetConfigRegisterAsync(sirm + 0x0020, 4); //max final payload transfer 1 size (value from WireShark dump) rez = await _cameraHelper.SetConfigRegisterAsync(sirm + 0x0024, 206848); //max final payload transfer 1 size (value from WireShark dump) rez = await _cameraHelper.SetConfigRegisterAsync(sirm + 0x0028, 0); //leader and trailer sizes rez = await _cameraHelper.SetConfigRegisterAsync(sirm + 0x0018, leaderSize); rez = await _cameraHelper.SetConfigRegisterAsync(sirm + 0x002c, trailerSize); //exposure mode,registers from props.txt //EnumEntry_ExposureMode_Timed = 1 //EnumEntry_ExposureMode_TriggerWidth = 2 rez = await _cameraHelper.SetConfigRegisterAsync(263172, 1); //Exposure time, registers from props.txt rez = await _cameraHelper.SetConfigRegisterAsync(263268, (int)acquireParams.ExposureTime); //enable exposure rez = await _cameraHelper.SetConfigRegisterAsync(sirm + 0x0004, 1); //start exposure rez = await _cameraHelper.SetConfigRegisterAsync(0x40024, 0x01); byte[] data = new byte[0]; var leader = await _cameraHelper.GetImageData(); while (data.Length < width * height * 2) { data = ArrayHelper.ConcatArrays(data, await _cameraHelper.GetImageData()); } var trailer = await _cameraHelper.GetImageData(); //stop exposure rez = await _cameraHelper.SetConfigRegisterAsync(0x40044, 0x01); ImageHeight = height; ImageWidth = width; return(ArrayHelper.UnpackImage(data, width, height)); } catch (ArgumentException) { OnDisconnect(); return(null); } }
/// <summary>Computations that depend on the observed value of vVector__325</summary> private void Changed_vVector__325() { if (this.Changed_vVector__325_iterationsDone == 1) { return; } this.vVector__325_marginal = new PointMass <Vector[]>(this.VVector__325); // The constant 'vVectorGaussian325' VectorGaussian vVectorGaussian325 = VectorGaussian.FromNatural(DenseVector.FromArray(new double[3] { 1547829870.0, 525077980.0, 200270.0 }), new PositiveDefiniteMatrix(new double[3, 3] { { 4254590363351.0, 1127383488860.0, 433199230.0 }, { 1127383488860.0, 482723521821.0, 146764360.0 }, { 433199230.0, 146764360.0, 56221.0 } })); this.vVector975_marginal_F = ArrayHelper.MakeUniform <VectorGaussian>(vVectorGaussian325); // Buffer for ReplicateOp_Divide.Marginal<VectorGaussian> VectorGaussian vVector975_rep_B_toDef = default(VectorGaussian); // Message to 'vVector975_rep' from Replicate factor vVector975_rep_B_toDef = ReplicateOp_Divide.ToDefInit <VectorGaussian>(vVectorGaussian325); // Message to 'vVector975_marginal' from Variable factor this.vVector975_marginal_F = VariableOp.MarginalAverageConditional <VectorGaussian>(vVector975_rep_B_toDef, vVectorGaussian325, this.vVector975_marginal_F); DistributionStructArray <Gaussian, double> vdouble__975_F = default(DistributionStructArray <Gaussian, double>); // Create array for 'vdouble__975' Forwards messages. vdouble__975_F = new DistributionStructArray <Gaussian, double>(1); for (int index325 = 0; index325 < 1; index325++) { vdouble__975_F[index325] = Gaussian.Uniform(); } DistributionStructArray <Gaussian, double> vdouble__976_F = default(DistributionStructArray <Gaussian, double>); // Create array for 'vdouble__976' Forwards messages. vdouble__976_F = new DistributionStructArray <Gaussian, double>(1); for (int index325 = 0; index325 < 1; index325++) { vdouble__976_F[index325] = Gaussian.Uniform(); } DistributionRefArray <VectorGaussian, Vector> vVector975_rep_F = default(DistributionRefArray <VectorGaussian, Vector>); DistributionRefArray <VectorGaussian, Vector> vVector975_rep_B = default(DistributionRefArray <VectorGaussian, Vector>); // Create array for 'vVector975_rep' Forwards messages. vVector975_rep_F = new DistributionRefArray <VectorGaussian, Vector>(1); // Create array for 'vVector975_rep' Backwards messages. vVector975_rep_B = new DistributionRefArray <VectorGaussian, Vector>(1); for (int index325 = 0; index325 < 1; index325++) { vVector975_rep_B[index325] = ArrayHelper.MakeUniform <VectorGaussian>(vVectorGaussian325); vVector975_rep_F[index325] = ArrayHelper.MakeUniform <VectorGaussian>(vVectorGaussian325); } // Buffer for ReplicateOp_Divide.UsesAverageConditional<VectorGaussian> VectorGaussian vVector975_rep_F_marginal = default(VectorGaussian); // Message to 'vVector975_rep' from Replicate factor vVector975_rep_F_marginal = ReplicateOp_Divide.MarginalInit <VectorGaussian>(vVectorGaussian325); // Message to 'vVector975_rep' from Replicate factor vVector975_rep_F_marginal = ReplicateOp_Divide.Marginal <VectorGaussian>(vVector975_rep_B_toDef, vVectorGaussian325, vVector975_rep_F_marginal); // Buffer for InnerProductOp.InnerProductAverageConditional // Create array for replicates of 'vVector975_rep_F_index325__AMean' Vector[] vVector975_rep_F_index325__AMean = new Vector[1]; for (int index325 = 0; index325 < 1; index325++) { // Message to 'vdouble__976' from InnerProduct factor vVector975_rep_F_index325__AMean[index325] = InnerProductOp.AMeanInit(vVector975_rep_F[index325]); } // Buffer for InnerProductOp.AMean // Create array for replicates of 'vVector975_rep_F_index325__AVariance' PositiveDefiniteMatrix[] vVector975_rep_F_index325__AVariance = new PositiveDefiniteMatrix[1]; for (int index325 = 0; index325 < 1; index325++) { // Message to 'vdouble__976' from InnerProduct factor vVector975_rep_F_index325__AVariance[index325] = InnerProductOp.AVarianceInit(vVector975_rep_F[index325]); // Message to 'vVector975_rep' from Replicate factor vVector975_rep_F[index325] = ReplicateOp_Divide.UsesAverageConditional <VectorGaussian>(vVector975_rep_B[index325], vVector975_rep_F_marginal, index325, vVector975_rep_F[index325]); } // Create array for 'vdouble__976_marginal' Forwards messages. this.vdouble__976_marginal_F = new DistributionStructArray <Gaussian, double>(1); for (int index325 = 0; index325 < 1; index325++) { this.vdouble__976_marginal_F[index325] = Gaussian.Uniform(); } // Message from use of 'vdouble__976' DistributionStructArray <Gaussian, double> vdouble__976_use_B = default(DistributionStructArray <Gaussian, double>); // Create array for 'vdouble__976_use' Backwards messages. vdouble__976_use_B = new DistributionStructArray <Gaussian, double>(1); for (int index325 = 0; index325 < 1; index325++) { vdouble__976_use_B[index325] = Gaussian.Uniform(); // Message to 'vdouble__976' from InnerProduct factor vVector975_rep_F_index325__AVariance[index325] = InnerProductOp.AVariance(vVector975_rep_F[index325], vVector975_rep_F_index325__AVariance[index325]); // Message to 'vdouble__976' from InnerProduct factor vVector975_rep_F_index325__AMean[index325] = InnerProductOp.AMean(vVector975_rep_F[index325], vVector975_rep_F_index325__AVariance[index325], vVector975_rep_F_index325__AMean[index325]); // Message to 'vdouble__976' from InnerProduct factor vdouble__976_F[index325] = InnerProductOp.InnerProductAverageConditional(vVector975_rep_F_index325__AMean[index325], vVector975_rep_F_index325__AVariance[index325], this.VVector__325[index325]); // Message to 'vdouble__976_marginal' from DerivedVariable factor this.vdouble__976_marginal_F[index325] = DerivedVariableOp.MarginalAverageConditional <Gaussian>(vdouble__976_use_B[index325], vdouble__976_F[index325], this.vdouble__976_marginal_F[index325]); } // Create array for 'vdouble__975_marginal' Forwards messages. this.vdouble__975_marginal_F = new DistributionStructArray <Gaussian, double>(1); for (int index325 = 0; index325 < 1; index325++) { this.vdouble__975_marginal_F[index325] = Gaussian.Uniform(); } // Message from use of 'vdouble__975' DistributionStructArray <Gaussian, double> vdouble__975_use_B = default(DistributionStructArray <Gaussian, double>); // Create array for 'vdouble__975_use' Backwards messages. vdouble__975_use_B = new DistributionStructArray <Gaussian, double>(1); for (int index325 = 0; index325 < 1; index325++) { vdouble__975_use_B[index325] = Gaussian.Uniform(); // Message to 'vdouble__975' from GaussianFromMeanAndVariance factor vdouble__975_F[index325] = GaussianFromMeanAndVarianceOp.SampleAverageConditional(vdouble__976_F[index325], 0.1); // Message to 'vdouble__975_marginal' from Variable factor this.vdouble__975_marginal_F[index325] = VariableOp.MarginalAverageConditional <Gaussian>(vdouble__975_use_B[index325], vdouble__975_F[index325], this.vdouble__975_marginal_F[index325]); } this.Changed_vVector__325_iterationsDone = 1; }
/// <summary>Computations that depend on the observed value of Cloudy and WetGrass</summary> public void Changed_Cloudy_WetGrass() { if (this.Changed_Cloudy_WetGrass_iterationsDone == 1) { return; } // The constant 'vBernoulli45' Bernoulli vBernoulli45 = Bernoulli.FromLogOdds(0); this.Cloudy_marginal = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli45); this.Cloudy_marginal = Distribution.SetPoint <Bernoulli, bool>(this.Cloudy_marginal, this.cloudy); // The constant 'vBernoulli50' Bernoulli vBernoulli50 = Bernoulli.FromLogOdds(4.5951198501345889); this.WetGrass_marginal = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli50); this.WetGrass_marginal = Distribution.SetPoint <Bernoulli, bool>(this.WetGrass_marginal, this.wetGrass); // The constant 'vBernoulli48' Bernoulli vBernoulli48 = Bernoulli.FromLogOdds(1.5163474893680882); Bernoulli Rain_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli48); this.Rain_marginal_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli48); // Message to use of 'Rain' Bernoulli Rain_use_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli48); // Message from use of 'Rain' Bernoulli Rain_use_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli48); if (this.cloudy) { // Message to 'Rain' from Copy factor Rain_F = Factor.Copy <Bernoulli>(vBernoulli48); } // The constant 'vBernoulli49' Bernoulli vBernoulli49 = Bernoulli.FromLogOdds(0.28185115214098749); if (!this.cloudy) { // Message to 'Rain' from Copy factor Rain_F = Factor.Copy <Bernoulli>(vBernoulli49); } // Rain_F is now updated in all contexts if (this.cloudy) { // Message to 'Rain_use' from DerivedVariable factor Rain_use_F = Factor.Copy <Bernoulli>(Rain_F); } Bernoulli Rain_cond_Sprinkler_0_selector_cases_0_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli()); // Message to 'Rain_cond_Sprinkler_0_selector_cases_0' from Random factor Rain_cond_Sprinkler_0_selector_cases_0_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli50)); DistributionStructArray <Bernoulli, bool> Rain_cond_Sprinkler_0_selector_cases_B = default(DistributionStructArray <Bernoulli, bool>); // Create array for 'Rain_cond_Sprinkler_0_selector_cases' Backwards messages. Rain_cond_Sprinkler_0_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2); for (int _ind0 = 0; _ind0 < 2; _ind0++) { Rain_cond_Sprinkler_0_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli()); } // Message to 'Rain_cond_Sprinkler_0_selector_cases' from Copy factor Rain_cond_Sprinkler_0_selector_cases_B[0] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_0_selector_cases_0_B); // The constant 'vBernoulli51' Bernoulli vBernoulli51 = Bernoulli.FromLogOdds(2.1972245773362196); Bernoulli Rain_cond_Sprinkler_0_selector_cases_1_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli()); // Message to 'Rain_cond_Sprinkler_0_selector_cases_1' from Random factor Rain_cond_Sprinkler_0_selector_cases_1_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli51)); // Message to 'Rain_cond_Sprinkler_0_selector_cases' from Copy factor Rain_cond_Sprinkler_0_selector_cases_B[1] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_0_selector_cases_1_B); if (!this.cloudy) { // Message to 'Rain_use' from DerivedVariable factor Rain_use_F = Factor.Copy <Bernoulli>(vBernoulli49); } // Rain_use_F is now updated in all contexts Bernoulli[] Sprinkler_selector_cases_0_uses_B = default(Bernoulli[]); // Create array for 'Sprinkler_selector_cases_0_uses' Backwards messages. Sprinkler_selector_cases_0_uses_B = new Bernoulli[5]; for (int _ind = 0; _ind < 5; _ind++) { Sprinkler_selector_cases_0_uses_B[_ind] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli()); } // Message to 'Sprinkler_selector_cases_0_uses' from Cases factor Sprinkler_selector_cases_0_uses_B[4] = Bernoulli.FromLogOdds(CasesOp.LogEvidenceRatio(Rain_cond_Sprinkler_0_selector_cases_B, Rain_use_F)); Bernoulli Sprinkler_selector_cases_0_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli()); // Message to 'Sprinkler_selector_cases_0' from Replicate factor Sprinkler_selector_cases_0_B = ReplicateOp.DefAverageConditional <Bernoulli>(Sprinkler_selector_cases_0_uses_B, Sprinkler_selector_cases_0_B); DistributionStructArray <Bernoulli, bool> Sprinkler_selector_cases_B = default(DistributionStructArray <Bernoulli, bool>); // Create array for 'Sprinkler_selector_cases' Backwards messages. Sprinkler_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2); for (int _ind0 = 0; _ind0 < 2; _ind0++) { Sprinkler_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli()); } // Message to 'Sprinkler_selector_cases' from Copy factor Sprinkler_selector_cases_B[0] = Factor.Copy <Bernoulli>(Sprinkler_selector_cases_0_B); Bernoulli Rain_cond_Sprinkler_1_selector_cases_0_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli()); // Message to 'Rain_cond_Sprinkler_1_selector_cases_0' from Random factor Rain_cond_Sprinkler_1_selector_cases_0_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli51)); DistributionStructArray <Bernoulli, bool> Rain_cond_Sprinkler_1_selector_cases_B = default(DistributionStructArray <Bernoulli, bool>); // Create array for 'Rain_cond_Sprinkler_1_selector_cases' Backwards messages. Rain_cond_Sprinkler_1_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2); for (int _ind0 = 0; _ind0 < 2; _ind0++) { Rain_cond_Sprinkler_1_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli()); } // Message to 'Rain_cond_Sprinkler_1_selector_cases' from Copy factor Rain_cond_Sprinkler_1_selector_cases_B[0] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_1_selector_cases_0_B); // The constant 'vBernoulli53' Bernoulli vBernoulli53 = Bernoulli.FromLogOdds(-2.4423470353692043); Bernoulli Rain_cond_Sprinkler_1_selector_cases_1_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli()); // Message to 'Rain_cond_Sprinkler_1_selector_cases_1' from Random factor Rain_cond_Sprinkler_1_selector_cases_1_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli53)); // Message to 'Rain_cond_Sprinkler_1_selector_cases' from Copy factor Rain_cond_Sprinkler_1_selector_cases_B[1] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_1_selector_cases_1_B); Bernoulli[] Sprinkler_selector_cases_1_uses_B = default(Bernoulli[]); // Create array for 'Sprinkler_selector_cases_1_uses' Backwards messages. Sprinkler_selector_cases_1_uses_B = new Bernoulli[5]; for (int _ind = 0; _ind < 5; _ind++) { Sprinkler_selector_cases_1_uses_B[_ind] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli()); } // Message to 'Sprinkler_selector_cases_1_uses' from Cases factor Sprinkler_selector_cases_1_uses_B[4] = Bernoulli.FromLogOdds(CasesOp.LogEvidenceRatio(Rain_cond_Sprinkler_1_selector_cases_B, Rain_use_F)); Bernoulli Sprinkler_selector_cases_1_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli()); // Message to 'Sprinkler_selector_cases_1' from Replicate factor Sprinkler_selector_cases_1_B = ReplicateOp.DefAverageConditional <Bernoulli>(Sprinkler_selector_cases_1_uses_B, Sprinkler_selector_cases_1_B); // Message to 'Sprinkler_selector_cases' from Copy factor Sprinkler_selector_cases_B[1] = Factor.Copy <Bernoulli>(Sprinkler_selector_cases_1_B); Bernoulli[] Sprinkler_selector_uses_B = default(Bernoulli[]); // Create array for 'Sprinkler_selector_uses' Backwards messages. Sprinkler_selector_uses_B = new Bernoulli[2]; // The constant 'vBernoulli46' Bernoulli vBernoulli46 = Bernoulli.FromLogOdds(-2.1972245773362191); for (int _ind = 0; _ind < 2; _ind++) { Sprinkler_selector_uses_B[_ind] = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli46); } // Message to 'Sprinkler_selector_uses' from Cases factor Sprinkler_selector_uses_B[0] = CasesOp.BAverageConditional(Sprinkler_selector_cases_B); Bernoulli Sprinkler_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli46); if (this.cloudy) { // Message to 'Sprinkler' from Copy factor Sprinkler_F = Factor.Copy <Bernoulli>(vBernoulli46); } if (!this.cloudy) { // Message to 'Sprinkler' from Copy factor Sprinkler_F = Factor.Copy <Bernoulli>(vBernoulli45); } // Sprinkler_F is now updated in all contexts // Message to use of 'Sprinkler' Bernoulli Sprinkler_use_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli46); if (this.cloudy) { // Message to 'Sprinkler_use' from DerivedVariable factor Sprinkler_use_F = Factor.Copy <Bernoulli>(Sprinkler_F); } if (!this.cloudy) { // Message to 'Sprinkler_use' from DerivedVariable factor Sprinkler_use_F = Factor.Copy <Bernoulli>(vBernoulli45); } // Sprinkler_use_F is now updated in all contexts // Buffer for Replicate2BufferOp.UsesAverageConditional<Bernoulli> Bernoulli Sprinkler_selector_uses_B_marginal = default(Bernoulli); // Message to 'Sprinkler_selector_uses' from Replicate factor Sprinkler_selector_uses_B_marginal = Replicate2BufferOp.MarginalInit <Bernoulli>(Sprinkler_use_F); // Message to 'Sprinkler_selector_uses' from Replicate factor Sprinkler_selector_uses_B_marginal = Replicate2BufferOp.Marginal <Bernoulli>(Sprinkler_selector_uses_B, Sprinkler_use_F, Sprinkler_selector_uses_B_marginal); Bernoulli[] Sprinkler_selector_uses_F = default(Bernoulli[]); // Create array for 'Sprinkler_selector_uses' Forwards messages. Sprinkler_selector_uses_F = new Bernoulli[2]; for (int _ind = 0; _ind < 2; _ind++) { Sprinkler_selector_uses_F[_ind] = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli46); } // Message to 'Sprinkler_selector_uses' from Replicate factor Sprinkler_selector_uses_F[1] = Replicate2BufferOp.UsesAverageConditional <Bernoulli>(Sprinkler_selector_uses_B, Sprinkler_use_F, Sprinkler_selector_uses_B_marginal, 1, Sprinkler_selector_uses_F[1]); Bernoulli Rain_cond_Sprinkler_0_selector_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli48); // Message to 'Rain_cond_Sprinkler_0_selector' from Cases factor Rain_cond_Sprinkler_0_selector_B = CasesOp.BAverageConditional(Rain_cond_Sprinkler_0_selector_cases_B); DistributionStructArray <Bernoulli, bool> Rain_cond_Sprinkler_B = default(DistributionStructArray <Bernoulli, bool>); // Create array for 'Rain_cond_Sprinkler' Backwards messages. Rain_cond_Sprinkler_B = new DistributionStructArray <Bernoulli, bool>(2); for (int _gateind = 0; _gateind < 2; _gateind++) { Rain_cond_Sprinkler_B[_gateind] = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli48); } // Message to 'Rain_cond_Sprinkler' from Copy factor Rain_cond_Sprinkler_B[0] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_0_selector_B); Bernoulli Rain_cond_Sprinkler_1_selector_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli48); // Message to 'Rain_cond_Sprinkler_1_selector' from Cases factor Rain_cond_Sprinkler_1_selector_B = CasesOp.BAverageConditional(Rain_cond_Sprinkler_1_selector_cases_B); // Message to 'Rain_cond_Sprinkler' from Copy factor Rain_cond_Sprinkler_B[1] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_1_selector_B); // Message to 'Rain_use' from EnterPartial factor Rain_use_B = GateEnterPartialOp <bool> .ValueAverageConditional <Bernoulli>(Rain_cond_Sprinkler_B, Sprinkler_selector_uses_F[1], Rain_use_F, new int[2] { 0, 1 }, Rain_use_B); if (this.cloudy) { // Message to 'Rain_marginal' from DerivedVariable factor this.Rain_marginal_F = DerivedVariableOp.MarginalAverageConditional <Bernoulli>(Rain_use_B, Rain_F, this.Rain_marginal_F); } if (!this.cloudy) { // Message to 'Rain_marginal' from DerivedVariable factor this.Rain_marginal_F = DerivedVariableOp.MarginalAverageConditional <Bernoulli>(Rain_use_B, vBernoulli49, this.Rain_marginal_F); } // Rain_marginal_F is now updated in all contexts this.Sprinkler_marginal_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli46); Bernoulli Sprinkler_selector_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli46); // Message to 'Sprinkler_selector' from Replicate factor Sprinkler_selector_B = ReplicateOp.DefAverageConditional <Bernoulli>(Sprinkler_selector_uses_B, Sprinkler_selector_B); if (this.cloudy) { // Message to 'Sprinkler_marginal' from DerivedVariable factor this.Sprinkler_marginal_F = DerivedVariableOp.MarginalAverageConditional <Bernoulli>(Sprinkler_selector_B, Sprinkler_F, this.Sprinkler_marginal_F); } if (!this.cloudy) { // Message to 'Sprinkler_marginal' from DerivedVariable factor this.Sprinkler_marginal_F = DerivedVariableOp.MarginalAverageConditional <Bernoulli>(Sprinkler_selector_B, vBernoulli45, this.Sprinkler_marginal_F); } // Sprinkler_marginal_F is now updated in all contexts this.Changed_Cloudy_WetGrass_iterationsDone = 1; }
/// <inheritdoc /> protected override bool OnSendInMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: ClearState(); break; case MessageTypes.MarketData: { var mdMsg = (MarketDataMessage)message; if (mdMsg.IsSubscribe) { var transId = mdMsg.TransactionId; Message[] suspended = null; lock (_sync) { if (_allChilds.TryGetValue(transId, out var tuple)) { if (tuple.Second != SubscriptionStates.Stopped) { if (tuple.Second == SubscriptionStates.Finished) { RaiseNewOutMessage(new SubscriptionFinishedMessage { OriginalTransactionId = transId, }); return(true); } else { RaiseNewOutMessage(new SubscriptionResponseMessage { OriginalTransactionId = transId, Error = new InvalidOperationException(LocalizedStrings.SubscriptionInvalidState.Put(transId, tuple.Second)), }); } return(true); } var child = _parents[tuple.First].Child[mdMsg.SecurityId]; child.State = SubscriptionStates.Active; suspended = child.Suspended.CopyAndClear(); this.AddDebugLog("New ALL map (active): {0}/{1} TrId={2}", child.Origin.SecurityId, child.Origin.DataType2, mdMsg.TransactionId); } else { if (!IsSecurityRequired(mdMsg.DataType2) || mdMsg.SecurityId == default) { var existing = _parents.FirstOrDefault(p => p.Value.Origin.DataType2 == mdMsg.DataType2); if (existing.Value == null) { _parents.Add(transId, new ParentSubscription(mdMsg.TypedClone())); // do not specify security cause adapter doesn't require it mdMsg.SecurityId = default; } else { var childs = existing.Value.Child; if (mdMsg.SecurityId != default) { var child = childs.SafeAdd(mdMsg.SecurityId, key => new ChildSubscription(mdMsg.TypedClone())); child.Subscribers.Add(transId, mdMsg.TypedClone()); } else { foreach (var pair in childs) { pair.Value.Subscribers.Add(transId, mdMsg.TypedClone()); } } RaiseNewOutMessage(new SubscriptionResponseMessage { OriginalTransactionId = transId }); return(true); } } } } if (suspended != null) { RaiseNewOutMessage(new SubscriptionResponseMessage { OriginalTransactionId = transId }); this.AddDebugLog("Flush {0} suspended: {1}/{2}/{3}.", suspended.Length, mdMsg.SecurityId, mdMsg.DataType, mdMsg.TransactionId); foreach (var msg in suspended) { RaiseNewOutMessage(msg); } return(true); } } else { var childIds = ArrayHelper.Empty <long>(); lock (_sync) { if (_allChilds.TryGetAndRemove(mdMsg.OriginalTransactionId, out var tuple)) { var childs = _parents[tuple.First].Child; var childSubscription = childs.FirstOrDefault(p => p.Value.Origin.TransactionId == mdMsg.OriginalTransactionId); childs.Remove(childSubscription.Key); Exception error = null; if (childSubscription.Value == null) { error = new InvalidOperationException(LocalizedStrings.SubscriptionNonExist.Put(mdMsg.OriginalTransactionId)); } else if (!tuple.Second.IsActive()) { error = new InvalidOperationException(LocalizedStrings.SubscriptionInvalidState.Put(mdMsg.OriginalTransactionId, tuple.Second)); } RaiseNewOutMessage(new SubscriptionResponseMessage { OriginalTransactionId = mdMsg.OriginalTransactionId, Error = error, }); return(true); } if (_parents.TryGetAndRemove(mdMsg.OriginalTransactionId, out var tuple2)) { childIds = tuple2.Child.Values.Select(s => s.Origin.TransactionId).ToArray(); } } foreach (var id in childIds) { RaiseNewOutMessage(new SubscriptionFinishedMessage { OriginalTransactionId = id }); } } break; } } return(base.OnSendInMessage(message)); }
public void SubselectFetchCriteria() { ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); Parent p = new Parent("foo"); p.Children.Add(new Child("foo1")); p.Children.Add(new Child("foo2")); Parent q = new Parent("bar"); q.Children.Add(new Child("bar1")); q.Children.Add(new Child("bar2")); ArrayHelper.AddAll(q.MoreChildren, p.Children); s.Save(p); s.Save(q); t.Commit(); s.Close(); s = OpenSession(); t = s.BeginTransaction(); Sfi.Statistics.Clear(); IList parents = s.CreateCriteria(typeof(Parent)) .Add(Expression.Between("Name", "bar", "foo")) .AddOrder(Order.Desc("Name")) .List(); p = (Parent)parents[0]; q = (Parent)parents[1]; Assert.IsFalse(NHibernateUtil.IsInitialized(p.Children)); Assert.IsFalse(NHibernateUtil.IsInitialized(q.Children)); Assert.AreEqual(p.Children.Count, 2); Assert.IsTrue(NHibernateUtil.IsInitialized(p.Children[0])); Assert.IsTrue(NHibernateUtil.IsInitialized(q.Children)); Assert.AreEqual(q.Children.Count, 2); Assert.IsTrue(NHibernateUtil.IsInitialized(q.Children[0])); Assert.IsFalse(NHibernateUtil.IsInitialized(p.MoreChildren)); Assert.IsFalse(NHibernateUtil.IsInitialized(q.MoreChildren)); Assert.AreEqual(p.MoreChildren.Count, 0); Assert.IsTrue(NHibernateUtil.IsInitialized(q.MoreChildren)); Assert.AreEqual(q.MoreChildren.Count, 2); Assert.IsTrue(NHibernateUtil.IsInitialized(q.MoreChildren[0])); Assert.AreEqual(3, Sfi.Statistics.PrepareStatementCount); Child c = (Child)p.Children[0]; NHibernateUtil.Initialize(c.Friends); s.Delete(p); s.Delete(q); t.Commit(); s.Close(); }
/// <summary> /// Дуга в плоскости (x, y). Точка начала дуги - a, точка конца дуги - b /// </summary> /// <param name="a">начало дуги</param> /// <param name="b">конец дуги</param> public Arc(Vector2d a, Vector2d b, Vector2d cp, bool direction) { //init _endPoint = new ArrayHelper <Vector2d>(2); _CP = new Vector2d(0, 0); _Direction = false; _R = 0; _Theta = 0; _ThetaZero = 0; _length = 0; _vDirect = new Vector2d(0, 0); _vDirectNorm = new Vector2d(0, 0); _IsClosed = false; _endPoint[true] = a; _endPoint[false] = b; _CP = cp; _Direction = direction; if (_Direction) { _DirectionInt = 1; } else { _DirectionInt = -1; } _R = (_endPoint[true] - _CP).Length();//?? точно ли до точки b будет тот же радиус?? if (_R == 0) { return; } _Theta = Angle_V1_v2(_endPoint[true] - _CP, _endPoint[false] - _CP); if (_DirectionInt * Sign(_Theta) < 0) { _Theta = 2 * PI - Abs(_Theta); } _Theta = _DirectionInt * Abs(_Theta); _ThetaZero = Angle_V1_v2(X2dAxes, _endPoint[true] - _CP); if (Equal_V1_V2(_endPoint[true], _endPoint[false])) { _Theta = 2 * PI * _DirectionInt; _IsClosed = true; } else { _IsClosed = false; } _length = _R * Abs(_Theta); _vDirect = _endPoint[false] - _endPoint[true]; _vDirectNorm = _vDirect; _vDirectNorm.Norm(); }
private static QuoteChange[] DeserializeQuotes(BitArrayReader reader, QuoteMetaInfo metaInfo, bool useLong, bool nonAdjustPrice, bool largeDecimal) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (metaInfo == null) { throw new ArgumentNullException(nameof(metaInfo)); } var count = reader.ReadInt(); if (count == 0) { return(ArrayHelper.Empty <QuoteChange>()); } var is56 = metaInfo.Version >= MarketDataVersions.Version56; var is57 = metaInfo.Version >= MarketDataVersions.Version57; var is58 = metaInfo.Version >= MarketDataVersions.Version58; var quotes = new QuoteChange[count]; for (var i = 0; i < count; i++) { var prevPrice = metaInfo.FirstPrice; var price = reader.ReadPrice(ref prevPrice, metaInfo, useLong, nonAdjustPrice); metaInfo.FirstPrice = prevPrice; var volume = reader.ReadVolume(metaInfo, largeDecimal); var ordersCount = is56 ? reader.ReadNullableInt() : null; var condition = is57 ? (QuoteConditions)(reader.ReadNullableInt() ?? 0) : default; var quote = new QuoteChange(price, volume, ordersCount, condition); if (is58) { if (reader.Read()) { quote.Action = (QuoteChangeActions)reader.ReadInt(); } if (reader.Read()) { quote.StartPosition = reader.ReadInt(); } if (reader.Read()) { quote.EndPosition = reader.ReadInt(); } } quotes[i] = quote; } return(quotes); }