Beispiel #1
0
 private void CreateClientSignature2()
 {
     /* SNIPPET 2: START */
     CultureInfo culture = new CultureInfo("it-IT");
     var         client  = new MetasysClient("hostname", true, ApiVersion.v2, culture);
     /* SNIPPET 2: END */
 }
Beispiel #2
0
        private void ChangeApiVersion()
        {
            /* SNIPPET 5: START */
            // Changing Api version after creating a client
            var client = new MetasysClient("hostname", version: ApiVersion.v3);

            client.Version = ApiVersion.v2;
            /* SNIPPET 5: END */
        }
Beispiel #3
0
        private void ChangeHostname()
        {
            /* SNIPPET 6: START */
            // Changing Metasys Server after creating a client
            var client = new MetasysClient("hostname");

            client.Hostname = "WIN2016-VM2";
            /* SNIPPET 6: END */
        }
Beispiel #4
0
 private void CreateClientSignature3()
 {
     /* SNIPPET 3: START */
     var client = new MetasysClient("hostname", logClientErrors: false);
     /* SNIPPET 3: END */
 }
Beispiel #5
0
 private void CreateClientSignature1()
 {
     /* SNIPPET 1: START */
     var client = new MetasysClient("hostname");
     /* SNIPPET 1: END */
 }
Beispiel #6
0
 public JsonOutputDemo(MetasysClient client)
 {
     this.client = client;
     log         = new LogInitializer(typeof(JsonOutputDemo));
 }
 public GetObjectIdentifierDemo(MetasysClient client)
 {
     this.client = client;
     log         = new LogInitializer(typeof(GetObjectIdentifierDemo));
 }
Beispiel #8
0
 public void Init()
 {
     client = new MetasysClient("hostname");
 }
Beispiel #9
0
 public AuditsDemo(MetasysClient client)
 {
     this.client = client;
     log         = new LogInitializer(typeof(AuditsDemo));
 }
Beispiel #10
0
        static void Main(string[] args)
        {
            var    log = new LogInitializer(typeof(Program));
            string connectionDetails;

            try
            {
                if (args.Length != 3)
                {
                    Console.WriteLine("Please enter in your credentials in this format: {username} {password} {hostname} {api_version} or as an alternative you can specify just the Credential Manager target and the hostname in this way {credmantarget} {hostname} {api_version}." +
                                      "\nRefer to the metasys-server/basic-services-dotnet README if you need help getting started.");
                    connectionDetails = Console.ReadLine();
                    args = connectionDetails.Split(' ');
                }
                string username = null, password = null, hostname = null, credManTarget = null; string version = null;

                if (args.Length > 3)
                {
                    username = args[0];
                    password = args[1];
                    hostname = args[2];
                    version  = args[3];
                }
                else
                {
                    credManTarget = args[0];
                    hostname      = args[1];
                    version       = args[2];
                }

                #region Login
                Console.WriteLine("Default culture is en_US. The culture for client translations can be changed in the code.");
                // CultureInfo culture = new CultureInfo("en-US");

                Console.WriteLine("\nLogging in...");
                var apiVersion = (ApiVersion)Enum.Parse(typeof(ApiVersion), version);
                var client     = new MetasysClient(hostname, true, apiVersion, logClientErrors: false); // Disable default logging since it is handled in this app.
                // var client = new MetasysClient(hostname, true); // Ignore Certificate Errors
                // var client = new MetasysClient(hostname, false, ApiVersion.v2, culture);

                AccessToken token;
                if (string.IsNullOrWhiteSpace(credManTarget))
                {
                    token = client.TryLogin(username, password);
                }
                else
                {
                    // Read and login using cred managerfrom Credential manager
                    token = client.TryLogin(credManTarget);
                }
                Console.WriteLine($"Access token: {token.Token} expires {token.Expires}.");
                #endregion

                bool showMenu = true;
                while (showMenu)
                {
                    showMenu = MainMenu(client);
                }
            }
            catch (Exception exception)
            {
                log.Logger.Error(string.Format("An error occured while login - {0}", exception.Message));
                Console.WriteLine("\n \nAn Error occurred. Press Enter to exit");
                Console.ReadLine();
            }
        }
Beispiel #11
0
        private static bool MainMenu(MetasysClient client)
        {
            Console.Clear();
            Console.WriteLine("Choose an option:");
            Console.WriteLine("1) Get Object Identifier");
            Console.WriteLine("2) General Demo");
            Console.WriteLine("3) Refresh Token");
            Console.WriteLine("4) Spaces");
            Console.WriteLine("5) Equipment");
            Console.WriteLine("6) Alarms");
            Console.WriteLine("7) Trends");
            Console.WriteLine("8) Audits");
            Console.WriteLine("9) JSON Output");
            Console.WriteLine("10) Exit");
            Console.Write("\r\nSelect an option: ");
            var option = "9";// Console.ReadLine();

            Console.WriteLine();
            switch (option)
            {
            case "1":
                new GetObjectIdentifierDemo(client).Run();
                return(true);

            case "2":
                new GeneralDemo(client).Run();
                return(true);

            case "3":
                new RefreshTokenDemo(client).Run();
                return(true);

            case "4":
                new SpacesDemo(client).Run();
                return(true);

            case "5":
                new EquipmentDemo(client).Run();
                return(true);

            case "6":
                new AlarmsDemo(client).Run();
                return(true);

            case "7":
                new TrendsDemo(client).Run();
                return(true);

            case "8":
                new AuditsDemo(client).Run();
                return(true);

            case "9":
                new JsonOutputDemo(client).Run();
                return(false);

            case "10":
                return(false);

            default:
                return(true);
            }
        }
 public SpacesDemo(MetasysClient client)
 {
     this.client = client;
     log         = new LogInitializer(typeof(SpacesDemo));
 }
Beispiel #13
0
 public GeneralDemo(MetasysClient client)
 {
     this.client = client;
     log         = new LogInitializer(typeof(GeneralDemo));
 }
 public void Init()
 {
     client = new MetasysClient("hostname", false, ApiVersion.v2, testCulture);
 }
 public TrendsDemo(MetasysClient client)
 {
     this.client = client;
     log         = new LogInitializer(typeof(TrendsDemo));
 }
Beispiel #16
0
 public RefreshTokenDemo(MetasysClient client)
 {
     this.client = client;
     log         = new LogInitializer(typeof(RefreshTokenDemo));
 }
Beispiel #17
0
        static void Main(string[] args)
        {
            // Add support for JSON Config File
            IConfiguration config = new ConfigurationBuilder()
                                    .SetBasePath(Directory.GetCurrentDirectory())
                                    .AddJsonFile("AppSettings.json", optional: false, reloadOnChange: true)
                                    .Build();
            // Read hostname from credential manager first
            var hostnameTarget = config.GetSection("CredentialManager:Targets:MetasysServer").Value;
            // Hostname is stored in the Credential Manager using password field
            var           secureHostname = CredentialUtil.GetCredential(hostnameTarget);
            MetasysClient metasysClient  = new MetasysClient(CredentialUtil.convertToUnSecureString(secureHostname.Password));
            // Retrieve Metasys Credentials to login
            var credTarget = config.GetSection("CredentialManager:Targets:MetasysCredentials").Value;

            // Use TryLogin overload that accepts Credential Manager Target
            metasysClient.TryLogin(credTarget);
            // Forecast container target is securely stored in Credential manager
            var containerTarget = config.GetSection("CredentialManager:Targets:ForecastContainer").Value;
            var secureContainer = CredentialUtil.GetCredential(containerTarget);
            // Get parent object of Weather Forecast to retrieve related children (securely stored in Credential Manager)
            Guid parentObjectId = metasysClient.GetObjectIdentifier(CredentialUtil.convertToUnSecureString(secureContainer.Password));
            IEnumerable <MetasysObject> weatherForecast = metasysClient.GetObjects(parentObjectId, 1);
            // Retrieve latitude and longitude to get weather forecast
            MetasysObject latitudePoint  = weatherForecast.FindByName("Latitude");
            MetasysObject longitudePoint = weatherForecast.FindByName("Longitude");
            double        latitude       = metasysClient.ReadProperty(latitudePoint.Id, "presentValue").NumericValue;
            double        longitude      = metasysClient.ReadProperty(longitudePoint.Id, "presentValue").NumericValue;
            // Forecast API key is securely stored in Credential manager
            var apiKeyTarget = config.GetSection("CredentialManager:Targets:OpenWeather").Value;
            var secureApiKey = CredentialUtil.GetCredential(apiKeyTarget);
            // Get Next Five Days forecast every 3 hours
            OpenWeatherMapClient weatherMapclient = new OpenWeatherMapClient(CredentialUtil.convertToUnSecureString(secureApiKey.Password));
            ForecastResult       forecastResult   = weatherMapclient.GetForecast(latitude, longitude).GetAwaiter().GetResult();
            // Get the closest forecast to be written
            Forecast forecast = forecastResult.list.First();
            // Read Metasys points to write the response back
            MetasysObject Day         = weatherForecast.FindByName("Day");
            MetasysObject Month       = weatherForecast.FindByName("Month");
            MetasysObject Year        = weatherForecast.FindByName("Year");
            MetasysObject Hour        = weatherForecast.FindByName("Hour");
            MetasysObject Minute      = weatherForecast.FindByName("Minute");
            MetasysObject Temperature = weatherForecast.FindByName("Temperature");
            MetasysObject Humidity    = weatherForecast.FindByName("Humidity");
            MetasysObject Rain        = weatherForecast.FindByName("Rain");
            MetasysObject Snow        = weatherForecast.FindByName("Snow");
            // Use commands to write the results
            string adjustCommand = "Adjust";
            var    date          = OpenWeatherMapClient.UnixTimeStampToDateTime(forecast.dt);

            metasysClient.SendCommand(Day.Id, adjustCommand, new List <object> {
                date.Day
            });
            metasysClient.SendCommand(Month.Id, adjustCommand, new List <object> {
                date.Month
            });
            metasysClient.SendCommand(Year.Id, adjustCommand, new List <object> {
                date.Year
            });
            metasysClient.SendCommand(Hour.Id, adjustCommand, new List <object> {
                date.Hour
            });
            metasysClient.SendCommand(Minute.Id, adjustCommand, new List <object> {
                date.Minute
            });
            metasysClient.SendCommand(Temperature.Id, adjustCommand, new List <object> {
                forecast.main.temp
            });
            metasysClient.SendCommand(Humidity.Id, adjustCommand, new List <object> {
                forecast.main.humidity
            });
            if (forecast.rain != null)
            {
                metasysClient.SendCommand(Rain.Id, adjustCommand, new List <object> {
                    forecast.rain.ThreeHours
                });
            }
            else
            {
                // Reset values in case there is no rain
                metasysClient.SendCommand(Rain.Id, adjustCommand, new List <object> {
                    0
                });
            }
            if (forecast.snow != null)
            {
                metasysClient.SendCommand(Snow.Id, adjustCommand, new List <object> {
                    forecast.snow.ThreeHours
                });
            }
            else
            {
                // Reset values in case there is no snow
                metasysClient.SendCommand(Rain.Id, adjustCommand, new List <object> {
                    0
                });
            }
        }