/// <summary> /// Created a clone of the orignal and copy the orignal releational rows to the clone database /// The copy is done only for the rows that are part of the sorted filtered rows table /// The row order is keep the same as the sorted filtered rows table /// Only rows in the paging range (speciefied by startIndex, blockSize) are copyied /// </summary> /// <param name="sortedRows">Sorted Rows row set</param> /// <param name="cloneName">The Name of the clone dataset</param> /// <param name="dsStore">The oringnal dataset</param> /// <param name="startIndex">The start index for paging</param> /// <param name="blockSize">The size of the paging block</param> /// <returns>The sorted, filtered, and paged dataset</returns> private static DataSet CopySortedDataToOrigClone(DataRow[] sortedRows, string cloneName, DataSet dsStore, int startIndex, int blockSize) { DataRowCollection offerRows = dsStore.Tables[0].Rows; //DataSet dsFinal = new DataSet(cloneName); // dsFinal = dsStore.Clone(); ServerPaymentItemsDataSets dataSets = new ServerPaymentItemsDataSets(); DataSet dsFinal = dataSets.CreateStoreDataSet(cloneName, true); dsFinal.DataSetName = cloneName; int startPosition = 0; int endPosition = sortedRows.Length; if (UseBlockSize(startIndex, blockSize, endPosition, 0)) { startPosition = startIndex; int maxEndPosition = blockSize + startIndex; if (maxEndPosition < endPosition) { endPosition = maxEndPosition; } } for (int rowIndex = startPosition; rowIndex < endPosition; rowIndex++) //foreach (DataRow row in sortedRows) { DataRow row = sortedRows[rowIndex]; DataRow offerRow = offerRows.Find((object)row["itemOffer_itemOffer_Id"]); if (offerRow != null) { DataRow[] itemRow = offerRow.GetChildRows("itemOffer_item"); DataRow[] priceRow = offerRow.GetChildRows("itemOffer_price"); DataRow[] moneyRow = priceRow[0].GetChildRows("price_money"); DataRow[] propertiesRow = itemRow[0].GetChildRows("item_properties"); // DataRow[] propertyRow = propertiesRow[0].GetChildRows("properties_property"); dsFinal.Tables["itemOffer"].ImportRow(offerRow); dsFinal.Tables["item"].ImportRow(itemRow[0]); dsFinal.Tables["price"].ImportRow(priceRow[0]); dsFinal.Tables["money"].ImportRow(moneyRow[0]); //if (propertiesRow.Length > 0) // { // dsFinal.Tables["properties"].ImportRow(propertiesRow[0]); // foreach (DataRow property in propertyRow) // { // dsFinal.Tables["property"].ImportRow(property); // } // } } } return(dsFinal); }
/// <summary> /// Update the store data with a new response /// </summary> /// <param name="response">xml string store response received from the PaymentItems</param> /// <param name="key">The key is the store name to copy</param> private void CopyResponseToStoreData(XmlDocument xmlDoc, string key) { string response = xmlDoc.InnerXml; try { // MemoryStream schema = LoadSchemaFile("StoreImportSchemaFull.xsd"); ServerPaymentItemsDataSets dataSets = new ServerPaymentItemsDataSets(); DataSet dsStoreCreated = dataSets.CreateStoreDataSet("StoreDataSet", true); XmlNode itemOffersNode = xmlDoc.SelectSingleNode("/Response/store"); XmlNodeList itemOffersNodeList = xmlDoc.SelectNodes("/Response/store/itemOffers/itemOffer"); lock (lockObject) { if (mDebug) { xmlDoc.Save(String.Format(@"{0}CopyResponseToStoreXml_{1}.xml", mDebugDir, key)); } mStoreXml[key].InnerXml = xmlDoc.InnerXml; //DataSet dsStore = LoadXMLInToDataSet(itemOffersNode, schema, "StoreDataSet"); DataSet dsStore = dataSets.LoadStoreDataXMLInToDataSet(itemOffersNodeList, dsStoreCreated, true); if (mDebug) { dsStore.WriteXml(String.Format(@"{0}CopyResponseToStoreData_{1}.xml", mDebugDir, key)); } mStoreDataSet[key] = dsStore; } } catch (Exception ex) { mLogger.Error(String.Format("Error in CopyResponseToStoreData for Store {0} Error: {1}\n Response: {2}", key, ex, response)); } }
/// <summary> /// Add Items node to the user inventory itemInstance node /// </summary> /// <param name="response">The Hangout user inventory xml response</param> /// <param name="handler">The ServerStores object, containing the item inventory information</param> /// <returns>The Hangout user inventory xml response with the user inventory node added to the itemInstance nodes</returns> public static XmlDocument AddItemsToUserInventory(XmlDocument response, ServerStores serverStores) { XmlDocument inventoryResponse = new XmlDocument(); try { if (response == null) { inventoryResponse = CreateErrorDoc("Error: Cached Response for PaymentItems User Inventory Response is not available"); } else { XmlNode itemInstancesNode = response.SelectSingleNode("/"); string itemTypeNames = itemInstancesNode.SelectSingleNode("/Response/itemInstances").Attributes["itemTypeNames"].InnerText.Trim(); //<itemInstances startIndex="5" blockSize="10" total="55"> int startIndex = serverStores.ConvertToInt(itemInstancesNode.SelectSingleNode("/Response/itemInstances").Attributes["startIndex"].InnerText, -1); int blockSize = serverStores.ConvertToInt(itemInstancesNode.SelectSingleNode("/Response/itemInstances").Attributes["blockSize"].InnerText, -1); int startPosition = 0; int endPosition = itemInstancesNode.SelectNodes("Response/itemInstances/itemInstance").Count; if (UseBlockSize(startIndex, blockSize, endPosition, itemTypeNames.Length)) { startPosition = startIndex; int maxEndPosition = blockSize + startIndex; if (maxEndPosition < endPosition) { endPosition = maxEndPosition; } } ServerPaymentItemsDataSets dataSets = new ServerPaymentItemsDataSets(); DataSet dsUserInventoryCreated = dataSets.CreateUserInventoryDataSet("InstanceDataSet"); // DataSet dsInstance = serverStores.LoadXMLInToDataSet(itemInstancesNode, dsUserInventoryCreated); DataSet dsInstance = dataSets.LoadUserInventoryXMLIntoDataSet(itemInstancesNode, dsUserInventoryCreated, startPosition, endPosition); //MemoryStream schema = serverStores.LoadSchemaFile("UserInventoryImportSchema.xsd"); //DataSet dsInstance = serverStores.LoadXMLInToDataSet(itemInstancesNode, schema, "InstanceDataSet"); DataTable dtInstance = dsInstance.Tables["itemInstance"]; DataTable dtItem = dsInstance.Tables["item"]; foreach (DataRow instanceRow in dtInstance.Rows) { string itemId = instanceRow["itemId"].ToString(); DataRow itemRow = serverStores.FindItemInStore(itemId); if (itemRow != null) { string hangoutItemId = instanceRow["itemName"].ToString(); itemRow["itemInstance_Id"] = instanceRow["itemInstance_Id"]; dtItem.ImportRow(itemRow); } } StringWriter sw = new StringWriter(); dsInstance.WriteXml(sw); XmlDocument responseTemp = new XmlDocument(); responseTemp.LoadXml(UnEscapeXml(sw.ToString())); if (itemTypeNames.Length > 0) { responseTemp = FilterUserInventoryByItemTypes(responseTemp, itemTypeNames, startIndex, blockSize); } inventoryResponse.LoadXml(responseTemp.SelectSingleNode("/InstanceDataSet").InnerXml); } } catch (Exception ex) { mLogger.Error("Inventory response Error: ", ex); inventoryResponse = CreateErrorDoc(ex.ToString()); } return(inventoryResponse); }
/// <summary> /// Add the item Assets To StoreInventory Items node /// </summary> /// <param name="response">xml string store response received from the PaymentItems</param> /// <param name="storeName">The name of the store used for debugging.</param> /// <returns>The reesponse xml document with the items assets added</returns> private XmlDocument AddAssetsToStoreInventoryItems(XmlDocument response, string storeName) { XmlDocument storeResponse = new XmlDocument(); storeResponse.InnerXml = response.InnerXml; try { if (response == null) { throw new Exception("Error: Cached Response for PaymentItems User Inventory Response is not available"); } else { XmlNode itemOffersNode = response.SelectSingleNode("/Response/store"); XmlNodeList itemOffersNodeList = response.SelectNodes("/Response/store/itemOffers/itemOffer"); ServerPaymentItemsDataSets dataSets = new ServerPaymentItemsDataSets(); DataSet dsStoreCreated = dataSets.CreateStoreDataSet("StoreDataSet", false); DataSet dsStore = dataSets.LoadStoreDataXMLInToDataSet(itemOffersNodeList, dsStoreCreated, false); //MemoryStream schema = LoadSchemaFile("StoreImportSchema.xsd"); //DataSet dsStore = LoadXMLInToDataSet(itemOffersNode, schema, "StoreDataSet"); if (mDebug) { dsStore.WriteXml(String.Format(@"{0}AddAssetsToStoreInventoryItems_{1}.xml", mDebugDir, storeName)); } DataTable dtOffer = dsStore.Tables["itemOffer"]; DataTable dtItem = dsStore.Tables["item"]; DataColumn itemAssets = new DataColumn("Assets", System.Type.GetType("System.String")); itemAssets.ColumnMapping = MappingType.Element; dtItem.Columns.Add(itemAssets); foreach (DataRow offerRow in dtOffer.Rows) { DataRow[] itemRowArray = offerRow.GetChildRows("itemOffer_item"); DataRow itemRow = itemRowArray[0]; string hangoutItemId = itemRow["name"].ToString(); itemRow["Assets"] = String.Format("<![CDATA[{0}]]>", mPaymentItemsManager.GetAssetDataSetDna(hangoutItemId)); } StringWriter sw = new StringWriter(); dsStore.WriteXml(sw); XmlDocument responseTemp = new XmlDocument(); responseTemp.LoadXml(UnEscapeXml(sw.ToString())); XmlNode storeItemOffersNode = storeResponse.SelectSingleNode("/Response/store/itemOffers"); storeItemOffersNode.RemoveAll(); XmlNodeList newOfferList = responseTemp.SelectNodes("/StoreDataSet/itemOffer"); foreach (XmlNode newOffer in newOfferList) { XmlNode newChildNode = storeResponse.ImportNode(newOffer, true); storeItemOffersNode.AppendChild(newChildNode); } //storeResponse.LoadXml(responseTemp.SelectSingleNode("/StoreDataSet").InnerXml); } } catch (Exception ex) { mLogger.Error(String.Format("Error in AddAssestsToStoreInventoryItems Error: {0}\n Response: {1}", ex, response)); } return(storeResponse); }