Sitecore 8.2 Glass Mapper Create item error - sitecore

We have recently upgraded our project to run on Sitecore 8.2, Rev3, as part of the upgrade we had to update Glass Mapper which is now running on version 4.3.4.197.
However, we are now getting an error when trying to create an item:
var service = new SitecoreService(_database);
service.Create(parent, redHotDeal);
The exception we are getting is:
Failed to find configuration for parent item type Sitecore.Data.Items.Item
StackTrace:
at Glass.Mapper.Sc.SitecoreService.Create[T,TK](TK parent, T newItem, Boolean updateStatistics, Boolean silent) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\SitecoreService.cs:line 200
at TTC.IV.Infrastructure.Import.RedHotDeals.RedHotDealsImporter.ImportRedHotDeals(IEnumerable`1 redhotdeals, Item parent) in G:\TFSProjects\IV\Source\TTC.IV.Infrastructure\Import\RedHotDeals\RedHotDealsImporter.cs:line 104
Has anyone experienced this issue or knows what might be causing it?
A bit more info on the setup:
parent item is of type Sitecore.Data.Items.Item
redHotDeal item is of type DealCollectionItem
DealCollectionItem model looks like this:
using System;
using Glass.Mapper.Sc.Configuration.Attributes;
namespace TTC.IV.Model.Templates.Items
{
[SitecoreType(TemplateId = TemplateStringId)]
public class DealCollectionItem : Item
{
public new static Guid TemplateId = new Guid(TemplateStringId);
private const string TemplateStringId = "{998CA212-92D5-4566-B877-44D1F378EFD6}";
/// <summary>
/// Gets or sets the mv code.
/// </summary>
/// <value>
/// The mv code.
/// </value>
[SitecoreField]
public virtual string MvCode { get; set; }
/// <summary>
/// Gets or sets the departure code.
/// </summary>
/// <value>
/// The departure code.
/// </value>
[SitecoreField]
public virtual string DepartureCode { get; set; }
/// <summary>
/// Gets or sets the discount.
/// </summary>
/// <value>
/// The discount.
/// </value>
[SitecoreField]
public virtual double Discount { get; set; }
/// <summary>
/// Gets or sets the promo code.
/// </summary>
/// <value>
/// The promo code.
/// </value>
[SitecoreField]
public virtual string PromoCode { get; set; }
/// <summary>
/// Gets or sets the price.
/// </summary>
/// <value>
/// The price.
/// </value>
[SitecoreField]
public virtual double Price { get; set; }
/// <summary>
/// Gets or sets the promo amount.
/// </summary>
/// <value>
/// The promo amount.
/// </value>
[SitecoreField]
public virtual double PromoAmount { get; set; }
/// <summary>
/// Gets or sets the table amount.
/// </summary>
/// <value>
/// The table amount.
/// </value>
[SitecoreField]
public virtual int TableAmount { get; set; }
/// <summary>
/// Gets or sets the import region.
/// </summary>
/// <value>
/// The import region.
/// </value>
public string ImportRegion { get; set; }
}
}

This is now resolved. I followed the advise as per https://github.com/mikeedwards83/Glass.Mapper/issues/305 and mapped an Item as a property by calling it 'Item' and letting it automap.

Related

Creating std::thread in Class with Header

How do I initialize DefenseThread so that it will start executing Defend()? I have seen a lot of examples on how to do it from a .cpp file without a header, but non with.
void CommandDefend::DefendStart()
Gets the following error:
'&' requires I-value
Header:
#pragma once
#include <thread>
class CommandDefend : public ICommand
{
public:
CommandDefend();
~CommandDefend();
private:
thread* DefenseThread;
/// <summary>
/// Starts the commands execution.
/// </summary>
void DefendStart();
/// <summary>
/// Does the actual defending.
/// </summary>
void Defend();
};
CPP:
#include "stdafx.h"
#include "CommandDefend.h"
void CommandDefend::DefendStart()
{//ERROR HERE!!!!!!
DefenseThread = new thread(&CommandDefend::Defend);
}
void CommandDefend::Defend()
{
}
If you replace
DefenseThread = new thread(&CommandDefend::Defend);
with
DefenseThread = new thread(&CommandDefend::Defend, this);
it should work, because it's the way how I initialize class members of type std::thread (while they are not pointers).

Trying to write an "Observer" pattern

Did I correctly implement this pattern? The idea of my example is that there are document and application (app performs an observer role). At the beginning each document should attach the observer. Further, document could close all documents except himself by emitting a signal to observer (application).
Requirement - example should use an event model.
class Application
{
std::vector<Document *> docs;
public:
void add_document(Document *doc)
{
docs.push_back(doc);
}
public slots:
void close_non_active_docs_button_pressed(Document *active_doc)
{
for (auto idoc: this->docs)
{
if (idoc == active_doc)
continue;
idoc->close();
}
}
}
class Document
{
Application *app;
public:
void attach_to_app(Application *app)
{
this->curr_app = app;
app->add_document(this);
}
void close(){...};
public signals:
void close_non_active_docs_button_pressed(Document *active_doc);
...
emit close_non_active_docs_button_pressed(this);
}
///CONNECT(...)

Unexpected end-of-file in visual form

Getting error, when trying to run code. I am using Visual Forms. VS 2013
#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThread]
int main(array<String^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Project1::MyForm form;
Application::Run(%form);
return 0;
}
MyForm.cpp(17): fatal error C1004: unexpected end-of-file found
MyForm.h:
#pragma once
namespace Project1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->SuspendLayout();
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
}
};
}
MyForm.cpp(17): fatal error C1004: unexpected end-of-file found
I just missed something in the code.
#include "MyForm.h"
using namespace System;
using namespace System ::Windows::Forms;
[STAThread]
void main(array<String^>^ arg) {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Project1::MyForm form;
Application::Run(%form);
}

Accessing private instances of classes from another class

I'm a scholar for Computer Games Programming, currently studying C++. I'm trying to access a private Texture2D and Vector 2 type in a .h file from a .cpp file in order to give an object position and image.
This is the Player.cpp file
#include "Player.h"
#include <sstream>
Player::Player(int argc, char* argv[]) : Game(argc, argv), _cPlayerSpeed(0.1f), _cPlayerFrameTime(250)
{
//Player Inits
_playerDirection;
_playerFrame = 0;
_playerCurrentFrameTime = 0;
_playerSpeedMultiplier = 1.0f;
//Init of Important Game Aspects
Graphics::Initialise(argc, argv, this, 1024, 768, false, 25, 25, "Genocide: Remastered", 60);
Input::Initialise();
Graphics::StartGameLoop(); //Start of Game Loop, calls Update and Draw in game loop.
}
Player::~Player()
{
}
void Player::Input(int elapsedTime, Input::KeyboardState* state)
{
// Checks for directional keys pressed
if (state->IsKeyDown(Input::Keys::D))
{
_playerPosition->X += _cPlayerSpeed * elapsedTime;
}
}
/// <summary> All content should be loaded in this method. </summary>
void Player::LoadContent()
{
_playerPosition = new Vector2();
_playerTexture = new Texture2D();
_playerTexture->Load(" ", false);
_playerSourceRect = new Rect(0.0f, 0.0f, 0, 0);
}
/// <summary> Called every frame - update game logic here. </summary>
void Player::Update(int elapsedTime)
{
}
/// <summary> Called every frame - draw game here. </summary>
void Player::Draw(int elapsedTime)
{
}
This is the Player.h
#pragma once
#ifdef WIN32
#ifndef _DEBUG
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#endif
#endif
#include "S2D/S2D.h"
using namespace S2D;
class Player : public Game
{
public:
Player(int argc, char* argv[]);
~Player();
/// <summary> All content should be loaded in this method. </summary>
void virtual LoadContent();
/// <summary> Called every frame - update game logic here. </summary>
void virtual Update(int elapsedTime);
/// <summary> Called every frame - draw game here. </summary>
void virtual Draw(int elapsedTime);
private:
Vector2* _playerPostion;
Rect* _playerSourceRect;
Texture2D* _pacmanTexture;
const float _cPlayerSpeed;
const int _cPlayerFrameTime;
int _playerDirection;
int _playerFrame;
int _playerCurrentFrameTime;
float _playerSpeedMultiplier;
void Input(int elapsedTime, Input::KeyboardState* state);
void CheckPaused(Input::KeyboardState* state, Input::Keys pauseKey);
void CheckViewportCollision();
void UpdatePlayer();
};
I've literally copied and pasted something I've been working on with my Lecturer and changed variable, type and instantiation declaration and his works. Curious as to why mine isn't. Help will be much appreciated.
Many thanks,
Ryan.
In the header, your Texture2D* is called _pacmanTexture, whereas in your implementation, you've called it _playerTexture. Similarly, you've misspelled _playerPosition in the header.
Usual way to give access to private resources of a class to another class is to add public accessor methods (getter, setter).

Trying to run a thread from a form

I have two related qestions on the code included below
1) I am trying to read from a serial port that is part of a Visual C++ Form. I want to create a thread in the InitializeComponent function but I get this error on the form page when I include the call to start the thread:
"Warning 1 Could not find type 'Thread'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built."
2) The thread will run in the static function Read. Read needs to resolve the serial port that is in the main form (serial port is named arduino),
but it apparently can't resolve them: "left of .ReadLine' must have class/struct/union"
Suggestions?
using namespace System::IO::Ports;
using namespace System::Threading;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
private: void static Read(void)
{
while (1)
{
try
{
String^ message = arduino.ReadLine();
// this->ArduinoOutputTextBox->Text = message;
}
catch (TimeoutException ^) { }
}
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ USB_button;
private: System::IO::Ports::SerialPort^ arduino;
private: System::Windows::Forms::TextBox^ ArduinoOutputTextBox;
private: System::ComponentModel::IContainer^ components;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
Thread^ readThread = gcnew Thread(gcnew ThreadStart(Read));
this->components = (gcnew System::ComponentModel::Container());
this->USB_button = (gcnew System::Windows::Forms::Button());
this->arduino = (gcnew System::IO::Ports::SerialPort(this->components));
this->ArduinoOutputTextBox = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
arduino is a reference to an object, not an actual object.
You ned to write arduino->readLine().