Beispiel #1
0
        public static LicenserInfoModel FromDbModel(LicenseOwner model)
        {
            if (model == null)
            {
                return(null);
            }

            var result = new LicenserInfoModel();

            result.Id            = model.Id;
            result.Name          = model.Name;
            result.Phone         = model.Phone;
            result.Email         = model.Email;
            result.ContactPerson = model.ContactPerson;
            result.CompanyId     = (model.CompanyId ?? string.Empty).Trim();
            result.IsCompany     = model.IsCompany;
            result.EGN           = (model.EGN ?? string.Empty).Trim();
            result.IsDemo        = model.Licenses.All(x => x.IsDemo);
            result.RegNom        = model.RegNom;

            var extraInfo = model.LicenseOwnerExtraInfoes1.FirstOrDefault();

            if (extraInfo != null)
            {
                result.AccountingPerson = extraInfo.AccountingPerson;
                result.ContactPerson    = extraInfo.ContactPerson;
                result.VATRegistration  = extraInfo.VatRegistration ?? false;
                result.MOL                 = extraInfo.MOL;
                result.PostAddress         = extraInfo.PostAddress;
                result.PostCode            = extraInfo.PostCode ?? 0;
                result.RegistrationAddress = extraInfo.RegistrationAddress;
            }

            return(result);
        }
Beispiel #2
0
        public static LicenseOwner CreateDbModel(LicenserInfoModel model, LicenseOwner dbModel = null)
        {
            var result = dbModel ?? new LicenseOwner();

            result.Name          = model.Name;
            result.Phone         = model.Phone;
            result.Email         = model.Email;
            result.ContactPerson = model.ContactPerson;
            result.CompanyId     = model.IsCompany ? model.CompanyId.Trim() : null;
            result.EGN           = !model.IsCompany ? model.EGN.Trim() : null;
            result.IsCompany     = model.IsCompany;
            result.RegNom        = model.RegNom;

            if (!model.IsDemo)
            {
                var extraInfo = result.LicenseOwnerExtraInfoes1.FirstOrDefault();
                if (extraInfo == null)
                {
                    extraInfo = new LicenseOwnerExtraInfo1();
                    result.LicenseOwnerExtraInfoes1.Add(extraInfo);
                }

                extraInfo.AccountingPerson = model.AccountingPerson;
                extraInfo.ContactPerson    = model.ContactPerson;
                extraInfo.VatRegistration  = model.VATRegistration;
                extraInfo.MOL                 = model.MOL;
                extraInfo.PostAddress         = model.PostAddress;
                extraInfo.PostCode            = model.PostCode;
                extraInfo.RegistrationAddress = model.RegistrationAddress;
            }
            return(result);
        }
        private static void SendExpirationNotification(ExpirationNotifier notifier, License license, FrameworkServer server, bool sentRenewalRequest)
        {
            if (license.Owners.Count == 0)
            {
                LogError($"Unable to notify license expiration for '{server.HostName}'.  No contacts specified.");
                return;
            }

            LicenseOwner owner = license.Owners.FirstOrDefault();

            try
            {
                MailAddress recipient = new MailAddress(owner.Contact);
                string      subject   = string.Format(Resource.LicenseEmailSubject, license.Solution, server.HostName);
                string      body      = sentRenewalRequest ?
                                        string.Format(Resource.LicenseEmailBodyAuto, license.Solution, server.HostName, license.ExpirationDate.ToShortDateString(), Environment.MachineName) :
                                        string.Format(Resource.LicenseEmailBodyManual, license.Solution, server.HostName, license.ExpirationDate.ToShortDateString(), Environment.MachineName);
                notifier.SendNotification(recipient, subject, body);
            }
            catch (FormatException ex)
            {
                // Notification recipient is not a valid email address
                LogDebug(ex.ToString());
            }
        }
        private static void SendNewLicenseRequest(License license, FrameworkServer server)
        {
            if (license.Owners.Count == 0)
            {
                LogError($"Unable to request new license for '{server.HostName}'.  No contacts specified.");
                return;
            }

            LicenseOwner owner          = license.Owners.FirstOrDefault();
            string       formattedOwner = owner.Contact.Split('@')[0];
            string       requestData    = string.Format(Resource.LicenseRequestData, formattedOwner, BuildRequestDetails(license, server));

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Resource.LicenseTicketURL + "?" + requestData);

            webRequest.ContentType           = "application/x-www-form-urlencoded";
            webRequest.Proxy                 = null;
            webRequest.UseDefaultCredentials = true; // Uses Windows Credentials to verify user
            HttpWebResult webResult = HttpWebEngine.Get(webRequest);

            LogInfo($"Response from ACT Solution Support Ticket System: {webResult.Response}");
        }
Beispiel #5
0
        public string Create(LicenseModel model, long?userId = null)
        {
            try
            {
                using (var db = new LicenseDbEntities())
                {
                    var owner = db.LicenseOwners.FirstOrDefault(x => x.Id == model.User.Id);
                    if (owner == null)
                    {
                        owner = model.User.IsCompany
                            ? db.LicenseOwners.FirstOrDefault(x => x.CompanyId == model.User.CompanyId)
                            : db.LicenseOwners.FirstOrDefault(x => x.EGN == model.User.EGN);
                    }

                    if (owner == null)
                    {
                        owner = new LicenseOwner()
                        {
                            Name          = model.User.Name,
                            IsCompany     = model.User.IsCompany,
                            Email         = model.User.Email,
                            Phone         = model.User.Phone,
                            ContactPerson = model.User.ContactPerson,
                            CompanyId     = model.User.CompanyId,
                            EGN           = model.User.EGN
                        };
                    }

                    var extraInfo = owner.LicenseOwnerExtraInfoes1 != null?owner.LicenseOwnerExtraInfoes1.FirstOrDefault() : null;

                    if (extraInfo == null)
                    {
                        if (model.User.PostCode > 0 ||
                            !string.IsNullOrEmpty(model.User.PostAddress) ||
                            !string.IsNullOrEmpty(model.User.PostAddress) ||
                            !string.IsNullOrEmpty(model.User.RegistrationAddress) ||
                            !string.IsNullOrEmpty(model.User.MOL) ||
                            !string.IsNullOrEmpty(model.User.AccountingPerson) ||
                            !string.IsNullOrEmpty(model.User.ContactPerson))
                        {
                            extraInfo = new LicenseOwnerExtraInfo1();
                            extraInfo.LicenseOwnerId = owner.Id;

                            var userInfo = (LicenserInfoModel)model.User;

                            extraInfo.PostCode            = userInfo.PostCode;
                            extraInfo.PostAddress         = userInfo.PostAddress;
                            extraInfo.RegistrationAddress = userInfo.RegistrationAddress;
                            extraInfo.MOL              = userInfo.MOL;
                            extraInfo.ContactPerson    = userInfo.ContactPerson;
                            extraInfo.AccountingPerson = userInfo.AccountingPerson;
                            extraInfo.VatRegistration  = userInfo.VATRegistration;

                            owner.LicenseOwnerExtraInfoes1.Add(extraInfo);
                        }
                    }

                    var result = new License()
                    {
                        Id             = Guid.NewGuid(),
                        IsDemo         = model.IsDemo,
                        ValidTo        = !model.IsDemo ? model.ValidTo : DateTime.Now.AddMonths(1),
                        SubscribedTo   = !model.IsDemo ? model.SubscribedTo : DateTime.Now.AddMonths(1),
                        Type           = !model.IsDemo ? (byte)model.Type : (byte)LicenseTypeEnum.PerComputer,
                        LicenseOwner   = owner,
                        LicenseModules = model.LicenseModules.Select(x => new LicenseModule()
                        {
                            ModuleId = (short)x,
                            ValidTo  = model.ValidTo
                        }).ToList(),
                        Enabled           = !model.IsDemo ? false : true,//the real license should be enabled, afterwards e.g. after it is payed
                        CreatedDate       = DateTime.Now,
                        WorkstationsCount = model.Type == LicenseTypeEnum.PerUser ? 1 : model.WorkstationsCount.Value
                    };

                    var created = db.Licenses.Add(result);
                    db.SaveChanges();

                    var id = created.Id;

                    if (id != Guid.Empty)
                    {
                        LogLicenseChange(db, result.IsDemo,
                                         null,
                                         Serialize(result), id, userId);
                    }

                    return(id.ToString());
                }
            }
            catch (Exception ex)
            {
                var error = ((System.Data.Entity.Validation.DbEntityValidationException)ex).EntityValidationErrors;
                _logger.Log(LogLevel.Error, ex);

                throw;
            }
        }