Aras学习笔记 (14) DotNet操作Aras常用代码代码汇总(陆续更新中)

1、连接Aras Innovator。

HttpServerConnection conn = IomFactory.CreateHttpServerConnection("http://localhost/InnovatorServer/", "InnovatorSolutions", "admin", "innovator");
Item login = conn.Login();
Innovator inn = IomFactory.CreateInnovator(conn);
if (inn != null)
{
  
}

2、AML格式举例。

string aml = "<AML><Item type='User' action='get'><id>3C70CC6FD09B480092E49C12D4845392</id></Item></AML>"; //单条数据
//string aml = "<AML><Item type='User' action='get'></Item></AML>"; //多条数据

3、获取Item实体类的泛型方法。

/// <summary>
    /// 得到对象
    /// </summary>
    /// <param name="xml">传入值如user.node.InnerXml参数</param>
    /// <returns></returns>
    public T GetModelFromXml<T>(string xml)
    {
        T obj = default(T);

        try
        {
            //1、读取Xml
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xml);
            XmlNodeList nodeList = xmlDoc.GetElementsByTagName("Item");

            //2、取得对象属性列表
            PropertyInfo[] propertyList = typeof(T).GetProperties();

            //3、取得第一个节点
            XmlNode node = nodeList[0];
            obj = Activator.CreateInstance<T>();//创建指定类型实例

            foreach (PropertyInfo property in propertyList)
            {
                for (int i = 0; i < node.ChildNodes.Count; i++)
                {
                    if (node.ChildNodes[i].Name.ToLower() == property.Name.ToLower())
                    {
                        property.SetValue(obj, node.ChildNodes[i].InnerText, null);
                        break;
                    }
                }
            }
        }
        catch (Exception ex)
        {

        }
        finally
        {
            
        }

        return obj;
    }

 4、记录windows事件日志。

System.Diagnostics.EventLog MyEventLog = new System.Diagnostics.EventLog();
MyEventLog.WriteEntry("Terminating - no jobs to process",EventLogEntryType.Error);

 5、循环Item列表:

Item UserList = this.newItem("user", "get");
UserList = UserList .apply();

for(int i=0;i<UserList .getItemCount();i++)
{
    string Id = UserList.getItemByIndex(i).getProperty("id","");
    string LoginName= UserList .getItemByIndex(i).getProperty("login_name","");
}

6、获取当前时间:

string dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

7、

posted @ 2018-11-23 15:07  无敌师爷IT技术Blog  阅读(870)  评论(0)    收藏  举报