protected override void OnDelete(Entity item, out string message, ref Action <Entity> afterConfirm)
        {
            if (afterConfirm == null)
            {
                throw new ArgumentNullException(nameof(afterConfirm));
            }

            message = ((Position)item).Description;

            afterConfirm = currentItem =>
            {
                try
                {
                    var deletedItem = (Position)currentItem;


                    deletedItem.RowStatus = RecordStatus.DeletedRecord;

                    //Save to the Database
                    var dataWriter = new PositionDataWriter(App.CurrentUser.User.Username, deletedItem);
                    dataWriter.SaveChanges();

                    App.LogAction("Payroll Position", "Deleted Position: " + deletedItem.Description);

                    ItemDataCollection.Remove((Position)currentItem);
                }
                catch (Exception ex)
                {
                    MessageDialog.ShowError(ex, this);
                }
            };
        }
        public bool FileSave()
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (!DataIsValid())
                {
                    return(false);
                }

                ItemData.Code        = txtCode.Text.Trim();
                ItemData.Description = txtDescription.Text.Trim();

                var dataWriter = new PositionDataWriter(App.CurrentUser.User.Username, ItemData);
                dataWriter.SaveChanges();

                DirtyStatus.Clear();

                DialogResult = DialogResult.OK;

                return(true);
            }
            catch (Exception ex)
            {
                MessageDialog.ShowError(ex, this);
                return(false);
            }
        }
예제 #3
0
    static void publish(int domain_id, int sample_count, Route routeIn, Route.Bus busIn)
    {
        Random random       = new Random();
        int    randomNumber = random.Next(0, 100);

        // --- Create participant --- //

        /* To customize participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create publisher --- //

        /* To customize publisher QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        // --- Create topic --- //

        /* Register type before creating topic */
        System.String atype_name = AccidentTypeSupport.get_type_name();
        System.String ptype_name = PositionTypeSupport.get_type_name();
        try
        {
            AccidentTypeSupport.register_type(
                participant, atype_name);
            PositionTypeSupport.register_type(
                participant, ptype_name);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic atopic = participant.create_topic(
            "P3464_BHANDERSON: PT/ALR/ACC",
            atype_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        DDS.Topic ptopic = participant.create_topic(
            "P3464_BHANDERSON: PT/POS",
            ptype_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);

        if (atopic == null || ptopic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }


        // --- Create writer --- //

        /* To customize data writer QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DataWriter awriter = publisher.create_datawriter(
            atopic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        DDS.DataWriter pwriter = publisher.create_datawriter(
            ptopic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);

        if (awriter == null || pwriter == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        AccidentDataWriter Accident_writer =
            (AccidentDataWriter)awriter;
        PositionDataWriter Position_writer =
            (PositionDataWriter)pwriter;
        // --- Write --- //

        /* Create data sample for writing */
        Accident ainstance = AccidentTypeSupport.create_data();
        Position pinstance = PositionTypeSupport.create_data();

        if (ainstance == null || pinstance == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "(Accident|Position)TypeSupport.create_data error");
        }

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL;

        /*
         * instance_handle = Accident_writer.register_instance(instance);
         */



        int numPasses = 0;
        /* Main loop */
        int send_period = 4000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            if (count % routeIn.numStops == 0)
            {
                numPasses++;
            }
            if (numPasses > 3)
            {
                break;
            }

            Console.WriteLine("Writing Accident|Position, count {0}", count);

            /* Modify the data to be sent here */

            int traffic = random.Next(0, 100);
            if (traffic <= 25) // light 25%
            {
                pinstance.trafficConditions = "light";
                pinstance.timeBetweenStops  = (int)(Math.Ceiling(routeIn.timeBetweenStops * .75));
            }
            else if (traffic <= 50) // heavy 25%
            {
                pinstance.trafficConditions = "heavy";
                pinstance.timeBetweenStops  = (int)(routeIn.timeBetweenStops + Math.Ceiling(routeIn.timeBetweenStops * .25));
            }
            else // normal 50%
            {
                pinstance.trafficConditions = "normal";
                pinstance.timeBetweenStops  = routeIn.timeBetweenStops;
            }

            ainstance.timestamp  = DateTime.Now.ToString();
            ainstance.route      = routeIn.name;
            ainstance.vehicle    = busIn.id;
            ainstance.stopNumber = busIn.stop;

            pinstance.timestamp   = DateTime.Now.ToString();
            pinstance.route       = routeIn.name;
            pinstance.vehicle     = busIn.id;
            pinstance.stopNumber  = busIn.stop;
            pinstance.numStops    = routeIn.numStops;
            pinstance.fillInRatio = random.Next(0, 100);

            int aOccurs = random.Next(0, 100);

            if (aOccurs <= 10)
            {
                try
                {
                    Accident_writer.write(ainstance, ref instance_handle);
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("write error {0}", e);
                }
                pinstance.timeBetweenStops += 10;
            }

            send_period = pinstance.timeBetweenStops * 1000; // threads use milliseconds

            busIn.stop = (busIn.stop % routeIn.numStops) + 1;

            try
            {
                Position_writer.write(pinstance, ref instance_handle);
            }
            catch (DDS.Exception e)
            {
                Console.WriteLine("write error {0}", e);
            }

            System.Threading.Thread.Sleep(send_period);
        }

        /*
         * try {
         *  Accident_writer.unregister_instance(
         *      instance, ref instance_handle);
         * } catch(DDS.Exception e) {
         *  Console.WriteLine("unregister instance error: {0}", e);
         * }
         */

        // --- Shutdown --- //

        /* Delete data sample */
        try
        {
            AccidentTypeSupport.delete_data(ainstance);
            PositionTypeSupport.delete_data(pinstance);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine(
                "(Accident|Position)TypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }