Thứ Năm, 9 tháng 5, 2024

Kiểm tra bản quyền ứng dụng Plugin trên AutoDesk Store | Publish a plugins to the AutoDesk Store

Ứng dụng được phát triển bởi đội ngũ AutoLISP Thật là đơn giản

    

Thông tin thêm: 👉👉👉

ID Ứng dụng

Sau khi đã xuất bản ứng dụng lên Store, mỗi ứng dụng sẽ được cấp 1 mã số ID. Mã số ID này là cơ sở đầu tiên để kiểm tra bản quyền trên AutoDesk Store



Khởi tạo Project mới trong VS

Để sử dụng, hãy tạo mới 1 Solution và 1 Project mới có tên CheckEntitlement_by_AJS



Thêm code c#



1 Thêm class EntitlementResult.cs

(Copy nội dung sau)
Code:
namespace Check_Entitlement_by_AJS
{
    public class EntitlementResult
    {
        public string UserId { get; set; }
        public string AppId { get; set; }
        public bool IsValid { get; set; }
        public string Message { get; set; }
        //Example by www.lisp.vn
    }
}



2a Thêm class AJS_Lics.cs

(Copy nội dung sau - Lưu ý thay đổi _appID = "4688092142369552289")
Code:
using RestSharp;
using System;
using System.Windows;

namespace Check_Entitlement_by_AJS
{
    internal static class AJS_Lics
    {
        //Install-Package RestSharp -Version 105.2.3
        //Example by www.lisp.vn
        private static String _appID = "4688092142369552289";
        private static bool mCheckOnline;

        public static bool CheckOnline(bool msg = true)
        {
            if (mCheckOnline) return true;
            String _userID = "";
            try
            {
                _userID = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("ONLINEUSERID") as String;
            }
            catch
            {
                if (msg)
                    MessageBox.Show("Work on AutoCAD > 2014 Only");
                return false;
            }

            if (_userID.Equals(""))
            {
                if (msg)
                    MessageBox.Show("Please log-in to Autodesk 360");
                return false;
            }

            try
            {
                //check for online entitlement
                RestClient client = new RestClient("https://apps.autodesk.com");
                RestRequest req = new RestRequest("webservices/checkentitlement");
                req.Method = Method.GET;
                req.AddParameter("userid", _userID);
                req.AddParameter("appid", _appID);
                System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
                IRestResponse<EntitlementResult> resp = client.Execute<EntitlementResult>(req);

                mCheckOnline = resp.Data != null && resp.Data.IsValid;
            }
            catch
            {
                if (msg)
                    MessageBox.Show("Cannot connect to the https://apps.autodesk.com");
            }

            if (mCheckOnline != true && msg)
                MessageBox.Show("You are not entitled to use this plug-in!");

            //Example by www.lisp.vn
            return mCheckOnline;
        }
    }
}


2b Thêm thử viện RestSharp 105.2.3

(Copy nội dung sau và chạy trong Package Manager Console)
Code:
Install-Package RestSharp -Version 105.2.3




3 Thêm hoặc chỉnh sửa myCommands.cs

(Copy nội dung sau)
Code:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(Check_Entitlement_by_AJS.MyCommands))]

namespace Check_Entitlement_by_AJS
{
    // This class is instantiated by AutoCAD for each document when
    // a command is called by the user the first time in the context
    // of a given document. In other words, non static data in this class
    // is implicitly per-document!
    public class MyCommands
    {
        [CommandMethod("CheckEntitlement", CommandFlags.Modal)]
        public void MyCommand_CheckEntitlement()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            if (doc == null) return;
            Editor ed = doc.Editor;

            var HasEntitlement = AJS_Lics.CheckOnline(true);
            if (!HasEntitlement)
            {
                ed.WriteMessage("You are not entitled to use this plug-in!");
                return;
            }

            ed.WriteMessage("You are entitled to use this plug-in! Continue");
            // Put your command code here
            // Put your command code here
            // Put your command code here

            //
            //Example by www.lisp.vn
        }
    }
}

Build và chạy trong AutoCAD

Dùng lệnh Netload để tải tệp tin Check_Entitlement_by_AJS.dll vừa build.

Chạy lệnh CheckEntitlement

  • Khi chưa Log-in vào AutoCAD A360

  • Khi đã Log-in nhưng chưa có bản quyền


Lưu ý quan trọng

Để kiểm tra bản quyền Online, bắt buộc người dùng phải đáp ứng các yêu cầu:
  • Có tài khoản AutoDesk Store
  • Tải và đăng ký bản quyền bằng cùng tài khoản.
  • AutoCAD sử dụng có thể kết nối mạng
  • Đăng nhập vào AutoCad A360 trên máy sử dụng
Nếu không, việc kiểm tra bản quyền sẽ thất bại!



Tham khảo GitHub

Các bạn có thể tải Solution từ: https://github.com/AutoLISP-Just-Simple/Check_Entitlement_by_AJS

Solution hỗ trợ cả c# và vbNet





--------------------------------------------------------------------------------------------------------------
Ứng dụng được phát triển bởi đội ngũ AutoLISP Thật là đơn giản

    
--------------------------------------------------------------------------------------------------------------

Mọi thông tin xin liên hệ Fanpage AutoLISP Thật là đơn giản!
Cảm ơn bạn đã theo dõi!

Không có nhận xét nào:

Đăng nhận xét

Mở lại bản vẽ AutoCAD cuối cùng | Open last closed drawing in AutoCAD | AutoLisp Reviewer

Ứng dụng được phát triển bởi đội ngũ AutoLISP Thật là đơn giản       Thông tin thêm: 👉👉👉