public PropertyDescriptor GetPropertyDescriptor(PropertyDescriptor p)
 {
     if (VPLUtil.PropertyValueLinkEditor == null)
     {
         return(p);
     }
     if (_properties.ContainsKey(p.Name))
     {
         Attribute[] a;
         if (p.Attributes != null)
         {
             IPropertyValueLink pl  = GetValueLink(p.Name);
             List <Attribute>   lst = new List <Attribute>();
             for (int i = 0; i < p.Attributes.Count; i++)
             {
                 if (pl != null)
                 {
                     pl.SetValueAttribute(p.Attributes[i]);
                 }
                 EditorAttribute e = p.Attributes[i] as EditorAttribute;
                 if (e == null)
                 {
                     lst.Add(p.Attributes[i]);
                 }
             }
             a = new Attribute[lst.Count + 1];
             lst.CopyTo(a, 0);
         }
         a = new Attribute[1];
         a[a.Length - 1] = new EditorAttribute(VPLUtil.PropertyValueLinkEditor, typeof(UITypeEditor));
         PropertyDescriptorValueLink p0 = new PropertyDescriptorValueLink(this, p.Name, a);
         return(p0);
     }
     return(p);
 }
        public void CollectPropertyLinks(Dictionary <IPropertyValueLinkHolder, Dictionary <IPropertyValueLink, CodeExpression> > links)
        {
            string[] names = _links.GetLinkablePropertyNames();
            Dictionary <IPropertyValueLink, CodeExpression> kv = new Dictionary <IPropertyValueLink, CodeExpression>();

            for (int k = 0; k < names.Length; k++)
            {
                IPropertyValueLink pvk = GetPropertyLink(names[k]);
                if (pvk != null && pvk.IsValueLinkSet())
                {
                    //TreeViewX {this}.GetNodeTemplate(int level) to set link to names[k]
                    CodeMethodInvokeExpression mie = new CodeMethodInvokeExpression();
                    mie.Method.MethodName = "GetNodeTemplateBase";
                    mie.Parameters.Add(new CodePrimitiveExpression(this.Level));
                    mie.UserData.Add("name", names[k]);
                    kv.Add(pvk, mie);
                }
            }
            if (kv.Count > 0)
            {
                links.Add(this, kv);
            }
            if (Nodes.Count > 0)
            {
                for (int i = 0; i < Nodes.Count; i++)
                {
                    TreeNodeXTemplate tt = Nodes[i] as TreeNodeXTemplate;
                    if (tt != null)
                    {
                        tt.CollectPropertyLinks(links);
                        break;
                    }
                }
            }
        }
        public void SetPropertyLink(string name, IPropertyValueLink link)
        {
            PropertyValueLinker pvl;

            if (_properties.TryGetValue(name, out pvl))
            {
                pvl.Linker = link;
            }
        }
        public void SetConstValue(string name, object value)
        {
            IPropertyValueLink lk = GetValueLink(name);

            if (lk != null)
            {
                lk.SetConstValue(value);
            }
        }
        public Dictionary <IPropertyValueLinkHolder, Dictionary <IPropertyValueLink, CodeExpression> > GetPropertyValueLinks()
        {
            Dictionary <IPropertyValueLinkHolder, Dictionary <IPropertyValueLink, CodeExpression> > ret = new Dictionary <IPropertyValueLinkHolder, Dictionary <IPropertyValueLink, CodeExpression> >();
            CodePropertyReferenceExpression p1;
            CodePropertyReferenceExpression p2;
            Dictionary <IPropertyValueLink, CodeExpression> kv;
            IPropertyValueLink pl = this.DataSource.TextSource.GetPropertyLink(FILENAME);

            if (pl != null && pl.IsValueLinkSet())
            {
                p1 = new CodePropertyReferenceExpression();
                p1.PropertyName = "TextSource";
                p2 = new CodePropertyReferenceExpression();
                p1.TargetObject = p2;
                p2.PropertyName = "DataSource";
                p1.UserData.Add("name", FILENAME);

                kv = new Dictionary <IPropertyValueLink, CodeExpression>();

                kv.Add(pl, p1);
                ret.Add(this.DataSource.TextSource, kv);
            }
            //
            pl = this.DataDestination.TextDestination.GetPropertyLink(FILENAME);
            if (pl != null && pl.IsValueLinkSet())
            {
                p1 = new CodePropertyReferenceExpression();
                p1.PropertyName = "TextDestination";
                p2 = new CodePropertyReferenceExpression();
                p1.TargetObject = p2;
                p2.PropertyName = "DataDestination";
                p1.UserData.Add("name", FILENAME);

                kv = new Dictionary <IPropertyValueLink, CodeExpression>();
                kv.Add(pl, p1);
                ret.Add(this.DataDestination.TextDestination, kv);
            }
            return(ret);
        }
 public void SetPropertyLink(string propertyName, IPropertyValueLink link)
 {
     _links.SetPropertyLink(propertyName, link);
 }
        public void CreateActionPhpScript(string objectName, string methodName, StringCollection code, StringCollection parameters, string returnReceiver)
        {
            if (string.CompareOrdinal(methodName, "StartWithParameterValues") == 0)
            {
                if (!phpSupported())
                {
                    return;
                }
                if (DataDestination != null && DataDestination.DatabaseDestination != null && DataDestination.DatabaseDestination.Fields.Count > 0)
                {
                    if (this.PhpTimeoutInMinutes > 0)
                    {
                        addCode(code, "if($this->{0}->PhpTimeoutInMinutes>0) ini_set('max_execution_time', $this->{0}->PhpTimeoutInMinutes * 60);\r\n", this.Site.Name);
                    }
                    string tblVar = string.Format(CultureInfo.InvariantCulture, "tbl{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    if (DataSource.SourceType == EnumDataSource.Database)
                    {
                        EasyQuery qry = DataSource.DatabaseSource.QueryDef;
                        if (qry != null)
                        {
                            //===fetch data==================================================================
                            string mySql = string.Format(CultureInfo.InvariantCulture, "mysql{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                            addCode(code, "\t${0} = new JsonSourceMySql();\r\n", mySql);
                            //
                            addCode(code, "\t${0}->SetCredential($this->{1}->sourceCredential);\r\n", mySql, this.Site.Name);
                            addCode(code, "\t${0}->SetDebug($this->DEBUG);\r\n", mySql);
                            string sql = qry.SqlQuery;
                            //sqlParams contains parameter names orderred by the appearance in sql, may duplicate
                            string[] sqlParams = EasyQuery.GetParameterNames(sql, qry.NameDelimiterBegin, qry.NameDelimiterEnd);
                            if (this.Parameters != null)
                            {
                                for (int i = 0; i < this.Parameters.Count; i++)
                                {
                                    sql = sql.Replace(this.Parameters[i].Name, "?");
                                }
                            }
                            string sqlVar = string.Format(CultureInfo.InvariantCulture, "sql{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                            addCode(code, "\t${0} = \"{1} \";\r\n", sqlVar, sql);
                            addCode(code, "\t${0} = new JsonDataTable();\r\n", tblVar);
                            addCode(code, "\t${0}->TableName = '{1}';\r\n", tblVar, qry.TableName);
                            string psVar = string.Format(CultureInfo.InvariantCulture, "ps{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                            addCode(code, "\t${0} = array();\r\n", psVar);
                            if (qry.Parameters != null)
                            {
                                DbParameterList dbps = new DbParameterList(qry.Parameters);
                                for (int i = 0; i < sqlParams.Length; i++)
                                {
                                    int k = dbps.GetIndex(sqlParams[i]);
                                    if (k < 0)
                                    {
                                        throw new ExceptionLimnorDatabase("Query Parameter [{0}] not found", sqlParams[i]);
                                    }
                                    DbCommandParam dp   = dbps[k];
                                    string         pVar = string.Format(CultureInfo.InvariantCulture, "p{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                                    addCode(code, "\t${0} = new SqlClientParameter();\r\n", pVar);
                                    addCode(code, "\t${0}->name = '{1}';\r\n", pVar, dp.Name);
                                    addCode(code, "\t${0}->type = '{1}';\r\n", pVar, ValueConvertor.OleDbTypeToPhpMySqlType(dp.Type));
                                    addCode(code, "\t${0}->value = {1};\r\n", pVar, parameters[k]);
                                    addCode(code, "\t${0}[] = ${1};\r\n//\r\n", psVar, pVar);
                                }
                            }
                            addCode(code, "\t${0}->GetData(${1},${2},${3});\r\n", mySql, tblVar, sqlVar, psVar);
                            addCode(code, "\t$this->{0}->ErrorMessage = ${1}->errorMessage;\r\n", this.Site.Name, mySql);
                            //===data fetched on tblVar=============================================================
                        }
                    }
                    else if (DataSource.SourceType == EnumDataSource.TextFile)
                    {
                        string tblName    = string.Format(CultureInfo.InvariantCulture, "srcTbl{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                        string txtFileVar = string.Format(CultureInfo.InvariantCulture, "txtFile{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                        addCode(code, "${0} = new DataSourceTextFile();\r\n", txtFileVar);
                        addCode(code, "\t${0} = new JsonDataTable();\r\n", tblVar);
                        addCode(code, "\t${0}->TableName = '{1}';\r\n", tblVar, tblName);
                        //
                        if (this.DataSource.TextSource.Delimiter == enumSourceTextDelimiter.Comma)
                        {
                            addCode(code, "\t${0}->delimiter=',';\r\n", txtFileVar);
                        }
                        else if (this.DataSource.TextSource.Delimiter == enumSourceTextDelimiter.TAB)
                        {
                            addCode(code, "\t${0}->delimiter='\\t';\r\n", txtFileVar);
                        }
                        if (this.DataSource.TextSource.HasHeader)
                        {
                            addCode(code, "\t${0}->hasHeader=true;\r\n", txtFileVar);
                        }
                        else
                        {
                            addCode(code, "\t${0}->hasHeader=false;\r\n", txtFileVar);
                        }
                        IPropertyValueLink fnl = this.DataSource.TextSource.GetPropertyLink("Filename");
                        if (fnl != null && fnl.IsValueLinkSet())
                        {
                            addCode(code, "\t${0}->filepath={1};\r\n", txtFileVar, fnl.GetPhpScriptReferenceCode(code));
                        }
                        else
                        {
                            addCode(code, "\t${0}->filepath='{1}';\r\n", txtFileVar, this.DataSource.TextSource.Filename);
                        }
                        //
                        addCode(code, "\t${0}->GetData(${1});\r\n", txtFileVar, tblVar);
                        addCode(code, "\t$this->{0}->ErrorMessage = ${1}->errorMessage;\r\n", this.Site.Name, txtFileVar);
                        addCode(code, "\tif(strlen(${0}->errorMessage) > 0)\r\n", txtFileVar);
                        code.Add("\t{\r\n");
                        code.Add("\t\tif($this->DEBUG)\r\n\t\t{\r\n");
                        addCode(code, "\t\t\techo 'Error reading text file: '.${0}->filepath.' Error message:'.${0}->errorMessage;\r\n", txtFileVar);
                        code.Add("\t\t\treturn;\r\n");
                        code.Add("\t\t}\r\n");
                        code.Add("\t}\r\n");
                    }
                    //
                    string mySqlTVar = string.Format(CultureInfo.InvariantCulture, "mySqlT{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    addCode(code, "\t${0} = new JsonSourceMySql();\r\n", mySqlTVar);
                    addCode(code, "\t${0}->SetCredential($this->{1}->destinationCredential);\r\n", mySqlTVar, this.Site.Name);
                    addCode(code, "\t${0}->SetDebug($this->DEBUG);\r\n", mySqlTVar);
                    //
                    StringBuilder sbSql       = new StringBuilder();
                    StringBuilder sbSqlValues = new StringBuilder();
                    sbSql.Append("Insert into ");
                    sbSql.Append(DataDestination.DatabaseDestination.DatabaseConnection.NameDelimiterBegin);
                    sbSql.Append(DataDestination.DatabaseDestination.TableName);
                    sbSql.Append(DataDestination.DatabaseDestination.DatabaseConnection.NameDelimiterEnd);
                    sbSql.Append(" (");
                    sbSql.Append(DataDestination.DatabaseDestination.DatabaseConnection.NameDelimiterBegin);
                    sbSql.Append(DataDestination.DatabaseDestination.Fields[0].Name);
                    sbSql.Append(DataDestination.DatabaseDestination.DatabaseConnection.NameDelimiterEnd);
                    sbSqlValues.Append("?");
                    for (int i = 1; i < DataDestination.DatabaseDestination.Fields.Count; i++)
                    {
                        sbSql.Append(",");
                        sbSql.Append(DataDestination.DatabaseDestination.DatabaseConnection.NameDelimiterBegin);
                        sbSql.Append(DataDestination.DatabaseDestination.Fields[i].Name);
                        sbSql.Append(DataDestination.DatabaseDestination.DatabaseConnection.NameDelimiterEnd);
                        sbSqlValues.Append(",?");
                    }
                    sbSql.Append(") values (");
                    sbSql.Append(sbSqlValues.ToString());
                    sbSql.Append(")");
                    //
                    string myIVar = string.Format(CultureInfo.InvariantCulture, "mySqlI{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    addCode(code, "\t${0} = ${1}->GetMySqli();\r\n", myIVar, mySqlTVar);
                    string statementVar = string.Format(CultureInfo.InvariantCulture, "state{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    addCode(code, "\t${0}=${1}->prepareStatement(${2},\"{3}\");\r\n", statementVar, mySqlTVar, myIVar, sbSql.ToString());
                    //
                    string paramsVar = string.Format(CultureInfo.InvariantCulture, "params{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    //
                    code.Add("\t//loop through rows of $tbl\r\n");
                    string idxVar = string.Format(CultureInfo.InvariantCulture, "idx{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    string rowVar = string.Format(CultureInfo.InvariantCulture, "row{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    addCode(code, "\tforeach (${0}->Rows as ${1} => ${2})\r\n", tblVar, idxVar, rowVar);
                    code.Add("\t{\r\n");
                    addCode(code, "\t\t${0}=array();\r\n", paramsVar);
                    string paramVar = string.Format(CultureInfo.InvariantCulture, "param{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    for (int i = 0; i < DataDestination.DatabaseDestination.Fields.Count; i++)
                    {
                        addCode(code, "\t\t${0}=new SqlClientParameter();\r\n", paramVar);

                        addCode(code, "\t\t${0}->name = '{1}';\r\n", paramVar, DataDestination.DatabaseDestination.Fields[i].Name);
                        addCode(code, "\t\t${0}->type = '{1}';\r\n", paramVar, ValueConvertor.OleDbTypeToPhpMySqlType(DataDestination.DatabaseDestination.Fields[i].OleDbType));
                        addCode(code, "\t\t${0}->value = ${1}->ItemArray[{2}];\r\n", paramVar, rowVar, i);
                        addCode(code, "\t\t${0}[] = ${1};\r\n//\r\n", paramsVar, paramVar);
                    }
                    addCode(code, "\t\t${0}->executeStatement(${1},${2}, ${3});\r\n", mySqlTVar, myIVar, statementVar, paramsVar);
                    //
                    code.Add("\t}\r\n");
                    //
                    addCode(code, "\t${0}->free_result();\r\n", statementVar);
                    addCode(code, "\t${0}->close();\r\n", statementVar);
                    addCode(code, "\t${0}->close();\r\n", myIVar);
                }
                //
                code.Add(string.Format(CultureInfo.InvariantCulture, "\t$this->SetServerComponentName('{0}');\r\n", this.Site.Name));
            }
        }
Beispiel #8
0
        public override string ToString()
        {
            IPropertyValueLink pl = _links.GetValueLink(FILENAME);

            return(pl.ToString());
        }