Exemplo n.º 1
0
        public void SaveBode()
        {
            string Date = OscilloscopeViewModel.Day(DateTime.Now.Day) + ' ' + OscilloscopeViewModel.MonthTrans(DateTime.Now.Month) + ' ' + DateTime.Now.Year.ToString();
            string path = "\\MotorController\\Charts\\" + Date + ' ' + DateTime.Now.ToString("HH:mm:ss");

            path     = (path.Replace('-', ' ')).Replace(':', '_');
            path    += ".csv";
            path     = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + path;
            filePath = path;

            Thread.Sleep(100);
            StringBuilder sb = new StringBuilder();

            float[] yxls  = _excel_Y1_List.ToArray();
            float[] yxls2 = _excel_Y2_List.ToArray();

            string[] xstring = new string[_excel_X_List.Count + 1];

            string[] ystring = new string[_excel_Y1_List.Count + 1];

            xstring    = new string[_excel_X_List.Count + 1];
            ystring[0] = "Y1 - Magnitude (dB)";


            string[] ystring2 = new string[_excel_Y2_List.Count + 1];

            xstring     = new string[_excel_X_List.Count + 1];
            ystring2[0] = "Y2 - Phase (Degree)";

            xstring[0] = "Time";


            for (int i = 1; i < _excel_X_List.Count; i++)
            {
                xstring[i]  = (_excel_X_List.ElementAt(i)).ToString(CultureInfo.CurrentCulture);
                ystring[i]  = yxls[i - 1].ToString(CultureInfo.CurrentCulture);
                ystring2[i] = yxls2[i - 1].ToString(CultureInfo.CurrentCulture);
                sb.AppendLine(string.Join(delimiter, xstring[i - 1], ystring[i - 1], ystring2[i - 1]));
            }
            System.Windows.Forms.SaveFileDialog saveFile = new System.Windows.Forms.SaveFileDialog();
            saveFile.Filter   = "Excel (*.xlsx)|*.csv";
            saveFile.FileName = path;
            var t = new Thread((ThreadStart)(() =>
            {
                if (saveFile.ShowDialog() == DialogResult.OK)
                {
                    filePath = saveFile.FileName;
                }
                else
                {
                    return;
                }
                File.AppendAllText(filePath, sb.ToString());
                sb.Clear();
            }));

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }
Exemplo n.º 2
0
        private void ErrorLog(StackTrace _stackTrace, Exception _exception, String _functionName)
        {
            string Date = OscilloscopeViewModel.Day(DateTime.Now.Day) + ' ' + OscilloscopeViewModel.MonthTrans(DateTime.Now.Month) + ' ' + DateTime.Now.Year.ToString();
            string path = "\\ErrorLog\\";

            path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + path;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path  = "\\ErrorLog\\";
            path += Date + ' ' + DateTime.Now.ToString("HH:mm:ss");
            path  = (path.Replace('-', ' ')).Replace(':', '_');
            path  = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + path;
            path += ".txt";


            try
            {
                if (!Directory.Exists(path))
                {
                    using (StreamWriter writer = new StreamWriter(path))
                    {
                        writer.WriteLine("***  Function Name ***");
                        writer.WriteLine(_functionName);
                        writer.WriteLine(_exception.Message);
                        writer.WriteLine("***  Function Name ***");

                        for (int i = _stackTrace.FrameCount - 1; i >= 0; i--)
                        {
                            writer.WriteLine(_stackTrace.GetFrame(i).GetMethod().Name);
                        }
                    }
                }
            }
            catch { }
        }