예제 #1
0
        private string createM3SortingOrder(SortingOrderDefinition aSortingOrderDef)
        {
            string result = null;

            if (null != aSortingOrderDef && null != apiService)
            {
                string addResult = apiService.CRS021MI_AddSrtOpt(aSortingOrderDef.TableName, aSortingOrderDef.SortingOrder, aSortingOrderDef.Fields.ToArray());
                if (false == string.IsNullOrEmpty(addResult))
                {
                    try
                    {
                        miresults res = JsonConvert.DeserializeObject <miresults>(addResult);
                        if (null != res && null != res.results && res.results.Count > 0)
                        {
                            if (!string.IsNullOrEmpty(res.results[0].errorCode) && !string.IsNullOrEmpty(res.results[0].errorMessage))
                            {
                                result = res.results[0].errorCode + " " + res.results[0].errorMessage;
                            }
                            else
                            {
                                result = " created, must be manually activated";
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        result = ex.Message;
                    }
                }
            }

            return(result);
        }
예제 #2
0
        private void checkM3SortingOrders(SortingOrderDefinition aSortingOrderDef, bool aCreate = false)
        {
            try
            {
                if (null != apiService)
                {
                    Console.Write("Check: " + aSortingOrderDef.TableName + aSortingOrderDef.SortingOrder + " ... ");
                    string result = apiService.CRS021MI_GetSrtOpt(aSortingOrderDef.TableName, aSortingOrderDef.SortingOrder);

                    miresults res = JsonConvert.DeserializeObject <miresults>(result);

                    if (null != res && null != res.results && res.results.Count > 0 && null != res.results[0].records && res.results[0].records.Length > 0)
                    {
                        SortingOrderDefinition m3SortingOrderInfo = new SortingOrderDefinition(res.results[0], aSortingOrderDef.TableName, aSortingOrderDef.SortingOrder);

                        string[] m3Values     = m3SortingOrderInfo.Fields.ToArray();
                        string[] configValues = aSortingOrderDef.Fields.ToArray();

                        var variances = m3Values.Union(configValues).Except(m3Values.Intersect(configValues));   //m3Values.Except(configValues);

                        if (null != variances && Enumerable.Count(variances) > 0)
                        {
                            Console.WriteLine("has variations");
                            foreach (string key in variances)
                            {
                                Console.WriteLine("  " + key);
                            }
                        }
                        else
                        {
                            Console.WriteLine("matches");
                        }
                    }
                    else
                    {
                        if (null != res && null != res.results && res.results.Count > 0)
                        {
                            if (res.results[0].errorCode == "WOI0203")
                            {
                                Console.WriteLine("doesn't exist");
                                // sorting order doesn't exist, perhaps we should create it
                                if (aCreate)
                                {
                                    Console.WriteLine(createM3SortingOrder(aSortingOrderDef));
                                }
                                else
                                {
                                    Console.Write("");
                                }
                            }
                            else
                            {
                                Console.WriteLine(res.results[0].errorMessage);
                            }
                        }
                        else
                        {
                            string additionalMessage = "";
                            if (aCreate)
                            {
                                additionalMessage = ", not creating";
                            }
                            Console.WriteLine(" no result from M3" + additionalMessage);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
        }