i am pretty lame with using wsdl importer wizard with c++ Builder (XE6 Pro)
but finnally managed to properly import EBAY WSDL:
http://developer.ebay.com/webservices/latest/ebaySvc.wsdl
I can successfully run simple calls, but problem arises , when trying to set (or get )
Enum values.
At this point i am getting beautifull access violation after compilation.
Relevant piece of code:
void __fastcall TEbay::IndexBClick(TObject *Sender)
{
CallName="GetMyeBaySelling";
UnicodeString PUrl = MakeLink();
_di_eBayAPIInterface EbayCall = GeteBayAPIInterface(false,PUrl,HTP1);
CustomSecurityHeaderType *HDR = new RequesterCredentials;
HDR->eBayAuthToken=AuthToken;
HDR->Credentials = new UserIdPasswordType();
HDR->Credentials->AppId=AppId;
HDR->Credentials->DevId=DevId;
HDR->Credentials->AuthCert=CertId;
_di_ISOAPHeaders headers = EbayCall;
HTP1->SOAPHeaders->Send(HDR);
HTP1->SOAPHeaders->SetOwnsSentHeaders(True);
//GeteBayOfficialTimeRequest TR = new GeteBayOfficialTimeRequestType();
GetMyeBaySellingRequest *TR = new GetMyeBaySellingRequest();
GetMyeBaySellingResponse *ER =new GetMyeBaySellingResponse();
//ShowMessage(PUrl);
TR->Version=Version;
TR->ErrorLanguage="en_GB";
// This one raises error
TR->SoldList->OrderStatusFilter=OrderStatusFilterCodeType::All;
ShowMessage("2");
ER = EbayCall->GetMyeBaySelling(TR);
TDateTime ACK = ER->Timestamp->AsDateTime;
ShowMessage(UnicodeString("ODP:")+ACK);
// EbayCall->GeteBayOfficialTime(ER);
delete TR;
delete ER;
delete HDR;
}
Violation comes when i try to set up OrderStatusFilter or any enum values.
Declaration: (ebasvc.h) :
enum class OrderStatusFilterCodeType /* "urn:ebay:apis:eBLBaseComponents"[GblSmpl] */
{
All,
AwaitingPayment,
AwaitingShipment,
PaidAndShipped,
CustomCode
};
class OrderStatusFilterCodeType_TypeInfoHolder : public TObject {
OrderStatusFilterCodeType __instanceType;
public:
__published:
__property OrderStatusFilterCodeType __propType = { read=__instanceType };
};
I am getting mad allready with this, could anybody help me run this $#&^#$&^ ??
Best regards
TR->SoldList->OrderStatusFilter=OrderStatusFilterCodeType::All;
Looks like you are trying to assign a value to a property on the SoldList object, yet I can't see where you have created that object. Try the following.
TR->SoldList = new ItemListCustomizationType();
TR->SoldList->OrderStatusFilter=OrderStatusFilterCodeType::All;
Related
In my Unity3D Project I made a simple 2D Game and implemented a Data Manager to save and load Data. I created a List but get a NullReferenceException whenever I try to refer to it. I have a DataManager Class (saves & loads Data) and a UserData Class (stores the fields that are needed to be saved or loaded). In the User Data Class I declare in initialize a List of integer type. The List contains the unlocked Levels and it is initialized in the Constructor of the User Data Class.
This is the DataManager Class:
public static class DataManager
{
public static List<int> GetUnlockedLevels()
{
UserData userData = Load();
return userData.unlockedLevels; // This method returns nothing, not even null!
}
private static void Save(UserData data)
{
string path = GetDataFilePath();
BinaryFormatter binaryFormatter = new BinaryFormatter();
using (FileStream fileStream = File.Open(path, FileMode.OpenOrCreate))
{
binaryFormatter.Serialize(fileStream, data);
}
}
private static UserData Load()
{
string path = GetDataFilePath();
if (!File.Exists(path))
{
UserData userData = new UserData();
Save(userData);
}
BinaryFormatter binaryFormatter = new BinaryFormatter();
using (FileStream fileStream = File.Open(path, FileMode.Open))
{
return (UserData)binaryFormatter.Deserialize(fileStream);
}
}
And here comes the UserData Class:
[Serializable]
public class UserData
{
public int score;
public List<int> unlockedLevels;
public UserData()
{
score = 50;
unlockedLevels = new List<int>();
unlockedLevels.Add(1); //unlocked by default
unlockedLevels.Add(2); //unlocked by default
unlockedLevels.Add(3); //unlocked by default
}
}
The problem is: the first method of the DataManager "GetUnlockedLevels()" returns nothing.
The weird part: I have the exact same Data Manager in another project where it works properly. In that other project, the GetUnlockedLevels-method returns "System.Collections.Generic.List´1[System.Int32]" when I return it via "Debug.Log". But in the new project, the method returns literally nothing (not even null; the exception comes at a later point)
I am sure that I didn't make a copy-paste-mistake. What could be the root for this error?
What IDE are you using? I ask because the answer to your question is that you have a typo in your UserData constructor. Normally you would be alerted to this as soon as you built within your IDE as it would fail to compile.
[Serializable]
public class UserData
{
public int score;
public List<int> unlockedlevels; // This line
public UserData()
{
score = 50;
unlockedLevels = new List<int>(); // And this line
unlockedLevels.Add(1); // And this line
unlockedLevels.Add(2); // And this line
unlockedLevels.Add(3); // And this line
}
}
unlockedLevels
vs
unlockedlevels
Solution: the file was created but was empty. I manually deleted the saved file and from then it worked properly.
In my project , i use C++ , QScxmlCppDataModel , there is always occur a error , "No data-model instantiated" when i start the state machine,
I follow the Qt document says
1、Add data model in scxml file
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" binding="early" xmlns:qt="http://www.qt.io/2015/02/scxml-ext" datamodel="cplusplus:DataModel:DataModel.h" name="PowerStateMachine" qt:editorversion="4.6.1" initial="nomal">
2、Create a new data model subclass
#include "qscxmlcppdatamodel.h"
#include <QScxmlEvent>
class DataModel :public QScxmlCppDataModel
{
Q_OBJECT
Q_SCXML_DATAMODEL
public:
// DataModel();
bool isMoreThan50() const;
bool isLessThan50() const ;
int m_power;
QString m_Descript;
QVariant m_var;
};
3、load and start state machine
m_stateMachine = QScxmlStateMachine::fromFile(":/powerStateMachine.scxml");
for(QScxmlError& error:m_stateMachine->parseErrors())
{
qDebug()<<error.description();
}
m_stateMachine->connectToEvent("powerLoss", this, &MainWindow::onPowerLossEvent);
m_stateMachine->connectToEvent("pwoerUp", this, &MainWindow::onPowerUpEvent);
m_stateMachine->connectToState("low", this, &MainWindow::onLowState);
m_stateMachine->connectToState("nomal", this, &MainWindow::onNomalState);
m_stateMachine->connectToState("danger", this, &MainWindow::onDangerState);
m_stateMachine->connectToState("full", this, &MainWindow::onFullState);
DataModel *dataModel = new DataModel;
m_stateMachine->setDataModel(dataModel);
m_stateMachine->init();
m_stateMachine->start();
error image
but still have a error :"No data-model instantiated",when i start the
state machine , anybody know how to fix it ?? thank you
Qt's documentation on QScxmlCppDataModel specifically says:
The C++ data model for SCXML ... cannot be used when loading an SCXML
file at runtime.
And that is exactly what you are doing, so instead of loading the scxml file at runtime:
m_stateMachine = QScxmlStateMachine::fromFile(":/powerStateMachine.scxml");
Use the compiled statemachine directly:
MyStateMachine statemachine;
MyDataModel datamodel;
statemachine.setDataModel(&datamodel);
In the example above:
1- MyStateMachine is the value you have assigned to the <name> attribute of the scxml element (i.e. scxml file/model).
2- MyDataModel is the name you have given to your c++ data model class (i.e. your class derived from QScxmlCppDataModel)
class MyDataModel : public QScxmlCppDataModel
{
Q_OBJECT
Q_SCXML_DATAMODEL
public:
MyDataModel();
};
Too late an answer, but hope it helps others.
I've created a Xamarin.Forms UWP app and it felt to me like a bucket full of cement on your feet while trying to cross the mediterranean by swimming. So I switched to native UWP programming.
My application gets created to 95 % dynamically. All pages controls on the pages are dependend on what's saved in the database.
I have one login-page, a carouselPage (FlipView) and a QuitPage.
All other pages are dynamically loaded and added to the FlipView-ItemsSource.
In Xamarin I had a TemplateSelector like the one in this link:
https://github.com/alexrainman/CarouselView/blob/master/Demo/Views/MyTemplateSelector.cs
My question is:
How can I dynamically create DateTemplates out of my Views/Pages?
BTW:
I switched from Xamarin to native because there were heavy performance issues. The Carousel switches everytime to the first item and needed several seconds to show the "actual" page again, after the size was changed (through virtual keyboard).
I hope for a solution without such performance issues when there are more than 30 items in the list.
Maybe someone can explain why there is such a performance issue? I can't believe that every page is gonna be reloaded caused by the size changed by the virtual kb.
Thank you all in advance.
EDIT:
After I found the button for editing, here's what I got so far:
I have a Page named CarouselView. In the Xaml I have the FlipView named "myCarousel".
In the CodeBehind I have the following code:
public partial class WellcomeView : BasePage {
#region Fields + Properties
private int _position;
public int Position { get { return _position; } set { _position = value; } }
#endregion
public CarouselView() {
InitializeComponent();
myCarousel.ItemTemplateSelector = new MyTemplateSelector();
DataContext = new WellcomeViewModel(null, null, null, null, null);
}
public class MyTemplateSelector : Windows.UI.Xaml.Controls.DataTemplateSelector {
private DataTemplate GreetingTemplate;
...
public MyTemplateSelector() {
this.GreetingTemplate = (DataTemplate)Windows.UI.Xaml.Markup.XamlReader.Load(new GreetingView().Content.ToString());
...
// Here it throws an error. No matter if MainPage (with content) or other Views (with Content==null). But in every case I get a XamlParseException.
} // End Ctor
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) {
var TemplateType = item.GetType();
switch (TemplateType.Name) {
case "GreetingViewModel":
return base.SelectTemplateCore(GreetingTemplate );
default:
return base.SelectTemplateCore(BegruessungTemplate);
} // End switch-case
} // End SelectTemplateCore()
} // End MyTemplateSelector()
} // End class WellcomeView
Here's the Error I get...
And here's the StackTrace:
at Windows.UI.Xaml.Markup.XamlReader.Load(String xaml)
at MEDePORT_Win_Native.Views.WellcomeView.MyTemplateSelector..ctor()
at MEDePORT_Win_Native.Views.WellcomeView..ctor()
at MEDePORT_Win_Native.MEDePORT_Win_Native_XamlTypeInfo.XamlTypeInfoProvider.Activate_11_WellcomeView()
at MEDePORT_Win_Native.MEDePORT_Win_Native_XamlTypeInfo.XamlUserType.ActivateInstance()
at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter)
at MEDePORT_Win_Native.App.OnLaunched(LaunchActivatedEventArgs e)
EDIT:
With "new MyView().Content.ToString()" I only get the name of the type. For example "Windows.Ui.Xaml.Controls.Grid".
So it seems like I need to extract xaml out of a view and convert it to a string.
EDIT EDIT EDIT EDIT EDIT:
What is the UWP equivalent for the following code?
DataTemplate template = new DataTemplate { DataType = typeof(< Type of the object the template refers>) };
Try to create your templates not as xaml-Files. Just copy the the Template-content to a xaml-DataTemplate in a new Resources.Xaml.
Then create Your TemplateSelector like this:
public class MyTemplateSelector : DataTemplateSelector {
public DataTemplate GreetingTemplate;
static ResourceDictionary dataTemplates;
public MyTemplateSelector() {
if (dataTemplates == null) {
dataTemplates = new Templates.DataTemplates();
}
GreetingTemplate = dataTemplates["GreetingTemplate"] as DataTemplate; // Look how to load Your Templates!
}
And return your templates like this:
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) {
var TemplateType = item.GetType();
switch (TemplateType.Name) {
case "GreetingViewModel":
return GreetingTemplate;
default:
return base.SelectTemplateCore(GreetingTemplate);
}
}
The Class Templates.DataTemplates() from the first code example looks like this:
public partial class DataTemplates : ResourceDictionary {
public DataTemplates() {
InitializeComponent();
}
}
and it's xaml contains your DataTemplates.
Hope, this helps.
I'm facing a design problem. I want to separate building objects with a builder pattern, but the problem is that objects have to be built from configuration file.
So far I have decided that all objects, created from configuration, will be stored in DataContext class (container for all objects), because these objects states will be updated from a transmission (so it's easier to have them in one place).
I'm using external library for reading from XML file - and my question is how to hide it - is it better to inject it to concreteBuilder class? I have to notice that builder class will have to create lots of objects and at the end - connect them between each other.
Base class could look like that:
/*
* IDataContextBuilder
* base class for building data context object
* and sub obejcts
*/
class IDataContextBuilder {
public:
/*
* GetResult()
* returns result of building process
*/
virtual DataContext * GetResult () = 0;
/*
* Virtual destructor
*/
virtual ~IDataContextBuilder() { }
};
class ConcreteDataContextBuilder {
public:
ConcreteDataContextBuilder(pugi::xml_node & rootNode);
DataContext * GetResult ();
}
How to implement it correctly? What could be better pattern to build classes from configuration files?
I don't see a problem with that, but maybe you could inject another 'Director' class that receives a specific builder, loads the config files, and produces objects calling the respective builder-subclasses.
What I mean:
class DataContextDirector {
public:
void SetBuilder(IDataContextBuilder* builder);
void SetConfig(const std::string& configFilePath); // or whatever
DataContext* ProduceObject() {
// pseudo-code here:
// myBuilder->setup(xmlNodeOfConfig);
// return myBuilder->GetResult();
}
};
Since a while now I'm implementing services whenever possible with ServiceStack (or WebAPI) instead of WCF.
What I want to do now is sending an interface (-name) to the server and get a class-implementation back. Maybe that's confusing, so I'll give you an example:
My service-client has multiple operations - like "check form":
The logic for checking this form is not implemented. What it has is an interface called IFormChecker with methods like NameIsValid(string firstName, string middleName, string lastName).
Instead of sending the whole form-data to the server for validation, the client will request the implementation of IFormChecker from the server.
I know that's possible with WCF, but I have no idea how to do that with ServiceStack.
If that's possible, what's the way to go? I checked the documentation, but I'm not really wiser.
It seams like there's no "magic trick" or anything.
I have to serialize/deserialize the class "old-fashion way".
If you're interested, here's the solution:
I created a "Root"-Interface, in this example it is IModule.
This IModule contains only 1 property, called Name.
It is a string and only there for convenience:
The IFormChecker from the example would be derived from this interface:
My client knows the value of this Name-property and of course the interface itself.
It will now fire the Name-value to the server, which will return the serialized class.
All I have to do is:
var module = ModuleImplementations.FirstOrDefault(x => x.Name == name);
if(module == null) throw new SomeException();
return module.Serialize();
client-wise I can deserialize it and cast it to the interface. That's it.
Here's my ModuleSerialization-Class:
public static class ModuleSerialization
{
public static string Serialize(this IModule m)
{
using (var ms = new MemoryStream())
{
var bf = new BinaryFormatter();
bf.Serialize(ms, m);
return Convert.ToBase64String(ms.ToArray());
}
}
public static T Deserialize<T>(string serialized) where T : class, IModule
{
var ba = Convert.FromBase64String(serialized);
using (var s = new MemoryStream(ba))
{
var bf = new BinaryFormatter();
return bf.Deserialize(s) as T;
}
}
}
Cheers!