private static ChartPanel GetChartDescriptor(IEditableRoot instance, string exprFieldName, string spcFieldName, ChartTypesEnum chartType, int subgroupSize, int dataPoints = 0)
        {
            ChartPanel chartDescriptor = null;

            MobileDictionary<string, ChartPanel> dict = null;
            if (!exprFieldName.Contains("_Rule"))
            {
                dict = instance.GetValueByPropertyName("ChartDescriptorExp") as MobileDictionary<string, ChartPanel>;
                if (dict != null)
                    dict.TryGetValue(string.Format("{0}{1}", exprFieldName, spcFieldName), out chartDescriptor);
                else
                    dict = new MobileDictionary<string, ChartPanel>();
            }

            if (chartDescriptor == null)
            {
                chartDescriptor = SpcManager.CreateChartDescriptor(chartType);
                chartDescriptor.DataPoints = dataPoints;
                chartDescriptor.SubgroupSize = subgroupSize;

                chartDescriptor = MethodCaller.CallFactoryMethod(instance.GetType(), "GetSampleDataForSPC", spcFieldName, instance, chartType, chartDescriptor, true) as ChartPanel;

                if (!exprFieldName.Contains("_Rule"))
                {
                    ChartPanel chartPanel;
                    if (dict.TryGetValue(string.Format("{0}{1}", exprFieldName, spcFieldName), out chartPanel))
                        dict[string.Format("{0}{1}", exprFieldName, spcFieldName)] = chartDescriptor;
                    else
                        dict.Add(string.Format("{0}{1}", exprFieldName, spcFieldName), chartDescriptor);

                    instance.LoadValueByPropertyName("ChartDescriptorExp", dict);
                }
            }
            else
            {
                chartDescriptor.DataPoints = dataPoints;
                chartDescriptor.SubgroupSize = subgroupSize;

                chartDescriptor = MethodCaller.CallFactoryMethod(instance.GetType(), "GetSampleDataForSPC", spcFieldName, instance, chartType, chartDescriptor, true) as ChartPanel;
            }

            return chartDescriptor;
        }        
        private static Task<ChartPanel> GetChartDescriptorAsync(IEditableRoot instance, string exprFieldName, string spcFieldName, ChartTypesEnum chartType, int subgroupSize, int dataPoints = 0)
        {
            ChartPanel chartDescriptor = null;

            var dict = instance.GetValueByPropertyName("ChartDescriptorExp") as MobileDictionary<string, ChartPanel>;
            if (dict != null)
                dict.TryGetValue(string.Format("{0}{1}", exprFieldName, spcFieldName), out chartDescriptor);
            else
                dict = new MobileDictionary<string, ChartPanel>();

            if (chartDescriptor == null)
            {
                return SpcManager.CreateChartDescriptorAsync(chartType)
                    .ContinueWith(async task =>
                    {
                        if (task.Result != null)
                        {
                            chartDescriptor = task.Result;
                            chartDescriptor.DataPoints = dataPoints;
                            chartDescriptor.SubgroupSize = subgroupSize;

                            var getDataTask = MethodCaller.CallFactoryMethod(
                                instance.GetType(), "GetSampleDataForSPCAsync", instance, spcFieldName, chartType, chartDescriptor, true) as Task<ChartPanel>;
                            chartDescriptor = await getDataTask;

                            ChartPanel chartPanel;
                            if (dict.TryGetValue(string.Format("{0}{1}", exprFieldName, spcFieldName), out chartPanel))
                                dict[string.Format("{0}{1}", exprFieldName, spcFieldName)] = chartDescriptor;
                            else
                                dict.Add(string.Format("{0}{1}", exprFieldName, spcFieldName), chartDescriptor);

                            instance.LoadValueByPropertyName("ChartDescriptorExp", dict);

                            return chartDescriptor;
                        }

                        return task.Result;
                    }
                    , CancellationToken.None, TaskContinuationOptions.NotOnFaulted, TaskScheduler.FromCurrentSynchronizationContext()).Unwrap();
            }

            chartDescriptor.DataPoints = dataPoints;
            chartDescriptor.SubgroupSize = subgroupSize;

            var getSamplesTask = MethodCaller.CallFactoryMethod(
                instance.GetType(), "GetSampleDataForSPCAsync", instance, spcFieldName, chartType, chartDescriptor, true) as Task<ChartPanel>;
            return getSamplesTask;
        }