Exemple #1
0
    /// <summary>
    /// Demonstrates how to retrieve information from a key.
    /// </summary>
    public void SessionInfoDemo(Hasp hasp)
    {
        // sanity check
        if ((null == hasp) || !hasp.IsLoggedIn())
        {
            return;
        }

        Verbose("Get Session Information Demo");

        Verbose("Retrieving Key Information");

        // firstly we will retrieve the key info.
        string     info   = null;
        HaspStatus status = hasp.GetSessionInfo(Hasp.KeyInfo,
                                                ref info);

        ReportStatus(status);
        if (HaspStatus.StatusOk == status)
        {
            Verbose("Key Information:");
            Verbose(info.Replace("\n", "\r\n          "));
        }
        else
        {
            Verbose("");
        }

        Verbose("Retrieving Session Information");

        // next the session info.
        status = hasp.GetSessionInfo(Hasp.SessionInfo, ref info);
        ReportStatus(status);
        if (HaspStatus.StatusOk == status)
        {
            Verbose("Session Information:");
            Verbose(info.ToString());
        }
        else
        {
            Verbose("");
        }

        Verbose("Retrieving Update Information");

        // last the update information.
        status = hasp.GetSessionInfo(Hasp.UpdateInfo, ref info);
        ReportStatus(status);
        if (HaspStatus.StatusOk == status)
        {
            Verbose("Update Information:");
            Verbose(info.ToString());
        }
        else
        {
            Verbose("");
        }
    }
Exemple #2
0
        /// <summary>
        /// 返回ID
        /// </summary>
        /// <param name="tz">厂商</param>
        /// <param name="id">ID</param>
        /// <param name="er">错误代码</param>
        /// <returns></returns>
        public HaspStatus time(int tz, out string id, out string er)
        {
            id = string.Empty;

            er = string.Empty;

            try
            {
                string DateTime = string.Empty;
                scope = defaultScope;

                HaspFeature feature = HaspFeature.FromFeature(tz);

                hasp = new Hasp(feature);

                HaspStatus status = hasp.Login(strVendorCode, scope);

                if (status != HaspStatus.StatusOk)
                {
                    er = status.ToString();
                    return(status);
                }
                er = Convert.ToString(status);
                string xlmFile = "<haspformat root=" + "\"" + "hasp_info" + "\"" + ">" +
                                 "<hasp>" +
                                 "<attribute name=" + "\"" + "id" + "\"" + "/>" +
                                 "<feature>" +
                                 "<element name=" + "\"" + "license" + "\"" + "/>" +
                                 "</feature>" +
                                 "</hasp>" +
                                 "</haspformat>";

                string info = string.Empty;

                string Time2 = hasp.GetSessionInfo(xlmFile, ref info).ToString();

                string[] sArray = info.Split(new char[2] {
                    '"', '"'
                });

                if (sArray.Length > 6)
                {
                    id = sArray[5];
                }

                //释放内存
                status = hasp.Logout();

                return(status);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(HaspStatus.SystemError);
            }
        }