SqueezeBrains SDK 1.13
CheckLicense.cs
1using System;
2using sb_cs;
3using Tutorials_Common;
4
6{
22 {
23 static SbError execute()
24 {
25 SbProject prj = null;
26 SbError err = SbError.SB_ERR_NONE;
27
29 Console.WriteLine("Sb Init");
30 err = Sb.Init("NO_KEY");
31 if (err != SbError.SB_ERR_NONE)
32 {
33 Console.WriteLine("Sb.Init failed with error " + err);
34 return err;
35 }
36
38 String project_file = "../../solution/solution_test." + SbDefines.SbSolutionExt;
39 SbSolutionInfo solutionInfo = SbSolution.GetInfo(project_file);
40 if (solutionInfo == null || solutionInfo.Error() != SbError.SB_ERR_NONE)
41 {
42 err = solutionInfo == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : solutionInfo.Error();
43 Console.WriteLine("SbSolution.GetInfo failed");
44 goto FnExit;
45 }
46 else if (solutionInfo.projects.Length == 0)
47 {
48 err = SbError.SB_ERR_PROJECT_NOT_FOUND;
49 Console.WriteLine("SbSolution.GetInfo no projects found");
50 goto FnExit;
51 }
52 Console.WriteLine("GetProjectsInfo, found " + solutionInfo.projects.Length + " projects");
53
54 for (int t = 1; t <= 6; t += 5)
55 {
56 Console.WriteLine("----------------------------------------------------------------------");
57 Console.WriteLine("Test all the project in the solution with thread number equal to " + t);
58 Console.WriteLine("----------------------------------------------------------------------");
59
64 for (int i = 0; i < solutionInfo.projects.Length; i++)
65 {
66 Console.WriteLine("Project " + solutionInfo.projects[i].name);
67
68 // Load the project file.
69 prj = SbProject.Load(project_file, solutionInfo.projects[i].uuid, SbProjectMode.SB_PROJECT_MODE_DETECTION_ONLY);
70 if (prj == null || prj.Error() != SbError.SB_ERR_NONE)
71 {
72 err = prj == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : prj.Error();
73 Console.WriteLine("SbProject.Load failed with error " + err);
74 goto FnExit;
75 }
76
77 // Sets the thread num.
78 SbPar par = prj.GetPar();
79 par.num_threads = t;
80 prj.SetPar(par);
81
82 for (int j = 0; j < (int)SbLicenseConfigurationId.SB_LICENSE_CONFIGURATION_NUMBER; ++j)
83 {
84 Console.WriteLine("- Configuration " + SbLicense.FormatConfiguration((SbLicenseConfigurationId)j));
85
86 // Get license configuration compatibility
88 if(prj.Error() != SbError.SB_ERR_NONE)
89 {
90 Console.WriteLine("ERROR: you cannot use the project");
91 }
92 else if (msg != null)
93 {
94 Console.WriteLine("WARNING: you can use the project but with some limitations");
95 }
96 else
97 {
98 Console.WriteLine("OK: you can use the project without any limitations");
99 }
100 }
101
102 if (prj != null)
103 {
104 prj.Dispose();
105 prj = null;
106 }
107
108 Console.WriteLine("");
109 }
110 }
111
112
113 FnExit:
115 if (prj != null)
116 prj.Dispose();
117
118 Console.WriteLine("Release SqueezeBrains library");
119 Sb.Release();
120
121 Console.WriteLine("Press ENTER to terminate");
122 Console.ReadKey();
123
124 return err;
125 }
126
127 static void Main(string[] args)
128 {
129 execute();
130 }
131 }
132}
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:258
static const String SbSolutionExt
Solution file extension
Definition: cs_common.h:264
Sb Main Class
Definition: cs_sb.h:374
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:178
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:657
int num_threads
Num threads to be used for the detection
Definition: cs_par.h:681
Project Class You must call the Dispose() method to free all the resources of the returned instance.
Definition: cs_project.h:44
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