-
Notifications
You must be signed in to change notification settings - Fork 911
Pull trading code into it's own library. #64
Conversation
In Visual Studio 2010 at least.
Removed main.cs... point to correct Newtonsoft.Json proj for proj ref
This was the feature/user-handlers from Philipp15b
Has a new project called SteamTrade to hold SteamTrade.cs et. al.
This does not compile yet... refactoring will have to be done to remove the Bot dependency in Trade.cs
SteamWeb.cs now exists in both SteamTrade and ExampleBot (not good). Fix trade to not use bot (pass in timeout params and need to figure out the logger).
Probably create a factory class in SteamTrade to do this for us.
Also fixed to use the Log object instead of the bot.log (this was really all it was doing anyway)
pass in the log object into Trade ctor.
Include proper using directives where needed.
SteamTrade.SteamWeb now has the SteamKit based Auth method. Had to add more params.
Renamed getHandler -> GetUserHandler. Removed Authenticate (use SteamTrade.SteamWeb.Authenticate)
Merge pull request Jessecar96#62 from FunkyLoveCow/log-changes Resolved conflicts with the split library stuff. (Change old log ctor's to new ones)
This class moves the web stuff that was in Trade.cs into its own class. Trade.cs gets the same pass thru methods.
Also added XML doc comments. Will remove GetInventory from Trade
Also moved some data from Trade to TradeSession
Made a bunch of fields private. Changed public data auto properties. Add comments, moved public properties (following MS StyleCop guidelines loosly)
Move events delegates below public properties. Put comments on event not delegate. (Probably remove delegates in future and use Action<T>)
Set Version for use in TradeSession (like logpos). Remove some backing stores and redundant buffers (may be needed but really shouldn't be)
{ | ||
public class Inventory | ||
{ | ||
/// <summary> | ||
/// Fetchs the inventory for the given Steam ID using the Steam API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Fetches' 👅
@cwhelchel I do not agree with your changs in the I don't get why you set so many properties private that may be needed by I also don't get why you split And I also don't like how you integrated logging into the trade, in my understanding, moving trading to a library means removing all dependencies from the trading part to the bot itself. The bot should have to register callbacks which then log. |
@Philipp15b Let me try to change your mind. The
I tried my best to split off the URL building Steam Trade interaction as best I could. This would allow for testing of the Trade class without access a real trade (if it were tested). And I also think it's a good place to separate responsibilities. URL building and fetching has little to do with an actual Trade object, it's merely a "data provider" if you will. There are probably more things that could be added to the As far as making various data private, I feel that needs no arguing. Data should be private and exposed as public properties. Public data clutters up your public interface, which is way more important than access to the data itself. Granted, I made all data private that was not used externally, and some of these should be exposed via properites. I was not sure what would and would not be used, so this is something that should be exposed in the future. |
@cwhelchel I'm still not convinced. I still do not see a reason why you created a Regarding logging, you're correct. I'd love to see some cleaner splitting even if that means some more code. What you said about data encapsulation is also something I do not understand. When designing the API, I deliberately made those properties public. For data that is passed into the trade, I do not see a reason to hide them from the user. What I didn't do though was making those fields externally read-only, which is something that should definitely be added. The following properties should be publicy available:
|
By the way, squashing your commits would also be nice... |
@Philipp15b Regarding the
If the code was still in You're right about those other fields. I'll work on a commit that has them exposed as read-only properties. |
@cwhelchel You understood me wrong. I have absolutely no problem with the boilerplate code here. Now with code folding I have no problem with a 1000 lines class of things that belong together. I'd love to see both classes merged again. The only reason of yours I can understand is testing, but that reminds me of Java's class hell. I see no reason to make it an interface. Instead of replacing the As said before, if you have problems with too long files, just use |
Also a minor spelling fix because I can't spell. Resharper changed all read accesses for the exposed properties to use the getters.
@Philipp15b I think we're splitting hairs a bit. Either a separate class or a partial class will work. Personally I don't think a user needs access to the web methods and should only work with the I'll change it to a partial class if anyone else speaks up i.e. its not a decision I think I should make. |
@cwhelchel Many thanks for this. I don't understand what you mean by
A user should just use Error checking and logging should be kept out of the Trade. This is something that can be easily added by events and added into |
@Philipp15b I think we are thinking the same thing. I was just expressing it directly that a user should only call I think logging is part of making a secure and easy to use API. But that discussion is tangential to this pull request. I moved the Log class into the trade library for pragmatic reasons not ideological reasons. |
Why not use exceptions within the Trade class, and move the Log class out of |
@redjazz96 👍 |
@redjazz96 Agreed. That's a better design. Will change. |
If I remember right, this should increment the SteamBot version... |
MyOfferedItems = _OfferedItemsFromSteam; | ||
//_OfferedItemsFromSteam.Add (itemID); | ||
//MyOfferedItems = _OfferedItemsFromSteam; | ||
MyOfferedItems.Add (itemID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you do this? The whole point of it was to allow AddItemByDefindex
to add two items with the same Defindex without moving them instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean moving them in the trade slots? I think I removed this originally because I thought it was doing the same thing twice. Add to _Offered and copy that to MyOfferedItems.
I was unaware that it was required to get that method to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the Poll updates every 800ms, OnTradeAddItem
is called when an item is added. If an item is added in the function, MyOfferedItems
isn't updated until the next Poll.
What I did was I added a line to AddItem
(and RemoveItem
) that added the item that the user added to MyOfferedItems
; the lines that you commented out updated MyOfferedItems
to the list that steam has, so that it stays in sync with steam (as the request in AddItem
or RemoveItem
could have failed). _OfferedItemsFromSteam
always had the list from steam, so every item in there is pretty much guaranteed to be offered in the trade (unlike MyOfferedItems
, for reasons stated above).
I copied the semver stuff in the In this: will become this: And do you think this should be the same for the SteamTrade assembly? |
@cwhelchel I'd think it'd jump up to |
Made Trade a partial class as per Phillipp15b suggestions. Add back the copied list of ItemIDs that the Steam trade Poll side sees and copy it over the local offered items. Added Exceptions for the Trade library and throw them in Trade when the web stuff returns errors.
I don't get why there are |
They are more or less just helper functions that make the other methods (like The public methods |
I just think it makes the code more complicated. There is not much code that is there besides network stuff. You search longer to find very simple functionality. I simply don't get why you seperate these things. The functionality in the |
IDE's are glorified file systems managers and have great search capabilities. Arguing that the 5ms it takes to find a method (press Of course, we could put every single piece of code in one gigantic file and make life easier for everyone? Maybe even all in one method... that would work out well. |
I'm sorry, I realize I sound like a jerk in that last comment. @Philipp15b I know your just trying to do what you think is best. So am I. |
As long as there are no additional opinions on this, I think we should merge this now as I don't see an agreement, so we'll worry about that later. /cc @redjazz96, @FunkyLoveCow |
See issue #20. I'd also say issue #35 as well as I did add some comments where there weren't any.
This is a pretty big pull so be prepared for a headache. I've probably broke stuff for many people.
I've tested the functionality of the new TradesSession class and it appears to work for adding items, removing them, accepting trades, and canceling trades. I've also merged in the master branch to minimize some conflicts.
Let me know what I've missed as I'm sure there is something.