/// <summary>
        /// 可选择使用 DES/RSA 双向加密函数
        /// </summary>
        /// <param name="str">待加密的字符串</param>
        /// <param name="keyValue">对称加密密钥(密钥长度能且只能是8个字母) </param>
        /// <param name="privateKeyFilePath">非对称加密的私钥文件地址</param>
        /// <returns>string</returns>
        public static string EncryptString(string str, string keyValue, string privateKeyFilePath)
        {
            string strResult = str;

            if (!StringsFunction.CheckValiable(str))
            {
                return(strResult);
            }


            // 判断是否指定了对称加密的密钥, 指定则采用 DES 对称加密算法进行加密
            if (StringsFunction.CheckValiable(keyValue))
            {
                DESCrypto dc = new DESCrypto();
                strResult = dc.EncryptString(strResult, keyValue, keyValue);
            }


            // 判断非对称加密的私钥文件是否指定,指定则使用非对称加密算法(RSA)对其进行二次加密
            if (StringsFunction.CheckValiable(privateKeyFilePath))
            {
                string          privateKey = FileOP.ReadFile(GetRealFile(privateKeyFilePath));
                Regex           r          = new Regex(@"<Modulus>(.*?)</Exponent>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                MatchCollection mc         = r.Matches(privateKey);
                string          publicKey  = "<RSAKeyValue><Modulus>" + mc[0].Groups[1].Value + "</Exponent></RSAKeyValue>";


                RSACrypto rc = new RSACrypto();
                strResult = rc.RSAEncrypt(publicKey, strResult);
            }

            return(strResult);
        }
        /// <summary>
        /// 可选择使用 DES/RSA 双向解密函数
        /// </summary>
        /// <param name="str">待解密的字符串</param>
        /// <param name="privateKeyFilePath">非对称加密的私钥文件地址</param>
        /// <param name="keyValue">对称加密密钥(密钥长度能且只能是8个字母)</param>
        /// <returns>string</returns>
        public static string DecryptString(string str, string privateKeyFilePath, string keyValue)
        {
            string strResult = str;

            if (!StringsFunction.CheckValiable(str))
            {
                return(strResult);
            }


            // 判断非对称加密的私钥文件是否指定,指定则使用非对称加密算法(RSA)对其进行解密
            if (StringsFunction.CheckValiable(privateKeyFilePath))
            {
                string privateKey = FileOP.ReadFile(GetRealFile(privateKeyFilePath));

                RSACrypto rc = new RSACrypto();
                strResult = rc.RSADecrypt(privateKey, strResult);
            }


            // 判断是否指定了对称加密的密钥, 指定则采用 DES 对称加密算法进行解密
            if (StringsFunction.CheckValiable(keyValue))
            {
                DESCrypto dc = new DESCrypto();
                strResult = dc.DecryptString(strResult, keyValue);
            }

            return(strResult);
        }
Exemple #3
0
        public static void MakeDLL()
        {
            if (FileOP.IsExist(DLLWork.DLLName, FileOPMethod.File))
            {
                FileOP.Delete(DLLWork.DLLName, FileOPMethod.File);
            }
            Type type = MethodBase.GetCurrentMethod().DeclaringType;

            string _namespace = type.Namespace;
            //获得当前运行的Assembly
            Assembly _assembly = Assembly.GetExecutingAssembly();

            //根据名称空间和文件名生成资源名称
#if DEBUG
            string           resourceName = _namespace + ".DebugDLL.KeyDAL.dll";// +DLLWork.DLLName;
            System.IO.Stream so           = new System.IO.FileStream(DLLWork.DLLName, System.IO.FileMode.Create);
#else
            string           resourceName = _namespace + ".ReleaseDLL.KeyDAL.vmp.dll";// + DLLWork.DLLName;
            System.IO.Stream so           = new System.IO.FileStream(DLLWork.DLLName, System.IO.FileMode.Create);
#endif
            //根据资源名称从Assembly中获取此资源的Stream
            Stream stream = _assembly.GetManifestResourceStream(resourceName);

            //byte[] dll=Properties.Resources.KeyDAL;

            //so.Write(dll, 0, dll.Length);
            stream.CopyTo(so);
            so.Close();
        }
Exemple #4
0
        public static int MaxUsage = -1;//最大使用空间,单位为M
        public static void AddTextLog(string strLog, string file, bool newSection)
        {
            FileInfo f = new FileInfo(file);

            // 如果文件所在的文件夹不存在则创建文件夹
            if (!Directory.Exists(f.DirectoryName))
            {
                Directory.CreateDirectory(f.DirectoryName);
            }
            FileStream fs;

            try
            {
                fs = new FileStream(file, FileMode.Open);
            }
            catch (FileNotFoundException)
            {
                if (MaxUsage != -1)//有使用空间的限制
                {
                    while (true)
                    {
                        long[] dir   = FileOP.getDirInfos(f.DirectoryName);
                        int    usage = (int)(dir[0] / 1024 / 1024);
                        if (usage > MaxUsage)
                        {
                            DataTable dtfile  = FileOP.getDirectoryInfos(f.DirectoryName, FileOPMethod.File);
                            DataRow[] drs     = dtfile.Select("", "createTime DESC");
                            string    delFile = f.DirectoryName + "\\" + drs[0]["name"].ToString();
                            File.Delete(delFile);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                fs = new FileStream(file, FileMode.Create);
            }
            catch
            {
                return;
            }
            StreamWriter sw = new StreamWriter(fs);
            //开始写入
            DateTime dt = DateTime.Now;

            fs.Seek(0, SeekOrigin.End);
            if (newSection)
            {
                sw.WriteLine("---------------------" + dt.ToString() + "-------------------");
            }
            sw.WriteLine(strLog);
            //清空缓冲区
            sw.Flush();
            //关闭流
            sw.Close();
            fs.Close();/**/
        }
Exemple #5
0
        private void WFSession_Load()
        {
            if (FileOP.IsExist(this.filePath, FileOPMethod.File))
            {
                // 文件存在,将当前 XML 文件中的数据读入到 DataSet 中
                // ds.ReadXml(this.filePath, XmlReadMode.DiffGram);
                DataTable dt = ConvertXmlToDataTable(this.rootName);

                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    DataTable dd = ConvertXmlToDataTable("//" + this.rootName + "/" + dt.Columns[i].ColumnName);
                    dd.TableName = dt.Columns[i].ColumnName;

                    this.SessionDs.Tables.Add(dd);
                }

                WFGlobal.writeLine.Append("公有表 " + dt.Columns.Count + " 个\r\n");
            }
            else
            {
                // 文件不存在,开始创建
                OperateXml oXml = new OperateXml();
                oXml.filePath = this.filePath;
                oXml.CreateXml(this.rootName);

                DataTable dt = new DataTable(this.tableName);
                DataRow   dr;

                dr = dt.NewRow();
                dt.Rows.Add(dr);
                this.SessionDs.Tables.Add(dt);

                oXml.xPath = this.rootName;
                oXml.CreateNode(this.tableName, dt);
            }


            if (this.SessionDs.Tables.Contains(this.tableName))
            {
            }
            else
            {
                // 当前操作的表不存在,创建该表
                DataTable dt = new DataTable(this.tableName);
                DataRow   dr;

                dr = dt.NewRow();
                dt.Rows.Add(dr);
                this.SessionDs.Tables.Add(dt);

                OperateXml oXml = new OperateXml();
                oXml.filePath = this.filePath;
                oXml.xPath    = this.rootName;
                oXml.CreateNode(this.tableName, dt);
            }
        }
Exemple #6
0
        /// <summary>
        /// Merge all tiff images (multi-page or not) to a multi-page tif.
        /// </summary>
        /// <param name="targetPath">The target path to save the merged images to.</param>
        /// <param name="deleteSource">Delete source files when flag is true.</param>
        /// <param name="filePaths">The image\s to merge.</param>
        /// <returns>true when successfull.</returns>
        public static bool MergeImages(String targetPath, bool deleteSource, params String[] filePaths)
        {
            try
            {
                if (filePaths.Length <= 0)
                {
                    throw new Exception("No files specified in method: " + MethodBase.GetCurrentMethod().Name);
                }
                else if (filePaths.Length == 1)
                {
                    // TODO: use 3rd pary software to make the image compatiable (dpi bw etc)
                    if (deleteSource)
                    {
                        File.SetAttributes(filePaths[0], FileAttributes.Normal);
                        File.Move(filePaths[0], targetPath);
                    }
                    else
                    {
                        File.Copy(filePaths[0], targetPath);
                        File.SetAttributes(targetPath, FileAttributes.Normal);
                    }
                }
                else
                {
                    FileOP fop = new FileOP();
                    fop.MergeImageFile(targetPath, filePaths);
                    // TODO: use 3rd pary software to make the image compatiable (dpi bw etc)

                    if (deleteSource)
                    {
                        foreach (String s in filePaths)
                        {
                            try
                            {
                                if (File.Exists(s))
                                {
                                    File.SetAttributes(s, FileAttributes.Normal);
                                    File.Delete(s);
                                }
                            }
                            catch (Exception ep)
                            {
                                ILog.LogError(ep);
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                ILog.LogError(ex);
                return(false);
            }
        }
        public void ReadFileTest()
        {
            // Arrange
            FileOP.LoadFile(ReadFileTestFile);
            DataTable expected = CreateDataTable();

            // Act
            DataTable actual = FileOP.ReadFile();

            // Assert
            Assert.IsTrue(AreDataTablesEqual(actual, expected));
        }
        public void WriteLessLinesToFileTest()
        {
            // Arrange
            WriteLessLinesToFileTestReset();
            DataTable dataTable = CreateDataTable();

            // Act
            FileOP.WriteToFile(dataTable);

            // Assert
            Assert.IsTrue(AreCSVsEqual(TestFile, WriteToFileExpected));
        }
Exemple #9
0
        public void LoadFileWithKeyTest()
        {
            // Arrange
            LoadFileWithKeyTestReset();
            DirectoryInfo keyFileInfo = new DirectoryInfo(TestKeyFile);
            string        keyFilePath = keyFileInfo.FullName;

            // Act

            // Working in the master form
            ApplicationSession.FindElementByName("OpenFileButton").Click();

            // Save current working file if one is opened
            try {
                Thread.Sleep(TimeSpan.FromSeconds(2)); // Wait for 1 second in case save as dialog appears
                ApplicationSession.FindElementByName("No").Click();
            }
            catch { }

            Thread.Sleep(TimeSpan.FromSeconds(5));

            // Working in the load dialog
            ApplicationSession.FindElementByClassName("Edit").SendKeys(TargetFileLocation + TestFileGZ);
            ApplicationSession.FindElementByClassName("Button").FindElementByName("Open").Click();

            Thread.Sleep(TimeSpan.FromSeconds(2));

            // Working in enter password for file form
            ApplicationSession.FindElementByName("PasswordEntry").SendKeys("password");
            ApplicationSession.FindElementByName("FindKeyFile").Click();

            Thread.Sleep(TimeSpan.FromSeconds(2));

            // Working in Windows' open file dialog
            ApplicationSession.FindElementByClassName("Edit").SendKeys(keyFilePath);
            ApplicationSession.FindElementByClassName("Button").FindElementByName("Open").Click();

            Thread.Sleep(TimeSpan.FromSeconds(5));

            // Working in enter password for file form
            ApplicationSession.FindElementByName("Ok").Click();

            Thread.Sleep(TimeSpan.FromSeconds(5));

            // Assert
            Assert.AreEqual(FileOP.GetFile(), TestFileCSV);

            ApplicationSession.FindElementByName("LockButton").Click();
            Thread.Sleep(TimeSpan.FromSeconds(2));
            ApplicationSession.FindElementByName("Yes").Click();
            Thread.Sleep(TimeSpan.FromSeconds(5));
        }
        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            SystemParam.DeviceID = InputBox.ShowInputBox("请设定当前测试器件的芯片编号", SystemParam.DeviceID);
            iniFileOP.Write("System Run", "DeviceID", SystemParam.DeviceID);
            strCCDINIPath = SystemParam.ccdParamFilePath + SystemParam.DeviceID + ".ini";
            string Osat = iniFileOP.Read("CCD Param", "Osat", strCCDINIPath);

            if (!FileOP.IsExist(strCCDINIPath, FileOPMethod.File))
            {
                FileOP.CopyFile(System.Windows.Forms.Application.StartupPath + "\\ccdParamFileTemplate.ini", strCCDINIPath);
            }
            CCDTest();
        }
        /// <summary>
        /// Deletes files left over from previous tests and creates a fresh file for testing.
        /// </summary>
        private void WriteLessLinesToFileTestReset()
        {
            if (File.Exists(TestFile))
            {
                File.Delete(TestFile);
            }

            DirectoryInfo TestCSVInfo = new DirectoryInfo(WriteLessLinesToFileBase);

            File.Copy(TestCSVInfo.FullName, TestFile);

            FileOP.LoadFile(TestFile);

            return;
        }
        /// <summary>
        /// Removes the uncompressed file created by previous decompression tests
        /// and creates an compressed file to be tested with.
        /// </summary>
        private void DecompressTestReset()
        {
            if (!File.Exists(CompressedFile))
            {
                DirectoryInfo TestCSVInfo = new DirectoryInfo(OriginalCompressedFile);
                File.Copy(TestCSVInfo.FullName, CompressedFile);
            }

            if (File.Exists(UncompressedFile))
            {
                File.Delete(UncompressedFile);
            }

            FileOP.LoadFile(CompressedFile);

            return;
        }
Exemple #13
0
        public void LoadFileTest()
        {
            // Arrange
            LoadFileTestReset();

            // Act

            // Working in the master form
            ApplicationSession.FindElementByName("OpenFileButton").Click();

            // Save current working file if one is opened
            try {
                Thread.Sleep(TimeSpan.FromSeconds(2)); // Wait for 1 second in case save as dialog appears
                ApplicationSession.FindElementByName("No").Click();
            }
            catch { }
            Thread.Sleep(TimeSpan.FromSeconds(5));

            // Working in the load dialog
            ApplicationSession.FindElementByClassName("Edit").SendKeys(TargetFileLocation + TestFileGZ);
            ApplicationSession.FindElementByClassName("Button").FindElementByName("Open").Click();

            Thread.Sleep(TimeSpan.FromSeconds(5));

            // Working in enter password for file form
            ApplicationSession.FindElementByName("PasswordEntry").SendKeys("password");
            ApplicationSession.FindElementByName("Ok").Click();

            Thread.Sleep(TimeSpan.FromSeconds(5));

            // Assert
            Assert.AreEqual(TestFileCSV, FileOP.GetFile());

            ApplicationSession.FindElementByName("LockButton").Click();
            Thread.Sleep(TimeSpan.FromSeconds(2));
            ApplicationSession.FindElementByName("Yes").Click();
            Thread.Sleep(TimeSpan.FromSeconds(5));
        }
Exemple #14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string DeviceID, PocketIndex;
            string ret = "";

            try
            {
                DeviceID    = Request.QueryString["DeviceID"];
                PocketIndex = Request.QueryString["PocketIndex"];
                //信息|用户id|实验id,实验名,实验室;
                if (string.IsNullOrEmpty(DeviceID) || string.IsNullOrEmpty(PocketIndex))//没有这两个变量
                {
                    ret = webAPIFunc.GetRetString(ErrType.MissParam);
                    Response.Write(ret);
                    return;
                }
                int index;
                if (!int.TryParse(PocketIndex, out index))
                {
                    ret = webAPIFunc.GetRetString(ErrType.ErrParam);
                    Response.Write(ret);
                    return;
                }
                if (index == 1)
                {
                    DeviceInfoData did = DeviceInfoDataDBOption.Get(DeviceID);
                    if (did == null)
                    {
                        ret = webAPIFunc.GetRetString(ErrType.NoRegDevice);
                        Response.Write(ret);
                        return;
                    }
                }
                string fileName = Global.hexBINFolder + DeviceID + ".bin";
                if (!FileOP.IsExist(fileName, FileOPMethod.File))
                {
                    ret = webAPIFunc.GetRetString(ErrType.NoHexBin);
                    Response.Write(ret);
                    return;
                }
                FileInfo f;
                f = new FileInfo(fileName);
                Stream stream = File.OpenRead(f.FullName);
                byte[] pBuf   = new byte[stream.Length];
                stream.Read(pBuf, 0, (int)stream.Length);
                stream.Close();
                if (index == 0)
                {
                    ret = webAPIFunc.GetRetString(ErrType.retOK, pBuf.Length.ToString());
                    Response.Write(ret);
                    return;
                }
                else
                {
                    int    size  = 1024 * 5; // 0480;
                    int    count = pBuf.Length / size;
                    int    left  = pBuf.Length % size;
                    int    x     = size * (index - 1);
                    string str;
                    if (index > count)//最后一包
                    {
                        //ret = ((int)ErrType.retOK).ToString() + ",";
                        str = StringsFunction.byteToHexStr(pBuf, x, left, "");
                        Response.Write(webAPIFunc.GetRetString(ErrType.retOK, str));
                        return;
                    }
                    else
                    {
                        //ret = ((int)ErrType.retOK).ToString() + ",";
                        str = StringsFunction.byteToHexStr(pBuf, x, size, "");
                        ret = ret + str;
                        //Debug.WriteLine(ret);
                        Response.Write(webAPIFunc.GetRetString(ErrType.retOK, str));
                        return;
                    }
                }
            }
            catch (System.Exception ex)
            {
                ret = webAPIFunc.GetRetString(ErrType.UnkownErr);
                TextLog.AddTextLog("GetHexData_Unkown:" + ex.Message, Global.txtLogFolder + "Update.txt", true);
            }
            Response.Write(ret);
        }
        void CCD3TTest()
        {
            CCD3TTestResult.Reset();
            UIHide();
            CCD3TTestListView.Visible = true;
            for (int i = 0; i < 4; i++)
            {
                if (!ParamTestList[i])
                {
                    CCDParamTestListView.Items[4 + i].SubItems[1].Text      = "不进行测试";
                    CCDParamTestListView.Items[4 + 5 + i].SubItems[1].Text  = "不进行测试";
                    CCDParamTestListView.Items[4 + 10 + i].SubItems[1].Text = "不进行测试";
                }
                else
                {
                    CCDParamTestListView.Items[4 + i].SubItems[1].Text      = "待测";
                    CCDParamTestListView.Items[4 + 5 + i].SubItems[1].Text  = "待测";
                    CCDParamTestListView.Items[4 + 10 + i].SubItems[1].Text = "待测";
                }
            }

            CCDParamTestListView.Items[1].SubItems[1].Text = CCDParamTestResult.K.ToString();
            CCDParamTestListView.Items[2].SubItems[1].Text = SystemParam.L.ToString();
            if (ParamTestList[0])//暗电流
            {
                CCD3TTestResult.miu_I_miu   = new double[3];
                CCD3TTestResult.miu_I_delta = new double[3];
            }
            //DSNU
            if (ParamTestList[1] || ParamTestList[2])
            {
                CCD3TTestResult.DSNU = new double[3];
            }
            //FPN
            if (ParamTestList[2])
            {
                CCD3TTestResult.FPN = new double[3];
            }
            //读出噪声
            if (ParamTestList[3])
            {
                CCD3TTestResult.delta_raed = new double[3];
            }

            for (int i = 0; i < 3; i++)
            {
                while (!double.TryParse(InputBox.ShowInputBox("请设定温度" + (i + 1).ToString(), "25"), out CCD3TTestResult.T[i]))
                {
                    MessageBox.Show("设定温度有误,请重新设定");
                }
                if (ParamTestList[0])//暗电流
                {
                    CCDParamTest_Collect_DarkI();
                    CCDParamTest_Calc_DarkI();
                    CCD3TTestListView.Items[4 + 5 * i].SubItems[1].Text = CCDParamTestResult.miu_I_miu.ToString() + "; " + CCDParamTestResult.miu_I_delta.ToString();
                    CCD3TTestResult.miu_I_miu[i]   = CCDParamTestResult.miu_I_miu;
                    CCD3TTestResult.miu_I_delta[i] = CCDParamTestResult.miu_I_delta;
                    FileOP.CopyFile(SystemParam.TempPicPath + "DarkI1.jpg", SystemParam.TempPicPath + "DarkI1_T" + (i + 1).ToString() + ".jpg");
                    FileOP.CopyFile(SystemParam.TempPicPath + "DarkI2.jpg", SystemParam.TempPicPath + "DarkI2_T" + (i + 1).ToString() + ".jpg");
                }
                //DSNU,FPN,读出噪声
                if (ParamTestList[1] || ParamTestList[2] || ParamTestList[3])
                {
                    CCDParamTest_Collect_L(false);
                    CCDParamTest_Calc_L_bLight = false;
                    ParamTestWaitingProc       = new WaitingProc();
                    WaitingProcFunc wpf = null;
                    ParamTestWaitingProc.MaxProgress = SystemParam.L;
                    wpf = new WaitingProcFunc(CCDParamTest_Calc_L);
                    if (!ParamTestWaitingProc.Execute(wpf, "处理暗场空域测试结果", WaitingType.With_ConfirmCancel, "是否取消?"))
                    {
                        textBox1.AppendText("用户终止自动测试\r\n");
                        return;
                    }
                    //DSNU
                    if (ParamTestList[1] || ParamTestList[2])
                    {
                        CCD3TTestResult.DSNU[i] = Math.Sqrt(CCDParamTestResult.L_S_y_dark) / CCDParamTestResult.K;
                        CCD3TTestListView.Items[4 + 5 * i + 1].SubItems[1].Text = CCD3TTestResult.DSNU[i].ToString();
                    }
                    //FPN
                    if (ParamTestList[2])
                    {
                        CCDParamTest_Collect_MinMax();
                        CCDParamTest_Calc_FWC();
                        CCD3TTestResult.FPN[i] = CCD3TTestResult.DSNU[i] / CCDParamTestResult.FWC;
                        CCD3TTestListView.Items[4 + 5 * i + 2].SubItems[1].Text = CCD3TTestResult.FPN[i].ToString();
                    }
                    //读出噪声
                    if (ParamTestList[3])
                    {
                        CCD3TTestResult.delta_raed[i] = Math.Sqrt(CCDParamTestResult.delta_mid) / CCDParamTestResult.K;
                        CCD3TTestListView.Items[4 + 5 * i + 3].SubItems[1].Text = CCD3TTestResult.delta_raed[i].ToString();
                    }
                }
            }
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                TestReport.MakeReport3T(saveFileDialog1.FileName);
                textBox1.AppendText("自动测试结束,测试报告保存位置为:\r\n");
                textBox1.AppendText(saveFileDialog1.FileName);
            }
            else
            {
                textBox1.AppendText("自动测试结束,用户未保存报告\r\n");
            }
            MessageBox.Show("三温测试完成");
        }
Exemple #16
0
        private void button1_Click(object sender, EventArgs e)
        {
            FileOP fileOP = new FileOP();

            msg = fileOP.OpenPic();
        }