Esempio n. 1
0
        /// <summary>
        /// Gets the parsed data for an application.
        /// </summary>
        /// <param name="appVariables">The unstructured app variables.</param>
        /// <returns>An ApplicationParsedData object, that contains structured information about the application.</returns>
        public static ApplicationParsedData GetParsedData(ApplicationVariable[] appVariables)
        {
            if (appVariables == null)
            {
                throw new ArgumentNullException("appVariables");
            }

            Dictionary<string, string> variablesHash = new Dictionary<string, string>(appVariables.Length);

            foreach (ApplicationVariable variable in appVariables)
            {
                variablesHash[variable.Name] = variable.Value;
            }

            ApplicationVariable[] variables = appVariables;

            ApplicationInfo appInfo = new ApplicationInfo();

            VcapApplication vcapApplication = new VcapApplication();
            vcapApplication.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(variablesHash[PluginBaseRes.VcapApplicationVariable]));

            appInfo.InstanceId = vcapApplication.InstanceId;
            appInfo.LocalIP = variablesHash[PluginBaseRes.VcapAppHostVariable];
            appInfo.Name = vcapApplication.Name;
            appInfo.Path = Path.Combine(variablesHash[PluginBaseRes.HomeVariable], "app");
            appInfo.Port = int.Parse(variablesHash[PluginBaseRes.VcapAppPortVariable], CultureInfo.InvariantCulture);
            appInfo.WindowsPassword = variablesHash[PluginBaseRes.VcapWindowsUserPasswordVariable];
            appInfo.WindowsUserName = variablesHash[PluginBaseRes.VcapWindowsUserVariable];

            string runtime = vcapApplication.Runtime;

            string servicesJson = variablesHash[PluginBaseRes.VcapServicesVariable];
            Dictionary<string, object[]> vcapProvisionedServices = new Dictionary<string, object[]>();
            List<ApplicationService> services = new List<ApplicationService>();
            vcapProvisionedServices = JsonConvertibleObject.ObjectToValue<Dictionary<string, object[]>>(JsonConvertibleObject.DeserializeFromJson(servicesJson));

            foreach (string serviceLabel in vcapProvisionedServices.Keys)
            {
                foreach (object provisionedService in vcapProvisionedServices[serviceLabel])
                {
                    VcapProvisionedService service = new VcapProvisionedService();
                    service.FromJsonIntermediateObject(provisionedService);

                    ApplicationService appService = new ApplicationService(
                        service.Name,
                        string.IsNullOrEmpty(service.Credentials.User) ? service.Credentials.Username : service.Credentials.User,
                        service.Credentials.Password,
                        service.Credentials.Port,
                        service.Plan,
                        service.PlanOptions,
                        string.IsNullOrEmpty(service.Credentials.Hostname) ? service.Credentials.Host : service.Credentials.Hostname,
                        service.Credentials.InstanceName,
                        service.Label,
                        service.Tags);

                    services.Add(appService);
                }
            }

            VcapPluginStagingInfo vcapPluginStagingInfo = new VcapPluginStagingInfo();
            vcapPluginStagingInfo.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(variablesHash[PluginBaseRes.VcapPluginStagingInfoVariable]));

            string logFilePath = Path.Combine(variablesHash[PluginBaseRes.HomeVariable], vcapPluginStagingInfo.Logs.AppLog);
            string errorLogFilePath = Path.Combine(variablesHash[PluginBaseRes.HomeVariable], vcapPluginStagingInfo.Logs.AppErrorLog);
            string startupLogFilePath = Path.Combine(variablesHash[PluginBaseRes.HomeVariable], vcapPluginStagingInfo.Logs.StartupLog);

            return new ApplicationParsedData(
                appInfo,
                runtime,
                variables,
                services.ToArray(),
                vcapApplication.Urls,
                logFilePath,
                errorLogFilePath,
                startupLogFilePath,
                vcapPluginStagingInfo.AutoWireTemplates);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the parsed data for an application.
        /// </summary>
        /// <param name="appVariables">The unstructured app variables.</param>
        /// <returns>An ApplicationParsedData object, that contains structured information about the application.</returns>
        public static ApplicationParsedData GetParsedData(ApplicationVariable[] appVariables)
        {
            if (appVariables == null)
            {
                throw new ArgumentNullException("appVariables");
            }

            Dictionary <string, string> variablesHash = new Dictionary <string, string>(appVariables.Length);

            foreach (ApplicationVariable variable in appVariables)
            {
                variablesHash[variable.Name] = variable.Value;
            }

            ApplicationVariable[] variables = appVariables;

            ApplicationInfo appInfo = new ApplicationInfo();

            VcapApplication vcapApplication = new VcapApplication();

            vcapApplication.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(variablesHash[PluginBaseRes.VcapApplicationVariable]));

            appInfo.InstanceId      = vcapApplication.InstanceId;
            appInfo.LocalIP         = variablesHash[PluginBaseRes.VcapAppHostVariable];
            appInfo.Name            = vcapApplication.Name;
            appInfo.Path            = Path.Combine(variablesHash[PluginBaseRes.HomeVariable], "app");
            appInfo.Port            = int.Parse(variablesHash[PluginBaseRes.VcapAppPortVariable], CultureInfo.InvariantCulture);
            appInfo.WindowsPassword = variablesHash[PluginBaseRes.VcapWindowsUserPasswordVariable];
            appInfo.WindowsUserName = variablesHash[PluginBaseRes.VcapWindowsUserVariable];

            string runtime = vcapApplication.Runtime;

            string servicesJson = variablesHash[PluginBaseRes.VcapServicesVariable];
            Dictionary <string, object[]> vcapProvisionedServices = new Dictionary <string, object[]>();
            List <ApplicationService>     services = new List <ApplicationService>();

            vcapProvisionedServices = JsonConvertibleObject.ObjectToValue <Dictionary <string, object[]> >(JsonConvertibleObject.DeserializeFromJson(servicesJson));

            foreach (string serviceLabel in vcapProvisionedServices.Keys)
            {
                foreach (object provisionedService in vcapProvisionedServices[serviceLabel])
                {
                    VcapProvisionedService service = new VcapProvisionedService();
                    service.FromJsonIntermediateObject(provisionedService);

                    ApplicationService appService = new ApplicationService(
                        service.Name,
                        string.IsNullOrEmpty(service.Credentials.User) ? service.Credentials.Username : service.Credentials.User,
                        service.Credentials.Password,
                        service.Credentials.Port,
                        service.Plan,
                        service.PlanOptions,
                        string.IsNullOrEmpty(service.Credentials.Hostname) ? service.Credentials.Host : service.Credentials.Hostname,
                        service.Credentials.InstanceName,
                        service.Label,
                        service.Tags);

                    services.Add(appService);
                }
            }

            VcapPluginStagingInfo vcapPluginStagingInfo = new VcapPluginStagingInfo();

            vcapPluginStagingInfo.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(variablesHash[PluginBaseRes.VcapPluginStagingInfoVariable]));

            string logFilePath        = Path.Combine(variablesHash[PluginBaseRes.HomeVariable], vcapPluginStagingInfo.Logs.AppLog);
            string errorLogFilePath   = Path.Combine(variablesHash[PluginBaseRes.HomeVariable], vcapPluginStagingInfo.Logs.AppErrorLog);
            string startupLogFilePath = Path.Combine(variablesHash[PluginBaseRes.HomeVariable], vcapPluginStagingInfo.Logs.StartupLog);

            return(new ApplicationParsedData(
                       appInfo,
                       runtime,
                       variables,
                       services.ToArray(),
                       vcapApplication.Urls,
                       logFilePath,
                       errorLogFilePath,
                       startupLogFilePath,
                       vcapPluginStagingInfo.AutoWireTemplates));
        }