Пример #1
0
        /// <summary>
        /// Create the instance of specific product
        /// using reflection
        /// </summary>
        /// <param name="restAPIType"></param>
        /// <returns></returns>
        public IRestAPIType GetRestAPIClassType(RestAPIType restAPIType)
        {
            IRestAPIType restAPI = null;

            if (m_RestAPIClassMapping.ContainsKey(restAPIType))
            {
                Type apiType = (Type)m_RestAPIClassMapping[restAPIType];

                restAPI = Activator.CreateInstance(apiType) as IRestAPIType;
            }

            return(restAPI);
        }
Пример #2
0
        public static void CallFunctions(IRestAPIType singletonAPIObject, RestAPIActions siteRecords, ActionType action, RestAPIType type)
        {
            //RestAPIObject recordToProcess = null;
            //List<RestAPIObject> recordList = new List<RestAPIObject>();

            List <IRestAPIType> recordList = new List <IRestAPIType>();

            RestAPIClassFactory classFactory = new RestAPIClassFactory();



            #region Commented Code

            /*
             *          if (siteRecords.Type == GetRestAPIType(RestAPIType.Customer) )
             *          {
             *              recordToProcess = (Customer)singletonAPIObject;
             *          }
             *
             *          if (siteRecords.Type == GetRestAPIType(RestAPIType.CustomerGroup) )
             *          {
             *              recordToProcess = (CustomerGroup)singletonAPIObject;
             *          }
             *
             *
             *          if (siteRecords.Type == GetRestAPIType(RestAPIType.Order) )
             *          {
             *              recordToProcess = (Order)singletonAPIObject;
             *          }
             *
             *          if (siteRecords.Type == GetRestAPIType(RestAPIType.Product) )
             *          {
             *              recordToProcess = (Product)singletonAPIObject;
             *          }
             *
             *          if (siteRecords.Type == GetRestAPIType(RestAPIType.Manufacturer) )
             *          {
             *              recordToProcess = (Manufacturer)singletonAPIObject;
             *          }
             *
             *          if (siteRecords.Type == GetRestAPIType(RestAPIType.Distributor) )
             *          {
             *              recordToProcess = (Distributor)singletonAPIObject;
             *          }
             *
             *          if (siteRecords.Type ==  GetRestAPIType(RestAPIType.Category) )
             *          {
             *              recordToProcess = (Category)singletonAPIObject;
             *          }
             */

            #endregion

            string sIDPrefix = siteRecords.Type.Substring(0, siteRecords.Type.Length - 1) + "ID: ";


            if (action == ActionType.Get)
            {
                //GET
                RecordInfo recInf = siteRecords.GetRecords();


                if (recInf.Status == ActionStatus.Succeeded)
                {
                    Console.WriteLine("Record(s) retrieved successfully.");
                    try
                    {
                        List <Object> reclist = (List <Object>)recInf.ResultSet;

                        IRestAPIType restAPIRecord = classFactory.GetRestAPIClassType(type);


                        foreach (Object record in reclist)
                        {
                            string receiveStream = record.ToString();

                            //Use the type received from function

                            restAPIRecord = (IRestAPIType)JsonConvert.DeserializeObject(receiveStream, restAPIRecord.GetType());

                            #region Commented Code

                            /*
                             * if (siteRecords.Type == GetRestAPIType(RestAPIType.Customer) )
                             * {
                             *  restAPIRecord = (Customer)JsonConvert.DeserializeObject(receiveStream, restAPIRecord.GetType());
                             *  //restAPIRecord = (IRestAPIType) JsonConvert.DeserializeObject(receiveStream, restAPIRecord.GetType());
                             *
                             * }
                             * else if (siteRecords.Type == GetRestAPIType(RestAPIType.CustomerGroup) )
                             * {
                             *  restAPIRecord = (CustomerGroup)JsonConvert.DeserializeObject(receiveStream, restAPIRecord.GetType());
                             *
                             * }
                             *
                             * else if (siteRecords.Type == GetRestAPIType(RestAPIType.Product) )
                             * {
                             *  restAPIRecord = (Product)JsonConvert.DeserializeObject(receiveStream, typeof(Product));
                             * }
                             * else if (siteRecords.Type == GetRestAPIType(RestAPIType.Order))
                             * {
                             *  restAPIRecord = (Order)JsonConvert.DeserializeObject(receiveStream, typeof(Order));
                             * }
                             * else if (siteRecords.Type == GetRestAPIType(RestAPIType.Manufacturer) )
                             * {
                             *  restAPIRecord = (Manufacturer)JsonConvert.DeserializeObject(receiveStream, typeof(Manufacturer));
                             * }
                             * else if (siteRecords.Type == GetRestAPIType(RestAPIType.Distributor) )
                             * {
                             *  restAPIRecord = (Distributor)JsonConvert.DeserializeObject(receiveStream, typeof(Distributor));
                             * }
                             * else if (siteRecords.Type == GetRestAPIType(RestAPIType.Category) )
                             * {
                             *  restAPIRecord = (Category)JsonConvert.DeserializeObject(receiveStream, typeof(Category));
                             * }
                             */
                            #endregion

                            recordList.Add(restAPIRecord);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                else
                {
                    Console.WriteLine("Record(s) retrieval failed. Error description: " + recInf.Description);
                }
            }


            //IRestAPIType recordToProcess = classFactory.GetRestAPIClassType(type);


            if (action == ActionType.Add)
            {
                //POST
                //RecordInfo addInfo = siteRecords.AddRecord(recordToProcess);
                RecordInfo addInfo = siteRecords.AddRecord(singletonAPIObject);


                if (addInfo.Status == ActionStatus.Succeeded)
                {
                    Console.WriteLine("Record Added. " + sIDPrefix + addInfo.ResultSet);
                    Console.ReadKey();
                }

                else
                {
                    Console.WriteLine("Add failed.  Error Code: " + addInfo.CodeNumber + ", Description: " + addInfo.Description);
                    Console.ReadKey();
                }
            }


            if (action == ActionType.Update)
            {
                //PUT
                //RecordInfo updateInfo = siteRecords.UpdateRecord(recordToProcess);
                RecordInfo updateInfo = siteRecords.UpdateRecord(singletonAPIObject);


                if (updateInfo.Status == ActionStatus.Succeeded)
                {
                    Console.WriteLine("Record Updated. " + sIDPrefix + siteRecords.ID);
                    Console.ReadKey();
                }

                else
                {
                    Console.WriteLine("Update failed for " + sIDPrefix + siteRecords.ID + ". Error Code: " + updateInfo.CodeNumber + ", Description: " + updateInfo.Description);
                    Console.ReadKey();
                }
            }

            if (action == ActionType.Delete)
            {
                //DELETE
                RecordInfo deleteInfo = siteRecords.DeleteRecord();

                if (deleteInfo.Status == ActionStatus.Succeeded)
                {
                    Console.WriteLine("Record Deleted. " + sIDPrefix + "ID: " + siteRecords.ID);
                    Console.ReadKey();
                }

                else
                {
                    Console.WriteLine("Delete failed for " + sIDPrefix + siteRecords.ID + ". Error Code: " + deleteInfo.CodeNumber + ", Description: " + deleteInfo.Description);
                    Console.ReadKey();
                }
            }
        }
Пример #3
0
        public static void CallFunctions(IRestAPIType singletonAPIObject, RestAPIActions siteRecords, ActionType action, RestAPIType type )
        {
            //RestAPIObject recordToProcess = null;
            //List<RestAPIObject> recordList = new List<RestAPIObject>();
            
            List<IRestAPIType> recordList = new List<IRestAPIType>();

            RestAPIClassFactory classFactory = new RestAPIClassFactory();

            

            #region Commented Code

            /*            
                        if (siteRecords.Type == GetRestAPIType(RestAPIType.Customer) )
                        {
                            recordToProcess = (Customer)singletonAPIObject;
                        }

                        if (siteRecords.Type == GetRestAPIType(RestAPIType.CustomerGroup) )
                        {
                            recordToProcess = (CustomerGroup)singletonAPIObject;
                        }


                        if (siteRecords.Type == GetRestAPIType(RestAPIType.Order) )
                        {
                            recordToProcess = (Order)singletonAPIObject;
                        }

                        if (siteRecords.Type == GetRestAPIType(RestAPIType.Product) )
                        {
                            recordToProcess = (Product)singletonAPIObject;
                        }

                        if (siteRecords.Type == GetRestAPIType(RestAPIType.Manufacturer) )
                        {
                            recordToProcess = (Manufacturer)singletonAPIObject;
                        }

                        if (siteRecords.Type == GetRestAPIType(RestAPIType.Distributor) )
                        {
                            recordToProcess = (Distributor)singletonAPIObject;
                        }

                        if (siteRecords.Type ==  GetRestAPIType(RestAPIType.Category) )
                        {
                            recordToProcess = (Category)singletonAPIObject;
                        }
            */

            #endregion

            string sIDPrefix = siteRecords.Type.Substring(0, siteRecords.Type.Length - 1) + "ID: ";


            if (action == ActionType.Get)
            {
                //GET
                RecordInfo recInf = siteRecords.GetRecords();


                if (recInf.Status == ActionStatus.Succeeded)
                {
                    Console.WriteLine("Record(s) retrieved successfully.");
                    try
                    {
                        List<Object> reclist = (List<Object>)recInf.ResultSet;

                        IRestAPIType restAPIRecord = classFactory.GetRestAPIClassType(type);


                        foreach(Object record in reclist)
                        {
                            string receiveStream = record.ToString();
                            
                            //Use the type received from function

                            restAPIRecord = (IRestAPIType)JsonConvert.DeserializeObject(receiveStream, restAPIRecord.GetType());

                            #region Commented Code
                            /*
                            if (siteRecords.Type == GetRestAPIType(RestAPIType.Customer) )
                            {
                                restAPIRecord = (Customer)JsonConvert.DeserializeObject(receiveStream, restAPIRecord.GetType());
                                //restAPIRecord = (IRestAPIType) JsonConvert.DeserializeObject(receiveStream, restAPIRecord.GetType());

                            }
                            else if (siteRecords.Type == GetRestAPIType(RestAPIType.CustomerGroup) )
                            {
                                restAPIRecord = (CustomerGroup)JsonConvert.DeserializeObject(receiveStream, restAPIRecord.GetType());
                                
                            }

                            else if (siteRecords.Type == GetRestAPIType(RestAPIType.Product) )
                            {
                                restAPIRecord = (Product)JsonConvert.DeserializeObject(receiveStream, typeof(Product));
                            }
                            else if (siteRecords.Type == GetRestAPIType(RestAPIType.Order))
                            {
                                restAPIRecord = (Order)JsonConvert.DeserializeObject(receiveStream, typeof(Order));
                            }
                            else if (siteRecords.Type == GetRestAPIType(RestAPIType.Manufacturer) )
                            {
                                restAPIRecord = (Manufacturer)JsonConvert.DeserializeObject(receiveStream, typeof(Manufacturer));
                            }
                            else if (siteRecords.Type == GetRestAPIType(RestAPIType.Distributor) )
                            {
                                restAPIRecord = (Distributor)JsonConvert.DeserializeObject(receiveStream, typeof(Distributor));
                            }
                            else if (siteRecords.Type == GetRestAPIType(RestAPIType.Category) )
                            {
                                restAPIRecord = (Category)JsonConvert.DeserializeObject(receiveStream, typeof(Category));
                            }
                            */
                            #endregion

                            recordList.Add(restAPIRecord);
                        }

                        
                    }
                    catch (Exception ex)
                    { 

                    }

                }
                else
                {
                    Console.WriteLine("Record(s) retrieval failed. Error description: " + recInf.Description);
                }

            }


            //IRestAPIType recordToProcess = classFactory.GetRestAPIClassType(type);
            

            if (action == ActionType.Add)
            {

                //POST
                //RecordInfo addInfo = siteRecords.AddRecord(recordToProcess);
                RecordInfo addInfo = siteRecords.AddRecord(singletonAPIObject);


                if (addInfo.Status == ActionStatus.Succeeded)
                {
                    Console.WriteLine("Record Added. " + sIDPrefix + addInfo.ResultSet);
                    Console.ReadKey();
                }

                else
                {
                    Console.WriteLine("Add failed.  Error Code: " + addInfo.CodeNumber + ", Description: " + addInfo.Description);
                    Console.ReadKey();
                }

            }


            if (action == ActionType.Update)
            {

                //PUT
                //RecordInfo updateInfo = siteRecords.UpdateRecord(recordToProcess);
                RecordInfo updateInfo = siteRecords.UpdateRecord(singletonAPIObject);
                

                if (updateInfo.Status == ActionStatus.Succeeded)
                {
                    Console.WriteLine("Record Updated. " + sIDPrefix + siteRecords.ID);
                    Console.ReadKey();
                }

                else
                {
                    Console.WriteLine("Update failed for " + sIDPrefix + siteRecords.ID + ". Error Code: " + updateInfo.CodeNumber + ", Description: " + updateInfo.Description);
                    Console.ReadKey();
                }

            }

            if (action == ActionType.Delete)
            {
                //DELETE
                RecordInfo deleteInfo = siteRecords.DeleteRecord();

                if (deleteInfo.Status == ActionStatus.Succeeded)
                {
                    Console.WriteLine("Record Deleted. " + sIDPrefix + "ID: " + siteRecords.ID);
                    Console.ReadKey();
                }

                else
                {
                    Console.WriteLine("Delete failed for " + sIDPrefix + siteRecords.ID + ". Error Code: " + deleteInfo.CodeNumber + ", Description: " + deleteInfo.Description);
                    Console.ReadKey();
                }

            }


        }
Пример #4
0
        public static void CallFunctions(IRestAPIType singletonAPIObject, RestAPIActions siteRecords, ActionType action, RestAPIType type)
        {
            //RestAPIObject recordToProcess = null;
            //List<RestAPIObject> recordList = new List<RestAPIObject>();

            List <IRestAPIType> recordList = new List <IRestAPIType>();

            RestAPIClassFactory classFactory = new RestAPIClassFactory();



            #region Commented Code

            /*
             *          if (siteRecords.Type == GetRestAPIType(RestAPIType.Customer) )
             *          {
             *              recordToProcess = (Customer)singletonAPIObject;
             *          }
             *
             *          if (siteRecords.Type == GetRestAPIType(RestAPIType.CustomerGroup) )
             *          {
             *              recordToProcess = (CustomerGroup)singletonAPIObject;
             *          }
             *
             *
             *          if (siteRecords.Type == GetRestAPIType(RestAPIType.Order) )
             *          {
             *              recordToProcess = (Order)singletonAPIObject;
             *          }
             *
             *          if (siteRecords.Type == GetRestAPIType(RestAPIType.Product) )
             *          {
             *              recordToProcess = (Product)singletonAPIObject;
             *          }
             *
             *          if (siteRecords.Type == GetRestAPIType(RestAPIType.Manufacturer) )
             *          {
             *              recordToProcess = (Manufacturer)singletonAPIObject;
             *          }
             *
             *          if (siteRecords.Type == GetRestAPIType(RestAPIType.Distributor) )
             *          {
             *              recordToProcess = (Distributor)singletonAPIObject;
             *          }
             *
             *          if (siteRecords.Type ==  GetRestAPIType(RestAPIType.Category) )
             *          {
             *              recordToProcess = (Category)singletonAPIObject;
             *          }
             */

            #endregion

            string sIDPrefix = siteRecords.Type.Substring(0, siteRecords.Type.Length - 1) + "ID: ";


            if (action == ActionType.Get)
            {
                //GET
                RecordInfo recInf = siteRecords.GetRecords();


                if (recInf.Status == ActionStatus.Succeeded)
                {
                    Console.WriteLine("Record(s) retrieved successfully.");
                    try
                    {
                        List <Object> reclist = (List <Object>)recInf.ResultSet;

                        IRestAPIType restAPIRecord = classFactory.GetRestAPIClassType(type);

                        StringBuilder sb       = new StringBuilder();
                        var           date     = DateTime.Now.ToString("yyMMdd");
                        var           dateLong = DateTime.Now.ToString("yyyyMMdd");
                        var           time     = DateTime.Now.ToString("hhmm");
                        var           id       = "3142993930";
                        sb.AppendLine($"ISA*00*          *00*          *ZZ*{id}     *12*8003282935     *{date}*{time}*^*00403*000006383*0*P*>~");
                        sb.AppendLine($"GS*PO*{id}*8003282935*{dateLong}*{time}*6399*X*004030~");
                        int anotherCount = 1;
                        foreach (Object record in reclist)
                        {
                            string receiveStream = record.ToString();

                            //Use the type received from function

                            var order = (Order)JsonConvert.DeserializeObject(receiveStream, typeof(Order));
                            sb.AppendLine($"ST*850*000{anotherCount}~");
                            sb.AppendLine($"BEG*00*DS*{order.InvoiceNumber}**{dateLong}~");

                            var shipping = "CG";
                            if (order.ShipmentList[0].ShipmentMethodName.Contains("2nd"))
                            {
                                shipping = "SE";
                            }
                            else if (order.ShipmentList[0].ShipmentMethodName.Contains("Next"))
                            {
                                shipping = "ND";
                            }
                            sb.AppendLine($"TD5************{shipping}~");
                            var name = order.ShipmentList[0].ShipmentFirstName + " " + order.ShipmentList[0].ShipmentLastName;
                            sb.AppendLine($"N1*ST*{name}~");

                            var address = order.ShipmentList[0].ShipmentAddress;

                            if (!string.IsNullOrEmpty(order.ShipmentList[0].ShipmentAddress2))
                            {
                                address += "*" + order.ShipmentList[0].ShipmentAddress2;
                            }
                            sb.AppendLine($"N3*{address}~");
                            var city  = order.ShipmentList[0].ShipmentCity;
                            var state = order.ShipmentList[0].ShipmentState;
                            var zip   = order.ShipmentList[0].ShipmentZipCode;

                            sb.AppendLine($"N4*{city}*{state}*{zip}~");
                            int count = 1;
                            foreach (var item in order.OrderItemList)
                            {
                                sb.AppendLine($"PO1*{count}*{item.ItemQuantity}*EA*{item.ItemUnitCost}**VN*{item.ItemID}~");
                                sb.AppendLine($"PID*F****{item.ItemDescription}~");
                                count++;
                            }
                            sb.AppendLine($"CTT*{order.OrderItemList.Count}~");
                            int totalElements = 7 + order.OrderItemList.Count;
                            sb.AppendLine($"SE*{totalElements}*000{anotherCount}*~");

                            #region Commented Code

                            /*
                             * if (siteRecords.Type == GetRestAPIType(RestAPIType.Customer) )
                             * {
                             *  restAPIRecord = (Customer)JsonConvert.DeserializeObject(receiveStream, restAPIRecord.GetType());
                             *  //restAPIRecord = (IRestAPIType) JsonConvert.DeserializeObject(receiveStream, restAPIRecord.GetType());
                             *
                             * }
                             * else if (siteRecords.Type == GetRestAPIType(RestAPIType.CustomerGroup) )
                             * {
                             *  restAPIRecord = (CustomerGroup)JsonConvert.DeserializeObject(receiveStream, restAPIRecord.GetType());
                             *
                             * }
                             *
                             * else if (siteRecords.Type == GetRestAPIType(RestAPIType.Product) )
                             * {
                             *  restAPIRecord = (Product)JsonConvert.DeserializeObject(receiveStream, typeof(Product));
                             * }
                             * else if (siteRecords.Type == GetRestAPIType(RestAPIType.Order))
                             * {
                             *  restAPIRecord = (Order)JsonConvert.DeserializeObject(receiveStream, typeof(Order));
                             * }
                             * else if (siteRecords.Type == GetRestAPIType(RestAPIType.Manufacturer) )
                             * {
                             *  restAPIRecord = (Manufacturer)JsonConvert.DeserializeObject(receiveStream, typeof(Manufacturer));
                             * }
                             * else if (siteRecords.Type == GetRestAPIType(RestAPIType.Distributor) )
                             * {
                             *  restAPIRecord = (Distributor)JsonConvert.DeserializeObject(receiveStream, typeof(Distributor));
                             * }
                             * else if (siteRecords.Type == GetRestAPIType(RestAPIType.Category) )
                             * {
                             *  restAPIRecord = (Category)JsonConvert.DeserializeObject(receiveStream, typeof(Category));
                             * }
                             */
                            #endregion

                            //recordList.Add(restAPIRecord);
                            anotherCount++;
                        }
                        sb.AppendLine($"GE*{reclist.Count}*6383~");
                        sb.AppendLine($"IEA*1*000006383~");
                        var result = sb.ToString();
                    }
                    catch (Exception ex)
                    {
                    }
                }
                else
                {
                    Console.WriteLine("Record(s) retrieval failed. Error description: " + recInf.Description);
                }
            }


            //IRestAPIType recordToProcess = classFactory.GetRestAPIClassType(type);


            if (action == ActionType.Add)
            {
                //POST
                //RecordInfo addInfo = siteRecords.AddRecord(recordToProcess);
                RecordInfo addInfo = siteRecords.AddRecord(singletonAPIObject);


                if (addInfo.Status == ActionStatus.Succeeded)
                {
                    Console.WriteLine("Record Added. " + sIDPrefix + addInfo.ResultSet);
                    Console.ReadKey();
                }

                else
                {
                    Console.WriteLine("Add failed.  Error Code: " + addInfo.CodeNumber + ", Description: " + addInfo.Description);
                    Console.ReadKey();
                }
            }


            if (action == ActionType.Update)
            {
                //PUT
                //RecordInfo updateInfo = siteRecords.UpdateRecord(recordToProcess);
                RecordInfo updateInfo = siteRecords.UpdateRecord(singletonAPIObject);


                if (updateInfo.Status == ActionStatus.Succeeded)
                {
                    Console.WriteLine("Record Updated. " + sIDPrefix + siteRecords.ID);
                    Console.ReadKey();
                }

                else
                {
                    Console.WriteLine("Update failed for " + sIDPrefix + siteRecords.ID + ". Error Code: " + updateInfo.CodeNumber + ", Description: " + updateInfo.Description);
                    Console.ReadKey();
                }
            }

            if (action == ActionType.Delete)
            {
                //DELETE
                RecordInfo deleteInfo = siteRecords.DeleteRecord();

                if (deleteInfo.Status == ActionStatus.Succeeded)
                {
                    Console.WriteLine("Record Deleted. " + sIDPrefix + "ID: " + siteRecords.ID);
                    Console.ReadKey();
                }

                else
                {
                    Console.WriteLine("Delete failed for " + sIDPrefix + siteRecords.ID + ". Error Code: " + deleteInfo.CodeNumber + ", Description: " + deleteInfo.Description);
                    Console.ReadKey();
                }
            }
        }