Esempio n. 1
0
        //Is user allowed to save to XML document
        public bool CanSave(object obj)
        {
            TextValidation validation = new TextValidation();

            if (filePath == null)
            {
                return(false);
            }
            foreach (Employee employee in Employees)
            {
                if (!validation.ValidateEmployee(employee))
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 2
0
        private void BtnDecrypt_Click(object sender, EventArgs e)
        {
            TypesOfCiphers typesOfCipher = TypesOfCiphers.RailFence;

            if (rbRailFence.Checked)
            {
                typesOfCipher = TypesOfCiphers.RailFence;
            }
            else if (rbRotatingSquare.Checked)
            {
                typesOfCipher = TypesOfCiphers.RotatingSquare;
            }
            else if (rbVigenerCipher.Checked)
            {
                typesOfCipher = TypesOfCiphers.Vigenere;
            }

            tbKey.Text      = KeyValidation.ModifyKey(tbKey.Text, typesOfCipher).ToString();
            rtbSrcText.Text = TextValidation.ModifyText(rtbSrcText.Text, typesOfCipher);

            if (cbUseDataInRcb.Checked)
            {
                rtbResText.Text = MainController.Decrypt(rtbSrcText.Text, tbKey.Text,
                                                         typesOfCipher);
            }
            else
            {
                try
                {
                    MainController.Decrypt(tbPathToSrcFile.Text, tbPathToResFile.Text,
                                           tbKey.Text, typesOfCipher);
                }
                catch (ArgumentException)
                {
                    MessageBox.Show("Incorrect file path entered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (IOException)
                {
                    MessageBox.Show("Incorrect file path entered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Encrypts data from a file using the selected algorithm and writes the result to another file.
        /// </summary>
        /// <param name="pathToSrcFile">The path to the file with the text to be encrypted.</param>
        /// <param name="pathToDestFile">The path to the file where you want to save the encryption result.</param>
        /// <param name="key">The key for the encryption algorithm.</param>
        /// <param name="typeOfChiper">The name of the encryption algorithm.</param>
        public static void Encrypt(string pathToSrcFile, string pathToDestFile,
                                   string key, TypesOfCiphers typeOfChiper)
        {
            string plaintext;

            try
            {
                plaintext = File.ReadAllText(pathToSrcFile);
            }
            catch (ArgumentException)
            {
                throw new ArgumentException();
            }
            catch (IOException)
            {
                throw new IOException();
            }

            plaintext = TextValidation.ModifyText(plaintext, typeOfChiper);

            string ciphertext = PerformAction(plaintext, key, typeOfChiper, Model.Ciphers.Action.Encrypt);

            File.WriteAllText(pathToDestFile, ciphertext);
        }
        /// <summary>
        /// 处理关注事件
        /// </summary>
        /// <param name="xmlModel"></param>
        /// <returns></returns>
        public string SubscribeHandle(ref Dictionary <string, string> xmlModel)
        {
            string result        = "";                       //返回欢迎语内容
            string wxappusername = xmlModel["ToUserName"];   //事件发给哪个开发者微信号(注意这里不是公众号的AppID,而是公众号的微信号)
            string wxopenid      = xmlModel["FromUserName"]; //事件是哪个粉丝发起的(粉丝的openid)
            string strCreateTime = xmlModel["CreateTime"];

            if (string.IsNullOrEmpty(strCreateTime))
            {
                //无消息创建时间,无法排重,放弃处理
                return("");
            }
            double wxcreatetime;

            if (!double.TryParse(strCreateTime, out wxcreatetime))
            {
                //无法将createtime转换成功,无法排重,放弃处理
                return("");
            }
            string wxappid = "";

            DALWXMessageHandleBasic mydal = new DALWXMessageHandleBasic();
            //事件消息排重
            bool success = true;

            success = mydal.EventMsgPreventDuplicates(wxopenid, wxcreatetime);
            if (!success)
            {
                //事件消息排重失败,放弃处理
                return("");
            }


            wxappid = WXApiInfo.wxappid;

            CallWXInterface wxinterface = new CallWXInterface();
            //获取粉丝信息,这一步是必须的,因为在明文模式下,要防止虚构粉丝数据
            WXFansInfo wxuser = wxinterface.GetUserInfo(wxappid, wxopenid);

            if (wxuser == null || wxuser.errcode != 0)
            {
                return("");
            }


            //根据微信POST过来的事件数据,判断是普通关注还是带参数的二维码关注,如果是带参数二维码关注,需要读取相应的二维码应用信息
            string EventKey = "";

            if (xmlModel.ContainsKey("EventKey"))
            {
                EventKey = xmlModel["EventKey"];
            }

            //注意微信的坑:普通关注的事件是有EventKey的(而文档上面没有)。带参数二维码扫描关注的EventKey是qrscene_开头的。
            #region 根据二维码应用信息来处理
            //WXUser bllWXUser = new WXUser();
            if (string.IsNullOrEmpty(EventKey) || !TextValidation.CheckStringByRegexp(EventKey, "qrscene_.+"))
            {
                //普通关注
                string          errmsg = "";
                BLLWXFansManage mybll  = new BLLWXFansManage();
                mybll.SubscribeLog(wxopenid, 1, ref errmsg);//关注日志
                success = mybll.Subscribe(wxopenid, wxuser, ref errmsg);
                if (success)
                {
                    result = "欢迎关注每通系统!";
                }
                else
                {
                    result = errmsg;
                }
            }
            else
            {
                //二维码扫描
                //result = QRCodeApplication(wxopenid, EventKey.Replace("qrscene_", ""), wxuser);
                string          errmsg = "";
                BLLWXFansManage mybll  = new BLLWXFansManage();
                mybll.SubscribeLog(wxopenid, 1, ref errmsg);//关注日志
                success = mybll.QRCodeApplication(wxopenid, EventKey.Replace("qrscene_", ""), wxuser, ref errmsg);
                if (success)
                {
                    result = errmsg;
                }
                else
                {
                    result = errmsg;
                }
            }
            #endregion


            //因为对于关注粉丝,可以自动发送欢迎语或其他内容,所以这里可返回内容
            string rspxml = "";
            if (!string.IsNullOrEmpty(result))
            {
                rspxml = "<xml><ToUserName><![CDATA[" + xmlModel["FromUserName"] + "]]></ToUserName><FromUserName><![CDATA[" + xmlModel["ToUserName"] + "]]></FromUserName><CreateTime>" + xmlModel["CreateTime"] + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + result + "]]></Content><FuncFlag>0</FuncFlag></xml>";
            }
            return(rspxml);
        }