예제 #1
0
        static void Main(string[] args)
        {
            ILogger mylogger = new TextLogger();

            int i = 15;
            int d = 0;

            try
            {
                int rs = i / d;
            }
            catch (Exception ex)
            {
                mylogger.Error(ex);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            ILogger mylogger = new TextLogger();

            int i = 15;
            int d = 0;

            try
            {
                int rs = i / d;
            }
            catch (Exception ex)
            {
                mylogger.Error(ex);
            }
        }
예제 #3
0
        /// <summary>
        /// 封装了事务处理的方法
        /// 只需专注于业务逻辑的实现
        /// </summary>
        public static void HandleTransactionEvent(string sessionString, Action <DbSession> action, Action <Exception> onError = null)
        {
            using (var session1 = new DbSession(EDatabaseType.SQLite, sessionString))
            {
                session1.IsLogQuery = true;
                //业务逻辑处理
                try
                {
                    session1.Open();
                    session1.BeginTransaction();
                    try
                    {
                        action(session1);
                        session1.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        session1.RollBackTransaction();
                        if (onError != null)
                        {
                            onError(ex);

                            var dllLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
                            var logger      = new TextLogger("PmLogger.txt", dllLocation.Substring(0, dllLocation.LastIndexOf("\\")));
                            logger.Error(ex.ToString());
                        }
                    }
                    session1.Close();
                }
                catch (Exception ex)
                {
                    if (session1 != null && session1.Connection.State == System.Data.ConnectionState.Open)
                    {
                        session1.Close();
                    }
                    if (onError != null)
                    {
                        onError(ex);

                        var dllLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
                        var logger      = new TextLogger("PmLogger.txt", dllLocation.Substring(0, dllLocation.LastIndexOf("\\")));
                        logger.Error(ex.ToString());
                    }
                }
            }
        }
예제 #4
0
        public void Apply()
        {
            AppSettings opt = AppContext.Settings.AppSettings;

            if (Uri.IsWellFormedUriString(m_tbServerURL.Text, UriKind.Absolute))
            {
                opt.ServerURL = m_tbServerURL.Text;
            }
            else
            {
                TextLogger.Error("Le format de d'adresse du serveur est incorrect. Adresse du serveur ignorée.");
            }

            opt.Password     = m_tbPassword.Text;
            opt.UserName     = m_tbUserName.Text;
            opt.EnableProxy  = m_chkEnableProxy.Checked;
            opt.ProxyAddress = m_tbProxyHost.Text;
            opt.ProxyPort    = (ushort)m_nudProxyPort.Value;
        }
예제 #5
0
파일: PreviewPage.cs 프로젝트: Adel-dz/Hub
        private void Data_ItemActivate(object sender, EventArgs e)
        {
            var selTable = m_lvTables.SelectedItems[0].Tag as IDataTable;

            if (selTable.ID == TablesID.PLACE)
            {
                ModifyPalceCountry();
            }
            else if (selTable.ID == TablesID.COUNTRY)
            {
                try
                {
                    ModifyCountryName();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TextLogger.Error(ex.Message);
                }
            }
        }
예제 #6
0
        private void UploadAppUpdates_Click(object sender, EventArgs e)
        {
            var filesNames = new Dictionary <AppArchitecture_t, string>
            {
                { AppArchitecture_t.Win7SP1, WIN7SP1_UPDATE_FILENAME },
                { AppArchitecture_t.Win7SP1X64, WIN7SP1X64_UPADTE_FILENAME },
                { AppArchitecture_t.WinXP, WINXP_UPADTE_FILENAME }
            };


            var waitDlg = new Jobs.ProcessingDialog();


            Action run = () =>
            {
                KeyIndexer ndxer = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.APP_UPDATE);

                var seq = (from AppUpdate up in ndxer.Source.Enumerate()
                           where up.DeployTime == AppUpdate.NOT_YET
                           select up).ToArray();

                //maj app manifest + manifest global
                Dictionary <AppArchitecture_t, string> appManifest;

                try
                {
                    appManifest = UpdateEngin.ReadAppManifest(AppPaths.AppManifestPath);
                }
                catch (Exception ex)
                {
                    TextLogger.Warning(ex.Message);
                    appManifest = new Dictionary <AppArchitecture_t, string>();
                }



                IUpdateManifest gManifest;

                try
                {
                    gManifest = UpdateEngin.ReadUpdateManifest(AppPaths.ManifestPath);
                }
                catch (Exception ex)
                {
                    TextLogger.Warning(ex.Message);
                    gManifest = new UpdateManifest(0, 0);
                }



                var netEngin = new NetEngin(AppContext.Settings.NetworkSettings);

                foreach (AppUpdate up in seq)
                {
                    gManifest.Versions[up.AppArchitecture] = up.Version;
                    appManifest[up.AppArchitecture]        = filesNames[up.AppArchitecture];

                    string srcFileName  = up.ID.ToString("X");
                    string destFileName = filesNames[up.AppArchitecture];
                    string dst          = Urls.AppUpdateDirURL + destFileName;

                    waitDlg.Message = $"Transfert du fichier {destFileName}. Cette opération peut durer plusieurs minutes.";
                    netEngin.Upload(dst, Path.Combine(AppPaths.AppUpdateFolder, srcFileName));
                    up.DeployTime = DateTime.Now;

                    ndxer.Source.Replace(ndxer.IndexOf(up.ID), up);
                }

                waitDlg.Message = "Transfert du manifest des applications...";
                UpdateEngin.WriteAppManifest(AppPaths.AppManifestPath, appManifest);
                netEngin.Upload(Urls.AppManifestURL, AppPaths.AppManifestPath);

                waitDlg.Message = "Transfert du manifest global...";
                UpdateEngin.WriteUpdateManifest(gManifest, AppPaths.ManifestPath);
                netEngin.Upload(Urls.ManifestURL, AppPaths.ManifestPath);
            };


            Action onSucces = () =>
            {
                m_tsbUploadAppUpdates.Enabled = false;
                waitDlg.Dispose();
            };

            Action <Task> onErr = t =>
            {
                waitDlg.Dispose();
                this.ShowError(t.Exception.InnerException.Message);
                TextLogger.Error(t.Exception.InnerException.Message);
            };


            var task = new Task(run, TaskCreationOptions.LongRunning);

            task.OnSuccess(onSucces);
            task.OnError(onErr);
            task.Start();

            waitDlg.ShowDialog(this);
        }
예제 #7
0
        private void AddPackage_Click(object sender, EventArgs e)
        {
            using (var dlg = new AppUpdateDialog())
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    IDatumProvider dp      = null;
                    var            waitDlg = new Jobs.ProcessingDialog();

                    Action buildUpdate = () =>
                    {
                        var bag = new FilesBag();

                        foreach (string file in dlg.Files)
                        {
                            waitDlg.Message = $"Préparation de {file}";
                            string relDir = Path.GetDirectoryName(file.Remove(0, dlg.RootFolder.Length + 1));

                            if (relDir.Length > 0)
                            {
                                bag.Add(file, relDir);
                            }
                            else
                            {
                                bag.Add(file);
                            }
                        }

                        waitDlg.Message = "Compression en cours...";
                        dp = AppContext.TableManager.AppUpdates.DataProvider;
                        dp.Connect();

                        var update = new AppUpdate(AppContext.TableManager.AppUpdates.CreateUniqID(), dlg.Version, dlg.AppArchitecture);
                        bag.Compress(Path.Combine(AppPaths.AppUpdateFolder, update.ID.ToString("X")));

                        NormalizeAppUpdates(update);
                        dp.Insert(update);
                    };


                    Action <Task> onErr = t =>
                    {
                        TextLogger.Error(t.Exception.InnerException.Message);
                        this.ShowError(t.Exception.InnerException.Message);

                        dp?.Dispose();
                        waitDlg.Dispose();
                    };

                    Action onSuccess = () =>
                    {
                        dp?.Dispose();
                        waitDlg.Dispose();
                    };


                    var task = new Task(buildUpdate, TaskCreationOptions.LongRunning);
                    task.OnSuccess(onSuccess);
                    task.OnError(onErr);
                    task.Start();

                    waitDlg.ShowDialog(this);
                }
        }
예제 #8
0
파일: DatumView.cs 프로젝트: Adel-dz/Hub
        void InsertColumns()
        {
            Assert(!InvokeRequired);

            IDataColumn[]  colHeader = m_dataProvider.DataSource.Columns;
            ColumnHeader[] columns   = new ColumnHeader[colHeader.Length];

            for (int i = 0; i < columns.Length; ++i)
            {
                columns[i] = new ColumnHeader()
                {
                    Text      = colHeader[i].Caption,
                    TextAlign = HorizontalAlignment.Center,
                    Tag       = colHeader[i].DataType,
                }
            }
            ;

            m_lvData.Columns.AddRange(columns);
        }

        void InsertItems(ListViewEntry[] items)
        {
            Assert(!InvokeRequired);

            m_lvData.Items.AddRange(items);

            TextLogger.Info("\nNbre d'enregistrements {0}.", m_dataProvider.Count);
        }

        void LoadDataAsync()
        {
            Func <ListViewEntry[]> loadData = () =>
            {
                ConnectProvider();
                return(LoadItems());
            };


            var waitClue = new Waits.WaitClue(this);

            Action <Task <ListViewEntry[]> > onError = t =>
            {
                Exception ex = t.Exception.InnerException;
                TextLogger.Error(ex.Message);

                waitClue.LeaveWaitMode();


                if (ex is CorruptedStreamException == false)
                {
                    ex = new CorruptedStreamException(innerException: ex);
                }

                throw ex;
            };


            Action <Task <ListViewEntry[]> > onSuccess = t =>
            {
                InsertColumns();

                ListViewEntry[] items = t.Result;
                InsertItems(items);
                waitClue.LeaveWaitMode();

                m_tslblStatus.Text = $"Nombre d'neregistrements: {m_lvData.Items.Count}";
            };


            waitClue.EnterWaitMode();

            var loading = new Task <ListViewEntry[]>(loadData, TaskCreationOptions.LongRunning);

            loading.ContinueWith(onSuccess,
                                 CancellationToken.None,
                                 TaskContinuationOptions.OnlyOnRanToCompletion,
                                 TaskScheduler.FromCurrentSynchronizationContext());

            loading.ContinueWith(onError, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted,
                                 TaskScheduler.FromCurrentSynchronizationContext());

            loading.Start();
        }

        IColumnSorter SorterFactory(int ndxColumn)
        {
            var           dataType = (ColumnDataType_t)m_lvData.Columns[ndxColumn].Tag;
            IColumnSorter sorter   = null;

            switch (dataType)
            {
            case ColumnDataType_t.Text:
                sorter = new TextColumnSorter(ndxColumn);
                break;

            case ColumnDataType_t.Integer:
                sorter = new IntegerColumnSorter(ndxColumn);
                break;

            case ColumnDataType_t.Float:
                sorter = new FloatColumnSorter(ndxColumn);
                break;

            case ColumnDataType_t.Time:
                sorter = new TimeColumnSorter(ndxColumn);
                break;
            }

            Assert(sorter != null);

            return(sorter);
        }