예제 #1
0
    public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu)
    {
        if (!(provider is JScriptCodeProvider))
        {
            // GENERATES (C#):
            //
            //  namespace Namespace1 {
            //
            //      public class TEST {
            //
            //          public static void Main() {
            //              // the following is repeated Char.MaxValue times
            //              System.Console.WriteLine(/* character value goes here */);
            //          }
            //      }
            //  }
            CodeNamespace ns = new CodeNamespace("Namespace1");
            ns.Imports.Add(new CodeNamespaceImport("System"));
            cu.Namespaces.Add(ns);

            CodeTypeDeclaration cd = new CodeTypeDeclaration("TEST");
            cd.IsClass = true;
            ns.Types.Add(cd);
            CodeEntryPointMethod methodMain = new CodeEntryPointMethod();

            for (int i = 0; i < Char.MaxValue; i += 50)
            {
                methodMain.Statements.Add(CDHelper.ConsoleWriteLineStatement(new CodePrimitiveExpression(System.Convert.ToChar(i))));
            }

            cd.Members.Add(methodMain);
        }
    }
예제 #2
0
        void changePassword(string loginName, string password, string newPassword)
        {
            if (AccountID == We7Helper.EmptyGUID && String.Compare(loginName, SiteConfigs.GetConfig().AdministratorName, true) == 0)
            {
                if (CDHelper.AdminPasswordIsValid(password))
                {
                    SiteConfigInfo si       = SiteConfigs.GetConfig();
                    bool           isHashed = si.IsPasswordHashed;
                    if (isHashed != IsHashedPasswordCheckBox.Checked)
                    {
                        si.IsPasswordHashed = IsHashedPasswordCheckBox.Checked;
                    }
                    if (IsHashedPasswordCheckBox.Checked)
                    {
                        si.AdministratorKey = Security.Encrypt(newPassword);
                    }
                    else
                    {
                        si.AdministratorKey = newPassword;
                    }

                    SiteConfigs.SaveConfig(si);
                    //CDHelper.UpdateSystemInformation(si);

                    ShowMessage("您的密码已修改成功。");
                }
                else
                {
                    ShowMessage("对不起,您输入的旧密码不正确!");
                }
            }
            else
            {
                Account act = AccountHelper.GetAccountByLoginName(loginName);
                if (act == null)
                {
                    ShowMessage("指定的用户不存在。");
                }
                else if (!AccountHelper.IsValidPassword(act, password))
                {
                    ShowMessage("对不起,您输入的旧密码不正确!");
                }
                else if (act.State != 1)
                {
                    ShowMessage("该帐户不可用。");
                }
                else
                {
                    act.IsPasswordHashed = IsHashedPasswordCheckBox.Checked;
                    AccountHelper.UpdatePassword(act, newPassword);

                    //记录日志
                    string content = string.Format("修改了“{0}”的密码", act.LoginName);
                    AddLog("修改密码", content);

                    ShowMessage("您的密码已修改成功。");
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 验证用户
        /// </summary>
        void Authenticate()
        {
            if (String.Compare(LoginName, SiteConfigs.GetConfig().AdministratorName, false) == 0)
            {
                if (CDHelper.AdminPasswordIsValid(Password))
                {
                    Security.SetAccountID(We7Helper.EmptyGUID);
                    UserName = SiteConfigs.GetConfig().AdministratorName;
                    IsSignIn = true;
                }
                else
                {
                    IsSignIn = false;
                    Message  = "密码错误";
                }
            }
            else
            {
                if (Request["Authenticator"] != null && Request["accountID"] != null)
                {
                    SSORequest ssoRequest = SSORequest.GetRequest(HttpContext.Current);
                    string     actID      = ssoRequest.AccountID;
                    if (Authentication.ValidateEACToken(ssoRequest) && !string.IsNullOrEmpty(actID) && We7Helper.IsGUID(actID))
                    {
                        Security.SetAccountID(actID, IsPersist);
                        UserName = ssoRequest.UserName;
                        IsSignIn = true;
                    }
                    else if (Request["message"] != null)
                    {
                        Message  = Request["message"];
                        IsSignIn = false;
                        return;
                    }
                }
                else
                {
                    IAccountHelper AccountHelper = AccountFactory.CreateInstance();

                    string[] result = AccountHelper.Login(LoginName, Password);

                    if (result[0] == "false")
                    {
                        Message  = result[1];
                        IsSignIn = false;
                    }
                    else
                    {
                        IsSignIn = true;
                        UserName = AccountHelper.GetAccount(result[1], new string[] { "LoginName" }).LoginName;
                        Response.Redirect(ReturnUrl);
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// 原始登录的方法
        /// </summary>
        /// <param name="loginName">本地用户名</param>
        /// <param name="password">本地用户的密码</param>
        /// <param name="checkPassword">是否校验密码</param>
        void LoginAction(string loginName, string password)
        {
            if (String.IsNullOrEmpty(loginName) || String.IsNullOrEmpty(loginName.Trim()))
            {
                ShowMessage("错误:用户名不能为空!");
                return;
            }

            if (String.IsNullOrEmpty(password) || String.IsNullOrEmpty(password.Trim()))
            {
                ShowMessage("错误:密码不能为空!");
                return;
            }

            if (GeneralConfigs.GetConfig().EnableLoginAuhenCode == "true" && this.CodeNumberTextBox.Text != Request.Cookies["AreYouHuman"].Value)
            {
                ShowMessage("错误:您输入的验证码不正确,请重新输入!");
                this.CodeNumberTextBox.Text           = "";
                Response.Cookies["AreYouHuman"].Value = CaptchaImage.GenerateRandomCode();
                return;
            }

            bool loginSuccess = false;

            if (CheckLocalAdministrator(loginName))
            {
                if (CDHelper.AdminPasswordIsValid(password))
                {
                    Security.SetAccountID(We7Helper.EmptyGUID);
                    loginSuccess = true;
                    SSOLogin(loginName, password);
                }
                else
                {
                    ShowMessage("无法登录,原因:密码错误!");
                    return;
                }
            }
            else
            {
                string[] result = AccountHelper.Login(loginName, password);
                if (result[0] == "false")
                {
                    ShowMessage("无法登录,原因:" + result[1]);
                    return;
                }
                else
                {
                    SSOLogin(loginName, password);
                }
            }

            GoWhere();
        }
예제 #5
0
        protected void SaveSiteButton_Click(object sender, EventArgs e)
        {
            try
            {
                string siteID   = CDHelper.GetSiteID();
                string siteName = CDHelper.GetCompanyName();

                //保存共享站点信息
                if (SiteSharingDelsTextBox.Text != "")
                {
                    string[] dels = SiteSharingDelsTextBox.Text.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    IDHelper.DelSharingSites(siteID, dels);
                }

                if (SiteSharingAddsTextBox.Text != "")
                {
                    string[] adds    = SiteSharingAddsTextBox.Text.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    object   objEnum = null;
                    if (ValidateStyle.Checked)
                    {
                        objEnum = (int)EnumLibrary.SiteValidateStyle.MustReceived;
                    }
                    else
                    {
                        objEnum = (int)EnumLibrary.SiteValidateStyle.NoMustReceived;
                    }
                    IDHelper.AddSharingSites(siteID, siteName, adds, objEnum);
                }

                //保存接受站点信息
                if (SiteReceiveDelsTextBox.Text != "")
                {
                    string[] dels = SiteReceiveDelsTextBox.Text.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    IDHelper.DelReceivingSites(siteID, dels);
                }

                if (SiteReceiveAddsTextBox.Text != "")
                {
                    string[] adds = SiteReceiveAddsTextBox.Text.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    IDHelper.AddReceivingSites(siteID, siteName, adds);
                }

                Initilize();

                Messages.ShowMessage("站点关联保存成功!");
            }
            catch (Exception ex)
            {
                Messages.ShowMessage("保存信息时出错!出错原因:" + ex.Message);
            }
        }
 private void 重启ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems != null)
     {
         int id = int.Parse(this.listView1.SelectedItems[0].SubItems[0].Text);
         log.writeLog(System.DateTime.Now + "  开始重启tomcat...");
         //根据Id获取tomcat信息
         DataTable dt;
         string    str;
         dt = db.ExecuteQuery("SELECT tl.id,tl.lujing,tl.tomcatname,tl.lujingstop,ts.ipaddress,ts.port,ts.name,ts.operatingsystem FROM tomcatlist tl, serverslist ts WHERE tl.serverid=ts.id AND  tl.id=" + id, CommandType.Text);
         foreach (DataRow dr2 in dt.Rows)
         {
             //发送关闭命令
             string sendStr = null;
             log.writeLog(System.DateTime.Now + "  开始连接服务端...");
             sc = new SCHelper(int.Parse(dr2["port"].ToString()), dr2["ipaddress"].ToString());
             log.writeLog(System.DateTime.Now + "  向服务端发送消息:  hi");
             str = sc.sendCommond("hi");
             log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
             if (str != null && str.Equals("hi"))
             {
                 log.writeLog(System.DateTime.Now + "  向服务端发送消息:  executeCommand");
                 str = sc.sendCommond("executeCommand");
                 log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
                 if (str != null && str.StartsWith("ok"))
                 {
                     //tomcat路径
                     str = dr2["lujingstop"].ToString();
                     //获取关闭tomcat命令
                     sendStr = new CDHelper(dr2["operatingsystem"].ToString()).getMakeCommond().getStopTomcatCommond(str);
                     log.writeLog(System.DateTime.Now + "  向服务端发送消息:  " + sendStr);
                     str = sc.sendCommond(sendStr);
                     log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
                 }
             }
             System.Threading.Thread.Sleep(5000);
             //发送启动命令
             str = dr2["lujing"].ToString();
             //获取tomcat启动命令
             sendStr = new CDHelper(dr2["operatingsystem"].ToString()).getMakeCommond().getStartTomcatCommond(str);
             log.writeLog(System.DateTime.Now + "  向服务端发送消息:  " + sendStr);
             str = sc.sendCommond(sendStr);
             log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
             log.writeLog(System.DateTime.Now + "  向服务端发送消息:  exit");
             str = sc.sendCommond("exit");
             log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
             sc.socketClose();
         }
     }
 }
예제 #7
0
        /// <summary>
        /// 获取当前页标题设置参数
        /// </summary>
        /// <param name="channelID"></param>
        /// <param name="articleID"></param>
        /// <returns></returns>
        public string GetCurrentPageTitle(string channelID, string articleID)
        {
            string titleFormart = CDHelper.GetDefaultHomePageTitle();

            if (articleID != "" && channelID != "")//内容页
            {
                titleFormart = CDHelper.GetDefaultContentPageTitle();
            }
            else if (channelID != "") //栏目页
            {
                titleFormart = CDHelper.GetDefaultChannelPageTitle();
            }
            return(ParselFormatTitle(titleFormart, channelID, articleID));
        }
예제 #8
0
        string UploadImage(string url)
        {
            string ChannelPath = Server.MapPath(Channel.ChannelUrlPath);

            if (TitleImageFileUpload.FileName.Length < 1)
            {
                Messages.ShowError("图片不能为空!");
            }
            if (!CDHelper.CanUpload(TitleImageFileUpload.FileName))
            {
                Messages.ShowError("不支持上传该类型的图片。");
            }

            string logoName = url.Replace("/", "_");

            if (logoName.EndsWith("_"))
            {
                logoName = logoName.Remove(logoName.Length - 1);
            }
            if (logoName.StartsWith("_"))
            {
                logoName = logoName.Remove(0, 1);
            }
            string path              = string.Format("{0}\\{1}{2}", ChannelPath, logoName, Path.GetExtension(TitleImageFileUpload.FileName));
            string ImagefileName     = string.Format("{0}/{1}{2}", Channel.ChannelUrlPath, logoName, Path.GetExtension(TitleImageFileUpload.FileName));
            string thumbnailFilePath = string.Format("{0}\\{1}_S{2}", ChannelPath, logoName, Path.GetExtension(TitleImageFileUpload.FileName));

            if (!Directory.Exists(ChannelPath))
            {
                Directory.CreateDirectory(ChannelPath);
            }

            try
            {
                TitleImageFileUpload.SaveAs(path);
                ImageUtils.MakeThumbnail(path, thumbnailFilePath, 110, 90, "W");
            }
            catch (IOException)
            {
                Messages.ShowError("图片上传失败,请重试!");
            }

            return(ImagefileName);
        }
예제 #9
0
        //开启tomcat
        private void button1_Click(object sender, EventArgs e)
        {
            DataTable dt;

            dt = db.ExecuteQuery("SELECT tl.id,tl.lujing,tl.tomcatname,tl.lujingstop,ts.ipaddress,ts.port,ts.name,ts.operatingsystem FROM tomcatlist tl, serverslist ts WHERE tl.serverid=ts.id", CommandType.Text);
            foreach (DataRow dr2 in dt.Rows)
            {
                string str  = null;
                int    port = int.Parse(dr2["port"].ToString());
                string host = dr2["ipaddress"].ToString();
                log.writeLog(System.DateTime.Now + "  开始连接服务端...");
                sc = new SCHelper(port, host);
                log.writeLog(System.DateTime.Now + "  向服务端发送消息:  hi");
                str = sc.sendCommond("hi");
                log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
                if (str != null && str.Equals("hi"))
                {
                    log.writeLog(System.DateTime.Now + "  向服务端发送消息:  executeCommand");
                    str = sc.sendCommond("executeCommand");
                    log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
                    if (str != null && str.StartsWith("ok"))
                    {
                        //tomcat路径
                        str = dr2["lujing"].ToString();
                        //获取tomcat启动命令
                        string sendStr = new CDHelper(dr2["operatingsystem"].ToString()).getMakeCommond().getStartTomcatCommond(str);
                        log.writeLog(System.DateTime.Now + "  向服务端发送消息:  " + sendStr);
                        //发送启动命令
                        string reslut = sc.sendCommond(sendStr);
                        log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + reslut);
                        textBox1.AppendText("开启tomcat:[" + dr2["tomcatname"] + "]命令已发出。\r\n");
                        System.Threading.Thread.Sleep(1000);
                    }
                }
                log.writeLog(System.DateTime.Now + "  向服务端发送消息:  exit");
                str = sc.sendCommond("exit");
                log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
                sc.socketClose();
            }
        }
예제 #10
0
        void ArticleAttachmentFileUpload()
        {
            if (AttachmentFileUpload.FileName.Length < 1)
            {
                Messages.ShowError("附件不能为空!");
                return;
            }
            if (CDHelper.CanUploadAttachment(AttachmentFileUpload.FileName))
            {
                Messages.ShowError("不支持上传该类型的文件。");
                return;
            }
            string ap = GenerateFileName(Path.GetFileName(AttachmentFileUpload.FileName));

            try
            {
                AttachmentFileUpload.SaveAs(ap);
            }
            catch (IOException ex)
            {
                Messages.ShowError("附件上传失败!" + ex.Message);
                return;
            }

            Attachment a = new Attachment();

            a.FileName  = Path.GetFileName(ap);
            a.FilePath  = GetAttachmentPath();
            a.FileSize  = AttachmentFileUpload.PostedFile.ContentLength;
            a.FileType  = Path.GetExtension(ap);
            a.ArticleID = ArticleID;
            AttachmentHelper.AddAttachment(a);
            string rawurl = We7Helper.RemoveParamFromUrl(Request.RawUrl, "saved");

            rawurl = We7Helper.AddParamToUrl(rawurl, "saved", "1");
            Response.Redirect(rawurl);
        }
        //关机
        private void shudownServer(object sender, EventArgs e)
        {
            string str = null;
            int    id  = int.Parse(this.listView1.SelectedItems[0].SubItems[0].Text);
            //根据Id获取tomcat信息
            DataTable dt;

            dt = db.ExecuteQuery("SELECT id,ipaddress,port,name,operatingsystem FROM serverslist WHERE id=" + id, CommandType.Text);
            foreach (DataRow dr2 in dt.Rows)
            {
                log.writeLog(System.DateTime.Now + "  开始连接服务端...");
                sc = new SCHelper(int.Parse(dr2["port"].ToString()), dr2["ipaddress"].ToString());
                log.writeLog(System.DateTime.Now + "  向服务端发送消息:  hi");
                str = sc.sendCommond("hi");
                log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
                if (str != null && str.Equals("hi"))
                {
                    log.writeLog(System.DateTime.Now + "  向服务端发送消息:  executeCommand");
                    str = sc.sendCommond("executeCommand");
                    log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
                    if (str != null && str.StartsWith("ok"))
                    {
                        log.writeLog(System.DateTime.Now + "  向服务端发送消息:  shutdown -s -t 1");
                        //获取关机命令
                        string sendStr = new CDHelper(dr2["operatingsystem"].ToString()).getMakeCommond().getStopServer();
                        str = sc.sendCommond(sendStr);
                        MessageBox.Show("关闭服务器命令已发出", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
                }
            }
            log.writeLog(System.DateTime.Now + "  向服务端发送消息:  exit");
            str = sc.sendCommond("exit");
            log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
            sc.socketClose();
        }
예제 #12
0
        void UploadImageFile()
        {
            if (ImageFileUpload.FileName.Length < 1)
            {
                this.Messages.ShowError("请选择图片文件再上传!");
                return;
            }
            if (!CDHelper.CanUpload(ImageFileUpload.FileName))
            {
                this.Messages.ShowError("系统不支持上传该类型的图片,请在本地转换为gif或jpg格式的再试。");
                return;
            }

            try
            {
                UploadAndCreateThumbnails(Path.GetFileName(ImageFileUpload.FileName));
                Response.Redirect(Request.RawUrl + "&uploaded=" + Path.GetFileName(ImageFileUpload.FileName));
            }
            catch (IOException)
            {
                this.Messages.ShowError("图片上传失败,请重试!");
                return;
            }
        }
예제 #13
0
    public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu)
    {
        // GENERATES (C#):
        //
        //  namespace NSPC {
        //
        //      public class ClassWithMethod {
        //
        //          public static int ReturnMethod(int intInput) {
        //              if (((intInput <= 3)
        //                          && (intInput == 2))) {
        //                  intInput = (intInput + 16);
        //              }
        //              else {
        //                  intInput = (intInput + 1);
        //              }
        //              if ((intInput <= 10)) {
        //                  intInput = (intInput + 11);
        //              }
        //              return intInput;
        //          }
        //      }
        //  }

        AddScenario("CheckReturnMethod1", "Check return value of ReturnMethod()");
        AddScenario("CheckReturnMethod2", "Check return value of ReturnMethod()");
        CodeNamespace nspace = new CodeNamespace("NSPC");

        cu.Namespaces.Add(nspace);

        CodeTypeDeclaration class1 = new CodeTypeDeclaration("ClassWithMethod");

        class1.IsClass = true;
        nspace.Types.Add(class1);

        CodeMemberMethod retMethod = new CodeMemberMethod();

        retMethod.Name       = "ReturnMethod";
        retMethod.Attributes = MemberAttributes.Public | MemberAttributes.Static;
        retMethod.ReturnType = new CodeTypeReference(typeof(int));
        retMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "intInput"));
        retMethod.Statements.Add(
            new CodeConditionStatement(
                new CodeBinaryOperatorExpression(
                    new CodeBinaryOperatorExpression(
                        new CodeArgumentReferenceExpression("intInput"),
                        CodeBinaryOperatorType.LessThanOrEqual,
                        new CodePrimitiveExpression(3)),
                    CodeBinaryOperatorType.BooleanAnd,
                    new CodeBinaryOperatorExpression(
                        new CodeArgumentReferenceExpression("intInput"),
                        CodeBinaryOperatorType.ValueEquality,
                        new CodePrimitiveExpression(2))),
                CDHelper.CreateIncrementByStatement(new CodeArgumentReferenceExpression("intInput"), 16),
                CDHelper.CreateIncrementByStatement(new CodeArgumentReferenceExpression("intInput"), 1)));
        retMethod.Statements.Add(new CodeConditionStatement(
                                     new CodeBinaryOperatorExpression(new CodeArgumentReferenceExpression("intInput"), CodeBinaryOperatorType.LessThanOrEqual,
                                                                      new CodePrimitiveExpression(10)),
                                     new CodeAssignStatement(new CodeArgumentReferenceExpression("intInput"),
                                                             new CodeBinaryOperatorExpression(new CodeArgumentReferenceExpression("intInput"),
                                                                                              CodeBinaryOperatorType.Add, new CodePrimitiveExpression(11)))));
        retMethod.Statements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression("intInput")));
        class1.Members.Add(retMethod);
    }
예제 #14
0
        private void Initilize()
        {
            try
            {
                WebEngine2007.WebServices.ID.SitePartnership[] sps;
                System.Text.StringBuilder sb;
                string siteID = CDHelper.GetSiteID();

                #region 绑定共享站点数据源
                //查找当前站群下所有可共享站点
                WDWebService wws   = GetWDWebService();
                WebSite[]    sites = wws.GetWebSites();

                //Tips:使用泛型集合类,可以避免检查数组越界
                IList <WebSite> sitesCopy = new List <WebSite>();
                foreach (WebSite item in sites)
                {
                    if (item.ID != siteID)
                    {
                        if (item.IpOrDomain == 1 && item.ZoneName.ToLower().Equals("localhost"))
                        {
                            item.Url = item.ZoneName + ":" + item.Port.ToString();
                        }

                        sitesCopy.Add(item);
                    }
                }
                SiteListSharing.DataSource = sitesCopy;
                SiteListSharing.DataBind();

                //查找已创建共享站点
                object objEnum = (object)EnumLibrary.SitePartnership.Sharing;
                sps = null;
                sps = IDHelper.GetSharingSites(siteID, objEnum);
                sb  = new System.Text.StringBuilder();
                EnumLibrary.SiteValidateStyle svs = EnumLibrary.SiteValidateStyle.NoMustReceived;
                if (sps != null)
                {
                    foreach (WebEngine2007.WebServices.ID.SitePartnership sp in sps)
                    {
                        svs = (EnumLibrary.SiteValidateStyle)
                              StateMgr.GetStateValueEnum(sp.EnumState, EnumLibrary.Business.SiteValidateStyle);

                        if (sb.Length > 0)
                        {
                            sb.Append(";");
                        }
                        sb.Append(sp.ToSiteID + "," + sp.ToSiteName);
                    }
                }

                //站点生效方式仅共享存在此值,且一个站点唯一
                switch (svs)
                {
                case EnumLibrary.SiteValidateStyle.MustReceived:
                    ValidateStyle.Checked = true;
                    break;

                case EnumLibrary.SiteValidateStyle.NoMustReceived:
                    ValidateStyle.Checked = false;
                    break;

                default:
                    break;
                }

                SiteSharingAddsTextBox.Text = sb.ToString();
                SiteSharingDelsTextBox.Text = string.Empty;
                #endregion

                #region 绑定接收站点数据源
                //从SitePartnership查找所有可接收站点
                objEnum = (object)EnumLibrary.SitePartnership.Sharing;
                sps     = null;
                sps     = IDHelper.GetReceivingSites(siteID, objEnum);
                SiteListReceive.DataSource = sps;
                SiteListReceive.DataBind();

                objEnum = (object)EnumLibrary.SitePartnership.Receiving;
                sps     = null;
                sps     = IDHelper.GetReceivingSites(siteID, objEnum);
                sb      = new System.Text.StringBuilder();
                if (sps != null)
                {
                    foreach (WebEngine2007.WebServices.ID.SitePartnership sp in sps)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(";");
                        }
                        sb.Append(sp.FromSiteID + "," + sp.FromSiteName);
                    }
                }

                SiteReceiveAddsTextBox.Text = sb.ToString();
                SiteReceiveDelsTextBox.Text = string.Empty;
                #endregion

                //并获取已经设定好的数据范围,并直接赋值给
                //SiteReceiveTextBox、SiteSharingTextBox由前台分解而后对已选站点进行打勾
                //当然需要注册启动脚本
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>onDocumentLoad();</script>");
            }
            catch (Exception ex)
            {
                Messages.ShowMessage("页面初始化出错!出错原因:" + ex.Message);
            }
        }
        private string checkTomcatStatus(int id)
        {
            //根据Id获取tomcat信息
            log.writeLog(System.DateTime.Now + "  开始刷新tomcat状态...");
            DataTable dt;
            string    str;

            dt = db.ExecuteQuery("SELECT tl.id,tl.lujing,tl.tomcatname,tl.lujingstop,ts.ipaddress,ts.port,ts.name,ts.operatingsystem FROM tomcatlist tl, serverslist ts WHERE tl.serverid=ts.id AND  tl.id=" + id, CommandType.Text);
            foreach (DataRow dr2 in dt.Rows)
            {
                //发送关闭命令
                log.writeLog(System.DateTime.Now + "  开始连接服务端...");
                sc = new SCHelper(int.Parse(dr2["port"].ToString()), dr2["ipaddress"].ToString());
                log.writeLog(System.DateTime.Now + "  向服务端发送消息:  hi");
                str = sc.sendCommond("hi");
                log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
                if (str != null && str.Equals("hi"))
                {
                    log.writeLog(System.DateTime.Now + "  向服务端发送消息:  getresponse");
                    str = sc.sendCommond("getresponse");
                    log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
                    if (str != null && str.StartsWith("ok"))
                    {
                        //tomcat路径
                        str = dr2["lujingstop"].ToString();
                        //str = "D:\\apache-tomcat-7.0.62\\conf\\";
                        //获取tocat配置文件
                        string sendStr = new CDHelper(dr2["operatingsystem"].ToString()).getMakeCommond().getTomcatServerXml(str);
                        log.writeLog(System.DateTime.Now + "  向服务端发送消息:  " + sendStr);
                        str = sc.sendCommond(sendStr);
                        log.writeLog(System.DateTime.Now + "  服务端返回消息:  " + str);
                        //提取端口信息
                        string          pattern = @"<Connector port=""(\d+)""";
                        Regex           r       = new Regex(pattern, RegexOptions.IgnoreCase);
                        Match           m       = r.Match(str.ToString());
                        MatchCollection matchs  = r.Matches(str);
                        //如果匹配的tomcat为空,则返回未知
                        if (matchs.Count <= 0)
                        {
                            return("未知");
                        }
                        for (int i = 0; i < matchs.Count; i++)
                        {
                            Match match = matchs[i];
                            //match.Value是匹配的内容
                            // Console.WriteLine(match.Value);
                            string name = match.Groups[1].Value;
                            log.writeLog(System.DateTime.Now + "  匹配到端口:  " + name);
                            log.writeLog(System.DateTime.Now + "  开始验证端口是否开放:  " + name);
                            sendStr = "command" + "netstat -ano | findstr " + name;
                            log.writeLog(System.DateTime.Now + "  向服务端发送消息:  " + sendStr);
                            str = sc.sendCommond(sendStr);
                            log.writeLog(System.DateTime.Now + "  服务端返回消息:  " + str);
                            //判断端口是否被监听
                            bool l = Regex.IsMatch(str, @"([\s\S]*?):" + name + "(.*?)LISTENING");
                            if (!l)
                            {
                                return("关闭");
                            }
                        }
                    }
                }
                log.writeLog(System.DateTime.Now + "  向服务端发送消息:  exit");
                str = sc.sendCommond("exit");
                log.writeLog(System.DateTime.Now + "  服务端返回消息消息:  " + str);
                sc.socketClose();
            }
            return("开启");
        }
예제 #16
0
    public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu)
    {
        // GENERATES (C#):
        //  namespace Namespace1 {
        //      using System;
        //
        //
        //      public class Class1 : object {
        //
        //          public int ReturnMethod(int intInput) {

        AddScenario("ReturnMethod", "Verifies binary operators in a series of operations.");
        CodeNamespace ns = new CodeNamespace("Namespace1");

        ns.Imports.Add(new CodeNamespaceImport("System"));
        cu.Namespaces.Add(ns);

        CodeTypeDeclaration class1 = new CodeTypeDeclaration();

        class1.Name = "Class1";
        class1.BaseTypes.Add(new CodeTypeReference(typeof(object)));
        ns.Types.Add(class1);

        CodeMemberMethod retMethod = new CodeMemberMethod();

        retMethod.Name       = "ReturnMethod";
        retMethod.Attributes = (retMethod.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
        retMethod.ReturnType = new CodeTypeReference(typeof(int));
        retMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "intInput"));

        // GENERATES (C#):
        //              int x1;
        //              x1 = 6 - 4;
        //              double x1d = x1;
        //              x1d = 18 / x1d;
        //              x1 = (int) x1d;
        //              x1 = x1 * intInput;

        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "x1"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("x1", 6, CodeBinaryOperatorType.Subtract, 4));
        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(double), "x1d", new CodeVariableReferenceExpression("x1")));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("x1d", 18, CodeBinaryOperatorType.Divide, "x1d"));
        retMethod.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("x1"),
                                                         new CodeCastExpression(typeof(int), new CodeVariableReferenceExpression("x1d"))));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("x1", "x1", CodeBinaryOperatorType.Multiply,
                                                                        new CodeArgumentReferenceExpression("intInput")));

        // GENERATES (C#):
        //              int x2;
        //              x2 = (19 % 8);
        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "x2"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("x2", 19, CodeBinaryOperatorType.Modulus, 8));

        // GENERATES (C#):
        //              int x3;
        //              x3 = 15 & 35;
        //              x3 = x3 | 129;
        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "x3"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("x3", 15, CodeBinaryOperatorType.BitwiseAnd, 35));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("x3", "x3", CodeBinaryOperatorType.BitwiseOr, 129));

        // GENERATES (C#):
        //              int x4 = 0;
        retMethod.Statements.Add(
            new CodeVariableDeclarationStatement(
                typeof(int),
                "x4",
                new CodePrimitiveExpression(0)));

        // GENERATES (C#):
        //              bool res1;
        //              res1 = x2 == 3;
        //              bool res2;
        //              res2 = x3 < 129;
        //              bool res3;
        //              res3 = res1 || res2;
        //              if (res3) {
        //                  x4 = (x4 + 1);
        //              }
        //              else {
        //                  x4 = (x4 + 2);
        //              }
        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(bool), "res1"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("res1", "x2", CodeBinaryOperatorType.ValueEquality, 3));

        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(bool), "res2"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("res2", "x3", CodeBinaryOperatorType.LessThan, 129));

        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(bool), "res3"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("res3", "res1", CodeBinaryOperatorType.BooleanOr, "res2"));

        retMethod.Statements.Add(
            new CodeConditionStatement(new CodeVariableReferenceExpression("res3"),
                                       new CodeStatement [] { CDHelper.CreateIncrementByStatement("x4", 1) },
                                       new CodeStatement [] { CDHelper.CreateIncrementByStatement("x4", 2) }));

        // GENERATES (C#):
        //              bool res4;
        //              res4 = x2 > -1;
        //              bool res5;
        //              res5 = x3 > 5000;
        //              bool res6;
        //              res6 = res4 && res5;
        //              if (res6) {
        //                  x4 = (x4 + 4);
        //              }
        //              else {
        //                  x4 = (x4 + 8);
        //              }
        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(bool), "res4"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("res4", "x2", CodeBinaryOperatorType.GreaterThan, -1));

        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(bool), "res5"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("res5", "x3", CodeBinaryOperatorType.GreaterThanOrEqual, 5000));

        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(bool), "res6"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("res6", "res4", CodeBinaryOperatorType.BooleanAnd, "res5"));

        retMethod.Statements.Add(
            new CodeConditionStatement(
                new CodeVariableReferenceExpression("res6"),
                new CodeStatement [] { CDHelper.CreateIncrementByStatement("x4", 4) },
                new CodeStatement [] { CDHelper.CreateIncrementByStatement("x4", 8) }));

        // GENERATES (C#):
        //              bool res7;
        //              res7 = x2 < 3;
        //              bool res8;
        //              res8 = x3 != 1;
        //              bool res9;
        //              res9 = res7 && res8;
        //              if (res9) {
        //                  x4 = (x4 + 16);
        //              }
        //              else {
        //                  x4 = (x4 + 32);
        //              }
        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(bool), "res7"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("res7", "x2", CodeBinaryOperatorType.LessThanOrEqual, 3));

        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(bool), "res8"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("res8", "x3", CodeBinaryOperatorType.IdentityInequality, 1));

        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(bool), "res9"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("res9", "res7", CodeBinaryOperatorType.BooleanAnd, "res8"));

        retMethod.Statements.Add(
            new CodeConditionStatement(
                new CodeVariableReferenceExpression("res9"),
                new CodeStatement [] { CDHelper.CreateIncrementByStatement("x4", 16) },
                new CodeStatement [] { CDHelper.CreateIncrementByStatement("x4", 32) }));


        // GENERATES (C#):
        //              int theSum;
        //              theSum = x1 + x2;
        //              theSum = theSum + x3;
        //              theSum = theSum + x4;
        //              return theSum;
        //          }
        //
        retMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "theSum"));
        retMethod.Statements.Add(CDHelper.CreateBinaryOperatorStatement("theSum", "x1", CodeBinaryOperatorType.Add, "x2"));
        retMethod.Statements.Add(CDHelper.CreateIncrementByStatement("theSum", "x3"));
        retMethod.Statements.Add(CDHelper.CreateIncrementByStatement("theSum", "x4"));

        retMethod.Statements.Add(new CodeMethodReturnStatement(
                                     new CodeVariableReferenceExpression("theSum")));
        class1.Members.Add(retMethod);
    }
예제 #17
0
    public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu)
    {
        CodeNamespace nspace = new CodeNamespace("NSPC");

        nspace.Imports.Add(new CodeNamespaceImport("System"));
        cu.Namespaces.Add(nspace);


        // declare class with fields

        // GENERATES (C#):
        //    public class ClassWithFields {
        //        public int NonStaticPublicField = 6;
        //        private int PrivateField = 7;
        //        public int UsePrivateField(int i) {
        //            this.PrivateField = i;
        //            return this.PrivateField;
        //        }
        //    }
        CodeTypeDeclaration cd = new CodeTypeDeclaration("ClassWithFields");

        cd.IsClass = true;
        nspace.Types.Add(cd);

        CodeMemberField field = new CodeMemberField();

        field.Name           = "NonStaticPublicField";
        field.Attributes     = MemberAttributes.Public | MemberAttributes.Final;
        field.Type           = new CodeTypeReference(typeof(int));
        field.InitExpression = new CodePrimitiveExpression(6);
        cd.Members.Add(field);

        field                = new CodeMemberField();
        field.Name           = "PrivateField";
        field.Attributes     = MemberAttributes.Private | MemberAttributes.Final;
        field.Type           = new CodeTypeReference(typeof(int));
        field.InitExpression = new CodePrimitiveExpression(7);
        cd.Members.Add(field);

        // create a method to test access to private field
        CodeMemberMethod cmm = new CodeMemberMethod();

        cmm.Name       = "UsePrivateField";
        cmm.Attributes = MemberAttributes.Public | MemberAttributes.Final;
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(int)), "i"));
        cmm.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "PrivateField"), new CodeArgumentReferenceExpression("i")));
        cmm.Statements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "PrivateField")));
        cd.Members.Add(cmm);

        // GENERATES (C#):
        //    public class TestFields {
        //        public int UseFields(int i) {
        //            ClassWithFields number = new ClassWithFields();
        //            int someSum;
        //            int privateField;
        //            someSum = number.NonStaticPublicField;
        //            privateField = number.UsePrivateField (i);
        //            return someSum + privateField;
        //        }
        //    }
        cd         = new CodeTypeDeclaration("TestFields");
        cd.IsClass = true;
        nspace.Types.Add(cd);

        AddScenario("CheckTestFields");
        cmm            = new CodeMemberMethod();
        cmm.Name       = "UseFields";
        cmm.Attributes = MemberAttributes.Public;
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(int)), "i"));
        cmm.Statements.Add(new CodeVariableDeclarationStatement(new CodeTypeReference("ClassWithFields"), "number",
                                                                new CodeObjectCreateExpression("ClassWithFields")));

        cmm.Statements.Add(new CodeVariableDeclarationStatement(typeof(int),
                                                                "someSum"));
        cmm.Statements.Add(new CodeVariableDeclarationStatement(typeof(int),
                                                                "privateField"));

        cmm.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("someSum"),
                                                   CDHelper.CreateFieldRef("number", "NonStaticPublicField")));

        cmm.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("privateField"),
                                                   CDHelper.CreateMethodInvoke(new CodeVariableReferenceExpression("number"),
                                                                               "UsePrivateField", new CodeArgumentReferenceExpression("i"))));

        cmm.Statements.Add(new CodeMethodReturnStatement(CDHelper.CreateBinaryOperatorExpression("someSum",
                                                                                                 CodeBinaryOperatorType.Add, "privateField")));
        cd.Members.Add(cmm);
    }
예제 #18
0
    public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu)
    {
        // create a namespace
        CodeNamespace ns = new CodeNamespace("NS");

        ns.Imports.Add(new CodeNamespaceImport("System"));
        cu.Namespaces.Add(ns);

        // create a class
        CodeTypeDeclaration class1 = new CodeTypeDeclaration();

        class1.Name    = "Test";
        class1.IsClass = true;
        ns.Types.Add(class1);

        if (Supports(provider, GeneratorSupport.TryCatchStatements))
        {
            // try catch statement with just finally
            // GENERATE (C#):
            //       public static int FirstScenario(int a) {
            //            try {
            //            }
            //            finally {
            //                a = (a + 5);
            //            }
            //            return a;
            //        }
            AddScenario("CheckFirstScenario");
            CodeMemberMethod cmm = new CodeMemberMethod();
            cmm.Name       = "FirstScenario";
            cmm.ReturnType = new CodeTypeReference(typeof(int));
            cmm.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(typeof(int), "a");
            cmm.Parameters.Add(param);

            CodeTryCatchFinallyStatement tcfstmt = new CodeTryCatchFinallyStatement();
            tcfstmt.FinallyStatements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression("a"), new
                                                                  CodeBinaryOperatorExpression(new CodeArgumentReferenceExpression("a"), CodeBinaryOperatorType.Add,
                                                                                               new CodePrimitiveExpression(5))));
            cmm.Statements.Add(tcfstmt);
            cmm.Statements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression("a")));
            class1.Members.Add(cmm);

            // in VB (a = a/a) generates an warning if a is integer. Cast the expression just for VB language.
            CodeBinaryOperatorExpression cboExpression   = new CodeBinaryOperatorExpression(new CodeArgumentReferenceExpression("a"), CodeBinaryOperatorType.Divide, new CodeArgumentReferenceExpression("a"));
            CodeAssignStatement          assignStatement = null;
            if (provider is Microsoft.VisualBasic.VBCodeProvider)
            {
                assignStatement = new CodeAssignStatement(new CodeArgumentReferenceExpression("a"), new CodeCastExpression(typeof(int), cboExpression));
            }
            else
            {
                assignStatement = new CodeAssignStatement(new CodeArgumentReferenceExpression("a"), cboExpression);
            }

            // try catch statement with just catch
            // GENERATE (C#):
            //        public static int SecondScenario(int a, string exceptionMessage) {
            //            try {
            //                a = (a / a);
            //            }
            //            catch (System.Exception e) {
            //                a = 3;
            //                exceptionMessage = e.ToString();
            //            }
            //            finally {
            //                a = (a + 1);
            //            }
            //            return a;
            //        }
            AddScenario("CheckSecondScenario");
            cmm            = new CodeMemberMethod();
            cmm.Name       = "SecondScenario";
            cmm.ReturnType = new CodeTypeReference(typeof(int));
            cmm.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            param          = new CodeParameterDeclarationExpression(typeof(int), "a");
            cmm.Parameters.Add(param);
            cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(String), "exceptionMessage"));

            tcfstmt = new CodeTryCatchFinallyStatement();
            CodeCatchClause catchClause = new CodeCatchClause("e");
            tcfstmt.TryStatements.Add(assignStatement);
            catchClause.Statements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression("a"),
                                                               new CodePrimitiveExpression(3)));
            catchClause.Statements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression("exceptionMessage"),
                                                               new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("e"), "ToString")));
            tcfstmt.CatchClauses.Add(catchClause);
            tcfstmt.FinallyStatements.Add(CDHelper.CreateIncrementByStatement(new CodeArgumentReferenceExpression("a"), 1));

            cmm.Statements.Add(tcfstmt);
            cmm.Statements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression("a")));

            class1.Members.Add(cmm);

            // try catch statement with multiple catches
            // GENERATE (C#):
            //        public static int ThirdScenario(int a, string exceptionMessage) {
            //            try {
            //                a = (a / a);
            //            }
            //            catch (System.ArgumentNullException e) {
            //                a = 10;
            //                exceptionMessage = e.ToString();
            //            }
            //            catch (System.DivideByZeroException f) {
            //                exceptionMessage = f.ToString();
            //                a = 9;
            //            }
            //            return a;
            //        }
            AddScenario("CheckThirdScenario");
            cmm            = new CodeMemberMethod();
            cmm.Name       = "ThirdScenario";
            cmm.ReturnType = new CodeTypeReference(typeof(int));
            cmm.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            param          = new CodeParameterDeclarationExpression(typeof(int), "a");
            cmm.Parameters.Add(param);
            cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(String), "exceptionMessage"));

            tcfstmt     = new CodeTryCatchFinallyStatement();
            catchClause = new CodeCatchClause("e", new CodeTypeReference(typeof(ArgumentNullException)));
            tcfstmt.TryStatements.Add(assignStatement);
            catchClause.Statements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression("a"),
                                                               new CodePrimitiveExpression(9)));
            catchClause.Statements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression("exceptionMessage"),
                                                               new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("e"), "ToString")));
            tcfstmt.CatchClauses.Add(catchClause);

            // add a second catch clause
            catchClause = new CodeCatchClause("f", new CodeTypeReference(typeof(Exception)));
            catchClause.Statements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression("exceptionMessage"),
                                                               new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("f"), "ToString")));
            catchClause.Statements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression("a"),
                                                               new CodePrimitiveExpression(9)));
            tcfstmt.CatchClauses.Add(catchClause);

            cmm.Statements.Add(tcfstmt);
            cmm.Statements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression("a")));
            class1.Members.Add(cmm);

            // catch throws exception
            // GENERATE (C#):
            //        public static int FourthScenario(int a) {
            //            try {
            //                a = (a / a);
            //            }
            //            catch (System.Exception e) {
            //                // Error handling
            //                throw e;
            //            }
            //            return a;
            //        }
            AddScenario("CheckFourthScenario");
            cmm            = new CodeMemberMethod();
            cmm.Name       = "FourthScenario";
            cmm.ReturnType = new CodeTypeReference(typeof(int));
            cmm.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            param          = new CodeParameterDeclarationExpression(typeof(int), "a");
            cmm.Parameters.Add(param);

            tcfstmt     = new CodeTryCatchFinallyStatement();
            catchClause = new CodeCatchClause("e");
            tcfstmt.TryStatements.Add(assignStatement);
            catchClause.Statements.Add(new CodeCommentStatement("Error handling"));
            catchClause.Statements.Add(new CodeThrowExceptionStatement(new CodeArgumentReferenceExpression("e")));
            tcfstmt.CatchClauses.Add(catchClause);
            cmm.Statements.Add(tcfstmt);
            cmm.Statements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression("a")));
            class1.Members.Add(cmm);
        }
    }
예제 #19
0
    public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu)
    {
        CodeNamespace ns = new CodeNamespace("Namespace1");

        cu.Namespaces.Add(ns);

        // Generate Class1
        CodeTypeDeclaration class1 = new CodeTypeDeclaration("Class1");

        class1.IsClass = true;
        ns.Types.Add(class1);

        // GENERATES (C#):
        //       public int ArrayMethod(int parameter) {
        //                int arraySize = 3;
        //                int[] array1;
        //                int[] array2 = new int[3];
        //                int[] array3 = new int[] {1,
        //                        4,
        //                        9};
        //                array1 = new int[arraySize];
        //                int retValue = 0;
        //                int i;
        //                for (i = 0; (i < array1.Length); i = (i + 1)) {
        //                    array1[i] = (i * i);
        //                    array2[i] = (array1[i] - i);
        //                    retValue = retValue + array1[i];
        //                    retValue = retValue + array2[i];
        //                    retValue = retValue + array3[i];
        //                }
        //                return retValue;
        //            }
        AddScenario("ArrayMethod", "Tests sized arrays, initialized arrays, standard arrays of small size");
        CodeMemberMethod arrayMethod = new CodeMemberMethod();

        arrayMethod.Name = "ArrayMethod";
        arrayMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "parameter"));
        arrayMethod.Attributes = (arrayMethod.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
        arrayMethod.ReturnType = new CodeTypeReference(typeof(System.Int32));
        arrayMethod.Statements.Add(
            new CodeVariableDeclarationStatement(typeof(int), "arraySize", new CodePrimitiveExpression(3)));

        arrayMethod.Statements.Add(
            new CodeVariableDeclarationStatement(typeof(int[]), "array1"));

        arrayMethod.Statements.Add(
            new CodeVariableDeclarationStatement(
                new CodeTypeReference("System.Int32", 1),
                "array2",
                new CodeArrayCreateExpression(typeof(int[]), new CodePrimitiveExpression(3))));

        arrayMethod.Statements.Add(
            new CodeVariableDeclarationStatement(
                new CodeTypeReference("System.Int32", 1),
                "array3",
                new CodeArrayCreateExpression(
                    new CodeTypeReference("System.Int32", 1),
                    new CodeExpression[] {
            new CodePrimitiveExpression(1),
            new CodePrimitiveExpression(4),
            new CodePrimitiveExpression(9)
        })));

        arrayMethod.Statements.Add(
            new CodeAssignStatement(
                new CodeVariableReferenceExpression("array1"),
                new CodeArrayCreateExpression(typeof(int[]), new CodeVariableReferenceExpression("arraySize"))));

        arrayMethod.Statements.Add(
            new CodeVariableDeclarationStatement(typeof(System.Int32), "retValue", new CodePrimitiveExpression(0)));

        arrayMethod.Statements.Add(
            new CodeVariableDeclarationStatement(typeof(int), "i"));

        arrayMethod.Statements.Add(
            new CodeIterationStatement(
                new CodeAssignStatement(new CodeVariableReferenceExpression("i"), new CodePrimitiveExpression(0)),
                new CodeBinaryOperatorExpression(
                    new CodeVariableReferenceExpression("i"),
                    CodeBinaryOperatorType.LessThan,
                    new CodePropertyReferenceExpression(
                        new CodeVariableReferenceExpression("array1"),
                        "Length")),
                new CodeAssignStatement(
                    new CodeVariableReferenceExpression("i"),
                    new CodeBinaryOperatorExpression(
                        new CodeVariableReferenceExpression("i"),
                        CodeBinaryOperatorType.Add,
                        new CodePrimitiveExpression(1))),
                new CodeAssignStatement(
                    new CodeArrayIndexerExpression(
                        new CodeVariableReferenceExpression("array1"),
                        new CodeVariableReferenceExpression("i")),
                    new CodeBinaryOperatorExpression(
                        new CodeVariableReferenceExpression("i"),
                        CodeBinaryOperatorType.Multiply,
                        new CodeVariableReferenceExpression("i"))),
                new CodeAssignStatement(
                    new CodeArrayIndexerExpression(
                        new CodeVariableReferenceExpression("array2"),
                        new CodeVariableReferenceExpression("i")),
                    new CodeBinaryOperatorExpression(
                        new CodeArrayIndexerExpression(
                            new CodeVariableReferenceExpression("array1"),
                            new CodeVariableReferenceExpression("i")),
                        CodeBinaryOperatorType.Subtract,
                        new CodeVariableReferenceExpression("i"))),
                CDHelper.CreateIncrementByStatement("retValue",
                                                    CDHelper.CreateArrayRef("array1", "i")),
                CDHelper.CreateIncrementByStatement("retValue",
                                                    CDHelper.CreateArrayRef("array2", "i")),
                CDHelper.CreateIncrementByStatement("retValue",
                                                    CDHelper.CreateArrayRef("array3", "i"))));

        arrayMethod.Statements.Add(
            new CodeMethodReturnStatement(new CodeVariableReferenceExpression("retValue")));
        class1.Members.Add(arrayMethod);
    }
예제 #20
0
    public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu)
    {
        CodeNamespace nspace = new CodeNamespace("NSPC");

        nspace.Imports.Add(new CodeNamespaceImport("System"));
        cu.Namespaces.Add(nspace);

        CodeTypeDeclaration cd = new CodeTypeDeclaration("TEST");

        cd.IsClass = true;
        nspace.Types.Add(cd);


        // GENERATES (C#):
        //        public int CallingOverrideScenario(int i) {
        //            ClassWVirtualMethod t = new ClassWOverrideMethod();
        //            return t.VirtualMethod(i);
        //        }
        AddScenario("Check1CallingOverrideScenario", "Check an overridden method.");
        CodeMemberMethod cmm = new CodeMemberMethod();

        cmm.Name = "CallingOverrideScenario";
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "i"));
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Attributes = MemberAttributes.Public;
        cmm.Statements.Add(new CodeVariableDeclarationStatement("ClassWVirtualMethod", "t", new CodeCastExpression(new CodeTypeReference("ClassWVirtualMethod"), new CodeObjectCreateExpression("ClassWOverrideMethod"))));
        CodeMethodInvokeExpression methodinvoke = new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("t"), "VirtualMethod");

        methodinvoke.Parameters.Add(new CodeArgumentReferenceExpression("i"));
        cmm.Statements.Add(new CodeMethodReturnStatement(methodinvoke));
        cd.Members.Add(cmm);

        // declare a method without parameters
        cmm            = new CodeMemberMethod();
        cmm.Name       = "NoParamsMethod";
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Attributes = MemberAttributes.Public | MemberAttributes.Final;
        cmm.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(16)));
        cd.Members.Add(cmm);

        // declare a method with multiple parameters
        cmm      = new CodeMemberMethod();
        cmm.Name = "MultipleParamsMethod";
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "a"));
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "b"));
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Attributes = MemberAttributes.Public | MemberAttributes.Final;
        cmm.Statements.Add(new CodeMethodReturnStatement(new CodeBinaryOperatorExpression(new
                                                                                          CodeArgumentReferenceExpression("a"), CodeBinaryOperatorType.Add,
                                                                                          new CodeArgumentReferenceExpression("b"))));
        cd.Members.Add(cmm);

        // call method with no parameters, call a method with multiple parameters,
        // and call a method from a method call
        //         public virtual int CallParamsMethods() {
        //              TEST t = new TEST();
        //              int val;
        //              val = t.NoParamsMethod ();
        //              return t.MultipleParamsMethod(78, val);
        //         }
        AddScenario("CheckCallParamsMethod", "Check CheckCallParamsMethod.");
        cmm            = new CodeMemberMethod();
        cmm.Name       = "CallParamsMethods";
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Attributes = MemberAttributes.Public;
        cmm.Statements.Add(new CodeVariableDeclarationStatement(new CodeTypeReference("TEST"), "t", new CodeObjectCreateExpression("TEST")));

        CodeVariableReferenceExpression cvre = new CodeVariableReferenceExpression();  //To increase code coverage

        cvre.VariableName = "t";

        CodeVariableReferenceExpression valCVRE = new CodeVariableReferenceExpression();

        valCVRE.VariableName = "val";

        cmm.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "val"));
        cmm.Statements.Add(new CodeAssignStatement(valCVRE,
                                                   CDHelper.CreateMethodInvoke(new CodeVariableReferenceExpression("t"), "NoParamsMethod")));

        cmm.Statements.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression(cvre,
                                                                                        "MultipleParamsMethod", new CodePrimitiveExpression(78), valCVRE)));
        cd.Members.Add(cmm);

        // method to test the 'new' scenario by calling the 'new' method
        // GENERATES (C#):
        //        public int CallingNewScenario(int i) {
        //            ClassWVirtualMethod t = new ClassWNewMethod();
        //            int x1;
        //            int x2;
        //            x1 = ((ClassWNewMethod)(t)).VirtualMethod(i);
        //            x2 = t.VirtualMethod(i);
        //            return (x1 - x2);
        //        }
        AddScenario("CheckCallingNewScenario", "Check CheckCallingNewScenario.");
        cmm      = new CodeMemberMethod();
        cmm.Name = "CallingNewScenario";
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "i"));
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Attributes = MemberAttributes.Public;

        cmm.Statements.Add(new CodeVariableDeclarationStatement("ClassWVirtualMethod", "t", new CodeCastExpression(new CodeTypeReference("ClassWVirtualMethod"), new CodeObjectCreateExpression("ClassWNewMethod"))));
        cmm.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "x1"));
        cmm.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "x2"));


        methodinvoke = new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("t"), "VirtualMethod");
        methodinvoke.Parameters.Add(new CodeArgumentReferenceExpression("i"));

        CodeMethodInvokeExpression methodinvoke2 = new CodeMethodInvokeExpression(new CodeCastExpression("ClassWNewMethod", new
                                                                                                         CodeVariableReferenceExpression("t")), "VirtualMethod");

        methodinvoke2.Parameters.Add(new CodeArgumentReferenceExpression("i"));

        cmm.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("x1"),
                                                   methodinvoke2));

        cmm.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("x2"),
                                                   methodinvoke));

        cmm.Statements.Add(new CodeMethodReturnStatement(
                               CDHelper.CreateBinaryOperatorExpression("x1", CodeBinaryOperatorType.Subtract, "x2")));

        cd.Members.Add(cmm);


        // ***************** declare method using new ******************
        // first declare a class with a virtual method in it
        // GENERATES (C#):
        //         public class ClassWVirtualMethod {
        //                 public virtual int VirtualMethod(int a) {
        //                     return a;
        //                 }
        //         }
        cd         = new CodeTypeDeclaration("ClassWVirtualMethod");
        cd.IsClass = true;
        nspace.Types.Add(cd);
        cmm            = new CodeMemberMethod();
        cmm.Name       = "VirtualMethod";
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "a"));
        cmm.Attributes = MemberAttributes.Public;
        cmm.Statements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression("a")));
        cd.Members.Add(cmm);

        // now declare a class that inherits from the previous class and has a 'new' method with the
        // name VirtualMethod
        // GENERATES (C#):
        //    public class ClassWNewMethod : ClassWVirtualMethod {
        //         public new virtual int VirtualMethod(int a) {
        //             return (2 * a);
        //         }
        //     }
        cd = new CodeTypeDeclaration("ClassWNewMethod");
        cd.BaseTypes.Add(new CodeTypeReference("ClassWVirtualMethod"));
        cd.IsClass = true;
        nspace.Types.Add(cd);
        cmm            = new CodeMemberMethod();
        cmm.Name       = "VirtualMethod";
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "a"));
        cmm.Attributes = MemberAttributes.Public | MemberAttributes.New;
        cmm.Statements.Add(new CodeMethodReturnStatement(new CodeBinaryOperatorExpression(
                                                             new CodePrimitiveExpression(2), CodeBinaryOperatorType.Multiply
                                                             , new CodeArgumentReferenceExpression("a"))));
        cd.Members.Add(cmm);

        // now declare a class that inherits from the previous class and has a 'new' method with the
        // name VirtualMethod
        // GENERATES (C#):
        //            public class ClassWOverrideMethod : ClassWVirtualMethod {
        //                 public override int VirtualMethod(int a) {
        //                     return (2 * a);
        //                 }
        //             }
        cd = new CodeTypeDeclaration("ClassWOverrideMethod");
        cd.BaseTypes.Add(new CodeTypeReference("ClassWVirtualMethod"));
        cd.IsClass = true;
        nspace.Types.Add(cd);
        cmm            = new CodeMemberMethod();
        cmm.Name       = "VirtualMethod";
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "a"));
        cmm.Attributes = MemberAttributes.Public | MemberAttributes.Override;
        cmm.Statements.Add(new CodeMethodReturnStatement(new CodeBinaryOperatorExpression(
                                                             new CodePrimitiveExpression(2), CodeBinaryOperatorType.Multiply
                                                             , new CodeArgumentReferenceExpression("a"))));
        cd.Members.Add(cmm);

        //*************** overload member function ****************
        // new class which will include both functions
        // GENERATES (C#):
        //    public class TEST7 {
        //         public int OverloadedMethod(int a) {
        //             return a;
        //         }
        //         public int OverloadedMethod(int a, int b) {
        //             return (b + a);
        //         }
        //         public int CallingOverloadedMethods(int i) {
        //             int one = OverloadedMethod(i, i);
        //             int two = OverloadedMethod(i);
        //             return (one - two);
        //         }
        //     }
        AddScenario("CheckTEST7.CallingOverloadedMethods", "Check CallingOverloadedMethods()");
        cd         = new CodeTypeDeclaration("TEST7");
        cd.IsClass = true;
        nspace.Types.Add(cd);
        cmm            = new CodeMemberMethod();
        cmm.Name       = "OverloadedMethod";
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "a"));
        cmm.Attributes = MemberAttributes.Public;
        cmm.Statements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression("a")));
        cd.Members.Add(cmm);
        cmm            = new CodeMemberMethod();
        cmm.Name       = "OverloadedMethod";
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "a"));
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "b"));
        cmm.Attributes = MemberAttributes.Public;
        cmm.Statements.Add(new CodeMethodReturnStatement(new CodeBinaryOperatorExpression(
                                                             new CodeArgumentReferenceExpression("b"), CodeBinaryOperatorType.Add,
                                                             new CodeArgumentReferenceExpression("a"))));
        cd.Members.Add(cmm);

        // declare a method that will call both OverloadedMethod functions
        cmm            = new CodeMemberMethod();
        cmm.Name       = "CallingOverloadedMethods";
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "i"));
        cmm.Attributes = MemberAttributes.Public;
        CodeMethodReferenceExpression methodref = new CodeMethodReferenceExpression();

        methodref.MethodName = "OverloadedMethod";

        cmm.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "one",
                                                                new CodeMethodInvokeExpression(methodref, new
                                                                                               CodeArgumentReferenceExpression("i"), new CodeArgumentReferenceExpression("i"))));

        cmm.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "two",
                                                                new CodeMethodInvokeExpression(methodref, new
                                                                                               CodeArgumentReferenceExpression("i"))));

        cmm.Statements.Add(new CodeMethodReturnStatement(
                               CDHelper.CreateBinaryOperatorExpression("one", CodeBinaryOperatorType.Subtract, "two")));
        cd.Members.Add(cmm);


        // GENERATES (C#):
        //
        //   namespace NSPC2 {
        //
        //
        //       public class TEST {
        //
        //           public virtual int CallingOverrideScenario(int i) {
        //               NSPC.ClassWVirtualMethod t = new NSPC.ClassWOverrideMethod();
        //               return t.VirtualMethod(i);
        //           }
        //       }
        //   }

        nspace = new CodeNamespace("NSPC2");
        cu.Namespaces.Add(nspace);

        cd         = new CodeTypeDeclaration("TEST");
        cd.IsClass = true;
        nspace.Types.Add(cd);

        AddScenario("Check2CallingOverrideScenario", "Check CallingOverrideScenario()");
        cmm      = new CodeMemberMethod();
        cmm.Name = "CallingOverrideScenario";
        cmm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "i"));
        cmm.ReturnType = new CodeTypeReference(typeof(int));
        cmm.Attributes = MemberAttributes.Public;
        cmm.Statements.Add(new CodeVariableDeclarationStatement("NSPC.ClassWVirtualMethod", "t", new CodeCastExpression(new CodeTypeReference("NSPC.ClassWVirtualMethod"), new CodeObjectCreateExpression("NSPC.ClassWOverrideMethod"))));
        methodinvoke = new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("t"), "VirtualMethod");
        methodinvoke.Parameters.Add(new CodeArgumentReferenceExpression("i"));
        cmm.Statements.Add(new CodeMethodReturnStatement(methodinvoke));
        cd.Members.Add(cmm);
    }
예제 #21
0
    public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu)
    {
        // GENERATES (C#):
        //
        //  namespace NSPC {
        //    public class DelegateClass {
        //
        //        public virtual int Sum(
        //                    int val1,
        //                    int val2,
        //                    int val3,
        //                    int val4,
        //                    int val5,
        //                    int val6,
        //                    int val7,
        //                    int val8,
        //                    int val9,
        //                    int val10,
        //                    int val11,
        //                    int val12,
        //                    int val13,
        //                    int val14,
        //                    int val15,
        //                    int val16,
        //                    int val17,
        //                    int val18,
        //                    int val19,
        //                    int val20) {
        //            int mySum = 0;
        //            mySum = (mySum + val1);
        //            mySum = (mySum + val2);
        //            mySum = (mySum + val3);
        //            mySum = (mySum + val4);
        //            mySum = (mySum + val5);
        //            mySum = (mySum + val6);
        //            mySum = (mySum + val7);
        //            mySum = (mySum + val8);
        //            mySum = (mySum + val9);
        //            mySum = (mySum + val10);
        //            mySum = (mySum + val11);
        //            mySum = (mySum + val12);
        //            mySum = (mySum + val13);
        //            mySum = (mySum + val14);
        //            mySum = (mySum + val15);
        //            mySum = (mySum + val16);
        //            mySum = (mySum + val17);
        //            mySum = (mySum + val18);
        //            mySum = (mySum + val19);
        //            mySum = (mySum + val20);
        //            return mySum;
        //        }
        //
        //        public virtual int Do() {
        //            MyDelegate myDel = new DelegateClass.MyDelegate(this.Sum);
        //            return myDel(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765);
        //        }
        //    }
        //
        //    public delegate int MyDelegate(
        //                    int val1,
        //                    int val2,
        //                    int val3,
        //                    int val4,
        //                    int val5,
        //                    int val6,
        //                    int val7,
        //                    int val8,
        //                    int val9,
        //                    int val10,
        //                    int val11,
        //                    int val12,
        //                    int val13,
        //                    int val14,
        //                    int val15,
        //                    int val16,
        //                    int val17,
        //                    int val18,
        //                    int val19,
        //                    int val20);
        //    }

        CodeNamespace nspace = new CodeNamespace("NSPC");

        cu.Namespaces.Add(nspace);

        // only produce code if the generator can declare delegates
        if (Supports(provider, GeneratorSupport.DeclareDelegates))
        {
            CodeTypeDeclaration class1 = new CodeTypeDeclaration("DelegateClass");
            class1.IsClass = true;
            nspace.Types.Add(class1);

            CodeTypeDelegate td = new CodeTypeDelegate("MyDelegate");
            td.ReturnType = new CodeTypeReference(typeof(Int32));
            for (int i = 1; i <= 5; i++)
            {
                td.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(Int32)), "val" + i));
            }
            nspace.Types.Add(td);

            CodeMemberMethod cmm = new CodeMemberMethod();
            cmm.Name       = "Sum";
            cmm.ReturnType = new CodeTypeReference(typeof(Int32));
            for (int i = 1; i <= 5; i++)
            {
                cmm.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(Int32)), "val" + i));
            }
            cmm.Attributes = MemberAttributes.Public;

            cmm.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "mySum", new CodePrimitiveExpression(0)));

            for (int i = 1; i <= 5; i++)
            {
                cmm.Statements.Add(CDHelper.CreateIncrementByStatement("mySum", new CodeArgumentReferenceExpression("val" + i)));
            }

            cmm.Statements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("mySum")));

            class1.Members.Add(cmm);

#if !WHIDBEY
            if (!(provider is VBCodeProvider))
            {
#endif
            AddScenario("CheckDo", "Check Do()'s return value.");
            cmm            = new CodeMemberMethod();
            cmm.Name       = "Do";
            cmm.ReturnType = new CodeTypeReference(typeof(Int32));
            cmm.Attributes = MemberAttributes.Public;

            cmm.Statements.Add(new CodeVariableDeclarationStatement(new CodeTypeReference("MyDelegate"), "myDel",
                                                                    new CodeDelegateCreateExpression(new CodeTypeReference("NSPC.MyDelegate"),
                                                                                                     new CodeThisReferenceExpression(), "Sum")));

            CodeDelegateInvokeExpression delegateInvoke = new CodeDelegateInvokeExpression();
            delegateInvoke.TargetObject = new CodeVariableReferenceExpression("myDel");
            for (int i = 1; i <= 5; i++)
            {
                delegateInvoke.Parameters.Add(new CodePrimitiveExpression(fib(i)));
            }
            cmm.Statements.Add(new CodeMethodReturnStatement(delegateInvoke));

            class1.Members.Add(cmm);
#if !WHIDBEY
        }
#endif
        }
    }
예제 #22
0
        private void Initilize()
        {
            try
            {
                //所有当前站点的共享站点
                SitePartnership[] sps = null;

                //查找当前站点、当前栏目所创建的共享站点
                string siteID  = CDHelper.GetSiteID();
                object objEnum = (object)EnumLibrary.SitePartnership.Sharing;
                sps = IDHelper.GetSharingSites(siteID, objEnum);

                if (sps != null)
                {
                    SiteDropDownList.Items.Clear();
                    foreach (SitePartnership sp in sps)
                    {
                        ListItem item = new ListItem();
                        item.Text  = sp.ToSiteName;
                        item.Value = sp.ToSiteID;
                        SiteDropDownList.Items.Add(item);
                    }
                }

                if (SiteDropDownList.Items.Count > 0)
                {
                    SiteDropDownList.SelectedIndex = 0;
                    BindSelectForm(SiteDropDownList.SelectedValue);
                }

                //对已建立的关联关系进行查找并给赋值
                //获取当前站点siteID与channelID
                string fromSiteID    = siteID;
                string fromChannelID = ChannelID;

                ChannelPartnership[] result = IDHelper.GetChannelPartnerships(fromSiteID, fromChannelID, objEnum);

                ChannelSelected.Items.Clear();

                if (result != null && result.Length > 0)
                {
                    EnumLibrary.SiteAutoUsering useringType = (EnumLibrary.SiteAutoUsering)
                                                              StateMgr.GetStateValueEnum(result[0].EnumState, EnumLibrary.Business.SiteAutoUsering);
                    switch (useringType)
                    {
                    case EnumLibrary.SiteAutoUsering.MatchingUser:
                        IfAutoUseringCHK.Checked = true;
                        break;

                    case EnumLibrary.SiteAutoUsering.UnMatchingUser:
                        IfAutoUseringCHK.Checked = false;
                        break;

                    default:
                        break;
                    }

                    EnumLibrary.SiteSyncType syncType = (EnumLibrary.SiteSyncType)
                                                        StateMgr.GetStateValueEnum(result[0].EnumState, EnumLibrary.Business.SiteSyncType);
                    switch (syncType)
                    {
                    case EnumLibrary.SiteSyncType.ManualSync:
                        IfAutoSharingCHK.Checked = false;
                        break;

                    case EnumLibrary.SiteSyncType.AutoSync:
                        IfAutoSharingCHK.Checked = true;
                        break;

                    default:
                        break;
                    }

                    foreach (ChannelPartnership sp in result)
                    {
                        string   value = sp.ToSiteID + "→" + sp.ToChannelID;
                        string   text  = sp.ToSiteName + "→" + sp.ToChannelName;
                        ListItem item  = new ListItem(text, value);
                        ChannelSelected.Items.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                Messages.ShowMessage("页面初始化出错!出错原因:" + ex.Message);
            }
        }
    public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu)
    {
        // GENERATES (C#):
        //  namespace Namespace1 {
        //      using System;
        //
        //
        //      public class Class1 : object {
        //
        //          public int ReturnMethod(int intInput) {

        CodeNamespace ns = new CodeNamespace("Namespace1");

        ns.Imports.Add(new CodeNamespaceImport("System"));
        cu.Namespaces.Add(ns);

        CodeTypeDeclaration class1 = new CodeTypeDeclaration();

        class1.Name = "Class1";
        class1.BaseTypes.Add(new CodeTypeReference(typeof(object)));
        ns.Types.Add(class1);

        AddScenario("CheckReturnMethod", "Tests varying operators.");
        CodeMemberMethod retMethod = new CodeMemberMethod();

        retMethod.Name       = "ReturnMethod";
        retMethod.Attributes = (retMethod.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
        retMethod.ReturnType = new CodeTypeReference(typeof(int));
        retMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "intInput"));

        // GENERATES (C#):
        //              int x1 = ((18
        //                          / (6 - 4))
        //                          * intInput);
        //
        // in VB (a = a/a) generates an warning if a is integer. Cast the expression just for VB language.
        CodeBinaryOperatorExpression cboExpression = new CodeBinaryOperatorExpression(
            new CodeBinaryOperatorExpression(
                new CodePrimitiveExpression(18),
                CodeBinaryOperatorType.Divide,
                new CodeBinaryOperatorExpression(
                    new CodePrimitiveExpression(6),
                    CodeBinaryOperatorType.Subtract,
                    new CodePrimitiveExpression(4))),
            CodeBinaryOperatorType.Multiply,
            new CodeArgumentReferenceExpression("intInput"));

        CodeVariableDeclarationStatement variableDeclaration = null;

        if (provider is Microsoft.VisualBasic.VBCodeProvider)
        {
            variableDeclaration = new CodeVariableDeclarationStatement(typeof(int), "x1", new CodeCastExpression(typeof(int), cboExpression));
        }
        else
        {
            variableDeclaration = new CodeVariableDeclarationStatement(typeof(int), "x1", cboExpression);
        }

        retMethod.Statements.Add(variableDeclaration);

        // GENERATES (C#):
        //              int x2 = (19 % 8);
        retMethod.Statements.Add(
            new CodeVariableDeclarationStatement(
                typeof(int),
                "x2",
                new CodeBinaryOperatorExpression(
                    new CodePrimitiveExpression(19),
                    CodeBinaryOperatorType.Modulus,
                    new CodePrimitiveExpression(8))));

        // GENERATES (C#):
        //              int x3 = ((15 & 35)
        //                          | 129);
        retMethod.Statements.Add(
            new CodeVariableDeclarationStatement(
                typeof(int),
                "x3",
                new CodeBinaryOperatorExpression(
                    new CodeBinaryOperatorExpression(
                        new CodePrimitiveExpression(15),
                        CodeBinaryOperatorType.BitwiseAnd,
                        new CodePrimitiveExpression(35)),
                    CodeBinaryOperatorType.BitwiseOr,
                    new CodePrimitiveExpression(129))));

        // GENERATES (C#):
        //              int x4 = 0;
        retMethod.Statements.Add(
            new CodeVariableDeclarationStatement(
                typeof(int),
                "x4",
                new CodePrimitiveExpression(0)));

        // GENERATES (C#):
        //              if (((x2 == 3)
        //                          || (x3 < 129))) {
        //                  x4 = (x4 + 1);
        //              }
        //              else {
        //                  x4 = (x4 + 2);
        //              }

        retMethod.Statements.Add(
            new CodeConditionStatement(
                new CodeBinaryOperatorExpression(
                    new CodeBinaryOperatorExpression(
                        new CodeVariableReferenceExpression("x2"),
                        CodeBinaryOperatorType.ValueEquality,
                        new CodePrimitiveExpression(3)),
                    CodeBinaryOperatorType.BooleanOr,
                    new CodeBinaryOperatorExpression(
                        new CodeVariableReferenceExpression("x3"),
                        CodeBinaryOperatorType.LessThan,
                        new CodePrimitiveExpression(129))),
                CDHelper.CreateIncrementByStatement("x4", 1),
                CDHelper.CreateIncrementByStatement("x4", 2)));

        // GENERATES (C#):
        //              if (((x2 > -1)
        //                          && (x3 >= 5000))) {
        //                  x4 = (x4 + 4);
        //              }
        //              else {
        //                  x4 = (x4 + 8);
        //              }
        retMethod.Statements.Add(
            new CodeConditionStatement(
                new CodeBinaryOperatorExpression(
                    new CodeBinaryOperatorExpression(
                        new CodeVariableReferenceExpression("x2"),
                        CodeBinaryOperatorType.GreaterThan,
                        new CodePrimitiveExpression(-1)),
                    CodeBinaryOperatorType.BooleanAnd,
                    new CodeBinaryOperatorExpression(
                        new CodeVariableReferenceExpression("x3"),
                        CodeBinaryOperatorType.GreaterThanOrEqual,
                        new CodePrimitiveExpression(5000))),
                CDHelper.CreateIncrementByStatement("x4", 4),
                CDHelper.CreateIncrementByStatement("x4", 8)));

        // GENERATES (C#):
        //              if (((x2 <= 3)
        //                          && (x3 != 1))) {
        //                  x4 = (x4 + 16);
        //              }
        //              else {
        //                  x4 = (x4 + 32);
        //              }
        retMethod.Statements.Add(
            new CodeConditionStatement(
                new CodeBinaryOperatorExpression(
                    new CodeBinaryOperatorExpression(
                        new CodeVariableReferenceExpression("x2"),
                        CodeBinaryOperatorType.LessThanOrEqual,
                        new CodePrimitiveExpression(3)),
                    CodeBinaryOperatorType.BooleanAnd,
                    new CodeBinaryOperatorExpression(
                        new CodeVariableReferenceExpression("x3"),
                        CodeBinaryOperatorType.IdentityInequality,
                        new CodePrimitiveExpression(1))),
                CDHelper.CreateIncrementByStatement("x4", 16),
                CDHelper.CreateIncrementByStatement("x4", 32)));


        // GENERATES (C#):
        //              return (x1
        //                          + (x2
        //                          + (x3 + x4)));
        //          }
        retMethod.Statements.Add(
            new CodeMethodReturnStatement(
                new CodeBinaryOperatorExpression(
                    new CodeVariableReferenceExpression("x1"),
                    CodeBinaryOperatorType.Add,
                    new CodeBinaryOperatorExpression(
                        new CodeVariableReferenceExpression("x2"),
                        CodeBinaryOperatorType.Add,
                        new CodeBinaryOperatorExpression(
                            new CodeVariableReferenceExpression("x3"),
                            CodeBinaryOperatorType.Add,
                            new CodeVariableReferenceExpression("x4"))))));
        class1.Members.Add(retMethod);

        //
        // GENERATES (C#):
        //          public int SecondReturnMethod(int intInput) {
        //              // To test CodeBinaryOperatorType.IdentityEquality operator
        //              if ((((Object)(intInput)) == ((Object)(5)))) {
        //                  return 5;
        //              }
        //              else {
        //                  return 4;
        //              }
        //          }
        //      }
        AddScenario("CheckSecondReturnMethod", "Tests identity equality.");
        retMethod            = new CodeMemberMethod();
        retMethod.Name       = "SecondReturnMethod";
        retMethod.Attributes = (retMethod.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
        retMethod.ReturnType = new CodeTypeReference(typeof(int));
        retMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "intInput"));

        retMethod.Statements.Add(new CodeCommentStatement("To test CodeBinaryOperatorType.IdentiEquality operator"));
        retMethod.Statements.Add(
            new CodeConditionStatement(
                new CodeBinaryOperatorExpression(new CodeCastExpression("Object",
                                                                        new CodeArgumentReferenceExpression("intInput")),
                                                 CodeBinaryOperatorType.IdentityEquality, new CodeCastExpression("Object",
                                                                                                                 new CodePrimitiveExpression(5))),
                new CodeStatement[] { new CodeMethodReturnStatement(new
                                                                    CodePrimitiveExpression(5)) }, new CodeStatement[] { new
                                                                                                                         CodeMethodReturnStatement(new CodePrimitiveExpression(4)) }));
        class1.Members.Add(retMethod);

        // GENERATES (C#):
        //      public class Class2 : object {
        //      }
        //  }

        /*class1 = new CodeTypeDeclaration ();
         * class1.Name = "Class2";
         * class1.BaseTypes.Add (new CodeTypeReference (typeof (object)));
         * ns.Types.Add (class1);*/
    }
예제 #24
0
 protected void SendButton_Click(object sender, EventArgs e)
 {
     ShowMessage(CDHelper.GetMyPassword(LoginNameTextBox.Text, MailTextBox.Text, AccountHelper));
 }
예제 #25
0
    public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu)
    {
        // create a namespace
        CodeNamespace ns = new CodeNamespace("NS");

        ns.Imports.Add(new CodeNamespaceImport("System"));
        ns.Imports.Add(new CodeNamespaceImport("System.Windows.Forms"));
        cu.ReferencedAssemblies.Add("System.Windows.Forms.dll");
        cu.Namespaces.Add(ns);

        // create a class
        CodeTypeDeclaration class1 = new CodeTypeDeclaration();

        class1.Name    = "Test";
        class1.IsClass = true;
        ns.Types.Add(class1);


        // create method to test casting enum -> int
        //     GENERATE (C#):
        //        public int EnumToInt(System.Windows.Forms.AnchorStyles enum1) {
        //            return ((int)(enum1));
        //        }
        AddScenario("CheckEnumToInt1", "Check the return value of EnumToInt() with a single flag");
        AddScenario("CheckEnumToInt2", "Check the return value of EnumToInt() with multiple flags");
        CodeMemberMethod enumToInt = new CodeMemberMethod();

        enumToInt.Name       = "EnumToInt";
        enumToInt.ReturnType = new CodeTypeReference(typeof(int));
        enumToInt.Attributes = MemberAttributes.Public;
        CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(typeof(System.Windows.Forms.AnchorStyles), "enum1");

        enumToInt.Parameters.Add(param);
        enumToInt.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(typeof(int), new CodeArgumentReferenceExpression("enum1"))));
        class1.Members.Add(enumToInt);

        // create method to test casting enum -> int
        //     GENERATE (C#):
        //       public virtual int CastReturnValue(string value) {
        //          float val = System.Single.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
        //          return ((int) val);
        //       }
        AddScenario("CheckCastReturnValue", "Check the return value of CastReturnValue()");
        CodeMemberMethod castReturnValue = new CodeMemberMethod();

        castReturnValue.Name       = "CastReturnValue";
        castReturnValue.ReturnType = new CodeTypeReference(typeof(int));
        castReturnValue.Attributes = MemberAttributes.Public;
        CodeParameterDeclarationExpression strParam = new CodeParameterDeclarationExpression(typeof(string), "value");

        castReturnValue.Parameters.Add(strParam);
        castReturnValue.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "val",
                                                                            CDHelper.CreateMethodInvoke(new CodeTypeReferenceExpression(new CodeTypeReference("System.Int32")), // F#: Type conversion "int -> float" is not a type-cast!
                                                                                                        "Parse", new CodeArgumentReferenceExpression("value"),
                                                                                                        new CodePropertyReferenceExpression(new CodeTypeReferenceExpression("System.Globalization.CultureInfo"),
                                                                                                                                            "InvariantCulture"))));
        castReturnValue.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(typeof(int), new CodeVariableReferenceExpression("val"))));
        class1.Members.Add(castReturnValue);


        // create method to test casting interface -> class
        //     GENERATE (C#):
        //        public string CastInterface(System.ICloneable value) {
        //            return ((string)(value));
        //        }
        AddScenario("CheckCastInterface", "Check the return value of CastInterface()");
        CodeMemberMethod castInterface = new CodeMemberMethod();

        castInterface.Name       = "CastInterface";
        castInterface.ReturnType = new CodeTypeReference(typeof(string));
        castInterface.Attributes = MemberAttributes.Public;
        CodeParameterDeclarationExpression interfaceParam = new CodeParameterDeclarationExpression(typeof(System.ICloneable), "value");

        castInterface.Parameters.Add(interfaceParam);
        castInterface.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(typeof(string), new CodeArgumentReferenceExpression("value"))));
        class1.Members.Add(castInterface);

        // create method to test casting value type -> reference type
        //     GENERATE (C#):
        //         public object ValueToReference(int value) {
        //             return ((object)(value));
        //         }
        AddScenario("CheckValueToReference", "Check the return value of ValueToReference()");
        CodeMemberMethod valueToReference = new CodeMemberMethod();

        valueToReference.Name       = "ValueToReference";
        valueToReference.ReturnType = new CodeTypeReference(typeof(System.Object));
        valueToReference.Attributes = MemberAttributes.Public;
        CodeParameterDeclarationExpression valueParam = new CodeParameterDeclarationExpression(typeof(int), "value");

        valueToReference.Parameters.Add(valueParam);
        valueToReference.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(typeof(System.Object), new CodeArgumentReferenceExpression("value"))));
        class1.Members.Add(valueToReference);
    }