Coder Social home page Coder Social logo

Comments (6)

trbngr avatar trbngr commented on June 24, 2024

Unfortunately, this infusionsoft API is one hell of a moving target.

Likely the best option is to apply a change property name refactoring to the property.

I accept pull requests. ;)

If you can't get to it, let me know and I'll do it tomorrow afternoon.

Cheers,
Chris

from infusionsoft.net.

richard-brash avatar richard-brash commented on June 24, 2024

Chris,

Thanks for the quick response. I had abandoned using another library because it had been error prone and I ended up writing my own wrapper as needed but it was never complete. I found yours on NuGet and decided to give it a try for this project. As it is, I don't have much time to find and fix this issue. For now, I am using the standard method signature instead of the LINQ expressions just so I can move forward. If I get time, I'll take a look and see if I can push a fix unless you beat me to it.

Thanks again,
Richard

On Jan 22, 2014, at 1:46 AM, Chris Martin [email protected] wrote:

Unfortunately, this infusionsoft API is one hell of a moving target.

Likely the best option is to apply a change property name refactoring to the property.

I accept pull requests. ;)

If you can't get to it, let me know and I'll do it tomorrow afternoon.

Cheers,
Chris

โ€”
Reply to this email directly or view it on GitHub.

from infusionsoft.net.

piranout avatar piranout commented on June 24, 2024

There is a problem with the way Infusionsoft designed the Company table. Instead of Name or CompanyName, they called the name field Company. C# doesn't allow property names to be the same as their enclosing type though. So the generated class creates an aliasโ€”CompanyNameโ€”and tells XmlRpc to map it to the Company field. The definition looks like this:

  [XmlRpcMember("Company")]
  [Access(Access.Edit | Access.Delete | Access.Add | Access.Read)]
  public string CompanyName { get; set; }

Ultimately, the query translator needs to check if the XmlRpcMember attribute name matches the property name. If they don't match, it needs to use the attribute value when serializing the query.

Unfortunately, even using the untyped Query method, I get zero results for a query that should have 200+. The only way I can query companies right now is to fetch them all & do my LINQ filtering on the client side. Here's a wildcard query (name starts with A) that I think should work, but either I'm missing something or something outside my control is borked:

 var queryData = new XmlRpcStruct() { { "Company", "A%" } };
 var cs = client.DataService.Query(
    table: "Company",
    limit: 1000,
    page: 1,
    queryData: queryData,
    selectedFields: new[] {"CompanyID", "Company", "State", "PostalCode", "Country"});

from infusionsoft.net.

piranout avatar piranout commented on June 24, 2024

I have a fix for this. The query builder just needs a dictionary of property names that don't match Infusionsoft's actual column names. Here's the patch that got it working for me (I can do a normal query on CompanyName now; this should also enable LINQ query expressions to address any field that's not named the same as the table column). First, add the following extension class in the InfusionSoft namespace:

internal static class QueryBuilderExtensions
{
    private static Dictionary<Type, Dictionary<string, string>> _columnNames;
    private static Dictionary<Type, Dictionary<string, string>> ColumnNames
    {
        get
        {
            return _columnNames ?? (_columnNames = new Dictionary<Type, Dictionary<string, string>>());
        }
    }
    public static string GetColumnName<T>(this IQueryBuilder<T> builder, string propertyName) where T : ITable
    {
        if (!ColumnNames.ContainsKey(typeof(T)))
        {
            ColumnNames[typeof(T)] = new Dictionary<string, string>();
            typeof(T).GetProperties()
                .Where(p => !p.Name.Equals("CustomFields") && !p.Name.EndsWith("Comparer"))
                .ToList()
                .ForEach(p =>
                {
                    var attributes = p.GetCustomAttributes(typeof(XmlRpcMemberAttribute), false);
                    if (!attributes.Any())
                        return;
                    var attribute = attributes.Cast<XmlRpcMemberAttribute>().First();
                    if (!String.IsNullOrEmpty(attribute.Member) && attribute.Member != p.Name)
                    {
                        ColumnNames[typeof(T)].Add(p.Name, attribute.Member);
                    }
                });
        }
        return ColumnNames[typeof(T)].ContainsKey(propertyName) ? _columnNames[typeof(T)][propertyName] : propertyName;
    }
}

Then change the main overload of QueryBuilder.Add as such:

public IQueryBuilder<T> Add<TV>(Expression<Func<T, TV>> expression, TV value, ValuePosition valuePosition)
{
    string name = Express.PropertyWithLambda(expression).Name;
        name = this.GetColumnName(name);
    _dictionary.Add(name, BuildPositionalValue(valuePosition, value));
    return this;
}

from infusionsoft.net.

trbngr avatar trbngr commented on June 24, 2024

Excellent. Thanks for the effort.

If you issue a pull request, I'll merge it in.

from infusionsoft.net.

piranout avatar piranout commented on June 24, 2024

Done, thanks! Let me know if everything's satisfactory.

from infusionsoft.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.