Esempio n. 1
0
        public Main(String[] args)
        {
            Console.SetOut(logger);
            Console.WriteLine("Initializing launcher");
            if (args.Length != 0)
            {
                Console.WriteLine(args[0]);
                Console.WriteLine(args[1]);
                Console.WriteLine(args[2]);
                Console.WriteLine(args[3]);
            }

            InitializeComponent();

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            RestClient client = new RestClient();
            Lib.CARDINAL_SERVER = client.GetRequest(Lib.API_LOADBALANCE, Lib.CARDINAL_BALANCER);

            CheckForUpdates();

            AuthManager = new AuthManager(this);

            Dictionary<string,Profile> Profiles = AuthManager.GetProfiles(); // Retrieve profiles from authentication file
            RefreshProfileList();

            Starting = false;
            Console.WriteLine("Initialised");
        }
        public async void AuthenticateNewProfile(string email, string password)
        {
            ResponseLogin response = new ResponseLogin();
            try
            {

                foreach (KeyValuePair<String, Profile> profile in AuthenticationDb.Profiles)
                {
                    if (profile.Value.Email.Equals(email))
                    {
                        MessageBox.Show("This user is already in the profiles list");
                        return;
                    }
                }

                Dictionary<string, string> Data = new Dictionary<string, string>()
                {
                    {"email", email},
                    {"password", password},
                    {"clientToken", AuthenticationDb.ClientToken}
                };
                var client = new RestClient();

                string json = await client.MakeRequestAsync(Lib.API_LOGIN, Data);

                response = JsonConvert.DeserializeObject<ResponseLogin>(json);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            if (response != null & !response.Equals(""))
            {
                if (response.statusCode.Equals(StatusCode.OK))
                {
                    AuthenticationDb.ClientToken = response.clientToken;
                    AddNewProfile(email, response.accessToken, response.cardinalId);
                    Parent.RefreshProfileList();
                }
                else
                {
                    if (response.statusCode.Equals(StatusCode.INVALID_CREDENTIALS))
                    {
                        MessageBox.Show("Invalid email/password combination");
                    }
                    else
                    {
                        MessageBox.Show("An internal error occured.\n Please wait and try again, and if you still cannot log in, contact customer support with Unique Support Code: " + response.uniqueSupport);
                    }
                    
                }
            }
        }
Esempio n. 3
0
        private void CheckForUpdates()
        {
            RestClient client = new RestClient();

            String versionFileLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Lib.VERSION_FILE_LOCATION);

            String tempLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Lib.TEMP_LOCATION);

            String version = "";

            if (File.Exists(tempLocation + ".update"))
            {
                String FileContents = File.ReadAllText(tempLocation + ".update");
                Dictionary<string, string> UpdateFileContents = JsonConvert.DeserializeObject<Dictionary<string, string>>(FileContents);
                if (UpdateFileContents.Count > 0)
                {
                    UpdateFileContents.TryGetValue("version", out version);
                    File.WriteAllText(versionFileLocation, JsonConvert.SerializeObject(UpdateFileContents, Formatting.Indented));
                }
                File.Delete(tempLocation + ".update");
            }

            String remoteVersion = client.GetRemoteVersionNumber();
            String localVersion = "0";
            Dictionary<string, string> RemoteVersionDict = new Dictionary<string, string>();
            RemoteVersionDict.Add("version", remoteVersion);

            if (!File.Exists(versionFileLocation))
            {
                File.WriteAllText(versionFileLocation, JsonConvert.SerializeObject(new Dictionary<string, string>() { { "version", "1431371514" } }, Formatting.Indented));
            }
            else
            {
                Dictionary<string, string> contents = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(versionFileLocation));
                if (contents.Count > 0)
                {
                   contents.TryGetValue("version", out localVersion);
                }
            }

            if (Int64.Parse(localVersion) < Int64.Parse(remoteVersion))
            {
                RetrieveUpdates(RemoteVersionDict);
            }
            
        }
Esempio n. 4
0
        private async void RetrieveUpdates(Dictionary<string,string> ver)
        {
            MessageBox.Show("The application will now prepare to update", "Update Required");
            RestClient client = new RestClient();
            this.Enabled = false;
            await client.DownloadInstaller();


            Process process = new Process();
            // Configure the process using the StartInfo properties.
            process.StartInfo.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Lib.TEMP_INSTALLER_LOCATION);
            process.StartInfo.Arguments = "/SILENT /NOCANCEL /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS";
            process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;

            String tempLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Lib.TEMP_LOCATION);

            File.WriteAllText(tempLocation + ".update", JsonConvert.SerializeObject(ver, Formatting.Indented));

            process.Start();
            process.WaitForExit();
            if (process.ExitCode != 0)
            {
                File.Delete(tempLocation + ".update");
            }
            Application.Exit();

        }