public void AddNewConnection(ConnectionObject connectionObject) { XmlDocument connectionXml = new XmlDocument(); connectionXml.Load(connectionXmlFilePath); //Display all the book titles. XmlNodeList rootElementList = connectionXml.GetElementsByTagName(XmlStaticValue.xmlMainTagName); if (rootElementList.Count == 1) { string encryptPassword = EncryptPassword(connectionObject.Password); Guid systemId = Guid.NewGuid(); XDocument doc = XDocument.Load(connectionXmlFilePath); XElement root = new XElement(XmlStaticValue.xmlRootElement); root.Add(new XAttribute(XmlStaticValue.rootAttributeForValue, connectionObject.SystemName)); root.Add(new XAttribute(XmlStaticValue.rootAttributeForGuid, systemId)); XElement child = new XElement(XmlStaticValue.xmlChildElement); child.Add(new XAttribute(XmlStaticValue.childAttributeForUrl, connectionObject.URL)); child.Add(new XAttribute(XmlStaticValue.childAttributeForUserName, connectionObject.UserName)); child.Add(new XAttribute(XmlStaticValue.childAttributeForPassword, encryptPassword)); root.Add(child); doc.Element(XmlStaticValue.xmlMainTagName).Add(root); doc.Save(connectionXmlFilePath); } }
public MSCRMConnection(ConnectionObject connectionObject) { string realURL = connectionObject.URL + "/XRMServices/2011/Organization.svc"; CRMUrl = realURL; UserName = connectionObject.UserName; Password = connectionObject.Password; }
public Result ControlMSCRMConnection(ConnectionObject connectionObject) { Result returnValue = new Result(); MSCRMConnection crmConnection = new MSCRMConnection(connectionObject); try { IOrganizationService service = MSCRMConnection.AdminOrgService; CrmService = service; returnValue.IsSuccess = true; } catch (Exception ex) { returnValue.IsSuccess = false; returnValue.Message = ex.Message; } return(returnValue); }
public List <ConnectionObject> ReadConnection() { List <ConnectionObject> connectionObjectList = new List <ConnectionObject>(); XmlDocument connectionXml = new XmlDocument(); connectionXml.Load(connectionXmlFilePath); XmlNodeList rootElementList = connectionXml.GetElementsByTagName(XmlStaticValue.xmlRootElement); foreach (XmlNode systemNode in rootElementList) { if (systemNode != null) { ConnectionObject connectionObject = new ConnectionObject(); XmlNode valueNode = systemNode.Attributes.GetNamedItem(XmlStaticValue.rootAttributeForValue); string systemValue = valueNode.Value; XmlNode connectionIdNode = systemNode.Attributes.GetNamedItem(XmlStaticValue.rootAttributeForGuid); string connectionId = connectionIdNode.Value; XmlNode connectionNode = systemNode.ChildNodes[0]; XmlNode urlNode = connectionNode.Attributes.GetNamedItem(XmlStaticValue.childAttributeForUrl); string urlValue = urlNode.Value; XmlNode userNameNode = connectionNode.Attributes.GetNamedItem(XmlStaticValue.childAttributeForUserName); string userNameValue = userNameNode.Value; XmlNode passwordNode = connectionNode.Attributes.GetNamedItem(XmlStaticValue.childAttributeForPassword); string encryptPasswordValue = passwordNode.Value; string passwordValue = DecryptPassword(encryptPasswordValue); connectionObject.SystemName = systemValue; connectionObject.ConnectionId = connectionId; connectionObject.URL = urlValue; connectionObject.UserName = userNameValue; connectionObject.Password = passwordValue; connectionObjectList.Add(connectionObject); } } return(connectionObjectList); }
public void UpdateConnection(ConnectionObject connectionObject) { XmlDocument connectionXml = new XmlDocument(); connectionXml.Load(connectionXmlFilePath); XmlNodeList rootElementList = connectionXml.GetElementsByTagName(XmlStaticValue.xmlRootElement); foreach (XmlNode systemNode in rootElementList) { if (systemNode != null) { XmlNode connectionIdNode = systemNode.Attributes.GetNamedItem(XmlStaticValue.rootAttributeForGuid); string connectionId = connectionIdNode.Value; if (connectionId == connectionObject.ConnectionId) { XmlNode valueNode = systemNode.Attributes.GetNamedItem(XmlStaticValue.rootAttributeForValue); valueNode.Value = connectionObject.SystemName; XmlNode connectionNode = systemNode.ChildNodes[0]; XmlNode urlNode = connectionNode.Attributes.GetNamedItem(XmlStaticValue.childAttributeForUrl); urlNode.Value = connectionObject.URL; XmlNode userNameNode = connectionNode.Attributes.GetNamedItem(XmlStaticValue.childAttributeForUserName); userNameNode.Value = connectionObject.UserName; string encryptPassword = EncryptPassword(connectionObject.Password); XmlNode passwordNode = connectionNode.Attributes.GetNamedItem(XmlStaticValue.childAttributeForPassword); passwordNode.Value = encryptPassword; connectionXml.Save(connectionXmlFilePath); break; } } } }