Esempio n. 1
0
        public static ActionResult JsonFileAppsettings(Session session)
        {
            try
            {
                if (session == null) { throw new ArgumentNullException("session"); }

                CustomActionData data = null;

                if(session["INSTALLATIONMODE"] == "virtualdirectory")
                    data = new CustomActionData(session["JsonFileAppsettingsVirtualDirectory"]);
                else
                    data = new CustomActionData(session["JsonFileAppsettingsWebsite"]);

                string file = data.ContainsKey("File") ? data["File"] : "";
                string rootKey = data.ContainsKey("RootKey") ? data["RootKey"] : "";
                string key = data.ContainsKey("Key") ? data["Key"] : "";
                string value = data.ContainsKey("Value") ? data["Value"] : "";
                if (value.IndexOf("[") > -1 && value.IndexOf("]") > -1)
                    value = session.Format(data["Value"]);

                var dir = session["INSTALLDIR"];
                if (dir == null)
                    return ActionResult.Success;

                file = Path.Combine(dir, file);
                if ( !File.Exists(file))
                    return ActionResult.Success;

                ReplaceInJsonFile(file, rootKey, key, value);

                return ActionResult.Success;
            }
            catch (Exception e)
            {
                if (session != null)
                    session.Log("Custom Action Exception " + e);
            }

            return ActionResult.Failure;
        }