Example #1
0
        /* TODO ERROR: Skipped EndRegionDirectiveTrivia */
        /* TODO ERROR: Skipped RegionDirectiveTrivia */
        private void loadCloudFiles()
        {
            taskManager.setStatus("loadCloudFiles", Conversions.ToInteger(tasksManager.tasksManagerClass.BUSY));
            LoadingCounter += 1;
            updatePrgressBar?.Invoke(this, (int)(LoadingCounter / (double)LoadingCounterTotalTasks * 100));
            updateStatusMessage?.Invoke(this, "Loading cloud settings...");

            // TODO review
            dynamicAssembliesToLoadIndex = new List <int>();
            bool found = false;

            for (int i = 0, loopTo = state.assemblies.Count - 1; i <= loopTo; i++)
            {
                found = false;
                for (int j = 0, loopTo1 = dynamicAssembliesToLoad.Count - 1; j <= loopTo1; j++)
                {
                    if (dynamicAssembliesToLoad.ElementAt(j).Equals(state.assemblies.ElementAt(i).Key))
                    {
                        dynamicAssembliesToLoadIndex.Add(i);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    messageBoxForm msgbox;
                    msgbox = new messageBoxForm("Incorrect Dll files. You need to download and install the lastest version of the program at " + state.customization.websiteToLoadProgram, "exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    msgbox.ShowDialog();
                    taskManager.unload();
                    Application.Exit();
                    return;
                }
            }

            if (!Directory.Exists(state.tmpPath) | !Directory.Exists(state.libraryPath) | !Directory.Exists(state.templatesPath))
            {
                messageBoxForm msgbox;
                msgbox = new messageBoxForm("Folders not found. You need to download and install the lastest version of the program at " + state.customization.websiteToLoadProgram, "exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                msgbox.ShowDialog();
                Application.Exit();
                return;
            }

            var myDir = new DirectoryInfo(state.tmpPath);

            if (myDir.EnumerateFiles().Any())
            {
                try
                {
                    FileSystem.Kill(string.Format("{0}", state.tmpPath + "*.*"));
                }
                catch (Exception ex)
                {
                    messageBoxForm msgbox;
                    msgbox = new messageBoxForm("Unable do delete temporary files. Clear tmp folder and start the App again.", "exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    msgbox.ShowDialog();
                    Application.Exit();
                    return;
                }
            }

            myDir = new DirectoryInfo(state.templatesPath);
            if (myDir.EnumerateFiles().Any())
            {
                try
                {
                    FileSystem.Kill(string.Format("{0}", state.templatesPath + "*.*"));
                }
                catch (Exception ex)
                {
                    messageBoxForm msgbox;
                    msgbox = new messageBoxForm("Unable do delete templates files. Clear templates folder and start the App again.", "exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    msgbox.ShowDialog();
                    Application.Exit();
                    return;
                }
            }

            if (Directory.EnumerateFiles(state.libraryPath, "*.dll").Count() > 0)
            {
                try
                {
                    FileSystem.Kill(string.Format("{0}", state.libraryPath + "*.dll"));
                }
                catch (Exception ex)
                {
                    messageBoxForm msgbox;
                    msgbox = new messageBoxForm("Unable do delete dll files. Clear dll files in library folder and start the App again.", "exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    msgbox.ShowDialog();
                    taskManager.unload();
                    Application.Exit();
                    return;
                }
            }

            getFiles = new HttpDataFilesDownload(state);
            getFiles.initialize();
            // add DLLS to queue
            for (int j = 0, loopTo2 = dynamicAssembliesToLoad.Count - 1; j <= loopTo2; j++)
            {
                var vars = new Dictionary <string, string>();
                vars.Add("task", "1100");
                vars.Add("file", dynamicAssembliesToLoad.ElementAt(j));
                getFiles.loadQueue(vars, null, state.libraryPath);
            }

            // add templates to queue
            if (state.authorizedFileTemplates is object)
            {
                var templates = state.authorizedFileTemplates;
                for (int j = 0, loopTo3 = templates.Count - 1; j <= loopTo3; j++)
                {
                    var vars = new Dictionary <string, string>();
                    vars.Add("task", "1050");
                    vars.Add("file", templates.ElementAt(j).Key);
                    getFiles.loadQueue(vars, null, state.templatesPath);
                }
            }

            getFiles.startRequest();
        }
Example #2
0
        private void loadLoginData_dataArrived(object sender, string responseData, Dictionary <string, string> misc)
        {
            if (!ManagementNetwork.IsResponseOk(responseData))
            {
                loginError?.Invoke(this, ManagementNetwork.GetMessage(responseData));
                return;
            }

            dynamicAssembliesToLoad = new List <string>();
            try
            {
                var data = JsonConvert.DeserializeObject <Dictionary <string, object> >(responseData);

                // USER CREDENTIALS
                state.userType     = data["type"].ToString();
                state.userConnType = data["conntype"].ToString();
                state.username     = data["username"].ToString();

                // USER PROFILE PHOTO
                if (data.ContainsKey("photo"))
                {
                    state.userPhoto = Conversions.ToString(data["photo"]);
                }

                // PROGRAM UPDATE STAUTS
                if (data.ContainsKey("status"))
                {
                    var jsonPuStatus = JsonConvert.DeserializeObject <Dictionary <string, object> >(data["status"].ToString());
                    programUpdateStatus.Add("version", jsonPuStatus["version"].ToString());
                    programUpdateStatus.Add("url", jsonPuStatus["url"].ToString());
                    programUpdateStatus.Add("changelog", jsonPuStatus["changelog"].ToString());
                    programUpdateStatus.Add("checksum", jsonPuStatus["checksum"].ToString());
                    programUpdateStatus.Add("mandatory", jsonPuStatus["mandatory"].ToString());
                }

                // LOAD DYNAMIC ASSEMBLIES
                if (data.ContainsKey("dlls") & state.customization.hasDynamicAssemblies)
                {
                    var DllsJson = JArray.Parse(data["dlls"].ToString());
                    for (int i = 0, loopTo = DllsJson.Count - 1; i <= loopTo; i++)
                    {
                        dynamicAssembliesToLoad.Add(DllsJson[i].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                state.successLogin = false;
                state.userId       = "";
                // 'TODO message error
                loginError?.Invoke(this, "");
                return;
            }
            finally
            {
                state.userId = cardId;

                // TODO
                // add raise event here to load TOTP dialog for code verification
                // in case of needed to download dynamic assemblies outside the assemblies defined as static
                if (state.customization.hasDynamicAssemblies)
                {
                }
                else
                {
                    // only static assemblies
                    state.successLogin = true;
                }
            }

            // ÇONTINUE LOADING =========================================
            // 'DEFINE TASKS TO DO
            {
                var withBlock = taskManager;
                withBlock.registerTask("loadEnvironmentVarsFromCloud", Conversions.ToInteger(tasksManager.tasksManagerClass.TO_START));
                withBlock.registerTask("loadServerSettings", Conversions.ToInteger(tasksManager.tasksManagerClass.TO_START));
                withBlock.registerTask("sendCrashReports", Conversions.ToInteger(tasksManager.tasksManagerClass.TO_START));
                withBlock.registerTask("loadCloudFiles", Conversions.ToInteger(tasksManager.tasksManagerClass.TO_START));
                withBlock.registerTask("checkUpdates", Conversions.ToInteger(tasksManager.tasksManagerClass.TO_START));
            }

            taskManager.startListening();
            updatePrgressBar?.Invoke(this, 0);

            // Calculating number of tasks to do
            LoadingCounter = 0;
            var crashFile = new FileInfo(Path.Combine(state.basePath, "crash.log"));

            crashFile.Refresh();
            if (crashFile.Exists & state.SendDiagnosticData)
            {
                LoadingCounterTotalTasks = dynamicAssembliesToLoad.Count + state.authorizedFileTemplates.Count + 3;
            }
            else
            {
                LoadingCounterTotalTasks = dynamicAssembliesToLoad.Count + state.authorizedFileTemplates.Count + 2;
            }

            // ' in between load settings from cloud
            loadEnvironmentVarsFromCloud();
            loadServerSettings();
            sendCrashReports();
            loadCloudFiles();
            if (!My.MyProject.Application.Info.Version.ToString().Equals(programUpdateStatus["version"]) & programUpdateStatus["mandatory"].Equals("true"))
            {
                updateStatusMessage?.Invoke(this, "checking for updates ...");
                getUpdateFile = new HttpDataFilesDownload(state, state.customization.updateServerAddr);
                getUpdateFile.initialize();
                var vars = new Dictionary <string, string>();
                vars.Add("key", programUpdateStatus["checksum"]);
                getUpdateFile.loadQueue(vars, null, state.templatesPath);
                getUpdateFile.startRequest();
                taskManager.setStatus("checkUpdates", Conversions.ToInteger(tasksManager.tasksManagerClass.BUSY));
            }
        }