DBStorage and Sub-Dictionaries
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
DBStorage and Sub-Dictionaries

 
Post new topic   Reply to topic    Windows Server Forum Index -> Commerce Server
Author Message
Colin Bowern
Guest





Posted: Sat Sep 17, 2005 12:51 am    Post subject: DBStorage and Sub-Dictionaries Reply with quote

I'm just starting to figure out how to persist PurchaseOrder values in database
tables. It appears that you need to make additional calls after you call
Basket.SaveAsOrder(). From my tests so far it seems DBStorage is very picky
on types. I understand that it's a COM object and as such it will only accept
COM types.

What I'm wondering is there a more efficient way to handle Dictionary or
SimpleList objects inside a Dictionary that I'm trying to store?

For example, looking at the shipments collection produced by the Splitter
there are two things that kill DBStorage currently - ItemIndexes (a simple
list), and shipping_method_name (dictionary with a child dictionary which
has a property which is also a dictionary -- yup - three dictionaries).
Currently I have to kill those objects from the dictionary as below:

---
PurchaseOrder Receipt = BasketObject.SaveAsOrder();
....
IDBStorage DatabaseStorage = new DBStorageClass();

// Initialize DBStorage Object
DatabaseStorage.InitStorage(
CSConfiguration.TransactionConnectionString,
"OrderShipment",
"ordershipment_id",
"Commerce.Dictionary",
"marshaled_data",
"d_DateLastChanged");

// Extract each shipment from default order form.
ISimpleList Shipments = Receipt.OrderForms[0]["shipments"] as ISimpleList;
for(int index = 0; index < Shipments.Count; index++)
{
IDictionary Shipment = Shipments[index] as IDictionary;

// ItemIndexes is not compatible with DBStorage - throws a type error.
Shipment.let_Value("ItemIndexes", "");

// Remove shipping_method_name - throws a type error.
Shipment.let_Value("shipping_method_name", "");

// Add some additional items.
Shipment["ordergroup_id"] = Receipt.OrderGroupID.ToString("B");
Shipment["g_UserIDChangedBy"] = Receipt["g_UserIDChangedBy"];

DatabaseStorage.InsertData(null, Shipment);
}
---

Also, having to call let_Value is a bit annoying. It seems I can't call
Shipment["ItemIndexes"] = null directly. Just some feedback for the product
group that is lurking. :)

Cheers,
Coli
Back to top
Colin Bowern
Guest





Posted: Sat Sep 17, 2005 6:39 am    Post subject: Re: DBStorage and Sub-Dictionaries Reply with quote

(Ignore that last comment about let_Value - turns out that it works in code
but not in the Command Window. <grin>)

Quote:
I'm just starting to figure out how to persist PurchaseOrder values in
database tables. It appears that you need to make additional calls
after you call Basket.SaveAsOrder(). From my tests so far it seems
DBStorage is very picky on types. I understand that it's a COM object
and as such it will only accept COM types.

What I'm wondering is there a more efficient way to handle Dictionary
or SimpleList objects inside a Dictionary that I'm trying to store?

For example, looking at the shipments collection produced by the
Splitter there are two things that kill DBStorage currently -
ItemIndexes (a simple list), and shipping_method_name (dictionary with
a child dictionary which has a property which is also a dictionary --
yup - three dictionaries). Currently I have to kill those objects
from the dictionary as below:

---
PurchaseOrder Receipt = BasketObject.SaveAsOrder();
...
IDBStorage DatabaseStorage = new DBStorageClass();
// Initialize DBStorage Object
DatabaseStorage.InitStorage(
CSConfiguration.TransactionConnectionString,
"OrderShipment",
"ordershipment_id",
"Commerce.Dictionary",
"marshaled_data",
"d_DateLastChanged");
// Extract each shipment from default order form.
ISimpleList Shipments = Receipt.OrderForms[0]["shipments"] as
ISimpleList;
for(int index = 0; index < Shipments.Count; index++)
{
IDictionary Shipment = Shipments[index] as IDictionary;
// ItemIndexes is not compatible with DBStorage - throws a type
error.
Shipment.let_Value("ItemIndexes", "");
// Remove shipping_method_name - throws a type error.
Shipment.let_Value("shipping_method_name", "");
// Add some additional items.
Shipment["ordergroup_id"] = Receipt.OrderGroupID.ToString("B");
Shipment["g_UserIDChangedBy"] = Receipt["g_UserIDChangedBy"];
DatabaseStorage.InsertData(null, Shipment);
}
---
Also, having to call let_Value is a bit annoying. It seems I can't
call Shipment["ItemIndexes"] = null directly. Just some feedback for
the product group that is lurking. :)

Cheers,
Colin
Back to top
Colin Bowern
Guest





Posted: Sat Sep 17, 2005 7:16 am    Post subject: Re: DBStorage and Sub-Dictionaries Reply with quote

A little more testing has shown it is the Shipping_Method_Name field is definetly
what that causes the following exception:

System.Runtime.InteropServices.COMException : Arguments are of the wrong
type, are out of acceptable range, or are in conflict with one another.
at Microsoft.CommerceServer.Interop.Orders.DBStorageClass.InsertData(Object
vtReserved, Object pdispData)

The following is the original value:

<DICTITEM key="shipping_method_name">
<VALUE dt:dt="object" dt:classid="classid:B7990D09-45FD-11D0-8176-00A0C90A90C7">
<DICTIONARY xmlns:dt="uuid:304FB305-29A4-11d3-B0D4-00C04F8ED7A2" version="1.0">
<DICTITEM key="{00000000-0000-0000-0000-002468008034}">
<VALUE dt:dt="object" dt:classid="classid:B7990D09-45FD-11D0-8176-00A0C90A90C7">
<DICTIONARY xmlns:dt="uuid:304FB305-29A4-11d3-B0D4-00C04F8ED7A2" version="1.0">
<DICTITEM key="config">
<VALUE dt:dt="object" dt:classid="classid:B7990D09-45FD-11D0-8176-00A0C90A90C7">
<DICTIONARY xmlns:dt="uuid:304FB305-29A4-11d3-B0D4-00C04F8ED7A2"
version="1.0">
<DICTITEM key="mode">
<VALUE dt:dt="i2">1</VALUE>
</DICTITEM>
</DICTIONARY>
</VALUE>
</DICTITEM>
<DICTITEM key="progid">
<VALUE dt:dt="string" xml-space="preserve">commerce.stepwiseshipping</VALUE>

</DICTITEM>
<DICTITEM key="shipping_method_name">
<VALUE dt:dt="string" xml-space="preserve">Quick</VALUE>
</DICTITEM>
<DICTITEM key="description">
<VALUE dt:dt="string" xml-space="preserve">(7 to 10 business days)</VALUE>

</DICTITEM>
</DICTIONARY>
</VALUE>
</DICTITEM>
</DICTIONARY>
</VALUE>
</DICTITEM>

To make it work I replace it with:

<DICTITEM key="shipping_method_name">
<VALUE dt:dt="string" xml-space="preserve">Quick</VALUE>
</DICTITEM>

---

/// <summary>
/// Saves the shipments.
/// </summary>
/// <param name="purchaseOrder">Purchase order.</param>
private void SaveShipments(PurchaseOrder purchaseOrder)
{
Microsoft.CommerceServer.Interop.Orders.IDBStorage DatabaseStorage = null;

try
{
DatabaseStorage = new Microsoft.CommerceServer.Interop.Orders.DBStorageClass();

DatabaseStorage.InitStorage(
CommerceServerConfiguration.Current.TransactionConnectionString,
"OrderFormShipments",
ShipmentField.OrderShipmentId,
"Commerce.Dictionary",
ShipmentField.MarshaledData,
ShipmentField.DateLastChanged);

for(int OuterIndex = 0; OuterIndex < purchaseOrder.OrderForms.Count; OuterIndex++)
{
OrderForm orderForm = purchaseOrder.OrderForms[OuterIndex] as OrderForm;
ISimpleList Shipments = orderForm[OrderFormField.Shipments] as ISimpleList;
for(int index = 0; index < Shipments.Count; index++)
{
IDictionary Shipment = Shipments[index] as IDictionary;

Shipment[ShipmentField.OrderGroupId] = purchaseOrder.OrderGroupID.ToString("B",
CultureInfo.InvariantCulture);
Shipment[ShipmentField.OrderFormId] = orderForm[OrderFormField.OrderFormId];

Shipment[ShipmentField.OrderShipmentId] = ProfileSystem.GenerateProfileId();
Shipment[ShipmentField.LastChangedBy] = orderForm[OrderFormField.LastChangedBy];

// Simplify the Shipping Method Name field so it can be saved by DBStorage
string ShippingMethodId = Shipment[ShipmentField.ShippingMethodId] as
string;

IDictionary DictionaryProperty = Shipment[ShipmentField.ShippingMethodName]
as IDictionary;
DictionaryProperty = DictionaryProperty[ShippingMethodId] as IDictionary;

Shipment[ShipmentField.ShippingMethodName] = DictionaryProperty[ShipmentField.ShippingMethodName]
as string;

DatabaseStorage.InsertData(null, Shipment);

// Save Item Indexes in a Separate Table
SaveShipmentItems(purchaseOrder.OrderGroupID.ToString(),
orderForm[OrderFormField.OrderFormId] as string,
Shipment[ShipmentField.OrderShipmentId] as string,
Shipment[ShipmentField.ItemIndexes] as ISimpleList);
}
}
}
finally
{
if(DatabaseStorage != null)
Marshal.ReleaseComObject(DatabaseStorage);
}
}

/// <summary>
/// Saves the shipment items.
/// </summary>
/// <param name="orderGroupId">Order group id.</param>
/// <param name="orderFormId">Order form id.</param>
/// <param name="orderShipmentId">Order shipment id.</param>
/// <param name="itemIndexes">Item indexes.</param>
private void SaveShipmentItems(string orderGroupId, string orderFormId, string
orderShipmentId, ISimpleList itemIndexes)
{
Microsoft.CommerceServer.Interop.Orders.IDBStorage DatabaseStorage = null;

try
{
DatabaseStorage = new Microsoft.CommerceServer.Interop.Orders.DBStorageClass();

DatabaseStorage.InitStorage(
CommerceServerConfiguration.Current.TransactionConnectionString,
"OrderFormShipmentLineItems",
ShipmentLineItemField.LineItemId,
"Commerce.Dictionary",
null,
null);

for(int index = 0; index < itemIndexes.Count; index++)
{
IDictionary ShipmentLineItem = null;
try
{
ShipmentLineItem = new DictionaryClass();

ShipmentLineItem[ShipmentLineItemField.LineItemId] = Convert.ToString(itemIndexes[index],
CultureInfo.InvariantCulture);
ShipmentLineItem[ShipmentLineItemField.OrderGroupId] = orderGroupId;
ShipmentLineItem[ShipmentLineItemField.OrderFormId] = orderFormId;
ShipmentLineItem[ShipmentLineItemField.OrderShipmentId] = orderShipmentId;

DatabaseStorage.InsertData(null, ShipmentLineItem);
}
finally
{
if(ShipmentLineItem != null)
Marshal.ReleaseComObject(ShipmentLineItem);
}
}
}
finally
{
if(DatabaseStorage != null)
Marshal.ReleaseComObject(DatabaseStorage);
}
}
---


Quote:
(Ignore that last comment about let_Value - turns out that it works in
code but not in the Command Window. <grin>)

I'm just starting to figure out how to persist PurchaseOrder values
in database tables. It appears that you need to make additional
calls after you call Basket.SaveAsOrder(). From my tests so far it
seems DBStorage is very picky on types. I understand that it's a COM
object and as such it will only accept COM types.

What I'm wondering is there a more efficient way to handle Dictionary
or SimpleList objects inside a Dictionary that I'm trying to store?

For example, looking at the shipments collection produced by the
Splitter there are two things that kill DBStorage currently -
ItemIndexes (a simple list), and shipping_method_name (dictionary
with a child dictionary which has a property which is also a
dictionary -- yup - three dictionaries). Currently I have to kill
those objects from the dictionary as below:

---
PurchaseOrder Receipt = BasketObject.SaveAsOrder();
...
IDBStorage DatabaseStorage = new DBStorageClass();
// Initialize DBStorage Object
DatabaseStorage.InitStorage(
CSConfiguration.TransactionConnectionString,
"OrderShipment",
"ordershipment_id",
"Commerce.Dictionary",
"marshaled_data",
"d_DateLastChanged");
// Extract each shipment from default order form.
ISimpleList Shipments = Receipt.OrderForms[0]["shipments"] as
ISimpleList;
for(int index = 0; index < Shipments.Count; index++)
{
IDictionary Shipment = Shipments[index] as IDictionary;
// ItemIndexes is not compatible with DBStorage - throws a type
error.
Shipment.let_Value("ItemIndexes", "");
// Remove shipping_method_name - throws a type error.
Shipment.let_Value("shipping_method_name", "");
// Add some additional items.
Shipment["ordergroup_id"] = Receipt.OrderGroupID.ToString("B");
Shipment["g_UserIDChangedBy"] = Receipt["g_UserIDChangedBy"];
DatabaseStorage.InsertData(null, Shipment);
}
---
Also, having to call let_Value is a bit annoying. It seems I can't
call Shipment["ItemIndexes"] = null directly. Just some feedback for
the product group that is lurking. :)
Cheers,
Colin
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Commerce Server All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB