Exemple #1
0
        /// <summary>
        /// The internal aggregate Step function callback, which wraps the raw context pointer and calls the virtual Step() method.
        /// WARNING: Must not throw exceptions.
        /// </summary>
        /// <remarks>
        /// This function takes care of doing the lookups and getting the important information put together to call the Step() function.
        /// That includes pulling out the user's contextData and updating it after the call is made.  We use a sorted list for this so
        /// binary searches can be done to find the data.
        /// </remarks>
        /// <param name="context">A raw context pointer</param>
        /// <param name="nArgs">Number of arguments passed in</param>
        /// <param name="argsptr">A pointer to the array of arguments</param>
        internal void StepCallback(IntPtr context, int nArgs, IntPtr argsptr)
        {
            try
            {
                AggregateData data = null;

                if (_base != null)
                {
                    IntPtr nAux = _base.AggregateContext(context);

                    if ((_contextDataList != null) &&
                        !_contextDataList.TryGetValue(nAux, out data))
                    {
                        data = new AggregateData();
                        _contextDataList[nAux] = data;
                    }
                }

                if (data == null)
                {
                    data = new AggregateData();
                }

                try
                {
                    _context = context;
                    Step(ConvertParams(nArgs, argsptr),
                         data._count, ref data._data); /* throw */
                }
                finally
                {
                    data._count++;
                }
            }
#if !PLATFORM_COMPACTFRAMEWORK
            catch (Exception e) /* NOTE: Must catch ALL. */
            {
                try
                {
                    if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                    {
                        SQLiteLog.LogMessage(COR_E_EXCEPTION, String.Format(
                                                 CultureInfo.CurrentCulture,
                                                 "Caught exception in \"Step\" method: {1}",
                                                 e)); /* throw */
                    }
                }
                catch
                {
                    // do nothing.
                }
            }
#else
            catch /* NOTE: Must catch ALL. */
            {
                // do nothing (Windows CE).
            }
#endif
        }
        private static void Aggregate(AggregateData agg, double value)
        {
            switch (agg.AggregateType)
            {
            case ColumnAggregateType.Sum:
                agg.Value = (agg.Value ?? 0) + value;
                break;

            case ColumnAggregateType.Count:
                agg.Count++;
                break;

            case ColumnAggregateType.Avg:
                agg.Value = (agg.Value ?? 0) + value;
                agg.Count++;
                break;

            case ColumnAggregateType.Max:
                agg.Value = agg.Value == null ? value : Math.Max(agg.Value.Value, value);
                break;

            case ColumnAggregateType.Min:
                agg.Value = agg.Value == null ? value : Math.Min(agg.Value.Value, value);
                break;
            }
        }
Exemple #3
0
        private List <string> MergeAllListData(AggregateData ad)
        {
            List <string> devAndQa     = ad.DevData.Union(ad.QaData).ToList();
            List <string> qtsAndProd   = ad.QtsData.Union(ad.ProdData).ToList();
            List <string> environments = devAndQa.Union(qtsAndProd).ToList();
            List <string> fullVarsList = ad.GlobalData.Union(environments).ToList();

            return(fullVarsList);
        }
Exemple #4
0
 void SetAggregation(Table.AggregateType type)
 {
     if (shiftDown)
     {
         AggregateData.Insert(SelectedColumn + 1, new Table.AggregateData(AggregateData[SelectedColumn].Column, type));
         ++SelectedColumn;
     }
     else
     {
         AggregateData[SelectedColumn].Aggregation = type;
     }
 }
Exemple #5
0
        /// <summary>
        /// The internal aggregate Step function callback, which wraps the raw context pointer and calls the virtual Step() method.
        /// </summary>
        /// <remarks>
        /// This function takes care of doing the lookups and getting the important information put together to call the Step() function.
        /// That includes pulling out the user's contextData and updating it after the call is made.  We use a sorted list for this so
        /// binary searches can be done to find the data.
        /// </remarks>
        /// <param name="context">A raw context pointer</param>
        /// <param name="nArgs">Number of arguments passed in</param>
        /// <param name="argsptr">A pointer to the array of arguments</param>
        internal void StepCallback(SqliteContextHandle context, int nArgs, SqliteValueHandle[] argsptr)
        {
            SqliteValueHandle nAux;
            AggregateData     data;

            nAux = (SqliteValueHandle)_base.AggregateContext(context);
            if (_contextDataList.TryGetValue(nAux, out data) == false)
            {
                data = new AggregateData();
                _contextDataList[nAux] = data;
            }

            try {
                _context = context;
                Step(ConvertParams(nArgs, argsptr), data._count, ref data._data);
            }
            finally {
                data._count++;
            }
        }
Exemple #6
0
        internal void StepCallback(IntPtr context, int nArgs, IntPtr argsptr)
        {
            AggregateData data;
            long          key = (long)this._base.AggregateContext(context);

            if (!this._contextDataList.TryGetValue(key, out data))
            {
                data = new AggregateData();
                this._contextDataList[key] = data;
            }
            try
            {
                this._context = context;
                this.Step(this.ConvertParams(nArgs, argsptr), data._count, ref data._data);
            }
            finally
            {
                data._count++;
            }
        }
        /// <summary>
        /// The internal aggregate Step function callback, which wraps the raw context pointer and calls the virtual Step() method.
        /// </summary>
        /// <remarks>
        /// This function takes care of doing the lookups and getting the important information put together to call the Step() function.
        /// That includes pulling out the user's contextData and updating it after the call is made.  We use a sorted list for this so
        /// binary searches can be done to find the data.
        /// </remarks>
        /// <param name="context">A raw context pointer</param>
        /// <param name="nArgs">Number of arguments passed in</param>
        /// <param name="argsptr">A pointer to the array of arguments</param>
        internal void StepCallback(IntPtr context, int nArgs, IntPtr argsptr)
        {
            long          nAux;
            AggregateData data;

            nAux = (long)_base.AggregateContext(context);
            if (_contextDataList.TryGetValue(nAux, out data) == false)
            {
                data = new AggregateData();
                _contextDataList[nAux] = data;
            }

            try
            {
                _context = context;
                Step(ConvertParams(nArgs, argsptr), data._count, ref data._data);
            }
            finally
            {
                data._count++;
            }
        }
Exemple #8
0
        public void AddAggregateData(AggregateData aggregateData)
        {
            Logger.Info("SQLiteFileRepository", "AddSensorData Get started");
            AggregateData lastData;

            if (_dataCache.TryGetValue(aggregateData.SenderMAC, out lastData))
            {
                if (aggregateData.Temperature == lastData.Temperature && aggregateData.Humidity == lastData.Humidity &&
                    aggregateData.BatteryLevel == lastData.BatteryLevel && lastData.TScheduledTarget == aggregateData.TScheduledTarget &&
                    aggregateData.TValve == lastData.TValve)
                {
                    Logger.Info("SQLiteFileRepository", "AddSensorData Data skipped");
                    Logger.Info("SQLiteFileRepository", "AddSensorData Get finished");
                    return;
                }
            }

            ExecuteOnThreadPool(() => {
                GetDbInstance().Insert(aggregateData);
            });

            _dataCache[aggregateData.SenderMAC] = aggregateData;
            Logger.Info("SQLiteFileRepository", "AddSensorData Get finished");
        }
Exemple #9
0
        public AggregateData IncrementAggregate(AggregateData data, EveType type, float value, int damage, bool kills)
        {
            if (kills)
            {
                data.KillsTotal       += 1;
                data.ISKKilledTotal   += value;
                data.DamageDealtTotal += damage;

                if (IsStructure(type.TypeId))
                {
                    data.KillsStructure       += 1;
                    data.ISKKilledStructure   += value;
                    data.DamageDealtStructure += damage;

                    if (IsMediumStructure(type.TypeId))
                    {
                        data.MediumStructureKills += 1;
                    }
                    else if (IsLargeStructure(type.TypeId))
                    {
                        data.LargeStructureKills += 1;
                    }
                    else if (IsXLargeStructure(type.TypeId))
                    {
                        data.XLStructureKills += 1;
                    }
                }
                else if (IsCapital(type))
                {
                    data.KillsCapital       += 1;
                    data.ISKKilledCapital   += value;
                    data.DamageDealtCapital += damage;

                    if (IsDreadnought(type))
                    {
                        data.DreadKills += 1;
                    }
                    else if (IsCarrier(type))
                    {
                        data.CarrierKills += 1;
                    }
                    else if (IsForceAuxiliary(type))
                    {
                        data.FaxesKills += 1;
                    }
                    else if (IsRorqual(type))
                    {
                        data.RorqualKills += 1;
                    }
                }
                else if (IsPod(type.TypeId))
                {
                    data.KillsPod       += 1;
                    data.ISKKilledPod   += value;
                    data.DamageDealtPod += damage;
                }
                else
                {
                    data.KillsSubCap       += 1;
                    data.ISKKilledSubCap   += value;
                    data.DamageDealtSubCap += damage;
                }
            }
            else
            {
                data.LossesTotal      += 1;
                data.ISKLostTotal     += value;
                data.DamageTakenTotal += damage;

                if (IsStructure(type.TypeId))
                {
                    data.LossesStructure      += 1;
                    data.ISKLostStructure     += value;
                    data.DamageTakenStructure += damage;

                    if (IsMediumStructure(type.TypeId))
                    {
                        data.MediumStructureLosses += 1;
                    }
                    else if (IsLargeStructure(type.TypeId))
                    {
                        data.LargeStructureLosses += 1;
                    }
                    else if (IsXLargeStructure(type.TypeId))
                    {
                        data.XLStructureLosses += 1;
                    }
                }
                else if (IsCapital(type))
                {
                    data.LossesCapital      += 1;
                    data.ISKLostCapital     += value;
                    data.DamageTakenCapital += damage;

                    if (IsDreadnought(type))
                    {
                        data.DreadLosses += 1;
                    }
                    else if (IsCarrier(type))
                    {
                        data.CarrierLosses += 1;
                    }
                    else if (IsForceAuxiliary(type))
                    {
                        data.FaxesLosses += 1;
                    }
                    else if (IsRorqual(type))
                    {
                        data.RorqualLosses += 1;
                    }
                }
                else if (IsPod(type.TypeId))
                {
                    data.LossesPod      += 1;
                    data.ISKLostPod     += value;
                    data.DamageTakenPod += damage;
                }
                else
                {
                    data.LossesSubCap      += 1;
                    data.ISKLostSubCap     += value;
                    data.DamageTakenSubCap += damage;
                }
            }

            return(data);
        }
Exemple #10
0
    static void Main(string[] args)
    {
        int dataSize = 10000000;
        using (MPI.Environment env = new MPI.Environment(ref args))
        {
            if (Communicator.world.Size != 2)
            {
                System.Console.WriteLine("The Datatypes test must be run with two processes.");
                System.Console.WriteLine("Try: mpiexec -np 2 datatypes.exe");
            }
            else if (Communicator.world.Rank == 0)
            {
                // Send an object that contains a "fixed" field
                Dimensions dims;
                unsafe
                {
                    for (int i = 0; i < 11; ++i)
                        dims.values[i] = (float)i;
                }
                Communicator.world.Send(dims, 1, 0);

                // Send an object that contains non-public fields
                Secretive secret = new Secretive(17, 25);
                Communicator.world.Send(secret, 1, 1);

                // Send an object with complex data
                AggregateData aggregate = new AggregateData(dataSize);
                Communicator.world.Send(aggregate, 1, 2);

                // Send an object with a private type
                Hidden hidden = new Hidden(17, 25);
                Communicator.world.Send(hidden, 1, 3);

                // Send a struct that requires serialization.
                ContainsBool containsBool = new ContainsBool(17);
                Communicator.world.Send(containsBool, 1, 4);
            }
            else
            {
                // Receive and check an object that contains a "fixed" field
                Dimensions dims;
                Communicator.world.Receive(0, 0, out dims);
                unsafe
                {
                    for (int i = 0; i < 11; ++i)
                    {
                        System.Console.WriteLine(dims.values[i].ToString() + " ");
                        Debug.Assert(dims.values[i] == (float)i);
                    }
                }

                // Receive and check an object that contains non-public fields
                Secretive secret;
                Communicator.world.Receive(0, 1, out secret);
                System.Console.WriteLine(secret);
                Debug.Assert(secret == new Secretive(17, 25));

                // Receive and check the "complex data"
                AggregateData aggregate = Communicator.world.Receive<AggregateData>(0, 2);
                if (!aggregate.Check(dataSize))
                {
                    System.Console.Error.WriteLine("Error: complex data not properly transmitted");
                    MPI.Environment.Abort(1);
                }

                // Receive and check an object with a private type
                Hidden hidden;
                Communicator.world.Receive(0, 3, out hidden);
                System.Console.WriteLine(hidden);
                Debug.Assert(hidden == new Hidden(17, 25));

                // Receive and check a struct that requires serialization
                ContainsBool containsBool;
                Communicator.world.Receive(0, 4, out containsBool);
                System.Console.WriteLine(containsBool);
                Debug.Assert(containsBool == new ContainsBool(17));
            }

        }
    }
Exemple #11
0
    /// <summary>
    /// The internal aggregate Step function callback, which wraps the raw context pointer and calls the virtual Step() method.
    /// </summary>
    /// <remarks>
    /// This function takes care of doing the lookups and getting the important information put together to call the Step() function.
    /// That includes pulling out the user's contextData and updating it after the call is made.  We use a sorted list for this so
    /// binary searches can be done to find the data.
    /// </remarks>
    /// <param name="context">A raw context pointer</param>
    /// <param name="nArgs">Number of arguments passed in</param>
    /// <param name="argsptr">A pointer to the array of arguments</param>
    internal void StepCallback(IntPtr context, int nArgs, IntPtr argsptr)
    {
      long nAux;
      AggregateData data;

      nAux = (long)_base.AggregateContext(context);
      if (_contextDataList.TryGetValue(nAux, out data) == false)
      {
        data = new AggregateData();
        _contextDataList[nAux] = data;
      }

      try
      {
        _context = context;
        Step(ConvertParams(nArgs, argsptr), data._count, ref data._data);
      }
      finally
      {
        data._count++;
      }
    }
Exemple #12
0
        void TablePreviewKeyDown(object sender, KeyEventArgs e)
        {
            e.Handled = true;
            var key = e.Key == Key.System ? e.SystemKey : e.Key;

            switch (key)
            {
            case Key.G: SetAggregation(Table.AggregateType.Group); break;

            case Key.A: SetAggregation(Table.AggregateType.All); break;

            case Key.D: SetAggregation(Table.AggregateType.Distinct); break;

            case Key.C: SetAggregation(Table.AggregateType.Count); break;

            case Key.O: SetAggregation(Table.AggregateType.CountNonNull); break;

            case Key.S: SetAggregation(Table.AggregateType.Sum); break;

            case Key.V: SetAggregation(Table.AggregateType.Average); break;

            case Key.N: SetAggregation(Table.AggregateType.Min); break;

            case Key.X: SetAggregation(Table.AggregateType.Max); break;

            case Key.Delete:
                if (Table.NumColumns != 0)
                {
                    AggregateData.RemoveAt(SelectedColumn);
                }
                break;

            case Key.Space:
            {
                var current = SortData.FirstOrDefault(data => data.Column == SelectedColumn);
                if (!shiftDown)
                {
                    SortData = SortData.Where(data => data == current).ToList();
                }
                if (current == null)
                {
                    SortData.Add(new Table.SortData(SelectedColumn));
                }
                else
                {
                    current.Ascending = !current.Ascending;
                }
            }
            break;

            case Key.Left:
                if ((controlDown) || (altDown))
                {
                    if (SelectedColumn != 0)
                    {
                        AggregateData.Insert(SelectedColumn - 1, AggregateData[SelectedColumn]);
                        AggregateData.RemoveAt(SelectedColumn + 1);
                        --SelectedColumn;
                    }
                }
                else
                {
                    e.Handled = false;
                }
                break;

            case Key.Right:
                if ((controlDown) || (altDown))
                {
                    if (SelectedColumn != Table.NumColumns - 1)
                    {
                        AggregateData.Insert(SelectedColumn + 2, AggregateData[SelectedColumn]);
                        AggregateData.RemoveAt(SelectedColumn);
                        ++SelectedColumn;
                    }
                }
                else
                {
                    e.Handled = false;
                }
                break;

            default: e.Handled = false; break;
            }

            if (e.Handled)
            {
                SetupTable();
            }
        }
Exemple #13
0
        private void StartExecutionLoop()
        {
            _executorThd = new Thread(async() =>
            {
                foreach (var item in _queue.GetConsumingEnumerable())
                {
                    try
                    {
                        AggregateData aggregateData = new AggregateData();

                        var masterData = _repository.LoadSensorMasterData().Where(x => x.SenderMAC == item.SenderMAC).First();

                        aggregateData.IngestionTimestamp = item.IngestionTimestamp;
                        aggregateData.SenderMAC          = item.SenderMAC;
                        aggregateData.Temperature        = item.Temperature;
                        aggregateData.Humidity           = item.Humidity;
                        aggregateData.BatteryLevel       = item.BatteryLevel;

                        if (masterData.NetatmoLink)
                        {
                            var token    = await _netatmoCloud.GetToken(_appsettings.ClientId, _appsettings.ClientSecret, _appsettings.Username, _appsettings.Password);
                            var schedule = await _netatmoCloud.GetActiveRoomSchedule(_appsettings.HomeId, token.Access_token);
                            if (schedule != null)
                            {
                                var roomScheduled = schedule.RoomSchedules.Where(x => x.RoomId == masterData.RoomId).FirstOrDefault();
                                aggregateData.TScheduledTarget = roomScheduled.TScheduledTarget;

                                var currentStatus = (await _netatmoCloud.GetRoomStatus(_appsettings.HomeId, token.Access_token, schedule.EndTime))?.Where(x => x.RoomId == masterData.RoomId).FirstOrDefault();
                                if (currentStatus != null)
                                {
                                    var newTarget = Number.HalfRound(currentStatus.TValve + roomScheduled.TScheduledTarget - item.Temperature);

                                    aggregateData.TCalculateTarget = newTarget;
                                    aggregateData.TCurrentTarget   = currentStatus.TCurrentTarget;
                                    aggregateData.TValve           = currentStatus.TValve;

                                    if ((Math.Abs(newTarget - currentStatus.TCurrentTarget) >= 0.5) && masterData.NetatmoSetTemp && !currentStatus.IsAway && currentStatus.TCurrentTarget > 15) //Less Then 15 is used as manual set
                                    {
                                        var result = await _netatmoCloud.SetThemp(_appsettings.HomeId, currentStatus.RoomId, newTarget, schedule.EndTime, token.Access_token);
                                        aggregateData.SetTempSended = true;
                                        Logger.Message("ProcessData", $"Set NewTarget!!: {result}");
                                    }
                                    Logger.Message("ProcessData", $"Time:{item.IngestionTimestamp} - Room:{masterData.SenderName} - IsAway:{currentStatus.IsAway} - RemoteTemp:{item.Temperature} - ValveTemp:{currentStatus.TValve} - CurrentTarget:{currentStatus.TCurrentTarget} - CalculateTarget: {newTarget} - ScheduledTarget: {roomScheduled.TScheduledTarget} - Humidity:{item.Humidity} - BatteryLevel:{item.BatteryLevel}");
                                }
                                else
                                {
                                    //Logger.Warn("ProcessData", $"The is no status for roomid:{masterData.RoomId} - MAC:{masterData.SenderMAC} - Name: {masterData.SenderName}");
                                }
                            }
                            else
                            {
                                Logger.Warn("ProcessData", "schedule is null");
                            }
                        }
                        _sharedData.LastSensorData[item.SenderMAC] = (Temperature: item.Temperature,
                                                                      Humidity: item.Humidity,
                                                                      IngestionTime: DateTime.ParseExact(item.IngestionTimestamp, "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture),
                                                                      BatteryLevel: item.BatteryLevel,
                                                                      SenderName: masterData.SenderName,
                                                                      ScheduledTemperature: aggregateData.TScheduledTarget);

                        _repository.AddAggregateData(aggregateData);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("ProcessData", "Error on execution. " + ex.Message);
                    }
                }
            });

            _executorThd.Start();
        }
Exemple #14
0
        public void UpsertVariable(NewVariable newVariableInfo, VarLists variableLists)
        {
            newVarInfo = newVariableInfo;
            varLists   = variableLists;
            var ad = new AggregateData();

            if (newVariableInfo.isEnvVar)
            {
                bool matchFound = false;
                ad.GlobalData = CreateVariableFileContents(varLists.GlobalList, newVarInfo.GlobalValue, out matchFound, true);
                if (matchFound)
                {
                    throw new Exception("Variable meant for environment variables already exists in global variables.");
                }
                ad.DevData  = CreateVariableFileContents(varLists.DevList, newVarInfo.DevValue, out matchFound);
                ad.QaData   = CreateVariableFileContents(varLists.QaList, newVarInfo.QaValue, out matchFound);
                ad.QtsData  = CreateVariableFileContents(varLists.QtsList, newVarInfo.QtsValue, out matchFound);
                ad.ProdData = CreateVariableFileContents(varLists.ProdList, newVarInfo.ProdValue, out matchFound);

                // Convert lists to strings
                ad.GlobalText = CreateVariableText(ad.GlobalData);
                ad.DevText    = CreateVariableText(ad.DevData);
                ad.QaText     = CreateVariableText(ad.QaData);
                ad.QtsText    = CreateVariableText(ad.QtsData);
                ad.ProdText   = CreateVariableText(ad.ProdData);

                // Generate VARS files
                ad.VariableNames = MergeAllListData(ad);
                ad.VariableText  = CreateVarsFileData(ad.VariableNames);

                fileControl.SaveFileWithContent(@"dev.tfvars", ad.DevText);
                fileControl.SaveFileWithContent(@"qa.tfvars", ad.QaText);
                fileControl.SaveFileWithContent(@"qts.tfvars", ad.QtsText);
                fileControl.SaveFileWithContent(@"prod.tfvars", ad.ProdText);
                fileControl.SaveFileWithContent(@"dev\vars.tf", ad.VariableText);
                fileControl.SaveFileWithContent(@"qa\vars.tf", ad.VariableText);
                fileControl.SaveFileWithContent(@"qts\vars.tf", ad.VariableText);
                fileControl.SaveFileWithContent(@"prod\vars.tf", ad.VariableText);
            }
            else
            {
                bool matchFound = false;
                ad.DevData  = CreateVariableFileContents(varLists.DevList, newVarInfo.DevValue, out matchFound, true);
                ad.QaData   = CreateVariableFileContents(varLists.QaList, newVarInfo.QaValue, out matchFound, true);
                ad.QtsData  = CreateVariableFileContents(varLists.QtsList, newVarInfo.QtsValue, out matchFound, true);
                ad.ProdData = CreateVariableFileContents(varLists.ProdList, newVarInfo.ProdValue, out matchFound, true);
                if (matchFound)
                {
                    throw new Exception("Variable meant for global variables already exists in environment variables.");
                }
                ad.GlobalData = CreateVariableFileContents(varLists.GlobalList, newVarInfo.GlobalValue, out matchFound);

                // Convert lists to strings
                ad.GlobalText = CreateVariableText(ad.GlobalData);
                // Generate VARS files
                ad.VariableNames = MergeAllListData(ad);
                ad.VariableText  = CreateVarsFileData(ad.VariableNames);

                if (string.IsNullOrWhiteSpace(ad.GlobalText) || string.IsNullOrWhiteSpace(ad.VariableText))
                {
                    throw new Exception("Something went horribly wrong! No files saved.");
                }
                fileControl.SaveFileWithContent(@"global.tfvars", ad.GlobalText);
                fileControl.SaveFileWithContent(@"dev\vars.tf", ad.VariableText);
                fileControl.SaveFileWithContent(@"qa\vars.tf", ad.VariableText);
                fileControl.SaveFileWithContent(@"qts\vars.tf", ad.VariableText);
                fileControl.SaveFileWithContent(@"prod\vars.tf", ad.VariableText);
            }
        }
Exemple #15
0
    static void Main(string[] args)
    {
        int dataSize = 10000000;

        using (MPI.Environment env = new MPI.Environment(ref args))
        {
            if (Communicator.world.Size != 2)
            {
                System.Console.WriteLine("The Datatypes test must be run with two processes.");
                System.Console.WriteLine("Try: mpiexec -np 2 datatypes.exe");
            }
            else if (Communicator.world.Rank == 0)
            {
                // Send an object that contains a "fixed" field
                Dimensions dims;
                unsafe
                {
                    for (int i = 0; i < 11; ++i)
                    {
                        dims.values[i] = (float)i;
                    }
                }
                Communicator.world.Send(dims, 1, 0);

                // Send an object that contains non-public fields
                Secretive secret = new Secretive(17, 25);
                Communicator.world.Send(secret, 1, 1);

                // Send an object with complex data
                AggregateData aggregate = new AggregateData(dataSize);
                Communicator.world.Send(aggregate, 1, 2);

                // Send an object with a private type
                Hidden hidden = new Hidden(17, 25);
                Communicator.world.Send(hidden, 1, 3);

                // Send a struct that requires serialization.
                ContainsBool containsBool = new ContainsBool(17);
                Communicator.world.Send(containsBool, 1, 4);
            }
            else
            {
                // Receive and check an object that contains a "fixed" field
                Dimensions dims;
                Communicator.world.Receive(0, 0, out dims);
                unsafe
                {
                    for (int i = 0; i < 11; ++i)
                    {
                        System.Console.WriteLine(dims.values[i].ToString() + " ");
                        Debug.Assert(dims.values[i] == (float)i);
                    }
                }

                // Receive and check an object that contains non-public fields
                Secretive secret;
                Communicator.world.Receive(0, 1, out secret);
                System.Console.WriteLine(secret);
                Debug.Assert(secret == new Secretive(17, 25));

                // Receive and check the "complex data"
                AggregateData aggregate = Communicator.world.Receive <AggregateData>(0, 2);
                if (!aggregate.Check(dataSize))
                {
                    System.Console.Error.WriteLine("Error: complex data not properly transmitted");
                    MPI.Environment.Abort(1);
                }

                // Receive and check an object with a private type
                Hidden hidden;
                Communicator.world.Receive(0, 3, out hidden);
                System.Console.WriteLine(hidden);
                Debug.Assert(hidden == new Hidden(17, 25));

                // Receive and check a struct that requires serialization
                ContainsBool containsBool;
                Communicator.world.Receive(0, 4, out containsBool);
                System.Console.WriteLine(containsBool);
                Debug.Assert(containsBool == new ContainsBool(17));
            }
        }
    }
    /// <summary>
    /// The internal aggregate Step function callback, which wraps the raw context pointer and calls the virtual Step() method.
    /// </summary>
    /// <remarks>
    /// This function takes care of doing the lookups and getting the important information put together to call the Step() function.
    /// That includes pulling out the user's contextData and updating it after the call is made.  We use a sorted list for this so
    /// binary searches can be done to find the data.
    /// </remarks>
    /// <param name="context">A raw context pointer</param>
    /// <param name="nArgs">Number of arguments passed in</param>
    /// <param name="argsptr">A pointer to the array of arguments</param>
    internal void StepCallback(SqliteContextHandle context, int nArgs, SqliteValueHandle[] argsptr)
    {
      SqliteValueHandle nAux;
      AggregateData data;

      nAux = (SqliteValueHandle)_base.AggregateContext(context);
      if (_contextDataList.TryGetValue(nAux, out data) == false)
      {
        data = new AggregateData();
        _contextDataList[nAux] = data;
      }

      try
      {
        _context = context;
        Step(ConvertParams(nArgs, argsptr), data._count, ref data._data);
      }
      finally
      {
        data._count++;
      }
    }
    /// <summary>
    /// The internal aggregate Step function callback, which wraps the raw context pointer and calls the virtual Step() method.
    /// WARNING: Must not throw exceptions.
    /// </summary>
    /// <remarks>
    /// This function takes care of doing the lookups and getting the important information put together to call the Step() function.
    /// That includes pulling out the user's contextData and updating it after the call is made.  We use a sorted list for this so
    /// binary searches can be done to find the data.
    /// </remarks>
    /// <param name="context">A raw context pointer</param>
    /// <param name="nArgs">Number of arguments passed in</param>
    /// <param name="argsptr">A pointer to the array of arguments</param>
    internal void StepCallback(IntPtr context, int nArgs, IntPtr argsptr)
    {
        try
        {
            AggregateData data = null;

            if (_base != null)
            {
                IntPtr nAux = _base.AggregateContext(context);

                if ((_contextDataList != null) &&
                    !_contextDataList.TryGetValue(nAux, out data))
                {
                    data = new AggregateData();
                    _contextDataList[nAux] = data;
                }
            }

            if (data == null)
                data = new AggregateData();

            try
            {
                _context = context;
                Step(ConvertParams(nArgs, argsptr),
                    data._count, ref data._data); /* throw */
            }
            finally
            {
                data._count++;
            }
        }
#if !PLATFORM_COMPACTFRAMEWORK
        catch (Exception e) /* NOTE: Must catch ALL. */
        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(COR_E_EXCEPTION, String.Format(
                        "Caught exception in \"Step\" method: {1}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
            }
        }
#else
        catch /* NOTE: Must catch ALL. */
        {
            // do nothing (Windows CE).
        }
#endif
    }
    /// <summary>
    /// The internal aggregate Step function callback, which wraps the raw context pointer and calls the virtual Step() method.
    /// WARNING: Must not throw exceptions.
    /// </summary>
    /// <remarks>
    /// This function takes care of doing the lookups and getting the important information put together to call the Step() function.
    /// That includes pulling out the user's contextData and updating it after the call is made.  We use a sorted list for this so
    /// binary searches can be done to find the data.
    /// </remarks>
    /// <param name="context">A raw context pointer</param>
    /// <param name="nArgs">Number of arguments passed in</param>
    /// <param name="argsptr">A pointer to the array of arguments</param>
    internal void StepCallback(IntPtr context, int nArgs, IntPtr argsptr)
    {
        try
        {
            AggregateData data = null;

            if (_base != null)
            {
                IntPtr nAux = _base.AggregateContext(context);

                if ((_contextDataList != null) &&
                    !_contextDataList.TryGetValue(nAux, out data))
                {
                    data = new AggregateData();
                    _contextDataList[nAux] = data;
                }
            }

            if (data == null)
                data = new AggregateData();

            try
            {
                _context = context;
                Step(ConvertParams(nArgs, argsptr),
                    data._count, ref data._data); /* throw */
            }
            finally
            {
                data._count++;
            }
        }
        catch (Exception e) /* NOTE: Must catch ALL. */
        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                        "Caught exception in \"Step\" method: {1}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
            }
        }
    }