Beispiel #1
0
        public static Item GetItem(Store objStore, ItemDescription objItemDesc)
        {
            Logger.WriteToLogFile(Utilities.GetCurrentMethod());

            Item objItem = new Item();

            var results = Neo4jController.m_graphClient.Cypher
                          .Match("(A: " + objStore.getLabel() + "{ id : { storeid }})")
                          .Match("(B: " + objItemDesc.getLabel() + "{ id : { itemdescid}})")
                          .Match("(A)-[: " + Rel_Store.store_item + "]->(C:" + objItem.getLabel() + ")")
                          .Match("(C)-[:" + Rel_Item.item_itemDescription + "]->(B)")
                          .WithParams(new
            {
                storeid    = objStore.id,
                itemdescid = objItemDesc.id
            })
                          .Return(C => C.As <Item>())
                          .Results;

            if (results.Count() == 0)
            {
                return(null);
            }
            else
            {
                return(results.First());
            }
        }
Beispiel #2
0
        public static ItemDescription GetItemDescription(Brand objBrand, String ModelNumber)
        {
            Logger.WriteToLogFile(Utilities.GetCurrentMethod());
            ItemDescription objItemDescr = new ItemDescription();

            if (String.IsNullOrEmpty(ModelNumber))
            {
                throw new Exception("Model Number is null");
            }

            var results = Neo4jController.m_graphClient.Cypher
                          .Match("(A:" + objBrand.getLabel() + "{id : { Brandid}})")
                          .Match("(A)-[R:" + Rel_Brand.brand_item + "]->(B: " + objItemDescr.getLabel() + "{ Model_Name : { modelNumber}})")
                          .WithParams(new
            {
                Brandid     = objBrand.id,
                modelNumber = ModelNumber
            })
                          .Return(B => B.As <ItemDescription>())
                          .Results;

            if (results.Count() == 0)
            {
                return(null);
            }
            else
            {
                return(results.First());
            }
        }
Beispiel #3
0
        public static void CreateItemDescriptionNode(ItemDescriptionWrapper objWrap)
        {
            Logger.WriteToLogFile(DBInteractor.Common.Utilities.GetCurrentMethod());
            Logger.WriteObjectToLogFile <ItemDescription>(objWrap.objItem);

            ItemDescription objItem  = objWrap.objItem;
            Brand           objBrand = objWrap.objBrand;


            var result = Neo4jController.m_graphClient.Cypher
                         .Match("(A:" + objBrand.getLabel() + " { id: { brandid }})")
                         .Create("(B:" + objItem.getLabel() + "{ objItem })")
                         .Merge("(A)-[:" + Rel_Brand.brand_item + "]->(B)")
                         .WithParams(new
            {
                brandid = objBrand.id,
                objItem = objItem
            })
                         .Return((B) => new
            {
                NodeCount = B.Count()
            })
                         .Results
                         .Single();

            if (result.NodeCount == 1)
            {
                Logger.WriteToLogFile("Successfully created Item");
            }
            else
            {
                Logger.WriteToLogFile("unable to create Item");
            }
        }
Beispiel #4
0
        public static void CreateItemNode(ItemWrapper objWrap)
        {
            Logger.WriteToLogFile(DBInteractor.Common.Utilities.GetCurrentMethod());
            Logger.WriteObjectToLogFile <Item>(objWrap.objItem);


            Brand           objBrand           = objWrap.objBrand;
            Item            objItem            = objWrap.objItem;
            ItemDescription objItemdescription = objWrap.objItemDescription;
            Store           objStore           = objWrap.objStore;

            Neo4jController.m_graphClient.Cypher
            .Match("(A1:" + objStore.getLabel() + "{ id : { objstoreid }})")
            .Match("(A2:" + objBrand.getLabel() + "{ id : {brandid }})")
            .Merge("(B2: " + objItemdescription.getLabel() + "{Model_Name: { modeNumber}})")
            .OnCreate()
            .Set("B2 = {objItemDesc}")
            .Merge("(A2)-[R2:" + Rel_Brand.brand_item + "]->(B2)")
            .Merge("(A1)-[:" + Rel_Store.store_item + "]->(A3 : " + objItem.getLabel() + ")-[:" + Rel_Item.item_itemDescription + "]->(B2)")
            .OnCreate()
            .Set("A3 = { objItem }")
            .WithParams(new
            {
                objstoreid  = objStore.id,
                brandid     = objBrand.id,
                objItem     = objItem,
                modeNumber  = objItemdescription.Model_Name,
                objItemDesc = objItemdescription
            })
            .ExecuteWithoutResults();


            /*
             * .Return((B2) => new
             * {
             *  NodeCount = B2.Count(),
             *  itemObj = B2.As<Item>()
             * })
             * .Results
             * .Single();
             *
             *
             *
             *
             * if (result.NodeCount == 1)
             * {
             * objItem = result.itemObj;
             * Logger.WriteToLogFile("Successfully created item");
             * }
             * else
             * Logger.WriteToLogFile("unable to create item");
             *
             *
             */
        }
Beispiel #5
0
        public static void DeleteItemDescriptionNode(ItemDescription objNode)
        {
            Logger.WriteToLogFile(DBInteractor.Common.Utilities.GetCurrentMethod());

            Neo4jController.m_graphClient.Cypher
            .Match("(C:" + objNode.getLabel() + "{ id : { Nodeid }})")
            .Match("(C)-[R]-()")
            .OptionalMatch("(D)-[:" + Rel_Item.item_itemDescription + "]->(C)")
            .Delete("C,R")
            .With("D")
            .Match("(D)-[R]-()")
            .Delete("D,R")
            .WithParams(new
            {
                Nodeid = objNode.id
            })
            .ExecuteWithoutResults();
        }
Beispiel #6
0
        public static ExcelStructure SaveToDB(ExcelStructure objExcelStruct, Store objStore, SubCategory objSubCategory, Brand objBrand, string server, string port, GridViewRowInfo row = null)
        {
            try
            {
                if (objStore == null)
                {
                    throw new Exception("Please select a store .....");
                }
                if (objSubCategory == null)
                {
                    throw new Exception("Subcateogry do not match or is empty");
                }
                if (objBrand == null)
                {
                    throw new Exception("Please add brand for this subcategory ir brand is null or not matching");
                }


                ItemDescription objItemDescr = DBGetInterface.GetItemDescription(objBrand, objExcelStruct.ModelNumber);

                if (objItemDescr == null)
                {
                    //Call flipkart scrapper

                    CFlipkartScrapper objscrapper = new CFlipkartScrapper();
                    ItemDescription   objItemdesc = ItemFactory.GetItem(objSubCategory);

                    if (String.IsNullOrEmpty(objExcelStruct.FlipKart))
                    {
                        //check if the item link is already scrapped, find in csv
                        string strFilePath = m_ResourcesFolder + "//" + m_CategoryMappingTxt;
                        if (System.IO.File.Exists(strFilePath))
                        {
                            //File exists
                            //read the file and check for that file in LinkFodler
                            try
                            {
                                using (System.IO.StreamReader sw = new System.IO.StreamReader(strFilePath))
                                {
                                    string line = String.Empty;
                                    while ((line = sw.ReadLine()) != null)
                                    {
                                        bool     bflag = false;
                                        string[] cat   = line.Split(' ');
                                        if (cat[0].Equals(objSubCategory.SubCategoryID.ToString(), StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            //search model number in that subcategory file
                                            string file = Constants.LINK_EXTRACTED_FOLDER + "//" + cat[1] + ".csv";

                                            //search in this csv file
                                            List <List <string> > lmap = Utilities.GetCSVSheet(file);
                                            foreach (List <string> product in lmap)
                                            {
                                                if (product.ElementAt(0).Equals(objExcelStruct.ModelNumber, StringComparison.InvariantCultureIgnoreCase))
                                                {
                                                    objExcelStruct.FlipKart = product.ElementAt(2);
                                                    bflag = true;
                                                    break;
                                                }
                                            }
                                        }

                                        if (bflag)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }

                    objscrapper.SetHTMLDocument(objExcelStruct.FlipKart);
                    objscrapper.ExtractData(ref objItemdesc);

                    string image = objItemdesc.image;
                    objItemdesc.image = null;

                    //Now do the following
                    //Create item, create item description.
                    Item objItem = new Item();
                    objItem.Price            = Convert.ToUInt32(objExcelStruct.Price);
                    objItem.OfferDescription = objExcelStruct.Offer;

                    ItemWrapper objWrap = new ItemWrapper();
                    objWrap.objBrand           = objBrand;
                    objWrap.objStore           = objStore;
                    objWrap.objItemDescription = objItemdesc;
                    objWrap.objItem            = objItem;
                    DBAddinterface.CreateItemNode(objWrap);

                    //Copy image
                    //Create a seperate thread for it as image copying is a tedious process
                    //Copy image to local machine and then copy it to tomcat machine
                    //build path
                    string imageDir = Utilities.GetImageDir(objItemdesc.getLabel());
                    Utilities.CreateFolder(imageDir);
                    string imagePath = Utilities.GetImagePath(imageDir, objItemdesc.id);
                    ImageController.GetImageFromUrlAndSave(image, imagePath);


                    //Create a seperate thread for this to do
                    Thread SaveImageThread = new Thread(() => SaveImageToRemoteMachineThread(imageDir, Utilities.AppendImageType(objItemdesc.id), server, port));
                    SaveImageThread.Start();


                    objExcelStruct.Completed = Constants.COMPLETED_DONE;
                    objExcelStruct.Comment   = String.Empty;
                }
                else
                {
                    objExcelStruct.Comment = Constants.ALREADY_IN_DB;
                    //Just update the price and offer of the item
                    Item objItem = DBGetInterface.GetItem(objStore, objItemDescr);
                    if (objItem == null)
                    {
                        //Add this node
                        objItem                  = new Item();
                        objItem.Price            = Convert.ToUInt32(objExcelStruct.Price);
                        objItem.OfferDescription = objExcelStruct.Offer;

                        ItemWrapper objWrap = new ItemWrapper();
                        objWrap.objBrand           = objBrand;
                        objWrap.objStore           = objStore;
                        objWrap.objItemDescription = objItemDescr;
                        objWrap.objItem            = objItem;
                        DBAddinterface.CreateItemNode(objWrap);

                        objExcelStruct.Completed = Constants.COMPLETED_ADDED;
                    }
                    else
                    {
                        //Check for any updates
                        bool bUpdate = false;
                        if (objItem.Price != Convert.ToUInt32(objExcelStruct.Price))
                        {
                            objItem.Price = Convert.ToUInt32(objExcelStruct.Price);
                            bUpdate       = true;
                        }

                        string offer = String.Empty;
                        if (objExcelStruct.Offer != null)
                        {
                            offer = objExcelStruct.Offer;
                        }

                        if (!objItem.OfferDescription.Equals(offer, StringComparison.InvariantCultureIgnoreCase))
                        {
                            objItem.OfferDescription = objExcelStruct.Offer;
                            bUpdate = true;
                        }

                        if (bUpdate)
                        {
                            objItem.lastUpdated = Utilities.GetDateTimeInUnixTimeStamp();
                            DBUpdateInterface.UpdateNode <Item>(objItem);
                            objExcelStruct.Completed = Constants.COMPLETED_UPDATED;
                        }
                        else
                        {
                            objExcelStruct.Completed = Constants.COMPLETED_NOUPDATES;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                objExcelStruct.Completed = Constants.COMPLETED_ERROR;
                objExcelStruct.Comment   = ex.Message;
            }

            if (row != null)
            {
                row.Cells["Completed"].Value = objExcelStruct.Completed;
                row.Cells["Comment"].Value   = objExcelStruct.Comment;
            }

            return(objExcelStruct);
        }