コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void fileWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            if (this.licenseFileOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                LoggerEx logEx = new LoggerEx(log);
                try
                {
                    fileWatcher.EnableRaisingEvents = false;
                    try
                    {
                        if (e.ChangeType == WatcherChangeTypes.Changed)
                        {
                            uint resultErr = 0;

                            byte[] bteLic;
                            if (File.Exists(strPathLic))
                            {
                                Thread.Sleep(1000);
                                FileStream files = File.Open(strPathLic, FileMode.Open, FileAccess.Read, FileShare.Read);
                                if (files.Length != 0)
                                {
                                    byte[] btemp = new byte[files.Length];
                                    files.Read(btemp, 0, btemp.Length);
                                    bteLic = btemp;
                                }
                                else
                                {
                                    bteLic = new byte[0];
                                }
                                files.Close();
                            }
                            else
                            {
                                byte[] b = new byte[0];
                                bteLic = b;
                            }
                            CLicenseManagedAdapter licMan = new CLicenseManagedAdapter();
                            SmcErr smcErr = Convert2ErrNo(licMan.ActivateLicenseKey(bteLic, ref resultErr));
                        }
                        GetControlLicItem(null);
                    }
                    catch (System.Exception ex)
                    {
                        logEx.Error("fileWatcher_Changed Exception:{0}", ex.ToString());
                    }
                    finally
                    {
                        fileWatcher.EnableRaisingEvents = true;
                    }
                }
                finally
                {
                    this.licenseFileOperateLock.ExitWriteLock();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 调用托管方法
        /// </summary>
        /// <returns></returns>
        public void LoadLicenseInfo()
        {
            SmcErr smcErr = new SmcErr();
            CLicenseManagedAdapter LicMan   = new CLicenseManagedAdapter();
            ProcLMMsgFunc          CallFunc = new ProcLMMsgFunc(this.ReceiveLicMsg);

            smcErr = Convert2ErrNo(LicMan.AddCallbackToLM(CallFunc));

            uint i = LicMan.ManagerLicenseInit(SMCConst.LICENSE_KEY_VALUES, LicProductKeyType.LicSMC20ProductKEY);

            smcErr = Convert2ErrNo(i);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void fileWatcher_Deleted(object sender, FileSystemEventArgs e)
        {
            if (this.licenseFileOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                LoggerEx logEx = new LoggerEx(log);
                try
                {
                    fileWatcher.EnableRaisingEvents = false;
                    if (e.ChangeType == WatcherChangeTypes.Deleted)
                    {
                        uint   resultErr = 0;
                        byte[] bteLic;
                        if (File.Exists(strPathLic))
                        {
                            bteLic = File.ReadAllBytes(strPathLic);
                        }
                        else
                        {
                            byte[] b = new byte[0];
                            bteLic = b;
                            int licCountNew = 0;
                            if (licCount != licCountNew)
                            {
                                SessionManage.Instance().RemoveAllSession();
                                logEx.Trace("License have changed! the New Count is:{0}, the Old Count:{1} ", licCountNew.ToString(), licCount.ToString());
                                licCount = licCountNew;
                            }
                        }
                        CLicenseManagedAdapter licMan = new CLicenseManagedAdapter();
                        SmcErr smcErr = Convert2ErrNo(licMan.ActivateLicenseKey(bteLic, ref resultErr));
                    }
                    fileWatcher.EnableRaisingEvents = true;
                }

                catch (Exception ex)
                {
                    logEx.Error("fileWatcher_Deleted Exception:{0}", ex.ToString());
                }
                finally
                {
                    this.licenseFileOperateLock.ExitWriteLock();
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// 获取控制项信息
        /// </summary>
        /// <param name="err"></param>
        /// <param name="licMan"></param>
        private SmcErr GetControlLicItem(List <ConfigItem> configList)
        {
            LoggerEx logEx  = new LoggerEx(log);
            SmcErr   smcErr = new SmcErr();
            CLicenseManagedAdapter licMan          = new CLicenseManagedAdapter();
            List <LKItemValue>     licItemTypeList = new List <LKItemValue>();

            smcErr = Convert2ErrNo(licMan.GetLicenseInfo(ref licItemTypeList));
            if (smcErr.IsSuccess())
            {
                licenseInfo.IsMonitorPlatform = false;
                licenseInfo.IsEltePlatform    = false;
                foreach (LKItemValue item in licItemTypeList)
                {
                    if (LicItemfType.LicItemMaxChannelNum == item.ItemID)
                    {
                        int licCountNew = Convert.ToInt32(item.ItemValue);
                        if (licCount != licCountNew)
                        {
                            SessionManage.Instance().RemoveAllSession();
                            logEx.Trace("License have changed! the New Count is:{0}, the Old Count:{1} ", licCountNew.ToString(), licCount.ToString());
                            licCount = licCountNew;
                        }
                    }
                    if (item.ItemID.ToString() == "LicItemMonitorEnable" && item.ItemValue.ToString() == "1")
                    {
                        licenseInfo.IsMonitorPlatform = true;
                    }
                    if (item.ItemID.ToString() == "LicItemELTEEnable" && item.ItemValue.ToString() == "1")
                    {
                        licenseInfo.IsEltePlatform = true;
                    }

                    logEx.Info("GetControlLicItem item:{0},{1}", item.ItemID, item.ItemValue);
                }
            }
            else
            {
                logEx.Warn("GetControlLicItem errNo:{0}", smcErr.ErrNo);
            }

            return(smcErr);
        }
コード例 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void fileWatcher_Created(object sender, FileSystemEventArgs e)
 {
     if (this.licenseFileOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
     {
         LoggerEx logEx = new LoggerEx(log);
         try
         {
             fileWatcher.EnableRaisingEvents = false;
             if (e.ChangeType == WatcherChangeTypes.Created)
             {
                 uint   resultErr = 0;
                 byte[] bteLic;
                 if (File.Exists(strPathLic))
                 {
                     Thread.Sleep(1000);
                     bteLic = File.ReadAllBytes(strPathLic);
                 }
                 else
                 {
                     byte[] b = new byte[0];
                     bteLic = b;
                 }
                 CLicenseManagedAdapter licMan = new CLicenseManagedAdapter();
                 SmcErr smcErr = Convert2ErrNo(licMan.ActivateLicenseKey(bteLic, ref resultErr));
             }
             fileWatcher.EnableRaisingEvents = true;
         }
         catch (Exception ex)
         {
             logEx.Error("fileWatcher_Created Exception:{0}", ex.ToString());
         }
         finally
         {
             this.licenseFileOperateLock.ExitWriteLock();
         }
     }
 }
コード例 #6
0
        /// <summary>
        /// 读取license信息
        /// </summary>
        /// <param name="licMsg"></param>
        /// <returns></returns>
        public uint ReceiveLicMsg(ref LicMsg licMsg)
        {
            CLicenseManagedAdapter licMan = new CLicenseManagedAdapter();
            SmcErr   smcErr = new SmcErr();
            LoggerEx logEx  = new LoggerEx(log);

            if (null == licMsg)
            {
                smcErr.ErrNo = SmcErr.SMC_INVALID_PARAM;
                logEx.Warn("Perform ReceiveLicMsg's licMsg is null msg!");
                return(smcErr.ErrNo);
            }
            else
            {
                logEx.Trace("ReceiveLicMsg licMsg msg: {0}", licMsg.GetType());
            }

            if (LicCallBackType.LicLKReadRevokeTicket == licMsg.MsgID)
            {
                LicMsg license = new LicMsg();
                if (LicPersisFileType.LicPersistentSafemem == licMsg.FileType)
                {
                    if (File.Exists(strPathPersistent))
                    {
                        license.MsgParam = File.ReadAllBytes(strPathPersistent);
                        logEx.Info("LoadLicPersistentSafemem is successful!");
                    }
                    else
                    {
                        //string str = "0x";
                        //byte[] b = Encoding.Default.GetBytes(str);
                        byte[] b = new byte[0];
                        license          = new LicMsg();
                        license.MsgParam = b;
                    }
                }
                else if (LicPersisFileType.LicPersistentInfo == licMsg.FileType)
                {
                    if (this.licenseFileOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                    {
                        try
                        {
                            try
                            {
                                if (File.Exists(strPathLic))
                                {
                                    license.MsgParam = File.ReadAllBytes(strPathLic);
                                    logEx.Info("LoadLicenseInfo is successful!");
                                }
                                else
                                {
                                    byte[] b = new byte[0];
                                    license          = new LicMsg();
                                    license.MsgParam = b;
                                }
                            }
                            catch (System.Exception ex)
                            {
                                logEx.Error(ex, "LicLKReadRevokeTicket faild!");
                                //记录系统加载License失败
                                SmcErr recordErr = new SmcErr(SmcErr.LICENSE_LOAD_ERR);
                                recordErr.ErrorInfoParam = new ErrorInfo();
                                recordErr.ErrorInfoParam.AddSmcErrInfo(smcErr);

                                logEx.Error(recordErr);
                            }
                        }
                        finally
                        {
                            this.licenseFileOperateLock.ExitWriteLock();
                        }
                    }
                }
                licMsg = license;
            }
            //License变更
            else if (LicCallBackType.LicLKStateChange == licMsg.MsgID)
            {
                GetControlLicItem(null);
            }
            //保存Licsense失效信息
            else if (LicCallBackType.LicLKWriteRevokeTicket == licMsg.MsgID)
            {
                File.WriteAllBytes(strPathPersistent, licMsg.MsgParam);
            }

            return(smcErr.ErrNo);
        }