/// <summary>
    /// 拼接两个 <paramref name="System.Linq.Expression"/> ,两个 <paramref name="System.Linq.Expression"/> 的参数必须完全相同。
    /// </summary>
    /// <typeparam name="T">表达式中的元素类型</typeparam>
    /// <param name="left">左边的 <paramref name="System.Linq.Expression"/></param>
    /// <param name="right">右边的 <paramref name="System.Linq.Expression"/></param>
    /// <param name="func">表达式拼接的具体逻辑</param>
    /// <returns>拼接完成的 <paramref name="System.Linq.Expression"/></returns>
    public static LambdaExpression MakeBinary(this LambdaExpression left, LambdaExpression right, Func <Expression, Expression, Expression> func)
    {
        var data = Combinate(right.Parameters, left.Parameters).ToArray();

        right = ParameterReplace.Replace(right, data) as LambdaExpression;
        return(Expression.Lambda(func(left.Body, right.Body), left.Parameters.ToArray()));
    }
Example #2
0
        private static Expression GetAccessor(Expression item, Type type)
        {
            Expression accessor = null;

            var getString = Expression.Property(item, $"{nameof(EntityProperty.StringValue)}");

            if (type == typeof(string))
            {
                return(getString);
            }

            if (KnownTypes.TryGetValue(type, out var accessorName))
            {
                accessor = Expression.Coalesce(Expression.Property(item, accessorName), Expression.Default(type));
            }
            else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                var underlying = Nullable.GetUnderlyingType(type);

                if (KnownTypes.TryGetValue(underlying, out accessorName))
                {
                    accessor = Expression.Property(item, accessorName);
                }
            }

            // Do a lookup to see if there is a type that is suitable
            if (accessor == null)
            {
                if (Converters.TryGetValue(type, out var converter))
                {
                    var lambda = converter as LambdaExpression;

                    // Create a temporary variable
                    // this ensures against multiple accesses to the getString in the lambda
                    var variable = Expression.Variable(typeof(string));
                    var assign   = Expression.Assign(variable, getString);

                    // inline the lambda by replacing the string parameter with the variable
                    var work = ParameterReplace.Modify(lambda.Body, lambda.Parameters[0], variable);
                    accessor = Expression.Block(variable, assign, work);
                }
            }

            if (accessor == null)
            {
                throw new ResolverException($"GetAccessor didn't recognize the type '{type.Name}' - add a conversion from string");
            }

            return(accessor);
        }
Example #3
0
        public string DistributionPoint(int dpId, string task)
        {
            var smb = new Services.Client.SMB();
            var dp  = BLL.DistributionPoint.GetDistributionPoint(dpId);

            smb.SharePath = "//" + ParameterReplace.Between(dp.Server) + "/" + dp.ShareName;
            smb.Domain    = dp.Domain;
            if (task == "pull")
            {
                smb.Username = dp.RwUsername;
                smb.Password = new Helpers.Encryption().DecryptText(dp.RwPassword);
            }
            else
            {
                smb.Username = dp.RoUsername;
                smb.Password = new Helpers.Encryption().DecryptText(dp.RoPassword);
            }

            return(JsonConvert.SerializeObject(smb));
        }
Example #4
0
    protected void btnUpdateSettings_OnClick(object sender, EventArgs e)
    {
        RequiresAuthorization(Authorizations.UpdateAdmin);
        if (!ValidateSettings())
        {
            return;
        }
        var listSettings = new List <Models.Setting>
        {
            new Models.Setting {
                Name = "Server IP", Value = txtIP.Text, Id = Setting.GetSetting("Server IP").Id
            },
            new Models.Setting {
                Name = "Web Server Port", Value = txtPort.Text, Id = Setting.GetSetting("Web Server Port").Id
            },
            new Models.Setting {
                Name = "Tftp Path", Value = txtTFTPPath.Text, Id = Setting.GetSetting("Tftp Path").Id
            },
            new Models.Setting {
                Name = "Default Computer View", Value = ddlComputerView.Text, Id = Setting.GetSetting("Default Computer View").Id
            },
            new Models.Setting {
                Name = "Web Path", Value = txtWebService.Text, Id = Setting.GetSetting("Web Path").Id
            }
        };

        var newBootMenu  = false;
        var newClientIso = false;

        if (Setting.UpdateSetting(listSettings))
        {
            EndUserMessage = "Successfully Updated Settings";
            if ((string)ViewState["serverIP"] != txtIP.Text)
            {
                newBootMenu  = true;
                newClientIso = true;
            }
            if ((string)ViewState["serverPort"] != txtPort.Text)
            {
                newBootMenu  = true;
                newClientIso = true;
            }
            if ((string)ViewState["servicePath"] != ParameterReplace.Between(txtWebService.Text))
            {
                newBootMenu  = true;
                newClientIso = true;
            }
        }
        else
        {
            EndUserMessage = "Could Not Update Settings";
        }

        if (!newBootMenu)
        {
            return;
        }


        lblTitle.Text =
            "Your Settings Changes Require A New PXE Boot File Be Created.  <br>Go There Now?";
        if (newClientIso)
        {
            lblClientISO.Text = "The Client ISO Must Also Be Updated.";
        }
        ClientScript.RegisterStartupScript(GetType(), "modalscript",
                                           "$(function() {  var menuTop = document.getElementById('confirmbox'),body = document.body;classie.toggle(menuTop, 'confirm-box-outer-open'); });",
                                           true);
        Session.Remove("Message");
    }
    public static Expression Replace(Expression e, IEnumerable <KeyValuePair <ParameterExpression, ParameterExpression> > paramList)
    {
        var item = new ParameterReplace(paramList);

        return(item.Visit(e));
    }