Example #1
0
        private void ParseProduct(XmlReader reader)
        {
            /*
             * There are 2380 products in the Fusepump feed and only 861 in our catalogue table
             * I need to introduce a flag that will restrict the updating of products to only those in the catalogue
             * At present all products in the Fusepump feed will be created
             */
            string strProductSKU = "";
            string strCareInstructions = "abc";
            try
            {
                //reader.ReadToDescendant("careInstructions");
                string strProduct = reader.ToString();
                reader.ReadToFollowing("productsku");
                strProductSKU = reader.ReadElementContentAsString();
                reader.ReadToFollowing("product_info");
                strCareInstructions = reader.ReadElementContentAsString();
                recordsRead++;

            /*                reader.ReadToNextSibling("sku");
                var sku = reader.ReadString(); // asin
                int intProductID = -1;
                intProductID = fetchProductID(sku);*/

            /*                // Create a new Product if not present
                string strSQL = "";
                if (intProductID == -1)
                {
                    // Need to create and amend as the parseOptions() routine needs to update an existing product
                    SqlConnection con3DB = new SqlConnection(MS.DHC.Configuration.Database.WorkerConnection);
                    con3DB.Open();
                    SqlCommand sqlComm3 = new SqlCommand();
                    sqlComm3 = con3DB.CreateCommand();
                    strSQL = "insert into product (ASIN) values ("
                                + "'" + sku + "')";
                    productsCreated++;
                    sqlComm3.CommandText = strSQL;

                    try
                    {
                        sqlComm3.ExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                        throw new Exception("oops!");
                    }
                    con3DB.Close();
                    intProductID = fetchProductID(sku);
                }*/

                // TODO <delivery_services> entity present with data = true
                // Now in MS Web service
                reader.ReadToDescendant("delivery_services");
            //                reader.ReadToNextSibling("dlv");
            //                string strDeliveryAvailable = reader.ReadString();

                // TODO Promotions entity. Now in MS Web service
            //                reader.ReadToNextSibling("promotion");
            //                var promotion = reader.ReadString();

                this.ParseSKUs(reader, strProductSKU);

                reader.ReadToNextSibling("storeCollection");
                string strStoreCollection = reader.ReadElementContentAsString();

                reader.ReadToNextSibling("safetyInformation");
                string strSafetyInformation = reader.ReadElementContentAsString();

                reader.ReadToNextSibling("returns");
                string strReturns = reader.ReadElementContentAsString();

                reader.ReadToNextSibling("returnsPolicy");
                string strReturnsPolicy = reader.ReadElementContentAsString();

                // Update the Product information
            /*                SqlConnection con2DB = new SqlConnection(MS.DHC.Configuration.Database.WorkerConnection);
                con2DB.Open();
                SqlCommand sqlComm = new SqlCommand();
                sqlComm = con2DB.CreateCommand();
                strSQL = "UPDATE product SET " +
                                        "CareInstructions = '" + careInstructions + "'"
                                        + ", TCode = '" + productCode + "'"
                                        + ", deliveryAvailable = '" + deliveryAvailable + "'"
                                        + ", promotion = '" + promotion + "'"
                                        + ", storeCollection = '" + storeCollection + "'"
                                        + ", safetyInformation = '" + safetyInformation + "'"
                                        + ", returns = '" + returns + "'"
                                        + ", returnsPolicy = '" + returnsPolicy + "'";*/

                /*            if (strCareInstruction != null)
                            {
                                strSQL = strSQL + ", CareInstructions = '" + strCareInstruction + "'";
                            }*/

            /*                strSQL = strSQL + " where ID = '" + intProductID + "'";
                productsAmended++;

                sqlComm.CommandText = strSQL;

                try
                {
                    sqlComm.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    throw new Exception("oops!");
                }
                con2DB.Close();*/
            }
            catch (Exception ex)
            {
                throw new Exception("help");
            }
        }
Example #2
0
        public virtual IGraphable ParseObject(XmlReader r, Type useType, Type interactionContext, XmlIts1FormatterParseResult resultContext)
        {
            ThrowIfDisposed();


            // Find a helper
            string typeName = GetStructureName(useType);

            IXmlStructureFormatter ixsf = null;
            
            // xsi type? - We want to adjust the type based on this value
            try
            {
                string xsiType = r.GetAttribute("type", NS_XSI);
                // Is this model / type registered somewhere ?
                if ((this.Settings & SettingsType.AlwaysCheckForOverrides) != 0 && xsiType == null &&
                    !typeof(ANY).IsAssignableFrom(useType))
                    xsiType = this.CreateXSITypeName(useType, interactionContext, r as IXmlNamespaceResolver);

                if (xsiType != null)
                {
                    if (useType.IsInterface || typeof(ANY).IsAssignableFrom(useType)) // HACK: We don't override the use type for ANY derivatives as some types are special and require special typing
                        ixsf = this.GetAdjustedFormatter(xsiType); //Util.ParseXSITypeName(r.GetAttribute("type", NS_XSI));
                    else
                        useType = this.ParseXSITypeName(xsiType, r as IXmlNamespaceResolver);
                }
                else
                    ixsf = (IXmlStructureFormatter)this.GraphAides.Find(t => t.HandleStructure.Contains(typeName));
            }
            catch (Exception e)
            {
                resultContext.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, r.ToString(), e));
            }

            string currentPath = r is XmlStateReader ? (r as XmlStateReader).CurrentPath : r.Name;
            // Does a helper have it?
            if (ixsf != null)
            {
                ixsf.Host = this;
                var aideResult = ixsf.Parse(r, useType);
                resultContext.AddResultDetail(aideResult.Details);
                return aideResult.Structure;
            }

#if WINDOWS_PHONE
            ITypeFormatter formatter = m_codeGeneratorFormatter.GetFormatter(useType);
            if (formatter == null)
                formatter = new ReflectFormatter();
#else
            ITypeFormatter formatter = m_codeGeneratorFormatter.GetFormatter(useType);
            // Is there a formatter and if there is not a formatter 
            // can we create one?
            if (formatter == null && (Settings & SettingsType.UseGeneratorFormat) == SettingsType.UseGeneratorFormat)
                s_threadPool.QueueUserWorkItem((WaitCallback)delegate(object state)
                {
                    BuildCache(new Type[] { (Type)state });
                }, useType);
            // If there is no connector can we use reflection?
            if (formatter == null && (Settings & SettingsType.UseReflectionFormat) == SettingsType.UseReflectionFormat)
                formatter = new ReflectFormatter();
            else if (formatter == null && (Settings & SettingsType.UseGeneratorFormat) == SettingsType.UseGeneratorFormat)
            {
                s_threadPool.WaitOne();
                formatter = m_codeGeneratorFormatter.GetFormatter(useType);
            }
#endif
            if (formatter == null)
                throw new InvalidOperationException(string.Format("Couldn't format '{0}' at {1}, verify formatter settings", useType.FullName, r.ToString()));

            // Parse using the formatter
            formatter.Host = this;

            // Parse the object
            IGraphable result = (IGraphable)formatter.Parse(r, useType, interactionContext, resultContext);

            IResultDetail[] details = null;
            if (details != null && result == null || ValidateConformance && (!formatter.Validate(result, currentPath, out details)))
                resultContext.AddResultDetail(details.Length > 0 ? details : new IResultDetail[] { new ResultDetail(ValidateConformance ? ResultDetailType.Error : ResultDetailType.Warning, String.Format("Couldn't parse type '{0}'", useType.ToString()), currentPath) });

            
            return result;
        }