/*
 * Copyright 2016-2017 Javier Garcia Alonso.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.profesorfalken.jsensors.manager.windows.powershell;

import com.profesorfalken.jpowershell.PowerShell;
import com.profesorfalken.jpowershell.PowerShellNotAvailableException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Javier Garcia Alonso
 */
public enum PowerShellOperations {
	GET;

	private static final Logger LOGGER = LoggerFactory.getLogger(PowerShellOperations.class);

	private PowerShell powerShell = null;
	private boolean initialized;

	// Hides constructor
	PowerShellOperations() {
		String rawData = null;
		this.powerShell = PowerShell.openSession();
	}

	public boolean isInitialized() {
		return this.initialized;
	}

	public static boolean isAdministrator() {
		String command = "([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] \"Administrator\")";

		return "true".equalsIgnoreCase(PowerShell.executeSingleCommand(command).getCommandOutput());
	}

	public String getRawSensorsData() {
		/*PowerShell powershell = null;
		String rawData = null;
		try {
			powershell = PowerShell.openSession();
			rawData = powershell.executeScript(PowerShellScriptHelper.generateScript()).getCommandOutput();
		} catch (PowerShellNotAvailableException ex) {
			LOGGER.error("Cannot find PowerShell in your system. Please install it", ex);
		} finally {
			if (powershell != null) {
				powershell.close();
			}
		}*/
		return this.powerShell.executeScript(PowerShellScriptHelper.generateScript()).getCommandOutput();
	}
}

@@ -1063,60 +1063,8 @@
 ll;%0A
-%09private boolean initialized;%0A%0A%09// Hides constructor
 %0A%09Po
@@ -1090,33 +1090,8 @@
 ) %7B%0A
-%09%09String rawData = null;%0A
 %09%09th
@@ -1140,73 +1140,8 @@
 %09%7D%0A%0A
-%09public boolean isInitialized() %7B%0A%09%09return this.initialized;%0A%09%7D%0A%0A
 %09pub
@@ -1501,424 +1501,8 @@
 ) %7B%0A
-%09%09/*PowerShell powershell = null;%0A%09%09String rawData = null;%0A%09%09try %7B%0A%09%09%09powershell = PowerShell.openSession();%0A%09%09%09rawData = powershell.executeScript(PowerShellScriptHelper.generateScript()).getCommandOutput();%0A%09%09%7D catch (PowerShellNotAvailableException ex) %7B%0A%09%09%09LOGGER.error(%22Cannot find PowerShell in your system. Please install it%22, ex);%0A%09%09%7D finally %7B%0A%09%09%09if (powershell != null) %7B%0A%09%09%09%09powershell.close();%0A%09%09%09%7D%0A%09%09%7D*/%0A
 %09%09re

Remove unused code