public BaseResponse Load(NippsLicenseRequest request)
        {
            NippsLicenseResponse response = new NippsLicenseResponse();

            response.Result         = Result.OK;
            response.ResultMessages = new List <string>();

            try
            {
                if (string.IsNullOrEmpty(request.Content))
                {
                    response.Result = Result.FAIL;
                    response.ResultMessages.Add("Request.Content");
                    Logger.Error(response.ResultMessages[0]);
                }
                else
                {
                    if (!LicenseWrapper.Valid(request.Content))
                    {
                        response.Result = Result.FAIL;
                        response.ResultMessages.Add(string.Format("License is not VALID."));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                response.Result = Result.FAIL;
                response.ResultMessages.Add(ex.ToString());
            }

            return(response);
        }
        public ActionResult LicenseAdd(HttpPostedFileBase license)
        {
            string sha1a = "---BEGIN SHA1 A---";
            string sha1b = "---BEGIN SHA1 B---";

            try
            {
                byte[] licenseBuffer = new byte[license.ContentLength];
                license.InputStream.Read(licenseBuffer, 0, license.ContentLength);
                string licenseString = System.Text.Encoding.Default.GetString(licenseBuffer);

                if (string.IsNullOrEmpty(licenseString) || !licenseString.Contains(sha1a) || !licenseString.Contains(sha1b))
                {
                    throw new InvalidDataException("SHA1 parts are not found in the license file.");
                }

                string svcUrl = CommonHelper.LicenseManagerServiceUrl + "LicenseService/Load";
                NippsLicenseRequest licenseRequest = new NippsLicenseRequest {
                    Content = licenseString
                };
                NippsLicenseResponse licenseResponse = RestHelper.RestPostObject <NippsLicenseResponse, NippsLicenseRequest>(svcUrl, licenseRequest);

                if (licenseResponse.Result != Result.OK)
                {
                    Logger.Error(licenseResponse.ResultMessages[0]);
                    ViewBag.Result         = Result.FAIL;
                    ViewBag.ResultMessages = new List <string> {
                        Resources.Global.MessageUnknownError
                    };
                    ViewBag.ReturnToAction     = ReturnToAction;
                    ViewBag.ReturnToController = ReturnToController;
                    ViewBag.Title = Resources.Global.LicenseAddTitle;

                    return(View(NippsSiteHelper.ResultMessageView));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                ViewBag.Result         = Result.FAIL;
                ViewBag.ResultMessages = new List <string> {
                    Resources.Global.MessageUnknownError
                };
                ViewBag.ReturnToAction     = ReturnToAction;
                ViewBag.ReturnToController = ReturnToController;
                ViewBag.Title = Resources.Global.LicenseAddTitle;

                return(View(NippsSiteHelper.ResultMessageView));
            }

            return(RedirectToAction("License"));
        }
Ejemplo n.º 3
0
 public static Assembly AssemblyLicense(Assembly ipps)
 {
     try
     {
         string              serviceUrl = ConfigurationManager.AppSettings["LicenseManagerServiceUrl"] + "LicenseService/Ipps";
         FileVersionInfo     fvi        = FileVersionInfo.GetVersionInfo(ipps.Location);
         string              fName      = fvi.InternalName.Replace("Netas.Nipps.Service.", "").Replace(".dll", "");
         NippsLicenseRequest licReq     = new NippsLicenseRequest {
             Version = string.Format("{0}:{1}", fName, fvi.FileVersion)
         };
         NippsLicenseResponse licRes = RestHelper.RestPostObject <NippsLicenseResponse, NippsLicenseRequest>(serviceUrl, licReq);
         return(licRes.Result == BaseDao.Model.Response.Result.OK ? ipps : null);
     }
     catch (Exception ex)
     {
         NLog.LogManager.GetCurrentClassLogger().Error(ex.ToString());
     }
     return(null);
 }
        public BaseResponse Ipps(NippsLicenseRequest ippsRequest)
        {
            NippsLicenseResponse response = new NippsLicenseResponse();

            response.Result         = Result.OK;
            response.ResultMessages = new List <string>();

            try
            {
                if (ippsRequest == null || string.IsNullOrEmpty(ippsRequest.Version))
                {
                    throw new ArgumentNullException("Request.Version.");
                }

                string[] psParts = ippsRequest.Version.Split(':');
                if (psParts == null || psParts.Length != 2)
                {
                    throw new ArgumentException("Request.Version");
                }

                if (!LicenseWrapper.Valid())
                {
                    response.Result = Result.FAIL;
                    response.ResultMessages.Add(string.Format("License is not VALID."));
                }

                LicenseWrapper.Valid(psParts[0], psParts[1]);
            }
            catch (Exception ex)
            {
                Logger.Error("{0}> {1}", ippsRequest.ToString(), ex.ToString());
                response.Result = Result.FAIL;
                response.ResultMessages.Add(ex.ToString());
            }
            return(response);
        }