コード例 #1
0
        /// <summary>
        /// 获取C2V XML
        /// </summary>
        /// <returns></returns>
        internal string getC2VXML()
        {
            string     info   = null;
            HaspStatus status = Hasp.GetInfo(safeNetEntity.scope, safeNetEntity.formatC2V, safeNetEntity.vendorCode, ref info);

            return(info);
        }
コード例 #2
0
        /// <summary>
        /// 获取SAFENET SLCODE XML
        /// </summary>
        /// <returns></returns>
        internal string getSLXML()
        {
            string info = null;

            Hasp.GetInfo(safeNetEntity.scope, safeNetEntity.format, safeNetEntity.vendorCode, ref info);
            return(info);
        }
コード例 #3
0
ファイル: HaspDemo.cs プロジェクト: 737871854/FireMen2
    /// <summary>
    /// Demonstrates how to use to retrieve a XML containing all available features.
    /// </summary>
    public void GetInfoDemo()
    {
        string queryFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
                             "<haspformat root=\"hasp_info\">" +
                             " <feature>" +
                             "  <attribute name=\"id\" />" +
                             "  <element name=\"license\" />" +
                             " </feature>" +
                             "</haspformat>";

        Verbose("Get Information Demo");

        Verbose("Retrieving Feature Information");

        string info = null;

        HaspStatus status = Hasp.GetInfo(scope, queryFormat, VendorCode.Code, ref info);

        ReportStatus(status);
        if (HaspStatus.StatusOk == status)
        {
            Verbose("Fature Information:");
            Verbose(info.Replace("\n", "\r\n          "));
        }
        else
        {
            Verbose("");
        }
    }
コード例 #4
0
        public string ExtractInstrumentName()
        {
            string currentName = null;

            try
            {
                PublicClass.InstrumentSerial = "";
                vendorCode    = m_sTest;
                hasp          = new Hasp(new HaspFeature(10));
                status        = hasp.Login(vendorCode);
                featureStatus = status.ToString();
                Int32    offset = 0;
                Int32    size   = 48;
                byte[]   data   = new byte[size];
                HaspFile file   = hasp.GetFile(HaspFileId.ReadWrite);
                file.FilePos = offset;
                status       = file.Read(data, 0, data.Length);
                currentName  = Encoding.ASCII.GetString(data).TrimEnd(new char[] { '\0' });
                string[] insName = currentName.Split(new string[] { "|" }, StringSplitOptions.None);
                currentName = insName[0];
                PublicClass.InstrumentSerial = insName[1];
            }
            catch (Exception ex)
            {
            }
            return(currentName);
        }
コード例 #5
0
 /// <summary>
 /// 生成SAFENET证书
 /// </summary>
 /// <param name="productKey"></param>
 /// <returns></returns>
 internal bool installSafeNet(string productKey, out string slId, out string msg)
 {
     msg  = null;
     slId = null;
     try
     {
         string v2c    = getV2C(productKey, out msg);
         string refXml = null;
         if (!string.IsNullOrEmpty(v2c))
         {
             xmlBiz      bll       = new xmlBiz();
             XmlDocument xml       = bll.getXmlDocument(v2c.ToString());
             XmlNode     haspInfo  = bll.getXmlSingleNode(xml, "hasp_info");
             XmlNode     haspscope = bll.getXmlSingleNode(haspInfo, "haspscope");
             XmlNode     vendor    = bll.getXmlSingleNode(haspscope, "vendor");
             XmlNode     hasp      = bll.getXmlSingleNode(vendor, "hasp");
             slId = bll.getXmlAttribute(hasp, "id");
         }
         HaspStatus status = Hasp.Update(v2c, ref refXml);
         return(status == HaspStatus.StatusOk);
     }
     catch (Exception ex)
     {
         msg += ex.Message + ex.StackTrace;
         return(false);
     }
 }
コード例 #6
0
        /// <summary>
        /// constructor
        /// </summary>
        public HaspDongle(int inProductcode, ushort inClientcode)
        {
            mProductcode  = inProductcode;//1001;// 1050;
            mCRCTable     = new uint[256];
            mKey          = 0;
            mClient       = inClientcode;
            mLicenseCount = 0;

            options = FeatureOptions.NotRemote;
            feature = HaspFeature.ProgNumDefault;
            feature.SetOptions(options, FeatureOptions.Default);

            hasp = new Hasp(feature);

            mLicenses = new List <License>();

            // first get the right key!
            using (hasp)
            {
                mKey = GetKey();
                if (mKey != 0 && hasp != null)
                {
                    GetGeneralInfo();
                    if (mLicenseCount > 0)
                    {
                        GetLicenses();
                    }
                }
            }
        }
コード例 #7
0
        internal string getSLInfo(string slCode)
        {
            string info = null;

            Hasp.GetInfo(safeNetEntity.loginScope.Replace("{slcode}", slCode), safeNetEntity.formatInfo, safeNetEntity.vendorCode, ref info);
            return(info);
        }
コード例 #8
0
        private void ToolStripMenuItemSaveAs_Click(object sender, EventArgs e)
        {
            HaspFeature feature = HaspFeature.Default;

            Hasp       hasp   = new Hasp(feature);
            HaspStatus status = hasp.Login(_vendorCode);

            var haspStatus = getHaspStatusMessage(status);

            if (haspStatus != "OK")
            {
                var res = MessageBox.Show(
                    "HASP HL key has been removed. If you need to save the file, click Cancel and save it",
                    "Error",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Error
                    );

                if (res == DialogResult.OK)
                {
                    Close();
                }
            }
            SaveFile();
        }
コード例 #9
0
        internal string rehost(string slcode, string recipient)
        {
            string     info   = null;
            HaspStatus status = Hasp.Transfer(safeNetEntity.actionRehost.Replace("{slcode}", slcode), safeNetEntity.scopeRehost.Replace("{slcode}", slcode), safeNetEntity.vendorCode, recipient, ref info);

            return(status == HaspStatus.StatusOk ? info : ((int)status + status.ToString()));
        }
コード例 #10
0
        public static string GetInfo(string scope, string format, bool checkBeforeLogin = false)
        {
            string     info      = null;
            HaspStatus getStatus = HaspStatus.AlreadyLoggedOut;

            if (Variables.myStatus == HaspStatus.StatusOk && !checkBeforeLogin)
            {
                getStatus = Hasp.GetInfo(scope, format, Variables.vendorCode[Variables.vendorCode.Keys.Where(k => k.Key == Variables.currentBatchCode).FirstOrDefault()], ref info);
                if (getStatus == HaspStatus.StatusOk)
                {
                    return(info);
                }
                else
                {
                    return(getStatus.ToString());
                }
            }
            else if (checkBeforeLogin)
            {
                getStatus = Hasp.GetInfo(scope, format, Variables.vendorCode[Variables.vendorCode.Keys.Where(k => k.Key == Variables.currentBatchCode).FirstOrDefault()], ref info);
                if (getStatus == HaspStatus.StatusOk)
                {
                    return(info);
                }
                else
                {
                    return(getStatus.ToString());
                }
            }
            return(getStatus.ToString());
        }
コード例 #11
0
ファイル: HaspDemo.cs プロジェクト: 737871854/FireMen2
    /// <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("");
        }
    }
コード例 #12
0
        public string loginstate(string slCode)
        {
            HaspFeature feature = HaspFeature.Default;

            Hasp       hasp   = new Hasp(feature);
            HaspStatus status = hasp.Login(safeNetEntity.vendorCode, safeNetEntity.loginScope.Replace("{slcode}", slCode));

            return(status.ToString());
        }
コード例 #13
0
        private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            HaspFeature feature = HaspFeature.Default;

            Hasp       hasp   = new Hasp(feature);
            HaspStatus status = hasp.Logout();

            getHaspStatusMessage(status);
        }
コード例 #14
0
ファイル: CSentinel.cs プロジェクト: GJSoftware/Tool
        /// <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);
            }
        }
コード例 #15
0
ファイル: HaspSession.cs プロジェクト: AlexSneg/VIRD-1.0
        internal void Open()
        {
            Hasp = new Hasp(HaspFeature.Default); // Используется feature по умолчанию (ID=0), которая всегда есть на ключе.
            HaspStatus status = Hasp.Login(VendorCode);

            if (HaspStatus.StatusOk != status)
            {
                throw new HaspException(status, "Log in failed.");
            }
        }
コード例 #16
0
        /// <summary>
        ///     Uses pre-defined vendor code for validating whether the HASP software license installed on the server is valid or not
        ///     Returns the detailed hasp pass/fail message only
        /// </summary>
        /// <remarks>
        ///     The HASP dlls (hasp_net_windows.dll, hasp_windows_x64_102489.dll, haspvlib_102489.dll, and hasp_windows_102489.dll)
        ///     must be placed in the windows system directory in order for IIS to access those external dlls
        /// </remarks>
        public static string validateLicenseDetails()
        {
            // Sentinel LDK API
            HaspFeature feature = HaspFeature.FromFeature(1001);  // Using feature 1 defined in EMS-Server; Actual product should be using 1001

            Hasp       hasp   = new Hasp(feature);
            HaspStatus status = hasp.Login(getVendorCode());

            return(status.ToString());
        }
コード例 #17
0
        public static string CancelDetachViaLicensingApi(string parentKeyId)
        {
            var myId = GetInfo(Variables.scopeForLocal, Variables.formatForGetId);

            string info = null;

            HaspStatus myCancelDetachStatus = Hasp.Transfer(Variables.actionForCancelDetach.Replace("{KEY_ID}", parentKeyId), Variables.scopeForSpecificKeyId.Replace("{KEY_ID}", parentKeyId), Variables.vendorCode[Variables.vendorCode.Keys.Where(k => k.Key == Variables.currentBatchCode).FirstOrDefault()], myId, ref info);

            return(myCancelDetachStatus.ToString());
        }
コード例 #18
0
ファイル: LicenseHelper.cs プロジェクト: hjlfmy/Rubezh
        public bool CheckLicense()
        {
            var hasp = new Hasp(_feature);
            var status = hasp.Login(_vendorCode);
            if (status == HaspStatus.StatusOk)
            {
                status = hasp.Logout();
                return true;
            }

            return false;
        }
コード例 #19
0
 public CSysPro()
 {
     m_objHasp = new Hasp(m_objHaspFeatue);
     //m_objHasp1 = new Hasp(m_objHaspFeatue1);
     m_objHaspForm           = new frmHasp();
     m_objHaspForm.SystemPro = this;
     if (m_objHaspForm != null)
     {
         m_objHaspForm.ExitButtonClicked += new frmHasp.ExitButtonClickedHandler(objHasp_ExitButtonClicked);
         m_objHaspForm.TryButtonClicked  += new frmHasp.ExitButtonClickedHandler(objHasp_TryButtonClicked);
         m_objHaspForm.DemoButtonClicked += new frmHasp.ExitButtonClickedHandler(objHasp_DemoButtonClicked);
     }
 }
コード例 #20
0
ファイル: HaspDemo.cs プロジェクト: 737871854/FireMen2
 public bool WriteMessageFirst(Hasp hasp, HaspFileId fileId, string str)
 {
     try
     {
         HaspFile file = hasp.GetFile(fileId);
         file.Write(str);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #21
0
        public bool logout()
        {
            bool        rtn     = false;
            HaspFeature feature = HaspFeature.Default;

            Hasp       hasp   = new Hasp(feature);
            HaspStatus status = hasp.Logout();

            if (HaspStatus.StatusOk == status)
            {
                rtn = true;
            }
            return(rtn);
        }
コード例 #22
0
        public bool login(string slCode)
        {
            bool        rtn     = false;
            HaspFeature feature = HaspFeature.Default;

            Hasp       hasp   = new Hasp(feature);
            HaspStatus status = hasp.Login(safeNetEntity.vendorCode, safeNetEntity.loginScope.Replace("{slcode}", slCode));

            if (HaspStatus.StatusOk == status)
            {
                rtn = true;
            }
            return(rtn);
        }
コード例 #23
0
        /// <summary>
        /// 获取C2V XML
        /// </summary>
        /// <returns></returns>
        internal string getImmigrationXML()
        {
            string     info   = null;
            HaspStatus status = Hasp.GetInfo(safeNetEntity.scope, safeNetEntity.formatImmigration, safeNetEntity.vendorCode, ref info);

            if (status == HaspStatus.StatusOk)
            {
                return(info);
            }
            else
            {
                return((int)status + status.ToString());
            }
        }
コード例 #24
0
        internal string TransferToolupdate(string v2c)
        {
            string     refXml = null;
            HaspStatus status = Hasp.Update(v2c, ref refXml);

            if (status == HaspStatus.StatusOk)
            {
                refXml = "ok";
            }
            else
            {
                refXml = ((int)status + status.ToString());
            }
            return(refXml);
        }
コード例 #25
0
ファイル: HaspDemo.cs プロジェクト: 737871854/FireMen2
    public string ReadToStr(Hasp hasp, HaspFileId fileId)
    {
        string dd = "";

        try
        {
            HaspFile file = hasp.GetFile(fileId);
            file.Read(ref dd);
            return(dd);
        }

        catch
        {
            return(null);
        }
    }
コード例 #26
0
ファイル: HaspDemo.cs プロジェクト: 737871854/FireMen2
    /// <summary>
    /// Demonstrates how to perform a login using the default
    /// feature and how to perform an automatic logout
    /// using the Hasp's Dispose method.
    /// </summary>
    public void LoginDisposeDemo()
    {
        Verbose("Login/Dispose Demo with Default Feature (HaspFeature.Default)");

        HaspFeature feature = HaspFeature.Default;

        Hasp hasp = new Hasp(feature);

        HaspStatus status = hasp.Login(VendorCode.Code, scope);

        ReportStatus(status);

        Verbose("Disposing object - will perform an automatic logout");
        hasp.Dispose();

        Verbose("");
    }
コード例 #27
0
        /// <summary>
        ///     Uses pre-defined vendor code for validating whether the HASP software license installed on the server is valid or not
        /// </summary>
        /// <remarks>
        ///     The HASP dlls (hasp_net_windows.dll, hasp_windows_x64_102489.dll, haspvlib_102489.dll, and hasp_windows_102489.dll)
        ///     must be placed in the windows system directory in order for IIS to access those external dlls
        /// </remarks>
        public static bool validateLicense()
        {
            // Sentinel LDK API
            HaspFeature feature = HaspFeature.FromFeature(1001);  // Using feature 1 defined in EMS-Server; Actual product should be using 1001

            Hasp       hasp   = new Hasp(feature);
            HaspStatus status = hasp.Login(getVendorCode());

            if (HaspStatus.StatusOk != status)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #28
0
ファイル: HaspDemo.cs プロジェクト: 737871854/FireMen2
    /// <summary>
    /// Demonstrates how to login using a feature id.
    /// </summary>
    public Hasp LoginDemo(HaspFeature feature)
    {
        //Verbose("Login Demo with Feature: " +
        //        feature.FeatureId.ToString() +
        //        (feature.IsProgNum ? " (Program Number)" : ""));

        // create a key object using a feature
        // and perform a login using the vendor code.
        Hasp hasp = new Hasp(feature);

        HaspStatus status = hasp.Login(VendorCode.Code, scope);

        ReportStatus(status);

        //Verbose("");

        return(hasp.IsLoggedIn() ? hasp : null);
    }
コード例 #29
0
ファイル: HaspDemo.cs プロジェクト: 737871854/FireMen2
    /// <summary>
    /// Demonstrates how to perform a login and an automatic
    /// logout using C#'s scope clause.
    /// </summary>
    public void LoginDefaultAutoDemo()
    {
        Verbose("Login Demo with Default Feature (HaspFeature.Default)");

        HaspFeature feature = HaspFeature.Default;

        // this will perform a logout and object disposal
        // when the using scope is left.
        using (Hasp hasp = new Hasp(feature))
        {
            HaspStatus status = hasp.Login(VendorCode.Code, scope);
            ReportStatus(status);

            Verbose("Object going out of scope - System will call Dispose");
        }

        Verbose("");
    }
コード例 #30
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            HaspFeature feature = HaspFeature.Default;

            Hasp       hasp   = new Hasp(feature);
            HaspStatus status = hasp.Login(_vendorCode);

            var haspStatus = getHaspStatusMessage(status);

            if (Properties.Settings.Default.number_of_starts < 5 && haspStatus == "OK")
            {
                Properties.Settings.Default.hasp_plugged_in = true;
            }

            if (haspStatus != "OK" && Properties.Settings.Default.hasp_plugged_in)
            {
                var res = MessageBox.Show(
                    "The key was plugged in once. Plug it in again",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                if (res == DialogResult.OK)
                {
                    Close();
                }
            }

            if (Properties.Settings.Default.number_of_starts >= 5 && haspStatus != "OK")
            {
                var res = MessageBox.Show(
                    haspStatus,
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                if (res == DialogResult.OK)
                {
                    Close();
                }
            }
        }
コード例 #31
0
ファイル: HaspDemo.cs プロジェクト: 737871854/FireMen2
    /// <summary>
    /// Performs a logout operation on the key.
    /// </summary>
    public void LogoutDemo(ref Hasp hasp)
    {
        // sanity check
        if ((null == hasp) || !hasp.IsLoggedIn())
        {
            return;
        }

        Verbose("Logout Demo");

        HaspStatus status = hasp.Logout();

        ReportStatus(status);

        // get rid of the key immediately.
        hasp.Dispose();
        hasp = null;
        Verbose("");
    }
コード例 #32
0
 private void btnTryAgain_Click(object sender, EventArgs e)
 {
     try
     {
         if (TryButtonClicked != null)
         {
             TryButtonClicked();
         }
         CheckAgain();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message, ex.StackTrace);
     }
     finally
     {
         m_objHasp  = null;
         m_objHasp1 = null;
     }
 }
コード例 #33
0
        public HaspStatus loginInHasp()
        {
            //HaspFeature feature = HaspFeature.FromFeature(10);
            HaspFeature feature = HaspFeature.FromFeature(50);

            string scope =
                "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
                "<haspscope>" +
                "    <hasp type=\"HASP-HL\" />" +
                "</haspscope>";

            hasp = new Hasp(feature);
            //HaspStatus status = hasp.Login(VendorCode.Code);
            HaspStatus status = hasp.Login(VendorCode.Code, scope);

            // mensagem = exibeMensagem(status, "Login no HASP efetuado com sucesso!");

            logger.logInfo("#loginInHasp - " + MapaDeStatus.getStatus((int) status));

            return status;
        }