コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: blalande/LQTools
        private async Task <bool> PostScoreCard(ScoreCard sc)
        {
            Properties.Settings p = new Properties.Settings();

            try
            {
                ScoreCardEnveloppe enveloppe = new ScoreCardEnveloppe();
                enveloppe.scoreCard = sc;
                enveloppe.CentreCle = p.CentreCle;
                JsonSerializerSettings jSettings = new JsonSerializerSettings();
                jSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
                jSettings.ReferenceLoopHandling      = ReferenceLoopHandling.Serialize;
                var stringPayload = JsonConvert.SerializeObject(enveloppe, jSettings);

                // Wrap our JSON inside a StringContent which then can be used by the HttpClient class
                var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");
                using (var httpClient = new HttpClient())
                {
                    // Do the actual request and await the response
                    var httpResponse = await httpClient.PostAsync(p.APIUrl + "/apilq/AddScoreCard", httpContent);

                    // If the response contains content we want to read it!
                    if (httpResponse.Content != null)
                    {
                        var responseContent = await httpResponse.Content.ReadAsStringAsync();

                        bool result = false;
                        if (bool.TryParse(responseContent, out result) && result)
                        {
                            return(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logMessage(string.Format("Erreur sur l'envoi de la fiche de score {0} : {1} ", sc.ToString(), ex.Message), alerte.ERREUR);
                return(false);
            }
            return(false);
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: blalande/LQTools
        private void switchKeepFile()
        {
            // on active que si le mode acquisition est activé
            modeExport = !modeExport;

            if (modeExport)
            {
                Properties.Settings pApp = new Properties.Settings();
                if (!Directory.Exists(pApp.RepertoireExport))
                {
                    logMessage("Le repertoire d'export n'existe pas");
                    modeExport = false;
                    return;
                }
                logMessage("Mode export activé");
            }
            else
            {
                logMessage("Mode export désactivé");
            }
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: blalande/LQTools
        /// <summary>
        /// Gestion de l'event fichier modifié
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void eventRaised(object sender, System.IO.FileSystemEventArgs e)
        {
            // on est dans un thread différent du GUI... il faut qu'on puisse acceder au datagrid et au fichier log...
            // ca ne devrait pas arrivé...
            if (!modeAcquisition)
            {
                return;
            }
            // je ne m'interesse qu'a un seul fichier
            Properties.Settings pApp = new Properties.Settings();
            string fichier           = pApp.FichierSource;

            if (e.FullPath == fichier)
            {
                DateTime lastWriteTime = File.GetLastWriteTime(fichier);
                if (lastWriteTime == lastRead)
                {
                    // on a deja traité le fichier pour ce changement, on essaye d'éviter les doublons...
                    return;
                }
                lastRead = lastWriteTime;
                // on recopie le fichier ?
                logMessage("Début d'acquisition");
                try
                {
                    if (modeExport)
                    {
                        string rep = pApp.RepertoireExport;
                        logMessage("Fichier cible modifié " + e.ChangeType);
                        // on recopie le fichier dans le rep de destination en le renommant
                        File.Copy(fichier, string.Format("{0}\\fscore_{1}.txt", rep, DateTime.Now.Ticks));
                    }
                }
                catch (Exception ex)
                {
                    logMessage(string.Format("Erreur lors de l'export : {0}", ex.Message), alerte.ERREUR);
                }
                // on fait l'acquisition

                try
                {
                    List <ScoreCard> lstSc = LQModelLight.Tools.readScoreCardFromFile(pApp.FichierSource, pApp.DateFormat);
                    entr.lstScores.AddRange(lstSc);
                    // si pas d'url dans les settings, on est en mode hors connexion
                    if (!string.IsNullOrEmpty(pApp.APIUrl))
                    {
                        // ici on peut envoyé vers le WebService
                        foreach (ScoreCard sc in lstSc)
                        {
                            Task <bool> ok = PostScoreCard(sc);
                        }
                    }
                }
                catch (Exception ex)
                {
                    logMessage(string.Format("Erreur sur {0} : {1} ", pApp.FichierSource, ex.Message), alerte.ERREUR);
                }
            }
            SaveData();
            // on doit mettre a jour la grille d'affichage
            LoadDataGrid();
        }