Exemple #1
0
        public static LicenseControl GetLicenseData(SqlConnection conn, SqlTransaction trans, Int64 enterpriseId)
        {
            //Retorna zero para ilimitado



            String installKey = "";

            try
            {
                using (IAMDatabase db = new IAMDatabase(conn))
                {
                    //Server installation key
                    using (IAM.Config.ServerKey2 sk = new IAM.Config.ServerKey2(db.Connection))
                        installKey = sk.ServerInstallationKey.AbsoluteUri;

                    //Resgata todas as licenças desta empresa e de servidor
                    DataTable dtLic = db.ExecuteDataTable("select * from license where enterprise_id in (0, " + enterpriseId + ")", trans);
                    if (dtLic == null)
                    {
                        return(new LicenseControl(1, "Error on get licenses on server", installKey));
                    }

                    if (dtLic.Rows.Count == 0)
                    {
                        return(new LicenseControl(1, "License not found", installKey));
                    }

                    //Localiza a licença menos restrita
                    IAMKeyData key = null;
                    foreach (DataRow dr in dtLic.Rows)
                    {
                        try
                        {
                            IAMKeyData k = IAMKey.ExtractFromCert(dr["license_data"].ToString());

                            //Checa a validade da licença
                            if ((k.IsTemp) && (k.TempDate.Value.CompareTo(DateTime.Now) < 0))
                            {
                                continue;
                            }

                            if (key == null)
                            {
                                key = k;
                            }

                            if (k.NumLic > key.NumLic)
                            {
                                key = k;
                            }
                        }
                        catch { }
                    }

                    if (key == null)
                    {
                        return(new LicenseControl(1, "License not found", installKey));
                    }

                    //Resgata do banco a contagem atual de entidades
                    Int32 count = db.ExecuteScalar <Int32>(conn, "select count(e.id) from entity e with(nolock) inner join context c with(nolock) on c.id = e.context_id where e.deleted = 0 and c.enterprise_id = " + enterpriseId, CommandType.Text, null, trans);

                    LicenseControl lc = new LicenseControl((Int32)key.NumLic, count, installKey);

                    return(lc);
                }
            }
            catch (Exception ex)
            {
                return(new LicenseControl(0, ex.Message, installKey));
            }
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            WebJsonResponse contentRet = null;


            String action = "";

            if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"]))
            {
                action = (String)RouteData.Values["action"];
            }

            Int64 workflowId = 0;

            if (action != "add_container")
            {
                try
                {
                    workflowId = Int64.Parse((String)RouteData.Values["id"]);

                    if (workflowId < 0)
                    {
                        workflowId = 0;
                    }
                }
                catch { }

                if (workflowId == 0)
                {
                    contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    action     = "";
                }
            }

            String rData = "";
            //SqlConnection //conn = DB.GetConnection();
            String jData = "";

            try
            {
                switch (action)
                {
                case "delete":

                    var reqDel = new
                    {
                        jsonrpc    = "1.0",
                        method     = "container.delete",
                        parameters = new
                        {
                            workflowid = workflowId
                        },
                        id = 1
                    };

                    rData = JSON.Serialize2(reqDel);

                    using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString()))
                        jData = WebPageAPI.ExecuteLocal(database, this, rData);

                    if (String.IsNullOrWhiteSpace(jData))
                    {
                        throw new Exception("");
                    }

                    ContainerDeleteResult retDel = JSON.Deserialize <ContainerDeleteResult>(jData);
                    if (retDel == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    }
                    else if (retDel.error != null)
                    {
                        contentRet = new WebJsonResponse("", retDel.error.data, 3000, true);
                    }
                    else if (!retDel.result)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    }
                    else
                    {
                        contentRet = new WebJsonResponse();
                    }
                    break;

                case "change_name":

                    String name = Request.Form["name"];
                    if (String.IsNullOrEmpty(name))
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("invalid_name"), 3000, true);
                        break;
                    }

                    rData = JSON.Serialize2(new
                    {
                        jsonrpc    = "1.0",
                        method     = "workflow.change",
                        parameters = new
                        {
                            workflowid = workflowId,
                            name       = name
                        },
                        id = 1
                    });

                    using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData);

                    if (String.IsNullOrWhiteSpace(jData))
                    {
                        throw new Exception("");
                    }

                    ContainerGetResult retD = JSON.Deserialize <ContainerGetResult>(jData);
                    if (retD == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    }
                    else if (retD.error != null)
                    {
                        contentRet = new WebJsonResponse("", retD.error.data, 3000, true);
                    }
                    else if (retD.result == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    }
                    else if (retD.result == null || retD.result.info == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    }
                    else
                    {
                        contentRet = new WebJsonResponse("#workflow_name_" + workflowId, retD.result.info.name);
                    }
                    break;

                case "change":

                    String name1 = Request.Form["container_name"];
                    if (String.IsNullOrEmpty(name1))
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("invalid_name"), 3000, true);
                        break;
                    }


                    String parent_id1 = Request.Form["parent_container"];
                    if (String.IsNullOrEmpty(parent_id1))
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_parent_container"), 3000, true);
                        break;
                    }

                    rData = JSON.Serialize2(new
                    {
                        jsonrpc    = "1.0",
                        method     = "container.change",
                        parameters = new
                        {
                            workflowid = workflowId,
                            parentid   = parent_id1,
                            name       = name1
                        },
                        id = 1
                    });

                    using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData);

                    if (String.IsNullOrWhiteSpace(jData))
                    {
                        throw new Exception("");
                    }

                    ContainerGetResult retC1 = JSON.Deserialize <ContainerGetResult>(jData);
                    if (retC1 == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    }
                    else if (retC1.error != null)
                    {
                        contentRet = new WebJsonResponse("", retC1.error.data, 3000, true);
                    }
                    else if (retC1.result == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    }
                    else if (retC1.result == null || retC1.result.info == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    }
                    else
                    {
                        contentRet = new WebJsonResponse("", "Atualização realizada com sucesso", 3000, false);
                    }
                    break;


                case "add_user":
                    String user_id = Request.Form["user_id"];
                    if (String.IsNullOrEmpty(user_id))
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_username"), 3000, true);
                        break;
                    }


                    var reqAdd = new
                    {
                        jsonrpc    = "1.0",
                        method     = "container.adduser",
                        parameters = new
                        {
                            workflowid = workflowId,
                            userid     = user_id
                        },
                        id = 1
                    };

                    rData = JSON.Serialize2(reqAdd);

                    using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData);

                    if (String.IsNullOrWhiteSpace(jData))
                    {
                        throw new Exception("");
                    }

                    ContainerDeleteResult retAdd = JSON.Deserialize <ContainerDeleteResult>(jData);
                    if (retAdd == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    }
                    else if (retAdd.error != null)
                    {
                        contentRet = new WebJsonResponse("", retAdd.error.data, 3000, true);
                        //Tools.Tool.notifyException(new Exception(retAdd.error.data + retAdd.error.debug), this);
                    }
                    else if (!retAdd.result)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    }
                    else
                    {
                        contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/container/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : ""));
                    }

                    //

                    break;


                case "add_container":
                    String containerName = Request.Form["container_name"];
                    if (String.IsNullOrEmpty(containerName))
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("type_role_name"), 3000, true);
                        break;
                    }

                    String context_id = Request.Form["container_context"];
                    if (String.IsNullOrEmpty(context_id))
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_context"), 3000, true);
                        break;
                    }


                    String parent_id = Request.Form["parent_container"];
                    if (String.IsNullOrEmpty(parent_id))
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_parent_container"), 3000, true);
                        break;
                    }

                    if (parent_id != "0")
                    {
                        rData = SafeTrend.Json.JSON.Serialize2(new
                        {
                            jsonrpc    = "1.0",
                            method     = "container.list",
                            parameters = new
                            {
                                page_size = Int32.MaxValue,
                                page      = 1
                            },
                            id = 1
                        });


                        jData = "";
                        using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString()))
                            jData = WebPageAPI.ExecuteLocal(database, this, rData);

                        List <ContainerData> conteinerList = new List <ContainerData>();
                        ContainerListResult  cl            = JSON.Deserialize <ContainerListResult>(jData);
                        if ((cl != null) && (cl.error == null) && (cl.result != null) && (cl.result.Count > 0))
                        {
                            conteinerList.AddRange(cl.result);
                        }

                        ContainerData cd = null;

                        foreach (ContainerData c in conteinerList)
                        {
                            if (c.container_id.ToString() == parent_id)
                            {
                                cd = c;
                            }
                        }

                        if (cd == null)
                        {
                            contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_parent_container"), 3000, true);
                            break;
                        }

                        if (cd.context_id.ToString() != context_id)
                        {
                            contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_context_not_same"), 3000, true);
                            break;
                        }
                    }

                    var reqAddR = new
                    {
                        jsonrpc    = "1.0",
                        method     = "container.new",
                        parameters = new
                        {
                            name      = containerName,
                            contextid = context_id,
                            parentid  = parent_id
                        },
                        id = 1
                    };

                    rData = JSON.Serialize2(reqAddR);

                    using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData);

                    if (String.IsNullOrWhiteSpace(jData))
                    {
                        throw new Exception("");
                    }

                    ContainerGetResult retAddR = JSON.Deserialize <ContainerGetResult>(jData);
                    if (retAddR == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    }
                    else if (retAddR.error != null)
                    {
                        contentRet = new WebJsonResponse("", retAddR.error.data, 3000, true);
                        //Tools.Tool.notifyException(new Exception(retAdd.error.data + retAdd.error.debug), this);
                    }
                    else if ((retAddR.result == null) || (retAddR.result.info == null))
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_not_found"), 3000, true);
                    }
                    else
                    {
                        contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/container/" + retAddR.result.info.container_id + "/add_user/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : ""));
                    }

                    //

                    break;
                }
            }
            catch (Exception ex)
            {
                contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true);
            }
            finally
            {
            }

            if (contentRet != null)
            {
                if (!String.IsNullOrWhiteSpace((String)Request["cid"]))
                {
                    contentRet.callId = (String)Request["cid"];
                }


                Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON()));
            }
        }
Exemple #3
0
 public EntityTimeControl(IAMDatabase db, Int64 identityId)
 {
     this.db         = db;
     this.identityId = identityId;
 }