public override LicenseStatus DoExtraValidation() { var _licStatus = LicenseStatus.VALID; switch (Type) { case LicenseTypes.Single: //For Single License, check whether UID is matched if (UID != LicenseHandler.GenerateUID(AppName)) { _licStatus = LicenseStatus.INVALID; } break; case LicenseTypes.Volume: //No UID checking for Volume License break; default: _licStatus = LicenseStatus.INVALID; break; } return(_licStatus); }
public override LicenseStatus DoExtraValidation(out string validationMsg) { LicenseStatus _licStatus = LicenseStatus.UNDEFINED; validationMsg = string.Empty; switch (this.Type) { case LicenseTypes.Single: //For Single License, check whether UID is matched if (this.UID == LicenseHandler.GenerateUID(this.AppName)) { _licStatus = LicenseStatus.VALID; } else { validationMsg = "¡La licencia no es para esta copia!"; _licStatus = LicenseStatus.INVALID; } break; case LicenseTypes.Volume: //No UID checking for Volume License _licStatus = LicenseStatus.VALID; break; default: validationMsg = "Licencia Invalida"; _licStatus = LicenseStatus.INVALID; break; } return(_licStatus); }
/// <summary> /// 회사코드가 변경된 경우는 db재설치를 한경우 /// 신규이거나 변경사항 없으면 패스 /// 등록한 라이센스파일을 C:\eclues\AppData\config로 복사. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonNext_Click(object sender, EventArgs e) { ctrl.KeepPrevConfig = CkBoxKeepConfig.Checked; if (ctrl.CompanyCd != "" && !ctrl.CompanyCd.Equals(companyCd)) { if (MessageBox.Show(string.Format("이전에 사용하던 회사코드({0})와 다른 회사코드({1})가 적용되었습니다. " + "\n회사코드를 변경하시겠습니까?" , ctrl.CompanyCd , companyCd) , "회사코드 변경" , MessageBoxButtons.OKCancel) == DialogResult.Cancel) { DialogResult = DialogResult.None; ButtonLicenseFile.Focus(); return; } } ctrl.CompanyCd = companyCd; ctrl.CompanyName = companyName; ctrl.MsgrPort = Convert.ToInt16(TextBoxMsgrPort.Text); ctrl.CrmPort = Convert.ToInt16(TextBoxCrmPort.Text); FileInfo info = new FileInfo(LabelLicenseFile.Text); LicenseHandler handler = new LicenseHandler(info); handler.BackupLicenseFile(ConstDef.APP_DATA_CONFIG_DIR); }
public override LicenseStatus DoExtraValidation(out string validationMsg) { var _licStatus = LicenseStatus.Undefined; validationMsg = string.Empty; switch (Type) { case LicenseTypes.Single: //For Single License, check whether UID is matched if (UID == LicenseHandler.GenerateUid(AppName)) { _licStatus = LicenseStatus.Valid; } else { validationMsg = "The license is NOT for this copy!"; _licStatus = LicenseStatus.Invalid; } break; case LicenseTypes.Volume: //No UID checking for Volume License _licStatus = LicenseStatus.Valid; break; default: validationMsg = "Invalid license"; _licStatus = LicenseStatus.Invalid; break; } return(_licStatus); }
public static void InitLicense() { MemoryStream mem = new MemoryStream(); Assembly.GetExecutingAssembly().GetManifestResourceStream("PrivateWin10.LicenseVerify.cer").CopyTo(mem); byte[] certPubicKeyData = mem.ToArray(); string msg = string.Empty; LicenseStatus status = LicenseStatus.UNDEFINED; if (File.Exists("license.lic")) { lic = (MyLicense)LicenseHandler.ParseLicenseFromBASE64String(typeof(MyLicense), File.ReadAllText("license.lic"), certPubicKeyData, out status, out msg); } else { msg = "Your copy of this application is not activated"; } if (lic == null) { lic = new MyLicense(); // we always want this object } lic.LicenseStatus = status; if (status != LicenseStatus.VALID && msg.Length == 0) { msg = "Your license file is invalid or broken"; } if (status == LicenseStatus.INVALID || status == LicenseStatus.CRACKED) { MessageBox.Show(msg, App.mName, MessageBoxButton.OK, MessageBoxImage.Error); } Console.WriteLine(msg); }
private bool ValidateLicense() { if (string.IsNullOrWhiteSpace(License)) { MessageBox.Show("Please input license", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } //Check the activation string LicenseStatus _licStatus = LicenseStatus.UNDEFINED; string _msg = string.Empty; LicenseEntity _lic = LicenseHandler.ParseLicenseFromBASE64String(LicenseObjectType, License.Trim(), _certPubicKeyData, out _licStatus, out _msg); switch (_licStatus) { case LicenseStatus.VALID: MessageBox.Show(_msg, "License is valid", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); case LicenseStatus.CRACKED: case LicenseStatus.INVALID: case LicenseStatus.UNDEFINED: MessageBox.Show(_msg, "License is INVALID", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); default: return(false); } }
/// <summary> /// Returns the current server status. /// </summary> /// <returns>The current server status.</returns> public OpcServerStatus GetServerStatus() { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions); if (Server == null) { throw new NotConnectedException(); } OpcServerStatus status = ((ITsCAeServer)Server).GetServerStatus(); if (status != null) { if (status.StatusInfo == null) { status.StatusInfo = GetString($"serverState.{status.ServerState}"); } } else { if (Server == null) { throw new NotConnectedException(); } } return(status); }
/// <summary> /// Causes the server to send a data changed notification for all active items. /// </summary> /// <param name="requestHandle">An identifier for the request assigned by the caller.</param> /// <param name="request">An object that contains the state of the request (used to cancel the request).</param> /// <returns>A set of results containing any errors encountered when the server validated the items.</returns> public void Refresh( object requestHandle, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess); Subscription.Refresh(requestHandle, out request); }
/// <summary> /// Connects to the server with the specified OpcUrl and credentials. /// </summary> public override void Connect(OpcUrl url, OpcConnectData connectData) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions); if (Factory == null) { Factory = new Factory(); } // connect to server. base.Connect(url, connectData); // all done if no subscriptions. if (subscriptions_.Count == 0) { return; } // create subscriptions (should only happen if server has been deserialized). SubscriptionCollection subscriptions = new SubscriptionCollection(); foreach (TsCAeSubscription template in subscriptions_) { // create subscription for template. try { subscriptions.Add(EstablishSubscription(template)); } catch { // ignored } } // save new set of subscriptions. subscriptions_ = subscriptions; }
private void btnActivate_Click(object sender, RoutedEventArgs e) { try { License license = LicenseHandler.ValidProductKey(txtProductKey.Text.Trim().ToUpper()); if (license != null) { lbLicensingStatus.Visibility = Visibility.Visible; lbExpireDate.Visibility = Visibility.Visible; lbLicenseType.Visibility = Visibility.Visible; lbLicensingStatus.Text = "Your Product is activated"; lbExpireDate.Text = "Expire Date: " + license.ExpireDate; lbLicenseType.Text = "License Type: " + license.LicenseType.ToUpper(); } else { MessageBox.Show("Invalid Product Key"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Sends an asynchronous request to read the attributes of an item. /// </summary> /// <param name="startTime">The beginning of the history period to read.</param> /// <param name="endTime">The end of the history period to be read.</param> /// <param name="item">The item to read (must include the item name).</param> /// <param name="attributeIDs">The attributes to read.</param> /// <param name="requestHandle">An identifier for the request assigned by the caller.</param> /// <param name="callback">A delegate used to receive notifications when the request completes.</param> /// <param name="request">An object that contains the state of the request (used to cancel the request).</param> /// <returns>A set of results containing any errors encountered when the server validated the attribute ids.</returns> internal TsCHdaResultCollection ReadAttributes( TsCHdaTime startTime, TsCHdaTime endTime, OpcItem item, int[] attributeIDs, object requestHandle, TsCHdaReadAttributesCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) { throw new NotConnectedException(); } TsCHdaResultCollection results = ((ITsCHdaServer)Server).ReadAttributes( startTime, endTime, item, attributeIDs, requestHandle, callback, out request); return(results); }
/// <summary> /// Sends an asynchronous request to read item values that have been deleted or replaced. /// </summary> /// <param name="startTime">The beginning of the history period to read.</param> /// <param name="endTime">The end of the history period to be read.</param> /// <param name="maxValues">The number of values to be read for each item.</param> /// <param name="items">The set of items to read (must include the item name).</param> /// <param name="requestHandle">An identifier for the request assigned by the caller.</param> /// <param name="callback">A delegate used to receive notifications when the request completes.</param> /// <param name="request">An object that contains the state of the request (used to cancel the request).</param> /// <returns>A set of results containing any errors encountered when the server validated the items.</returns> internal OpcItemResult[] ReadModified( TsCHdaTime startTime, TsCHdaTime endTime, int maxValues, OpcItem[] items, object requestHandle, TsCHdaReadValuesCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) { throw new NotConnectedException(); } OpcItemResult[] results = ((ITsCHdaServer)Server).ReadModified( startTime, endTime, maxValues, items, requestHandle, callback, out request); return(results); }
/// <summary> /// Begins the playback of processed data from the historian database for a set of items. /// </summary> /// <param name="startTime">The beginning of the history period to read.</param> /// <param name="endTime">The end of the history period to be read.</param> /// <param name="resampleInterval">The interval between returned values.</param> /// <param name="numberOfIntervals">The number of resample intervals that the server should return in each callback.</param> /// <param name="updateInterval">The frequency, in seconds, that the server send data.</param> /// <param name="items">The set of items to read (must include the item name).</param> /// <param name="requestHandle">An identifier for the request assigned by the caller.</param> /// <param name="callback">A delegate used to receive notifications when the request completes.</param> /// <param name="request">An object that contains the state of the request (used to cancel the request).</param> /// <returns>A set of results containing any errors encountered when the server validated the items.</returns> internal OpcItemResult[] PlaybackProcessed( TsCHdaTime startTime, TsCHdaTime endTime, decimal resampleInterval, int numberOfIntervals, decimal updateInterval, TsCHdaItem[] items, object requestHandle, TsCHdaDataUpdateEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) { throw new NotConnectedException(); } OpcItemResult[] results = ((ITsCHdaServer)Server).PlaybackProcessed( startTime, endTime, resampleInterval, numberOfIntervals, updateInterval, items, requestHandle, callback, out request); return(results); }
private void btnGenSvrMgmLic_Click(object sender, EventArgs e) { //Event raised when "Generate License" button is clicked. //Call the core library to generate the license licenseStringContainerViewModel.LicenseString = LicenseHandler.GenerateLicenseBASE64String( new FinancialAnalysisLicense(), _certPubicKeyData, _certPwd); }
/// <summary> /// Adds items to the subscription. /// </summary> public virtual TsCDaItemResult[] AddItems(TsCDaItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess); if (items == null) { throw new ArgumentNullException(nameof(items)); } // check if there is nothing to do. if (items.Length == 0) { return(new TsCDaItemResult[0]); } // add items. TsCDaItemResult[] results = Subscription.AddItems(items); if (results == null || results.Length == 0) { throw new OpcResultException(new OpcResult(OpcResult.E_FAIL.Code, OpcResult.FuncCallType.SysFuncCall, null), "The browse operation cannot continue"); } // update locale item list. ArrayList itemList = new ArrayList(); if (daItems_ != null) { itemList.AddRange(daItems_); } for (int ii = 0; ii < results.Length; ii++) { // check for failure. if (results[ii].Result.Failed()) { continue; } // create locale copy of the item. // item name, item path and client handle may not be returned by server. TsCDaItem item = new TsCDaItem(results[ii]) { ItemName = items[ii].ItemName, ItemPath = items[ii].ItemPath, ClientHandle = items[ii].ClientHandle }; itemList.Add(item); } // save the new item list. daItems_ = (TsCDaItem[])itemList.ToArray(typeof(TsCDaItem)); // update the local state. GetState(); // return results. return(results); }
/// <summary> /// Cancels an asynchronous request. /// </summary> /// <param name="request">The state object for the request to cancel.</param> public void CancelRequest(IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) { throw new NotConnectedException(); } ((ITsCHdaServer)Server).CancelRequest(request); }
/// <summary> /// Replace the values into the history database for one or more items. /// </summary> /// <param name="items">The set of values to replace.</param> /// <returns></returns> public TsCHdaResultCollection[] Replace(TsCHdaItemValueCollection[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) { throw new NotConnectedException(); } return(((ITsCHdaServer)Server).Replace(items)); }
/// <summary> /// Reads data from the historian database for a set of items at specific times. /// </summary> /// <param name="timestamps">The set of timestamps to use when reading items values.</param> /// <param name="items">The set of items to read (must include the item name).</param> /// <returns>A set of values, qualities and timestamps within the requested time range for each item.</returns> internal TsCHdaItemValueCollection[] ReadAtTime(DateTime[] timestamps, OpcItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) { throw new NotConnectedException(); } return(((ITsCHdaServer)Server).ReadAtTime(timestamps, items)); }
/// <summary> /// Validates a set of items. /// </summary> /// <param name="items">The identifiers for the items to validate.</param> /// <returns>The results for each item containing the result code.</returns> public OpcItemResult[] ValidateItems(OpcItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) { throw new NotConnectedException(); } return(((ITsCHdaServer)Server).ValidateItems(items)); }
/// <summary> /// Creates a object used to browse the server address space. /// </summary> /// <param name="filters">The set of attribute filters to use when browsing.</param> /// <param name="results">A result code for each individual filter.</param> /// <returns>A browser object that must be released by calling Dispose().</returns> public ITsCHdaBrowser CreateBrowser(TsCHdaBrowseFilter[] filters, out OpcResult[] results) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) { throw new NotConnectedException(); } return(((ITsCHdaServer)Server).CreateBrowser(filters, out results)); }
/// <summary>Continues a browse operation with previously specified search criteria.</summary> /// <returns>The set of elements found.</returns> /// <requirements>OPC XML-DA Server or OPC Data Access Server V2.x / V3.x</requirements> /// <param name="position">An object containing the browse operation state information.</param> public TsCDaBrowseElement[] BrowseNext(ref TsCDaBrowsePosition position) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess); if (Server == null) { throw new NotConnectedException(); } return(((ITsDaServer)Server).BrowseNext(ref position)); }
/// <summary> /// Deletes the values at the specified times for one or more items. /// </summary> /// <param name="items">The set of timestamps to delete for one or more items.</param> /// <returns>The results of the operation for each timestamp.</returns> internal TsCHdaResultCollection[] DeleteAtTime(TsCHdaItemTimeCollection[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) { throw new NotConnectedException(); } return(((ITsCHdaServer)Server).DeleteAtTime(items)); }
public byte Initialize() // ToDo proper response class? Async? { if (string.IsNullOrEmpty(Token)) { if (UseDefaultActivationPanel) { //Shut down program, todo: debug notifications Environment.Exit(Environment.ExitCode); } return((byte)TokenValidationStatus.InvalidToken); } var tokenHandler = new TokenHandler(); switch (tokenHandler.ValidateToken(Token)) { case TokenValidationStatus.TokenValidated: //Now we check for a locally stored license file var licenseHandler = new LicenseHandler(Token); /*if (licenseHandler.ValidateLocalLicense()) * { * //return (byte)Status.Success; * } */ // No local file found, proceed if (UseDefaultActivationPanel) // { //Display activation panel var formValidator = new formValidator(ref licenseHandler); formValidator.ShowDialog(); } break; case TokenValidationStatus.InvalidToken: MessageBox.Show("Your API key is invalid."); Environment.Exit(Environment.ExitCode); break; case TokenValidationStatus.BannedToken: MessageBox.Show("Your API key is banned."); Environment.Exit(Environment.ExitCode); break; case TokenValidationStatus.SoftwareOutOfDate: break; case TokenValidationStatus.UnknownError: break; } return((byte)Status.Success); }
/// <summary> /// Begins an asynchronous write operation for a set of items. /// </summary> /// <param name="items">The set of item values to write (must include the item name).</param> /// <param name="requestHandle">An identifier for the request assigned by the caller.</param> /// <param name="callback">A delegate used to receive notifications when the request completes.</param> /// <param name="request">An object that contains the state of the request (used to cancel the request).</param> /// <returns>A set of results containing any errors encountered when the server validated the items.</returns> public OpcItemResult[] Write( TsCDaItemValue[] items, object requestHandle, TsCDaWriteCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess); return(Subscription.Write(items, requestHandle, callback, out request)); }
private void btnGenSvrMgmLic_Click(object sender, EventArgs e) { //Event raised when "Generate License" button is clicked. //Call the core library to generate the license licString.LicenseString = LicenseHandler.GenerateLicenseBASE64String( new MyLicense(), _certPrivateKeyData, _certPwd); }
private void frmMain_Shown(object sender, EventArgs e) { //Initialize variables with default values MyLicense _lic = null; var _msg = string.Empty; LicenseStatus _status; //Read public key from resources _certPubicKeyData = DemoLicense.Properties.Resource.Licensing; //Check if the XML license file exists if (File.Exists("license.lic")) { _lic = (MyLicense)LicenseHandler.ParseLicenseFromBASE64String( typeof(MyLicense), File.ReadAllText("license.lic"), _certPubicKeyData, out _status); } else { _status = LicenseStatus.INVALID; _msg = "Your copy of this application is not activated"; } switch (_status) { case LicenseStatus.VALID: //TODO: If license is valid, you can do extra checking here //TODO: E.g., check license expiry date if you have added expiry date property to your license entity //TODO: Also, you can set feature switch here based on the different properties you added to your license entity //Here for demo, just show the license information and RETURN without additional checking licInfo.ShowLicenseInfo(_lic); return; default: //for the other status of license file, show the warning message //and also popup the activation form for user to activate your application MessageBox.Show(_msg, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Warning); using (var frm = new frmActivation()) { frm.CertificatePublicKeyData = _certPubicKeyData; frm.ShowDialog(); //Exit the application after activation to reload the license file //Actually it is not nessessary, you may just call the API to reload the license file //Here just simplied the demo process Application.Exit(); } break; } }
/// <summary>Writes the value, quality and timestamp for a set of items.</summary> /// <returns>The results of the write operation for each item.</returns> /// <requirements>OPC XML-DA Server or OPC Data Access Server V3.x</requirements> /// <param name="items">The set of item values to write.</param> public OpcItemResult[] Write(TsCDaItemValue[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess); if (Server == null) { throw new NotConnectedException(); } return(((ITsDaServer)Server).Write(items)); }
/// <summary> /// Continues browsing the server's address space at the specified position. /// </summary> /// <param name="maxElements">The maximum number of elements to return.</param> /// <param name="position">The position object used to continue a browse operation.</param> /// <returns>The set of elements that meet the filter criteria.</returns> public TsCAeBrowseElement[] BrowseNext(int maxElements, ref IOpcBrowsePosition position) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions); if (Server == null) { throw new NotConnectedException(); } return(((ITsCAeServer)Server).BrowseNext(maxElements, ref position)); }
/// <summary> /// Modifies items that are already part of the subscription. /// </summary> public virtual TsCDaItemResult[] ModifyItems(int masks, TsCDaItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess); if (items == null) { throw new ArgumentNullException(nameof(items)); } // check if there is nothing to do. if (items.Length == 0) { return(new TsCDaItemResult[0]); } // modify items. TsCDaItemResult[] results = Subscription.ModifyItems(masks, items); if (results == null || results.Length == 0) { throw new OpcResultException(new OpcResult(OpcResult.E_FAIL.Code, OpcResult.FuncCallType.SysFuncCall, null), "The browse operation cannot continue"); } // update local item - modify item success means all fields were updated successfully. for (int ii = 0; ii < results.Length; ii++) { // check for failure. if (results[ii].Result.Failed()) { continue; } // search local item list. for (int jj = 0; jj < daItems_.Length; jj++) { if (daItems_[jj].ServerHandle.Equals(items[ii].ServerHandle)) { // update locale copy of the item. // item name, item path and client handle may not be returned by server. TsCDaItem item = new TsCDaItem(results[ii]) { ItemName = daItems_[jj].ItemName, ItemPath = daItems_[jj].ItemPath, ClientHandle = daItems_[jj].ClientHandle }; daItems_[jj] = item; break; } } } // update the local state. GetState(); // return results. return(results); }
private void CheckLicense() { //Initialize variables with default values MyLicense _lic = null; string _msg = string.Empty; LicenseStatus _status = LicenseStatus.UNDEFINED; //Read public key from assembly Assembly _assembly = Assembly.GetExecutingAssembly(); using (MemoryStream _mem = new MemoryStream()) { _assembly.GetManifestResourceStream("TMF_ftp.LicenseVerify.cer").CopyTo(_mem); _certPubicKeyData = _mem.ToArray(); } //Check if the XML license file exists if (File.Exists("license.lic")) { _lic = (MyLicense)LicenseHandler.ParseLicenseFromBASE64String( typeof(MyLicense), File.ReadAllText("license.lic"), _certPubicKeyData, out _status, out _msg); } else { _status = LicenseStatus.INVALID; _msg = "This application is not activated"; } switch (_status) { case LicenseStatus.VALID: //TODO: If license is valid, you can do extra checking here //TODO: E.g., check license expiry date if you have added expiry date property to your license entity //TODO: Also, you can set feature switch here based on the different properties you added to your license entity return; default: MessageBox.Show(_msg, "TMF ftp", MessageBoxButtons.OK, MessageBoxIcon.Warning); using (frmActivation frm = new frmActivation()) { frm.CertificatePublicKeyData = _certPubicKeyData; frm.ShowDialog(); Application.Exit(); } break; } }
/// <summary> /// 파일에서 라이센스정보를 읽어, 유효성검사를 한다. /// </summary> private void registerLicenseInfo() { try { logWrite("라이선스 체크중....."); mLicenseHandler = new LicenseHandler(this.licenseDir, this.MACID); mLicenseHandler.LogWriteHandler += this.OnLogWrite; //파일읽음&라이센스값 decode if (mLicenseHandler.ReadLicense()) { stringDele dele = new stringDele(disposeLicenseResult); Invoke(dele, mLicenseHandler.ResultMessage); } } catch (Exception ex) { logWrite(ex.ToString()); } }