{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"Configure Activation","type":"basic","slug":"add-activation","excerpt":"","body":"1. Take the steps described in [Integrate DevMateKit](doc:integrate-devmatekit) if you haven't done it yet.\n2. Add the following properties to `DMFrameworkSettings`:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"DMFrameworkSettings.PublickRSAKey = :::at:::\\\"-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzRWGeVD5D1FDuRhpSKzU P19hTLUNE0AHZHjdU05AZOUa8gxlCfMSHjsuM95dtk2Z+Pgd9Vq1OTGrYhav9jZP xUMdtHcinyAnXjAz2hgSSb3/1qrXPxaSoG05x8LPTEN5RYxal6PorRDGOAvG8sgN /nHIBmylZMpQOegWo8JppIpKHEfii23JcGuXkoo/oen33TQq5y/HhWWRKfxVbnGx RnD25WAOcWpvg+H2gWVrfLwRAu9GK0yGBhOhbgKsfO056NAwfM02HhRAtwfC7Xhc ID6kPWp/qThVLSfGhwXkUNwAxfCHh/5dH2rF/xfCAhvfBhxLYx7Njg3Ana/Ybo1L 5wIDAQAB -----END PUBLIC KEY-----\\\";\\n//!!! \\nDMFrameworkSettings.IsFirstRun = false;\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n\n[block:callout]\n{\n \"type\": \"info\",\n \"title\": \"NOTE\",\n \"body\": \"On first clean run of the application, the `IsFirstRun` property must be set to “true”.\\nAlso note that you must specify `PublickRSAKey` to enable the Activation functionality. A unique key is provided by DevMate's Add Application wizard on the Configure Activation step.\"\n}\n[/block]\n3. You can specify additional `DMFrameworkSettings` properties if needed. DevMate Activation provides the following configuration options:\n[block:parameters]\n{\n \"data\": {\n \"h-0\": \"Property\",\n \"h-1\": \"Type\",\n \"h-2\": \"Description\",\n \"0-0\": \"`IsFirstRun`\",\n \"0-1\": \"bool\",\n \"0-2\": \"Property (bool) must be set to “true” on first clean run of the application. In this case, DevMate will receive a report from the application that contains data on the first actual launch of the app.\",\n \"1-0\": \"`IsBeta`\",\n \"1-1\": \"bool\",\n \"1-2\": \"Specifies whether a current version of the application is Beta.\",\n \"2-0\": \"`URLActivationSchema`\",\n \"2-1\": \"string\",\n \"2-2\": \"Used for running the application by the URL Scheme. For more details, read [Configure Activation via URL Scheme](https://docs.devmate.com/v1.0/docs/add-activation#section-configuring-activation-via-url-scheme-optional-).\",\n \"3-0\": \"`StoreAdditionalParameters`\",\n \"3-1\": \"Dictionary<string,string>\",\n \"3-2\": \"Configures additional GET parameters for your Store Link.\",\n \"4-0\": \"`ApplicationIcon`\",\n \"4-1\": \"string\",\n \"4-2\": \"Sets a “TitleBar” icon for DevMate Framework windows. Must contain at least one 16x16pt icon. Example: *pack://application:,,,/TestApp;component/icon.ico*.\"\n },\n \"cols\": 3,\n \"rows\": 5\n}\n[/block]\n3. Configure a trial mode of an application.\nUse the following code snippet to disable the trial mode in the Activation window:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"DMActivationWindow window = new DMActivationWindow(); \\nwindow.BigIconSource = new BitmapImage(new Uri(“pack://application:,,,/Images/icon.png\\\")); \\nwindow.ShowDialog();\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n Use the following code snippet to enable the trial mode in the Activation window (make sure you've specified `DMFrameworkSettings.TrialType` before:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"DMActivationWindow window = new DMActivationWindow(true); window.BigIconSource = new BitmapImage(new Uri(“pack://application:,,,/Images/icon.png\\\")); \\nwindow.ShowDialog();\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\nNote that you must use 128x128pt icon for the `BigIconSource` property. \nIf you want to open “DMActivationWindow” on the Enter Activation Key screen, set the following property to “true” before calling `ShowDialog()`:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"window.ShowEnterActivationNumberScreenAtStart = true\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n#Configuring Activation via URL Scheme (optional)\n1. Register the URL scheme on the client PC by creating the following registry keys and values:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"HKEY_CLASSES_ROOT\\\\[URL_Schema_Name]:\\n\\tSet the default value to “URL [Application_Name] Activation Protocol”.\\n\\tCreate an empty string value in HKEY_CLASSES_ROOT\\\\[URL_Schema_Name] with the \\tname \\\"URL Protocol”.\\nHKEY_CLASSES_ROOT\\\\[URL_Schema_Name]\\\\shell\\nHKEY_CLASSES_ROOT\\\\[URL_Schema_Name]\\\\shell\\\\open\\nHKEY_CLASSES_ROOT\\\\[URL_Schema_Name]\\\\shell\\\\open\\\\command:\\n\\tSet the default value to \\\"[PATH_TO_MAIN_APPLICATION_EXE]\\\" “%1”\",\n \"language\": \"text\"\n }\n ]\n}\n[/block]\n\n[block:callout]\n{\n \"type\": \"info\",\n \"title\": \"NOTE\",\n \"body\": \"You need the administrator’s permissions to complete this action. You can get these permissions during installation process.\"\n}\n[/block]\n2. Add the following code snippet to your application (it processes command line arguments):\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"DMFrameworkSettings.URLActivationSchema = [URL_Schema_Name];\\nbool fromURL = ActivationFramework.Current.IsRunUsingURLSchema();\\nif (fromURL)\\n{\\n DMActivationWindow window = new DMActivationWindow( ActivationFramework.Current.GetKeyFromURLSchema());\\n window.BigIconSource = new BitmapImage(new Uri(“pack://application:,,,/Images/icon.png”));\\n window.ShowDialog(); \\n}\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n\n[block:callout]\n{\n \"type\": \"info\",\n \"title\": \"NOTE\",\n \"body\": \"Read <a href=\\\"https://msdn.microsoft.com/library/aa767914(v=vs.85).aspx\\\">Registering an Application to a URI Scheme (MSDN)</a> to find out more.\"\n}\n[/block]\n#Configuring Activation API\nActivation API contains the following properties that must be obtained through `FindDelegate` method:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"public class DelegateType\\n{\\n public const int IsActivated;\\n public const int LicenseInformation;\\n public const int Activate;\\n public const int StartTrial;\\n public const int GetTrial;\\n public const int GetRawTrialValue;\\n public const int GetStoreLink;\\n }\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n###IsActivated\nIf you use the `IsActivated` property, the method verifies whether the application is activated.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var func = ActivationFramework.Current.FindDelegate((int) DelegateType.IsActivated) as Func<int>;\\nint isActivated = func.Invoke();\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\nPossible results are the following:\n* 0 - not activated\n* 1 - activated\n* 2 - expired\n\n###LicenseInformation\nIf you use the `LicenseInformation` property, the method verifies the license information by comparing it to the user information from DevMate.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var func = ActivationFramework.Current.FindDelegate((int) DelegateType.LicenseInformation) as Func<int, object>;\\nstring ActivationIdKey = func.Invoke(LicenseInformationKeys.ActivationIdKey).ToString();\\nstring UserName = func.Invoke(LicenseInformationKeys.UserNameKey).ToString();\\nstring UserEmail = func.Invoke(LicenseInformationKeys.UserEmailKey).ToString();\\nlong ActivationDate = Convert.ToInt64(func.Invoke(LicenseInformationKeys.ActivationDateKey));\\nlong ExpirationDate = Convert.ToInt64(func.Invoke(LicenseInformationKeys.ExpirationDateKey));\\nstring ExpirationVersion = func.Invoke(LicenseInformationKeys.ExpirationVersionKey).ToString();\\nstring ActivationTag = func.Invoke(LicenseInformationKeys.ActivationTagKey).ToString();\\nbool IsBetaOnly = Convert.ToBoolean(func.Invoke(LicenseInformationKeys.BetaOnlyKey));\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n`UserName` and `UserEmail` values are not null/empty only if a user specified them during license activation. It becomes possible when an activation number has the pattern id<numbers>u<any two letters>. Entering this kind of an activation number opens an extended activation dialog with mandatory user name and email fields.\n`ExpirationVersion` value specifies the ultimate application version covered by the current license. An owner of this license is not eligible for upgrade to versions higher than the specified one. \n\n###Activate\nIf you use the `Activate` property, the method sends user data to DevMate to register (activate) a license.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var func = ActivationFramework.Current.FindDelegate((int) DelegateType.Activate) as Func<string, string, string, bool?, long>; Task.Factory.StartNew(() => \\n{\\t\\t\\t\\n return func.Invoke(ActivationCode, UserName, UserEmail, KeepUpToDate); }).ContinueWith((result) => \\n{\\n var activationResult = (ActivationResult)Marshal.PtrToStructure(new IntPtr(result.Result), typeof(ActivationResult));\\n if (activationResult.Success)\\n { //Show Success Screen\\n }\\n else\\n {\\n ErrorText = activationResult.Error;\\n }\\n});\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n###StartTrial\nIf you use the `StartTrial` property, the method sends a report about the beginning of a trial period when a user clicks the Start Trial button.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var func = ActivationFramework.Current.FindDelegate((int) DelegateType.StartTrial) as Func<long, bool>;\\nTrialType trialType = new TrialType() { DMTrialWeek = true }; \\n\\nIntPtr trialIntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(trialType));\\nMarshal.StructureToPtr(trialType, trialIntPtr, true);\\nlong timeTrialRef = (long)trialIntPtr; \\n\\nbool res = func.Invoke(timeTrialRef);\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n`TrialType` class includes the following properties:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"public bool DMTrialDay { get; set; }\\npublic bool DMTrialWeek { get; set; }\\npublic bool DMTrialTwoWeeks { get; set; }\\npublic bool DMTrialMonth { get; set; }\\npublic bool DMTrialYear { get; set; }\\n\\npublic bool DMCustom { get; set; }\\npublic long DMTrialPeriond { get; set; }\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\nPlease note that only one of the “TrialType” properties can be set to “true” at a time. If more than one property is set to “true”, DevMate will use only the last one applied.\nIf `DMCustom` is set to “true\", `DMTrialPeriond` is used. If `DMCustom` is set to “true” and `DMTrialPeriond` is not set, the default value is used (86400 seconds).\n\n###GetTrial\nIf you use the `GetTrial` property, the method returns total duration of a trial period (in hours) and the number of hours that is already spent in the trial mode.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var func = ActivationFramework.Current.FindDelegate((int) DelegateType.GetTrial) as Func<Tuple<int,int>>;\\nvar trialInfo = func.Invoke();\\n\\nif (trialInfo.Item1 == -1 || trialInfo.Item2 == -1) \\n{\\n //Trial not started \\n} \\nelse \\n{ \\nTrialPeriod = trialInfo.Item2; //In hours \\nPassedTrial = trialInfo.Item1; //In hours \\n}\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n###GetRawTrialValue\nIf you use the `GetRawTrialValue` property, the method returns total duration of a trial period (in seconds) and its expiration date (UNIX timestamp).\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var func = ActivationFramework.Current.FindDelegate((int) DelegateType.GetRawTrialValue) as Func<Tuple<long,long>>;\\nvar trialInfo = func.Invoke();\\n\\nif (trialInfo.Item1 == -1 || trialInfo.Item2 == -1) \\n{\\n //Trial not started \\n} \\nelse\\n{\\n TrialPeriod = trialInfo.Item2; //In seconds\\n TrialExpireDate = trialInfo.Item1; //In UNIX timestamp \\n}\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n###GetTrialTimeRemained\nIf you use the `GetTrialTimeRemained` property, the method returns a total number of seconds left till the end of a trial period.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var func = ActivationFramework.Current.FindDelegate((int) DelegateType.GetTrialTimeRemained) as Func<long>;\\nvar trialInfo = func.Invoke();\\n \\nif (trialInfo==-1)\\n{\\n //Trial not started\\n}\\nelse\\n{\\n TrialPeriodRemained = trialInfo ; //In seconds\\n}\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n###GetStoreLink\nIf you use the `GetStoreLink` property, the method returns a link to the store where a user can buy a license.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var func = ActivationFramework.Current.FindDelegate((int) DelegateType.GetStoreLink) as Func<string>; \\nstring storeLink = func.Invoke(); \\nProcess.Start(storeLink); //Open link in default browser\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\nNote that you can add GET parameters to the link by using this method:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"DMFrameworkSettings.StoreAdditionalParameters.Add(\\\"key\\\", “value\\\");\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]","updates":["5b58e97154276d0003a2cb1e"],"order":3,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"591f17b021d2ff0f00cf5a4c","__v":1,"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Get Started: Windows Apps","slug":"getting-started-windows-framework","order":2,"from_sync":false,"reference":false,"_id":"591f17af21d2ff0f00cf5a41","createdAt":"2016-07-21T09:47:49.247Z","__v":0,"project":"547cd7662eaee50800ed1089","version":"591f17ae21d2ff0f00cf5a3f"},"user":"547cd6ac78fd57080023ca99","version":{"version":"1.0.1","version_clean":"1.0.1","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["591f17af21d2ff0f00cf5a40","591f17af21d2ff0f00cf5a41","591f17af21d2ff0f00cf5a42","591f17af21d2ff0f00cf5a43","591f17af21d2ff0f00cf5a44","591f17af21d2ff0f00cf5a45","591f17af21d2ff0f00cf5a46","591f17af21d2ff0f00cf5a47","591f17af21d2ff0f00cf5a48","60805d13afe7e7003acde2f9"],"_id":"591f17ae21d2ff0f00cf5a3f","createdAt":"2017-05-19T16:05:02.775Z","__v":2,"project":"547cd7662eaee50800ed1089","releaseDate":"2017-05-19T16:05:02.775Z"},"createdAt":"2016-07-21T13:52:18.102Z","githubsync":"","parentDoc":null,"project":"547cd7662eaee50800ed1089"}