Esempio n. 1
0
        /// <summary>
        /// Load credentials from file using specified filename
        /// </summary>
        /// <param name="fileName">Configuration filename</param>
        public static ApiCredentials LoadFromFile(string fileName)
        {
            ApiCredentials result = null;

            if (System.IO.File.Exists(fileName))
            {
                return(Common.Serialization.XmlSerializer <ApiCredentials> .DeserializeFromFile(fileName));
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Open connection to Spark API
        /// </summary>
        /// <returns></returns>
        internal bool Connect()
        {
            bool result = true;

            lock (_syncLock)
            {
                try
                {
                    if (ConnectionStatus == SparkConnectionStatus.Disconnected)
                    {
                        //Instance Spark object
                        Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + "\t" + "Initiating Spark connection...");
                        Initialise();

                        //Connect to Spark server
                        ApiCredentials credentials = ApiCredentials.LoadFromFile();
                        if (credentials == null)
                        {
                            throw new ApplicationException("Spark API security credentials not available");
                        }
                        Spark.SetLogin(credentials.Username, credentials.Password);
                        if (!Spark.Connect())
                        {
                            Debug.WriteLine("Can't connect: {0}", Spark.DescribeError(Spark.GetLastError()));
                            result = false;
                        }
                        Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + "\t" + "Spark connection initiated");

                        //Wait to allow Spark API to data access
                        System.Threading.Thread.Sleep(1000);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("ERROR: APIControl - ", ex.Message);
                    result = false;
                }
            }
            return(result);
        }