Пример #1
0
        // STRING

        /**
         * Method declaration
         *
         *
         * @param s
         *
         * @return
         */
        public static int ascii(string s)
        {
/*			if (s == null || s.Length == 0)
 *                      {
 *                              return null;
 *                      }
 */
            return(Int32.FromString(s));
        }
Пример #2
0
        /// <summary>
        /// Converts DMTF datetime interval property value to System.TimeSpan
        /// </summary>
        /// <param name="prop"> </param>
        static public TimeSpan ToTimeSpan(string dmtf)
        {
            try
            {
                //set the defaults:
                Int32 days      = 0;
                Int32 hours     = 0;
                Int32 minutes   = 0;
                Int32 seconds   = 0;
                Int32 millisecs = 0;

                String str = dmtf;

                if (str == String.Empty ||
                    str.Length != DMTF_DATETIME_INTERVAL_STR_LENGTH)
                {
                    return(TimeSpan.Empty);
                }

                string strDay = str.Substring(0, 8);
                days = Int32.FromString(strDay);

                string strHour = str.Substring(8, 2);
                hours = Int32.FromString(strHour);

                string strMinute = str.Substring(10, 2);
                minutes = Int32.FromString(strMinute);


                string strSecond = str.Substring(12, 2);
                seconds = Int32.FromString(strSecond);

                //dot in the 14th position
                if (str.Substring(14, 1) != ".")
                {
                    return(TimeSpan.Empty);
                }


                //note: approximation here: DMTF actually stores microseconds
                string strMillisec = str.Substring(15, 3);
                if (strMillisec != "***")
                {
                    millisecs = Int32.FromString(strMillisec);
                }

                TimeSpan ret = new TimeSpan(days, hours, minutes, seconds, millisecs);

                return(ret);
            }
            catch (Exception e)
            {
                MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace));
                throw (e);
            }
        }
Пример #3
0
        /**
         * Method declaration
         *
         *
         * @throws Exception
         */
        private void runScript()
        {
            if (Trace.TRACE)
            {
                Trace.trace();
            }

            if (!(new File(sFileScript)).Exists)
            {
                return;
            }

            bRestoring = true;

            dDatabase.setReferentialIntegrity(false);

            ArrayList channel = new ArrayList();

            channel.Add(cSystem);

            Channel current = cSystem;
            int     size    = 1;

            try
            {
                DateTime     time = DateTime.Now;
                StreamReader r    = new StreamReader(sFileScript);

                while (true)
                {
                    string s = r.ReadLine();

                    if (s == null)
                    {
                        break;
                    }

                    if (s.StartsWith("/*C"))
                    {
                        int id = Int32.FromString(s.Substring(3, (s.IndexOf('*', 4) - 3)));

                        if (id > channel.Count)
                        {
                            current = new Channel(cSystem, id);

                            channel.Insert(id, current);
                            dDatabase.registerChannel(current);
                        }
                        else
                        {
                            current = (Channel)channel[id - 1];
                        }

                        s = s.Substring(s.IndexOf('/', 1) + 1);
                    }

                    if (!s.Equals(""))
                    {
                        dDatabase.execute(s, current);
                    }

                    if (s.Equals("DISCONNECT"))
                    {
                        int id = current.getId();

                        current = new Channel(cSystem, id);

                        channel.RemoveAt(id);
                        channel.Insert(id, current);
                    }
                }

                r.Close();

                for (int i = 0; i < size; i++)
                {
                    current = (Channel)channel[i];

                    if (current != null)
                    {
                        current.rollback();
                    }
                }

                TimeSpan execution = DateTime.Now.Subtract(time);

                if (Trace.TRACE)
                {
                    Trace.trace(execution.TotalMilliseconds.ToInt64());
                }
            }
            catch (IOException e)
            {
                throw Trace.error(Trace.FILE_IO_ERROR, sFileScript + " " + e);
            }

            dDatabase.setReferentialIntegrity(true);

            bRestoring = false;
        }
Пример #4
0
        /**
         * Method declaration
         *
         *
         * @param c
         * @param channel
         *
         * @return
         *
         * @throws Exception
         */
        private Result processSet(Tokenizer c,
                                  Channel channel)
        {
            string sToken = c.getstring();

            if (sToken.Equals("PASSWORD"))
            {
                channel.checkReadWrite();
                channel.setPassword(c.getstringToken());
            }
            else if (sToken.Equals("READONLY"))
            {
                channel.commit();
                channel.setReadOnly(processTrueOrFalse(c));
            }
            else if (sToken.Equals("LOGSIZE"))
            {
                channel.checkAdmin();

                int i = Int32.FromString(c.getstring());

                if (lLog != null)
                {
                    lLog.setLogSize(i);
                }
            }
            else if (sToken.Equals("IGNORECASE"))
            {
                channel.checkAdmin();

                bIgnoreCase = processTrueOrFalse(c);
            }
            else if (sToken.Equals("MAXROWS"))
            {
                int i = Int32.FromString(c.getstring());

                channel.setMaxRows(i);
            }
            else if (sToken.Equals("AUTOCOMMIT"))
            {
                channel.setAutoCommit(processTrueOrFalse(c));
            }
            else if (sToken.Equals("TABLE"))
            {
                channel.checkReadWrite();
                channel.checkAdmin();

                Table t = getTable(c.getstring(), channel);

                c.getThis("INDEX");
                c.getstring();
                t.setIndexRoots((string)c.getAsValue());
            }
            else if (sToken.Equals("REFERENCIAL_INTEGRITY") ||
                     sToken.Equals("REFERENTIAL_INTEGRITY"))
            {
                channel.checkAdmin();

                bReferentialIntegrity = processTrueOrFalse(c);
            }
            else if (sToken.Equals("WRITE_DELAY"))
            {
                channel.checkAdmin();

                bool delay = processTrueOrFalse(c);

                if (lLog != null)
                {
                    lLog.setWriteDelay(delay);
                }
            }
            else
            {
                throw Trace.error(Trace.UNEXPECTED_TOKEN, sToken);
            }

            return(new Result());
        }
Пример #5
0
        public static Object GetTypedObjectFromString(WbemCimtypeEnum cimType, String strValue)
        {
            switch (cimType)
            {
            case (WbemCimtypeEnum.wbemCimtypeBoolean):
            {
                Boolean bValue = Boolean.FromString(strValue);
                return(bValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeChar16):
            {
                Char charValue = Char.FromString(strValue);
                return(charValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeDatetime):
            {
                return(strValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeObject):
            {
                //VT_UNKNOWN
                //what's the format of strValue?
                //thios wouldn't work until there is a way to invoke custom type converters and editors
                return(null);
            }

            case (WbemCimtypeEnum.wbemCimtypeReal32):
            {
                Single retValue = Single.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeReal64):
            {
                Double retValue = Double.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeReference):
            {
                return(strValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeSint16):
            {
                Int16 retValue = Int16.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeSint32):
            {
                Int32 retValue = Int32.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeSint64):
            {
                return(strValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeSint8):
            {
                //NOTE that wbemCimtypeSint8 get expanded to VT_I2 in automation layer
                Int16 retValue = Int16.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeString):
            {
                return(strValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeUint16):
            {
                //NOTE that wbemCimtypeUint16 gets expanded to VT_I4 in automation layer
                Int32 retValue = Int32.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeUint32):
            {
                Int32 retValue = Int32.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeUint64):
            {
                return(strValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeUint8):
            {
                Byte retVal = Byte.FromString(strValue);
                return(retVal);
            }

            default:
                return(strValue);
            }
        }
Пример #6
0
        /// <summary>
        /// Converts DMTF datetime property value to System.DateTime
        /// </summary>
        /// <param name="prop"> </param>
        static public DateTime ToDateTime(String dmtf)
        {
            try
            {
                //set the defaults:
                Int32 year     = DateTime.Now.Year;
                Int32 month    = 1;
                Int32 day      = 1;
                Int32 hour     = 0;
                Int32 minute   = 0;
                Int32 second   = 0;
                Int32 millisec = 0;

                String str = dmtf;

                if (str == String.Empty ||
                    str.Length != DMTF_DATETIME_STR_LENGTH)
                //|| str.IndexOf("*") >= 0 )
                {
                    return(DateTime.Empty);
                }

                string strYear = str.Substring(0, 4);
                if (strYear != "****")
                {
                    year = Int32.FromString(strYear);
                }

                string strMonth = str.Substring(4, 2);
                if (strMonth != "**")
                {
                    month = Int32.FromString(strMonth);
                }

                string strDay = str.Substring(6, 2);
                if (strDay != "**")
                {
                    day = Int32.FromString(strDay);
                }

                string strHour = str.Substring(8, 2);
                if (strHour != "**")
                {
                    hour = Int32.FromString(strHour);
                }

                string strMinute = str.Substring(10, 2);
                if (strMinute != "**")
                {
                    minute = Int32.FromString(strMinute);
                }

                string strSecond = str.Substring(12, 2);
                if (strSecond != "**")
                {
                    second = Int32.FromString(strSecond);
                }

                //note: approximation here: DMTF actually stores microseconds
                string strMillisec = str.Substring(15, 3);
                if (strMillisec != "***")
                {
                    millisec = Int32.FromString(strMillisec);
                }

                DateTime ret = new DateTime(year, month, day, hour, minute, second, millisec);

                return(ret);
            }
            catch (Exception e)
            {
                MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace));
                throw (e);
            }
        }