Esempio n. 1
0
    public static void Main()
    {
        // Create and initialize a new CollectionBase.
        Int16Collection myCollectionBase = new Int16Collection();

        // Add elements to the collection.
        myCollectionBase.Add((Int16)1);
        myCollectionBase.Add((Int16)2);
        myCollectionBase.Add((Int16)3);
        myCollectionBase.Add((Int16)5);
        myCollectionBase.Add((Int16)7);

        // <Snippet2>
        // Get the ICollection interface from the CollectionBase
        // derived class.
        ICollection myCollection = myCollectionBase;

        lock (myCollection.SyncRoot)
        {
            foreach (object item in myCollection)
            {
                // Insert your code here.
            }
        }
        // </Snippet2>
    }
Esempio n. 2
0
    public static void Main()
    {
        // Create and initialize a new CollectionBase.
        Int16Collection myI16 = new Int16Collection();

        // Add elements to the collection.
        myI16.Add((Int16)1);
        myI16.Add((Int16)2);
        myI16.Add((Int16)3);
        myI16.Add((Int16)5);
        myI16.Add((Int16)7);

        // Display the contents of the collection using foreach. This is the preferred method.
        Console.WriteLine("Contents of the collection (using foreach):");
        PrintValues1(myI16);

        // Display the contents of the collection using the enumerator.
        Console.WriteLine("Contents of the collection (using enumerator):");
        PrintValues2(myI16);

        // Display the contents of the collection using the Count property and the Item property.
        Console.WriteLine("Initial contents of the collection (using Count and Item):");
        PrintIndexAndValues(myI16);

        // Search the collection with Contains and IndexOf.
        Console.WriteLine("Contains 3: {0}", myI16.Contains(3));
        Console.WriteLine("2 is at index {0}.", myI16.IndexOf(2));
        Console.WriteLine();

        // Insert an element into the collection at index 3.
        myI16.Insert(3, (Int16)13);
        Console.WriteLine("Contents of the collection after inserting at index 3:");
        PrintIndexAndValues(myI16);

        // Get and set an element using the index.
        myI16[4] = 123;
        Console.WriteLine("Contents of the collection after setting the element at index 4 to 123:");
        PrintIndexAndValues(myI16);

        // Remove an element from the collection.
        myI16.Remove((Int16)2);

        // Display the contents of the collection using the Count property and the Item property.
        Console.WriteLine("Contents of the collection after removing the element 2:");
        PrintIndexAndValues(myI16);
    }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Int16Collection myI16 = new Int16Collection();

            myI16.Add((Int16)1);
            //加入2,3,5,7作为元素
            Console.WriteLine("Initial contents of the collection:");
            PrintIndexAndValues(myI16);
            Console.WriteLine("Contains 3:{0}", myI16.Contains(3));
            Console.WriteLine("2 is at index {0}.", myI16.IndexOf(2));
            Console.WriteLine();
            myI16.Insert(3, (Int16)13);
            Console.WriteLine("Contents of the collection after inserting at index 3:");
            PrintIndexAndValues(myI16);
            myI16[4] = 123;
            Console.WriteLine("Contents of the collection after setting the element at index 4 to 123:");
            PrintIndexAndValues(myI16);
            myI16.Remove((Int16)2);
            Console.WriteLine("Contents of the collection after removing the element 2:");
            for (int i = 0; i < myI16.Count; i++)
            {
                Console.WriteLine(" [{0}]: {1}", myI16[i]);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Reads the TOU Schedule from the meter into a TOUSchedule object
        /// </summary>
        /// <returns>The TOU Schedule object.</returns>
        // Revision History
        // MM/DD/YY who Version Issue#  Description
        // -------- --- ------- ------  ---------------------------------------
        // 01/04/07 RCG 8.00.04		    Made more generic and promoted from CENTRON_AMI
        // 04/13/07 RCG 8.00.31 2919    Adding support for Output events.
        // 03/10/08 KRC 1.50.02         Adding Ability to create TOU Schedule from EDL file
        //  12/03/10 DEO 9.70.13        Promoted from ANSIDevice

        public static CTOUSchedule ReadCENTRON2TOUSchedule(TOUConfig TOUConfigTable, CalendarConfig CalendarConfigTable)
        {
            Int16Collection NormalDays;
            Int16Collection HolidayDays;
            ANSITOUSchedule TOUSchedule = new ANSITOUSchedule();

            TOUConfig.TOU_Season CurrentSeason;
            int iNextEventCounter = 0;
            int iPatternID        = 0;

            try
            {
                // First set up the typical week so that we know which day corresponds to which daytype
                if (TOUConfigTable.NumberOfSupportedSeasons > 0)
                {
                    CurrentSeason = TOUConfigTable.Seasons[0];

                    // We have to assume that the Typical week is that same for all seasons. NOTE: The Day to Daytype is 1 based
                    // so we need to subtract 1
                    TOUSchedule.TypicalWeek[(int)eTypicalDay.SUNDAY]    = TOUSchedule.NormalDays[CurrentSeason.TypicalSunday];
                    TOUSchedule.TypicalWeek[(int)eTypicalDay.MONDAY]    = TOUSchedule.NormalDays[CurrentSeason.TypicalMonday];
                    TOUSchedule.TypicalWeek[(int)eTypicalDay.TUESDAY]   = TOUSchedule.NormalDays[CurrentSeason.TypicalTuesday];
                    TOUSchedule.TypicalWeek[(int)eTypicalDay.WEDNESDAY] = TOUSchedule.NormalDays[CurrentSeason.TypicalWednesday];
                    TOUSchedule.TypicalWeek[(int)eTypicalDay.THURSDAY]  = TOUSchedule.NormalDays[CurrentSeason.TypicalThursday];
                    TOUSchedule.TypicalWeek[(int)eTypicalDay.FRIDAY]    = TOUSchedule.NormalDays[CurrentSeason.TypicalFriday];
                    TOUSchedule.TypicalWeek[(int)eTypicalDay.SATURDAY]  = TOUSchedule.NormalDays[CurrentSeason.TypicalSaturday];
                }

                for (int iSeasonCounter = 0; iSeasonCounter < TOUConfigTable.NumberOfSupportedSeasons; iSeasonCounter++)
                {
                    // Get the Season that we are dealing with.
                    CurrentSeason = TOUConfigTable.Seasons[iSeasonCounter];
                    NormalDays    = new Int16Collection();
                    HolidayDays   = new Int16Collection();

                    for (int iDayTypeCounter = 0; iDayTypeCounter < TOUConfigTable.DayTypesPerSeason; iDayTypeCounter++)
                    {
                        CSwitchPointCollection SPColl = new CSwitchPointCollection();
                        for (int iEventCounter = 0; iEventCounter < TOUConfigTable.EventsPerDayType; iEventCounter++)
                        {
                            // Get the Day Event
                            TOUConfig.DayEvent DayEvent = CurrentSeason.TimeOfDayEvents[iDayTypeCounter, iEventCounter];
                            ushort             usEvent  = DayEvent.Event;
                            if (usEvent != (ushort)TOUConfig.DayEvent.TOUEvent.NoMoreChanges)
                            {
                                if (IsRateChangeEvent(usEvent) == true)
                                {
                                    // We have a valid Event, so proceed with createing a SwitchPoint
                                    int iHour      = (int)DayEvent.Hour;
                                    int iMinute    = (int)DayEvent.Minute;
                                    int iStartTime = (iHour * 60) + iMinute;
                                    int iEndTime   = 24 * 60;

                                    iNextEventCounter = iEventCounter + 1;

                                    while (iNextEventCounter < TOUConfigTable.EventsPerDayType)
                                    {
                                        TOUConfig.DayEvent NextDayEvent = CurrentSeason.TimeOfDayEvents[iDayTypeCounter, iNextEventCounter];

                                        if (IsRateChangeEvent(NextDayEvent.Event) == true)
                                        {
                                            iHour    = (int)NextDayEvent.Hour;
                                            iMinute  = (int)NextDayEvent.Minute;
                                            iEndTime = (iHour * 60) + iMinute;

                                            // We need to stop looking once we find the next rate change event.
                                            break;
                                        }

                                        iNextEventCounter++;
                                    }

                                    // Add the rate change event
                                    int iRateIndex = GetRateIndex(usEvent);
                                    // Finally figure out the Switchpoint type
                                    CSwitchPoint SchedSwitchPoint = new CSwitchPoint(iStartTime, iEndTime,
                                                                                     iRateIndex, eSwitchPointType.RATE);

                                    SPColl.Add(SchedSwitchPoint);
                                }
                                else if (IsOutputOnEvent(usEvent) == true)
                                {
                                    // We have a valid output on Event, so proceed with createing a SwitchPoint
                                    int iHour      = (int)DayEvent.Hour;
                                    int iMinute    = (int)DayEvent.Minute;
                                    int iStartTime = (iHour * 60) + iMinute;
                                    int iEndTime   = 24 * 60;

                                    int iOutputIndex = GetOutputIndex(usEvent);

                                    // Find the OutputOff event for this rate if one exists
                                    iNextEventCounter = iEventCounter + 1;

                                    while (iNextEventCounter < TOUConfigTable.EventsPerDayType)
                                    {
                                        TOUConfig.DayEvent NextDayEvent = CurrentSeason.TimeOfDayEvents[iDayTypeCounter, iNextEventCounter];

                                        if (IsOutputOffEvent(NextDayEvent.Event) == true)
                                        {
                                            // Check to see if the index matches
                                            if (iOutputIndex == GetOutputIndex(NextDayEvent.Event))
                                            {
                                                iHour    = (int)NextDayEvent.Hour;
                                                iMinute  = (int)NextDayEvent.Minute;
                                                iEndTime = (iHour * 60) + iMinute;

                                                // We need to stop looking once we find the next rate change event.
                                                break;
                                            }
                                        }

                                        iNextEventCounter++;
                                    }

                                    // Finally figure out the Switchpoint type
                                    CSwitchPoint SchedSwitchPoint = new CSwitchPoint(iStartTime, iEndTime,
                                                                                     iOutputIndex, eSwitchPointType.OUTPUT);

                                    SPColl.Add(SchedSwitchPoint);
                                }

                                // We do not need to handle the OutputOff event since they get handled by the OutputOn check
                            }
                        }

                        // Since we have no way of knowing whether the the patterns for the current season are related
                        // to the patterns in other seasons we need to add the patterns regardless of whether or not it
                        // has already been duplicated in another season

                        // To keep the patterns unique we need to add in an offset for the season number

                        iPatternID = iDayTypeCounter + iSeasonCounter * TOUConfigTable.DayTypesPerSeason;

                        CPattern SchedPattern = new CPattern(iPatternID, "Pattern " + iDayTypeCounter.ToString(CultureInfo.InvariantCulture),
                                                             SPColl);

                        NormalDays.Add((short)iPatternID);

                        // The Day to Daytype conversions are 1's based so subract 1
                        if (iDayTypeCounter == CurrentSeason.TypicalHoliday)
                        {
                            // This Day Type is a holiday
                            HolidayDays.Add((short)iPatternID);
                        }

                        TOUSchedule.Patterns.Add(SchedPattern);
                    }

                    // Add the season to the schedule
                    CSeason SchedSeason = new CSeason(iSeasonCounter + 1, "Season " + (iSeasonCounter + 1).ToString(CultureInfo.InvariantCulture), NormalDays, HolidayDays);

                    TOUSchedule.Seasons.Add(SchedSeason);
                }

                // Now deal with the Calendar part of the config
                TOUSchedule.TOUID = CalendarConfigTable.CalendarID;

                for (int iYearCounter = 0; iYearCounter < CalendarConfigTable.MaxYears; iYearCounter++)
                {
                    CEventCollection EventColl = new CEventCollection();
                    CalendarEvent[]  CalEvents =
                        CalendarConfigTable.Years[iYearCounter].Events;
                    int iYear = 2000 + (int)CalendarConfigTable.Years[iYearCounter].Year;

                    // Start at Index 2, which is the first non-DST Event
                    for (int iDayEvent = CalendarConfigTable.DSTEventsPerYear;
                         iDayEvent < CalendarConfigTable.EventsPerYear; iDayEvent++)
                    {
                        eEventType eType       = CalendarConfigTable.GetEventType(CalEvents[iDayEvent].Type);
                        int        iEventIndex = iDayEvent;

                        if (eEventType.NO_EVENT != eType)
                        {
                            // It is a valid event
                            DateTime dtDate = new DateTime(iYear, CalEvents[iDayEvent].Month + 1,
                                                           CalEvents[iDayEvent].Day + 1);

                            // Determine the index for the event
                            if (eType == eEventType.SEASON)
                            {
                                iEventIndex = CalEvents[iDayEvent].Type - (int)CalendarEvent.CalendarEventType.SEASON1 - 1;
                            }
                            else if (eType == eEventType.HOLIDAY)
                            {
                                // Determine which Holiday day type to use
                                // Currently the ANSI devices only support 1 holiday day type so this is always 0
                                iEventIndex = 0;
                            }

                            CEvent Event = new CEvent(dtDate, eType,
                                                      iEventIndex, "Event " + iDayEvent.ToString(CultureInfo.InvariantCulture));

                            EventColl.Add(Event);
                        }
                    }
                    CYear Year = new CYear(iYear, EventColl);

                    TOUSchedule.Years.Add(Year);

                    // It may be possible that some of the years are not filled in so we need to
                    // make sure that the year is valid by checking to see if the next year is
                    // greater than the current
                    if (iYearCounter + 1 < CalendarConfigTable.MaxYears &&
                        (int)CalendarConfigTable.Years[iYearCounter + 1].Year + 2000 < iYear)
                    {
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                throw (e);
            }

            return(TOUSchedule);
        }
Esempio n. 5
0
        /// <summary>
        /// Reads a short array from the stream.
        /// </summary>
        public Int16Collection ReadInt16Array(string fieldName)
        {
            bool isNil = false;

            Int16Collection values = new Int16Collection();
                                    
            if (BeginField(fieldName, true, out isNil))
            {                                
                PushNamespace(Namespaces.OpcUaXsd);
                
                while (MoveToElement("Int16"))
                {
                    values.Add(ReadInt16("Int16"));
                }

                // check the length.
                if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
                {
                    throw new ServiceResultException(StatusCodes.BadEncodingLimitsExceeded);
                }

                PopNamespace();

                EndField(fieldName);
                return values;
            }

            if (isNil)
            {
                return null;
            }

            return values;
        }
Esempio n. 6
0
        /// <summary>
        /// Reads a short array from the stream.
        /// </summary>
        public Int16Collection ReadInt16Array(string fieldName)
        {
            int length = ReadArrayLength();

            if (length == -1)
            {
                return null;
            }

            Int16Collection values = new Int16Collection(length);

            for (int ii = 0; ii < length; ii++)
            {
                values.Add(ReadInt16(null));
            }

            return values;
        }
        /// <summary>
        /// Reads a short array from the stream.
        /// </summary>
        public Int16Collection ReadInt16Array(string fieldName)
        {
            var values = new Int16Collection();

            List<object> token = null;

            if (!ReadArrayField(fieldName, out token))
            {
                return values;
            }

            for (int ii = 0; ii < token.Count; ii++)
            {
                try
                {
                    m_stack.Push(token[ii]);
                    values.Add(ReadInt16(null));
                }
                finally
                {
                    m_stack.Pop();
                }
            }

            return values;
        }