Esempio n. 1
0
        public String GetCurrentVersions()
        {
            var verFilePath = _reader.MakeFullPath(String.Empty, "versions.json");

            if (!_reader.FileExists(verFilePath))
            {
                return(null);
            }
            String verJson  = _reader.FileReadAllText(verFilePath);
            var    versions = JsonConvert.DeserializeObject <AppVersionsList>(verJson);

            using (var cnn = new SqlConnection(_cnnString))
            {
                cnn.Open();
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = "a2sys.[GetVersions]";
                    cmd.CommandType = CommandType.StoredProcedure;
                    using (var rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
                    {
                        while (rdr.Read())
                        {
                            String module  = rdr.GetString(0);
                            Int32  version = rdr.GetInt32(1);
                            versions.SetInstalledVersion(module, version);
                        }
                    }
                }
            }
            return(JsonConvert.SerializeObject(versions));
        }
Esempio n. 2
0
        public static ApiRequestCommand GetCommand(IApplicationReader reader, String path)
        {
            var parts = path.Split('/');
            // dir/dir/dir/acton/{id};

            int len = parts.Length;

            if (len < 2)
            {
                throw new ApiV2Exception($"invalid path: {path}");
            }
            var p1 = String.Join("/", new ArraySegment <String>(parts, 0, len - 1));

            String id     = null;
            String action = null;

            String relPath  = $"_apiv2/{p1}";
            String filePath = reader.MakeFullPath(relPath, "model.json");

            if (!reader.FileExists(filePath))
            {
                // try to read with id
                if (len < 3)
                {
                    throw new ApiV2Exception($"invalid path: {path}");
                }
                p1       = String.Join("/", new ArraySegment <String>(parts, 0, len - 2));
                relPath  = $"_apiv2/{p1}";
                filePath = reader.MakeFullPath(relPath, "model.json");
                id       = parts[len - 1];
                if (!reader.FileExists(filePath))
                {
                    throw new ApiV2Exception($"path not found: {path}");
                }
                action = parts[len - 2];
            }
            else
            {
                action = parts[len - 1];
            }

            var json = reader.FileReadAllText(filePath);
            var rm   = JsonConvert.DeserializeObject <ApiV2RequestModel>(json, JsonHelpers.CamelCaseSerializerSettings);

            if (rm == null)
            {
                throw new ApiV2Exception($"invalid model.json");
            }
            rm.SetParent();
            if (rm.Commands.TryGetValue(action, out ApiRequestCommand cmd))
            {
                cmd.SetId(id);
                cmd.SetPath(relPath);
                return(cmd);
            }
            throw new ApiV2Exception($"command '{action}' not found");
        }