AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Разработка
CRM
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 18.02.2008, 11:00   #5  
Черничкин Станислав is offline
Черничкин Станислав
Злыдни
Аватар для Черничкин Станислав
Злыдни
 
53 / 18 (1) ++
Регистрация: 16.10.2007
Адрес: Екатеринбург
2: enot poloskun:
Если убрать SerializeIsDirty запросы на PIII начинают выполняться аж по пол секунды. Развлекайся:

function _GetErrorMessage(exception)
{
return (exception != null) && (exception.description != null) ? exception.description : exception;
}
function _IsNullOrEmpty(str)
{
return (str == null) || (str == "");
}
function _ParseBool(str)
{
return !_IsNullOrEmpty(str) && ((str.toLowerCase() == "true") || (str == "1"));
}
function _ThrowArgumentNullException(paramName)
{
var error = new Object();
error.description = "Значение не может быть неопределенным.";
if (paramName != null)
error.description += "\nИмя параметра: " + paramName;
throw error;
}
function _ThrowInvalidOperationException(message)
{
var error = new Object();
error.description = message;
throw error;
}
function ExtenderMethodInvoker(extender, methodInfo)
{
if (extender == null)
_ThrowArgumentNullException("extender");
return (function()
{
try
{
extender.InvokeExtenderMethod(methodInfo);
}
catch (e)
{
alert(_GetErrorMessage(e));
if (event != null)
event.returnValue = false;
}
});
}
function Extender()
{
this.ExtensionSiteAddress = "http://crm3.local:7010/"
this.ExtensionServiceNamespace = "urn:schemas-infosyst-biz:mscrm-extend";
this.CrmServiceNamespace = "http://schemas.microsoft.com/crm/2006/WebServices";
this.FormExtensionsFolder = "FormExtenders/"
this.ExtensionService = this.ExtensionSiteAddress + this.FormExtensionsFolder + crmForm.ObjectTypeName + ".asmx";
this.AttributeValueNull = function(attributeNode)
{
if (attributeNode == null)
_ThrowArgumentNullException("attributeNode");
return attributeNode.getAttribute("IsNull") == 'true';
}

this.DeserializeAttribute = function(attributeNode, attributeInfo)
{
if (attributeNode == null)
_ThrowArgumentNullException("attributeNode");
if (attributeInfo == null)
_ThrowArgumentNullException("attributeInfo");
switch (attributeInfo.Type)
{
case "String":
crmForm.all[attributeInfo.Name].DataValue = attributeNode.text;
break;
case "Float":
case "Currency":
if (this.AttributeValueNull(attributeNode))
crmForm.all[attributeInfo.Name].DataValue = null;
else
crmForm.all[attributeInfo.Name].DataValue = parseFloat(attributeNode.text);
break;
case "Integer":
case "Duration":
case "Picklist":
case "StatusReason":
case "State":
if (this.AttributeValueNull(attributeNode))
crmForm.all[attributeInfo.Name].DataValue = null;
else
crmForm.all[attributeInfo.Name].DataValue = parseInt(attributeNode.text);
break;
case "Customer":
case "Regarding":
case "Lookup":
case "PartyList":
if (this.AttributeValueNull(attributeNode))
crmForm.all[attributeInfo.Name].DataValue = null;
else
{
var lookup = new Object();
lookup.id = attributeNode.text;
var typeName = attributeNode.getAttribute("type");
lookup.typename = typeName != null ? typeName : attributeInfo.ReferencedType;
lookup.name = attributeNode.getAttribute("name");
var bullShit = new Array();
bullShit[0] = lookup;
crmForm.all[attributeInfo.Name].DataValue = bullShit;
}
break;
default:
_ThrowInvalidOperationException("Десериализация аттрибутов типа " + attributeInfo.Type + " не поддерживается.");
break;
}
}
this.DeserializeAttributeInfos = function(node)
{
if (node == null)
_ThrowArgumentNullException("node");
var attributeNodeList = node.selectNodes("attribute");
var attributeInfos = new Array();
for (var i = 0; i < attributeNodeList.length; i++)
{
var attributeNode = attributeNodeList.item(i);
var attributeInfo = new Object();
attributeInfo.Name = attributeNode.getAttribute("name");
attributeInfo.ReferencedType = attributeNode.getAttribute("referencedType");
attributeInfo.Type = attributeNode.getAttribute("type");
attributeInfos[i] = attributeInfo;
}
return attributeInfos;
}
this.DeserializeEntity = function(node, attributeInfos)
{
if (attributeInfos == null)
_ThrowArgumentNullException("attributeInfos");
if (node != null)
{
for (var i = 0; i < attributeInfos.length; i++)
{
var attributeInfo = attributeInfos[i];
try
{
var attributeNode = node.selectSingleNode(attributeInfo.Name);
if (attributeNode != null)
this.DeserializeAttribute(attributeNode, attributeInfo);
}
catch (e)
{
alert("Ошибка десериализации атрибута " + attributeInfo.Name + ": " + _GetErrorMessage(e) + "\nДесериализация будет продолжена.");
}
}
}
}
this.InvokeExtenderMethod = function(methodInfo)
{
if (methodInfo == null)
_ThrowArgumentNullException("methodInfo");
var request =
'<' + methodInfo.ExtenderMethod + ' xmlns="' + this.ExtensionServiceNamespace + '" >' +
'<formType>' + crmForm.FormType + '</formType>' +
'<entity xmlns="' + this.CrmServiceNamespace + '">' + this.SerializeEntity(methodInfo.InAttributes) + '</entity>';
if (methodInfo.SerializeIsDirty)
request += '<isDirty>' + crmForm.IsDirty + '</isDirty>';
request += '</' + methodInfo.ExtenderMethod + '>';
var message = this.WrapSoapMessage(request);
var messageResponse = this.InvokeSoapMethod(this.ExtensionService, message);
var response = this.ParseSoapResult(messageResponse, methodInfo.ExtenderMethod + "Response", this.ExtensionServiceNamespace);
this.DeserializeEntity(response.selectSingleNode(methodInfo.ResultNodeName), methodInfo.OutAttributes);
}
this.InvokeSoapMethod = function(service, message)
{
if (service == null)
_ThrowArgumentNullException("service");
if (message == null)
_ThrowArgumentNullException("message");
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", service, false);
xmlHttpRequest.setRequestHeader("Content-Type", "application/soap+xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", message.length);
xmlHttpRequest.send(message);
var responseText = xmlHttpRequest.responseText;
var responseDocument = new ActiveXObject("MSXML2.DOMDocument");
if (!responseDocument.loadXML(responseText))
{
var errorString =
(xmlHttpRequest.status != 200 ? "Ошибка выполнения WEB запроса " + xmlHttpRequest.status + ": " + xmlHttpRequest.statusText + "\n" : "Ошибка разбора ответного сообщения.\n") +
(_IsNullOrEmpty(responseText) ? "Ответное сообщение пусто." :
"Ответ сервера:\n" +
"---------------------------\n" +
responseText +
"\n---------------------------");
_ThrowInvalidOperationException(errorString);
}
return responseDocument;
}

this.ParseSoapResult = function(resultXml, exceptedElementName, exceptedElementNamespace)
{
if (resultXml == null)
_ThrowArgumentNullException("resultXml");
var namespaces = 'xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:extend="' + this.ExtensionServiceNamespace + '"';
if (exceptedElementNamespace != null)
namespaces += ' xmlns:result="' + exceptedElementNamespace + '"';
resultXml.setProperty("SelectionNamespaces", namespaces);
var faultNode = resultXml.selectSingleNode("/soap:Envelope/soap:Body/soap:Fault");
if (faultNode != null)
{
var friendlyMessageNode = faultNode.selectSingleNode('soapetail/extend:friendlyMessage');
if (friendlyMessageNode != null)
_ThrowInvalidOperationException(friendlyMessageNode.text);
else
{
var faultCodeNode = faultNode.selectSingleNode('soap:Code');
var faultStringNode = faultNode.selectSingleNode('soap:Reason');
var faultDetailNode = faultNode.selectSingleNode('soapetail');

var errorString = "Ошибка выполнения WEB запроса.\n" +
(faultCodeNode != null ? "Код ошибки: " + faultCodeNode.text + "\n" : "") +
(faultStringNode != null ? "Описание: " + faultStringNode.text + "\n" : "") +
(faultDetailNode != null ?
"Детальная информация: \n" +
"---------------------------\n" +
faultDetailNode.xml +
"\n---------------------------\n" : "");
_ThrowInvalidOperationException(errorString);
}
}
if (exceptedElementName != null)
{
var exceptedElement = resultXml.selectSingleNode((exceptedElementNamespace != null ? "/soap:Envelope/soap:Body/result:" : "/soap:Envelope/soap:Body/") + exceptedElementName);
if (exceptedElement == null)
{
var errorString1 = "Ошибка выполнения WEB запроса.\n" +
"Корневой элемент сообщения не найден либо не соответсвует ожидаемому значению.\n" +
"Ожидаемое имя корневого элемента: " + exceptedElementName + "\n" +
(exceptedElementNamespace != null ? "Ожидаемое пространство имен корневого элемента: " + exceptedElementNamespace + "\n" : "") +
"Текст сообщения: \n" +
"---------------------------\n" +
resultXml.xml +
"\n---------------------------\n";
_ThrowInvalidOperationException(errorString1);
}
return exceptedElement;
}
else
return resultXml.selectSingleNode("/soap:Envelope/soap:Body/*");
}
this.SerializeEntity = function(attributeInfos)
{
if (attributeInfos == null)
_ThrowArgumentNullException("attributeInfos");
var entityData = "";
for (var i = 0; i < attributeInfos.length; i++)
{
var attributeInfo = attributeInfos[i];
if (attributeInfo.Type == "Key")
{
if (!_IsNullOrEmpty(crmForm.ObjectId))
entityData += '<' + attributeInfo.Name + '>' + crmForm.ObjectId + '</' + attributeInfo.Name + '>';
}
else
{
var dataValue = crmForm.all[attributeInfo.Name].DataValue;
switch (attributeInfo.Type)
{
case "String":
if (dataValue != null)
entityData += '<' + attributeInfo.Name + '>' + dataValue + '</' + attributeInfo.Name + '>';
break;
case "Integer":
case "Duration":
case "DateTime":
case "Float":
case "Currency":
case "Boolean":
entityData += '<' + attributeInfo.Name;
if (dataValue == null)
entityData += ' IsNull="true" />';
else
entityData += '>' + dataValue + '</' + attributeInfo.Name + '>';
break;
case "Picklist":
case "StatusReason":
case "State":
entityData += '<' + attributeInfo.Name;
if (dataValue == null)
entityData += ' IsNull="true" />';
else
entityData += ' name="' + crmForm.all[attributeInfo.Name].SelectedText + '">' + dataValue + '</' + attributeInfo.Name + '>';
break;
case "Customer":
case "Regarding":
case "Lookup":
case "PartyList":
entityData += '<' + attributeInfo.Name;
if (dataValue == null)
entityData += ' IsNull="true" />';
else
entityData += ' name="' + dataValue[0].name + '" type="' + dataValue[0].typename + '">' + dataValue[0].id + '</' + attributeInfo.Name + '>';
break;
default:
_ThrowInvalidOperationException("Сериализация аттрибутов типа " + attributeInfo.Type + " не поддерживается");
break;
}
}
}
return entityData;
}
this.WrapSoapMessage = function(message)
{
if (message == null)
_ThrowArgumentNullException("message");
return '<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:Body>' + message + '</soap12:Body></soap12:Envelope>';
}

var extenderInfoRequest = '<getExtenderInfo xmlns="' + this.ExtensionServiceNamespace + '" />';
extenderInfoRequestMessage = this.WrapSoapMessage(extenderInfoRequest);
var extenderInfoResponseMessage = this.InvokeSoapMethod(this.ExtensionService, extenderInfoRequestMessage);
var extenderInfoResponse = this.ParseSoapResult(extenderInfoResponseMessage, "getExtenderInfoResponse", this.ExtensionServiceNamespace);
var methodNodeList = extenderInfoResponse.selectNodes("formExtenderInfo/methods/method");
for (var methodNode = methodNodeList.nextNode(); methodNode != null; methodNode = methodNodeList.nextNode())
{ //TODO: добавить механизм со
var methodInfo = new Object();
methodInfo.ExtenderMethod = methodNode.getAttribute("extenderMethod");
methodInfo.ResultNodeName = methodNode.getAttribute("resultNodeName");
methodInfo.SerializeIsDirty = _ParseBool(methodNode.getAttribute("serializeIsDirty"));
methodInfo.TargetElement = methodNode.getAttribute("targetElement");
methodInfo.TargetEvent = methodNode.getAttribute("targetEvent");
methodInfo.TargetMethod = methodNode.getAttribute("targetMethod");
methodInfo.InAttributes = this.DeserializeAttributeInfos(methodNode.selectSingleNode("inAttributes"));
methodInfo.OutAttributes = this.DeserializeAttributeInfos(methodNode.selectSingleNode("outAttributes"));
var entenderMethodInvoker = new ExtenderMethodInvoker(this, methodInfo);
if (!_IsNullOrEmpty(methodInfo.TargetElement))
{
var targetElement = crmForm.all[methodInfo.TargetElement];
if (!_IsNullOrEmpty(methodInfo.TargetEvent))
targetElement.attachEvent(methodInfo.TargetEvent, entenderMethodInvoker);
if (!_IsNullOrEmpty(methodInfo.TargetMethod))
targetElement[methodInfo.TargetMethod] = entenderMethodInvoker;
}
else
{
if (!_IsNullOrEmpty(methodInfo.TargetEvent))
if (methodInfo.TargetEvent == "onload")
this.OnLoad = entenderMethodInvoker;
else
crmForm.attachEvent(methodInfo.TargetEvent, entenderMethodInvoker);
if (!_IsNullOrEmpty(methodInfo.TargetMethod))
crmForm[methodInfo.TargetMethod] = entenderMethodInvoker;
}
}
}
var extender = new Extender();
if (extender.OnLoad != null)
extender.OnLoad();

ШУТКА!!!
На самом деле IsDirty вполне может подтормаживать, потому-что не факт, что он выполняется локально. Возможно он на каждой проверке лезет в базу и сравнивает поля на форме с полями в базе (такое поведение разумно, это один из паттернов оптимистической блокировки). Мне лень разбираться, я просто добавил if и скорость подскочила в несколько раз.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Сохраняется ли форма когда IsDirty == false? Черничкин Станислав Dynamics CRM: Разработка 2 13.12.2007 21:20
Ошибка на всех страничках glad Dynamics CRM: Администрирование 5 24.07.2006 10:36
Поменял подразделение у всех пользователей в CRM cruzo Dynamics CRM: Администрирование 2 29.09.2005 17:32

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 14:58.