Пример #1
0
        public string AccessResource(Func <string, object[], ISample> arrayAccessFunc, Func <string, Dictionary <string, object>, ISample> dictAccessFunc)
        {
            var path = MySession.CurrentPath;

            if (Path.Count == 1)
            {
                path = Path.Single();
            }

            if (!(new Uri(path, UriKind.RelativeOrAbsolute)).IsAbsoluteUri) //if not a absolute uri than it's a local path try to make a full path, it can be a relative path
            {
                path = GetAbsolutPahtAndQuery(path);
            }
            var realInputs = new object[] { };
            Dictionary <string, object> realInputDict = null;

            if (InputParams.Count() != 0)
            {
                realInputs = makeInputs(InputParams, IsJson);
            }
            if (!(string.IsNullOrEmpty(InputDict))) //we have dictinary input
            {
                realInputDict = JsonConvert.DeserializeObject <Dictionary <string, object> >(InputDict);
            }
            ISample result = null;

            if (realInputDict != null)
            {
                //result = MyHub.TryGetResourceSampleWithUri(path, realInputDict);
                result = dictAccessFunc(path, realInputDict);
            }
            else
            {
                //result = MyHub.TryGetResourceSampleWithUri(path, realInputs);
                result = arrayAccessFunc(path, realInputs);
            }

            var resultString = result.ToString();

            if (IsSample)
            {
                resultString = JsonConvert.SerializeObject(result, Formatting.Indented);
            }

            return(resultString);
        }