SqueezeBrains SDK 1.18
CheckLicense.cs
1using System;
2using sb_cs;
3using Tutorials_Common;
4
6{
22 {
23 static SbError execute()
24 {
25 SbProject prj = null;
26 SbPar par = null;
27 SbError err = SbError.SB_ERR_NONE;
28
30 Console.WriteLine("Sb Init");
31 err = Sb.Init("NO_KEY");
32 if (err != SbError.SB_ERR_NONE)
33 {
34 Console.WriteLine("Sb.Init failed with error " + err);
35 return err;
36 }
37
39 String project_file = "../../solution/solution_test." + SbDefines.SbSolutionExt;
40 SbSolutionInfo solutionInfo = SbSolution.GetInfo(project_file);
41 if (solutionInfo == null || solutionInfo.Error() != SbError.SB_ERR_NONE)
42 {
43 err = solutionInfo == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : solutionInfo.Error();
44 Console.WriteLine("SbSolution.GetInfo failed");
45 goto FnExit;
46 }
47 else if (solutionInfo.projects.Length == 0)
48 {
49 err = SbError.SB_ERR_PROJECT_NOT_FOUND;
50 Console.WriteLine("SbSolution.GetInfo no projects found");
51 goto FnExit;
52 }
53 Console.WriteLine("GetProjectsInfo, found " + solutionInfo.projects.Length + " projects");
54
55 for (int t = 1; t <= 6; t += 5)
56 {
57 Console.WriteLine("----------------------------------------------------------------------");
58 Console.WriteLine("Test all the project in the solution with thread number equal to " + t);
59 Console.WriteLine("----------------------------------------------------------------------");
60
65 for (int i = 0; i < solutionInfo.projects.Length; i++)
66 {
67 Console.WriteLine("Project " + solutionInfo.projects[i].name);
68
69 // Load the project file.
70 prj = SbProject.Load(project_file, solutionInfo.projects[i].uuid, SbProjectMode.SB_PROJECT_MODE_DETECTION_ONLY);
71 if (prj == null || prj.Error() != SbError.SB_ERR_NONE)
72 {
73 err = prj == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : prj.Error();
74 Console.WriteLine("SbProject.Load failed with error " + err);
75 goto FnExit;
76 }
77
78 // Sets the thread num.
79 par = prj.GetPar();
80 par.num_threads = t;
81 prj.SetPar(par);
82
83 for (int j = 0; j < (int)SbLicenseConfigurationId.SB_LICENSE_CONFIGURATION_NUMBER; ++j)
84 {
85 Console.WriteLine("- Configuration " + SbLicense.FormatConfiguration((SbLicenseConfigurationId)j));
86
87 // Get license configuration compatibility
89 if(prj.Error() != SbError.SB_ERR_NONE)
90 {
91 Console.WriteLine("ERROR: you cannot use the project");
92 }
93 else if (msg != null)
94 {
95 Console.WriteLine("WARNING: you can use the project but with some limitations");
96 }
97 else
98 {
99 Console.WriteLine("OK: you can use the project without any limitations");
100 }
101 }
102
103 if (prj != null)
104 {
105 prj.Dispose();
106 prj = null;
107 }
108 if (par != null)
109 {
110 par.Dispose();
111 par = null;
112 }
113
114 Console.WriteLine("");
115 }
116 }
117
118
119 FnExit:
121 if (prj != null)
122 prj.Dispose();
123 if (par != null)
124 par.Dispose();
125
126 Console.WriteLine("Release SqueezeBrains library");
127 Sb.Release();
128
129 Console.WriteLine("Press ENTER to terminate");
130 Console.ReadKey();
131
132 return err;
133 }
134
135 static void Main(string[] args)
136 {
137 execute();
138 }
139 }
140}
Tutorial 3 - How to check the compatibility of a project with a license configuration.
Definition: CheckLicense.cs:22
SbError Error()
Returns the error code of the last operation. If no error SbError.SB_ERR_NONE is returned.
Defines class
Definition: cs_common.h:309
static const String SbSolutionExt
Solution file extension
Definition: cs_common.h:315
Sb Main Class
Definition: cs_sb.h:401
static SbError Release()
Releases all the resources allocated in the library
static SbError Init(String ^ license_file)
Init the SB Library. The function initializes all the functionalities of the library including the li...
License Class that wraps the sb_t_license structure. You must call the Dispose() method to free all ...
Definition: cs_license.h:179
static String FormatConfiguration(SbLicenseConfigurationId id)
Formats the license configuration id
Parameters Class that wraps the sb_t_par structure. You must call the Dispose() method to free all th...
Definition: cs_par.h:751
int num_threads
Num threads to be used for the detection
Definition: cs_par.h:775
Project Class You must call the Dispose() method to free all the resources of the returned instance.
Definition: cs_project.h:51
static SbProject Load(String^ solution_file, String^ project_uuid, SbProjectMode mode)
Loads an existing project from file.
String LicenseConfigurationCheck(SbLicenseConfigurationId id)
Checks if the project can be used with a license configuration.
SbPar GetPar()
Retrieves the project parameters structure.
SbError SetPar(SbPar^ par)
Sets the project parameters.
Solution class
Definition: cs_solution.h:44
static SbSolutionInfo GetInfo(String^ solution_file)
Returns the information contained in the solution_file.
Solution Info Class that wraps the sb_t_solution_info structure
Definition: cs_solution.h:17
array< SbProjectInfo^> projects
Array of the projects information of the solution. sb_t_solution_info.projects
Definition: cs_solution.h:23
SbError
Enum error codes
Definition: cs_common.h:13
SbLicenseConfigurationId
License configuration id that wraps the sb_t_license_configuration_id enum.
Definition: cs_license.h:28
SbProjectMode
Project loading or saving mode that wraps the sb_t_project_mode enum
Definition: cs_project.h:18
SB Namespace
Definition: cs_common.h:3