/// <summary> /// This is the constructor for the <c>VersionConstraint</c>. The constructor /// is used to create the object and assign it to the proper license. /// </summary> /// <param name="license"> /// The <see cref=" Hemrika.SharePresence.SPLicenseFile"> Hemrika.SharePresence.SPLicenseFile</see> this constraint /// belongs to. /// </param> public VersionConstraint(SPLicenseFile license) { base.License = license; base.Name = "Version Constraint"; base.Description = "This VersionConstraint constrains the user to only use the license "; base.Description += "with a given range of versions attached to an Assembly."; }
/// <summary> /// This is the constructor for the <c>ProcessorConstraint</c>. The constructor /// is used to create the object and assign it to the proper license. /// </summary> /// <param name="license"> /// The <see cref=" Hemrika.SharePresence.SPLicenseFile"> Hemrika.SharePresence.SPLicenseFile</see> this constraint /// belongs to. /// </param> public ProcessorConstraint(SPLicenseFile license) { base.License = license; base.Name = "Processor Constraint"; base.Description = "This ProcessorConstraint constrains the user to only use the license "; base.Description += "with a given OS or Processor."; }
/// <summary> /// This is the constructor for the <c>DesigntimeConstraint</c>. The constructor /// is used to create the object and assign it to the proper license. /// </summary> /// <param name="license"> /// The <see cref=" Hemrika.SharePresence.SPLicenseFile"> Hemrika.SharePresence.SPLicenseFile</see> this constraint /// belongs to. /// </param> public DesigntimeConstraint(SPLicenseFile license) { base.License = license; base.Name = "Design Time Constraint"; base.Description = "This DesigntimeConstraint constrains the user to only running "; base.Description += "the license in a design time environment. If it is not in a "; base.Description += "Design Time environment then this constraint will fail."; }
/// <summary> /// This is the constructor for the <c>DayTimeConstraint</c>. The constructor /// is used to create the object and assign it to the proper license. /// </summary> /// <param name="license"> /// The <see cref=" Hemrika.SharePresence.SPLicenseFile"> Hemrika.SharePresence.SPLicenseFile</see> this constraint /// belongs to. /// </param> public DayTimeConstraint(SPLicenseFile license) { base.License = license; base.Name = "Day Time Constraint"; base.Description = "The DayTimeConstraint constrains the user "; base.Description += "to only using this license during a period of time within a day. I.E. A user may "; base.Description += "use the license between midnight and 7am and 5pm and midnight - Non business hours."; }
/// <summary> /// This is the constructor for the <c>BetaConstraint</c>. The constructor /// is used to create the object and assign it to the proper license. /// </summary> /// <param name="license"> /// The <see cref=" Hemrika.SharePresence.SPLicenseFile"> Hemrika.SharePresence.SPLicenseFile</see> this constraint /// belongs to. /// </param> public BetaConstraint(SPLicenseFile license) { base.License = license; base.Name = "Beta Constraint"; base.Description = "The BetaConstraint constrains the user to a given time "; base.Description += "period. It supports an end date that the license will "; base.Description += "expire. It also has the ability to show the user a link "; base.Description += "to download an update to the beta once it expires."; }
/// <summary> /// This is the constructor for the <c>UsageConstraint</c>. The constructor /// is used to create the object and assign it to the proper license. /// </summary> /// <param name="license"> /// The <see cref=" Hemrika.SharePresence.SPLicenseFile"> Hemrika.SharePresence.SPLicenseFile</see> this constraint /// belongs to. /// </param> public UsageConstraint(SPLicenseFile license) { base.License = license; base.Name = "Usage Constraint"; base.Description = "This UsageConstraint constrains the user to a usage "; base.Description += "limit. It supports a Maximum Usage, Hit and Days "; base.Description += "count. Once the maximum number is reached the license "; base.Description += "expires."; }
/// <summary> /// This is the constructor for the <c>DemoConstraint</c>. The constructor /// is used to create the object and assign it to the proper license. /// </summary> /// <param name="license"> /// The <see cref=" Hemrika.SharePresence.SPLicenseFile"> Hemrika.SharePresence.SPLicenseFile</see> this constraint /// belongs to. /// </param> public DemoConstraint(SPLicenseFile license) { base.License = license; base.Name = "Demo Constraint"; base.Description = "This DemoConstraint constrains the user to a given time period "; base.Description += "or duration. It supports start and end date that the license "; base.Description += "will expire. It also support a duration, to constrain the "; base.Description += "license to."; }
/// <summary> /// This is the constructor for the <c>OrConstraint</c>. The constructor /// is used to create the object and assign it to the proper license. /// </summary> /// <param name="license"> /// The <see cref=" Hemrika.SharePresence.SPLicenseFile"> Hemrika.SharePresence.SPLicenseFile</see> this constraint /// belongs to. /// </param> public OrConstraint(SPLicenseFile license) { base.License = license; base.Name = "Or Constraint"; base.Description = "This OrConstraint contains a collection of constraints that will "; base.Description += "be grouped together as a bitwise OR operation. It is responsible "; base.Description += "for validating the containing IConstraints and will be valid as "; base.Description += "long as one of the constraints contained is valid. The purpose of "; base.Description += "this is to allow multiple constraints to be added and create a run "; base.Description += "as long as one is valid scheme."; }
/// <summary> /// This is the constructor for the <c>AndConstraint</c>. The constructor /// is used to create the object and assign it to the proper license. /// </summary> /// <param name="license"> /// The <see cref=" Hemrika.SharePresence.SPLicenseFile"> Hemrika.SharePresence.SPLicenseFile</see> this constraint /// belongs to. /// </param> public AndConstraint(SPLicenseFile license) { base.License = license; base.Name = "And Constraint"; base.Description = "This AndConstraint contains a collection of constraints that "; base.Description += "will be grouped together as a bitwise AND operation. It is "; base.Description += "validating the containing IConstraints and will be valid "; base.Description += "all the constraints contained are valid. The purpose of this "; base.Description += "is to allow a user to force multiple constraints to pass before "; base.Description += "allowing the license to be valid."; }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="type"></param> /// <param name="instance"></param> /// <param name="allowExceptions"></param> /// <returns></returns> public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { SPLicenseFile license = serviceLicense.GetLicense(type, instance, allowExceptions); //SPLicenseFile license = new SPLicenseFile(type,"This is a key"); //SPLicenseFile license = serviceLicense.GetLicense(type, instance, allowExceptions); //license = serviceLicense.SetLicense(type, license); return(license); }
public SPLicenseFile Create(Type type, object instance, bool allowExceptions) { SPLicenseFile manualCreate = new SPLicenseFile(type, String.Empty); manualCreate.SetupEncryptionKey(String.Empty); manualCreate.Product = new Product(Assembly.GetAssembly(type), true, "", "LicenseManager", "License Manager", "1.0", "Hemrika", "License Management", false); manualCreate.User = new User("Rutger Hemrika", "*****@*****.**", "Hemrika"); manualCreate.Issuer = new Issuer("Hemrika", "*****@*****.**", "http://www.hemrika.nl/"); FarmConstraint fc = new FarmConstraint(manualCreate); fc.CurrentFarm = SPFarm.Local.Id.ToString(); manualCreate.Constraints.Add(fc); return(manualCreate); }
public EnhancedLayoutsPage() { try { if (_license == null) { _licenseType = SetTypeForLicense(); LicenseManager.Validate(_licenseType); System.ComponentModel.License license; LicenseManager.IsValid(_licenseType, this, out license); _license = (SPLicenseFile)license; } } catch (Exception ex) { error = ex.ToString(); } }
/// <summary> /// This is the constructor for the <c>DomainConstraint</c>. The constructor /// is used to create the object and assign it to the proper license. /// </summary> /// <param name="license"> /// The <see cref=" Hemrika.SharePresence.SPLicenseFile"> Hemrika.SharePresence.SPLicenseFile</see> this constraint /// belongs to. /// </param> /// <remarks> /// This constructor initializes the current domain. When initializing this /// an exception can be thrown. The constructor will catch the exception /// and set the current domain to an empty string. The license can handle this /// by setting one of the domains to an empty string which should allow the /// validation to pass. This call will throw an exception only when used in /// a non web environment. /// </remarks> public FarmConstraint(SPLicenseFile license) { base.License = license; base.Name = "Farm Constraint"; base.Description = "This FarmConstraint constrains the user to running within a given "; base.Description += "set of Farms. This is primarily used for farm based licensing to make "; base.Description += "sure that the license is only used for specific Farms."; try { this.context = HttpContext.Current; this.currentFarmUri = this.context.Request.Url; this.CurrentFarm = this.currentFarmUri.Host; } catch { this.CurrentFarm = String.Empty; } }
public SPLicense.LicenseFile.SPLicenseFile GetLicense(Type type, object instance, bool allowExceptions) { try { TestLicense test = new TestLicense(); SPLicenseFile license = test.Create(type, instance, allowExceptions); string key = new Guid("7F3A08D4-7308-4142-A1DF-DF705136D0A8").ToString(); SPAdministrationWebApplication centralWebApp = SPAdministrationWebApplication.Local; SPSite lowSite = centralWebApp.Sites[0]; SPUserToken oSysToken = GetSysToken(lowSite.ID); using (SPSite centralSite = new SPSite(lowSite.ID, oSysToken)) { centralSite.AllowUnsafeUpdates = true; using (SPWeb centralWeb = centralSite.OpenWeb()) { bool availableList = true; SPFile licenseFile = null; SPFolder licenseFolder = null; centralWeb.AllowUnsafeUpdates = true; try { SPList LicenseList = centralWeb.Lists["Hemrika License Files"]; SPDocumentLibrary LicenseLibrary = (SPDocumentLibrary)LicenseList; licenseFolder = centralWeb.Folders["Hemrika License Files"]; /* * if (!Farmbag.Contains("Hemrika_Encryption_Key")) * { * Farmbag["Hemrika_Encryption_Key"] = new Guid("7F3A08D4-7308-4142-A1DF-DF705136D0A8").ToString(); * } * * encrypt = Farmbag["Hemrika_Encryption_Key"]; */ SPQuery oQuery = new SPQuery(); oQuery.Query = string.Format("<Where><Contains><FieldRef Name=\"FileLeafRef\" /><Value Type=\"File\">" + type.Assembly.FullName + "</Value></Contains></Where><OrderBy><FieldRef Name=\"FileLeafRef\" /></OrderBy>"); SPListItemCollection colListItems = LicenseLibrary.GetItems(oQuery); foreach (SPListItem licenseItem in colListItems) { licenseFile = licenseItem.File; break; } } catch (Exception) { availableList = false; } MemoryStream lic = null; //= new MemoryStream(); XmlDocument xml = new XmlDocument(); if (licenseFile == null) { lic = new MemoryStream(); xml.LoadXml(license.ToXmlString()); SPLicenseFile.SaveFile(license, lic, false, String.Empty, false); if (availableList && licenseFolder != null) { licenseFile = licenseFolder.Files.Add(type.Assembly.FullName + ".lic", lic, true); licenseFile.Update(); licenseFile.Item.Update(); } } if (lic != null) { lic.Close(); //lic.Dispose(); } if (licenseFile != null) { //byte[] bytes = licenseFile.OpenBinary(); //lic = new MemoryStream(); //lic.Read(bytes, 0, bytes.Length); license = SPLicenseFile.LoadFile(licenseFile.OpenBinaryStream(), type, false, String.Empty);// true, key); } /* * if (lic != null) * { * lic.Close(); * //lic.Dispose(); * } */ centralWeb.AllowUnsafeUpdates = false; } centralSite.AllowUnsafeUpdates = false; } return(license); } catch (Exception ex) { throw new LicenseException(type, instance, ex.Message, ex); } }
protected void Btn_Save_Click(object sender, EventArgs e) { HttpFileCollection hfc = Request.Files; for (int i = 0; i < hfc.Count; i++) { HttpPostedFile file = hfc[i]; Stream openStream; if ((openStream = file.InputStream) != null) { BufferedStream bufferStream = new BufferedStream(openStream); StreamReader streamReader = new StreamReader(bufferStream); string str = streamReader.ReadToEnd(); bufferStream.Position = 0; license = SPLicenseFile.LoadFile(bufferStream, null, false, string.Empty); streamReader.Close(); //bufferStream.Close(); //openStream.Close(); } List <IConstraint> contraints = license.Constraints; foreach (IConstraint contraint in contraints) { FarmConstraint farmContraint = contraint as FarmConstraint; if (farmContraint != null) { foreach (string farm in farmContraint.Farms) { tbx_Result.Text += farm + Environment.NewLine; } } DomainConstraint domainContraint = contraint as DomainConstraint; if (domainContraint != null) { foreach (string domain in domainContraint.Domains) { tbx_Result.Text += domain + Environment.NewLine; } } } //SPLicense.LicenseFile.Constraints.FarmConstraint //tbx_Result.Text = license.LicenseKey+ Environment.NewLine; tbx_Result.Text += license.Product.ShortName + Environment.NewLine; tbx_Result.Text += license.User.Organization + Environment.NewLine; tbx_Result.Text += license.Issuer.FullName + Environment.NewLine; /* * if (license.Validate()) * { * tbx_Result.Text += license.ToXmlString(); * } */ } }
protected void Page_Load(object sender, EventArgs e) { //tbx_Result.Text = SPFarm.Local.Id.ToString(); tbx_Result.Text = String.Empty; license = new SPLicenseFile(null, String.Empty); }