protected string GetRegistrationPaymentUrl(Guid eventRegistrationId) { var portal = PortalCrmConfigurationManager.CreatePortalContext(PortalName); var website = portal.ServiceContext.CreateQuery("adx_website").FirstOrDefault(w => w.GetAttributeValue <Guid>("adx_websiteid") == portal.Website.Id); var page = portal.ServiceContext.GetPageBySiteMarkerName(website, "Event Registration - Payment Required"); if (page == null) { Tracing.FrameworkError(GetType().FullName, MethodBase.GetCurrentMethod().Name, "Page could not be found for Site Marker named 'Event Registration - Payment Required'"); return(null); } var url = portal.ServiceContext.GetUrl(page); if (string.IsNullOrWhiteSpace(url)) { Tracing.FrameworkError(GetType().FullName, MethodBase.GetCurrentMethod().Name, "Url could not be determined for Site Marker named 'Event Registration - Payment Required'"); return(null); } var urlBuilder = new UrlBuilder(url); urlBuilder.QueryString.Add(EventRegistrationIdQueryStringParameterName, eventRegistrationId.ToString()); return(urlBuilder.PathWithQueryString); }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { return; } if (Entity.LogicalName != "adx_webpage") { throw new ArgumentException(string.Format("Invalid target entity. This page template is designed for use with Web Page (adx_webpage) records. The current entity type is '{0}'", Entity.LogicalName)); } Subject = Entity.GetAttributeValue <EntityReference>("adx_subjectid"); if (Subject == null) { Tracing.FrameworkError(GetType().FullName, MethodBase.GetCurrentMethod().Name, "Current Web Page with ID equal to '{0}' does not have a required subject. Please ensure subjects have been created and that a subject has been assigned to the Web Page and any products that should be displayed for this page.", Entity.Id); Subject = new EntityReference("subject", Guid.NewGuid()); } Guid brandId; Brand = Guid.TryParse(Request.QueryString["brand"], out brandId) ? new EntityReference("adx_brand", brandId) : null; }
private WindowsLiveLogin.User GetWindowsLiveLoginUser(string token) { var user = new WindowsLiveLogin(true).ProcessToken(token); if (user == null) { Tracing.FrameworkError(ToString(), "GetPuid", "The Live ID token was not valid or could not be parsed -- No user created"); return(null); } return(user); }
protected override int ExecuteDelete(IDictionary keys, IDictionary oldValues) { Tracing.FrameworkInformation("CrmDataSourceView", "ExecuteDelete", "Begin"); if (!CanDelete) { throw new NotSupportedException("Delete not supported."); } var id = keys["ID"] as Guid?; var entityName = keys["Name"] as string; if (id == null || entityName == null) { throw new ArgumentException("Delete requires the 'ID' and 'Name' to be specified as DataKeyNames.", "keys"); } var rowsAffected = 0; var deletedEventArgs = new CrmDataSourceViewDeletedEventArgs(); try { var entity = _crmDataContext.Retrieve(entityName, id.Value, new ColumnSet(true)); if (entity == null) { throw new NullReferenceException("The {0} entity with ID='{1}' could not be found.".FormatWith(id, entityName)); } _crmDataContext.Attach(entity); _crmDataContext.DeleteObject(entity); var result = _crmDataContext.SaveChanges(); rowsAffected = result.HasError ? 0 : 1; } catch (Exception e) { Tracing.FrameworkError("CrmDataSourceView", "ExecuteDelete", "{0}", e); deletedEventArgs.Exception = e; deletedEventArgs.ExceptionHandled = true; } Tracing.FrameworkInformation("CrmDataSourceView", "ExecuteDelete", "End"); OnDeleted(deletedEventArgs); return(rowsAffected); }
protected void ConvertToOrder_Click(object sender, EventArgs args) { var quoteToEditEntity = QuoteToEdit != null ? QuoteToEdit.Entity : null; if (quoteToEditEntity == null || (quoteToEditEntity.GetAttributeValue <EntityReference>("customerid") != null && !quoteToEditEntity.GetAttributeValue <EntityReference>("customerid").Equals(Contact.ToEntityReference()))) { throw new InvalidOperationException("Unable to retrieve quote."); } Entity order; try { order = QuoteToEdit.CreateOrder(); if (order == null) { ConvertToOrderError.Visible = true; return; } } catch (Exception e) { Tracing.FrameworkError(GetType().FullName, MethodBase.GetCurrentMethod().Name, "{0}", e); ConvertToOrderError.Visible = true; return; } var orderid = order.GetAttributeValue <Guid>("salesorderid"); if (!ServiceContext.IsAttached(Website)) { ServiceContext.Attach(Website); } var page = ServiceContext.GetPageBySiteMarkerName(Website, "View Order") ?? ServiceContext.GetPageBySiteMarkerName(Website, "Order Status"); if (page == null) { return; } var url = new UrlBuilder(ServiceContext.GetUrl(page)); url.QueryString.Set("OrderID", orderid.ToString()); Response.Redirect(url.PathWithQueryString); }
protected override int ExecuteInsert(IDictionary values) { Tracing.FrameworkInformation("CrmDataSourceView", "ExecuteInsert", "Begin"); if (!CanInsert) { throw new NotSupportedException("Insert not supported."); } string entityName = values["EntityName"] as string; if (string.IsNullOrEmpty(entityName)) { throw new ArgumentException("Insert requires an 'EntityName' to be specified as one of the values.", "values"); } var entity = new Entity(entityName); SetEntityAttributes(entity, values); var rowsAffected = 0; var insertedEventArgs = new CrmDataSourceViewInsertedEventArgs(); try { _crmDataContext.AddObject(entity); _crmDataContext.SaveChanges(); insertedEventArgs.EntityId = entity.Id; rowsAffected = 1; } catch (Exception e) { Tracing.FrameworkError("CrmDataSourceView", "ExecuteInsert", "{0}", e); insertedEventArgs.Exception = e; insertedEventArgs.ExceptionHandled = true; } Tracing.FrameworkInformation("CrmDataSourceView", "ExecuteInsert", "End: rowsAffected={0}", rowsAffected); OnInserted(insertedEventArgs); return(rowsAffected); }
private static bool TryGetViewId(Entity entityList, out Guid viewId) { // First, try get the view from the newer view configuration JSON. viewId = Guid.Empty; var viewMetadataJson = entityList.GetAttributeValue <string>("adx_views"); if (!string.IsNullOrWhiteSpace(viewMetadataJson)) { try { var viewMetadata = ViewMetadata.Parse(viewMetadataJson); var view = viewMetadata.Views.FirstOrDefault(); if (view != null) { viewId = view.ViewId; return(true); } } catch (Exception e) { Tracing.FrameworkError(typeof(PackageRepositoryHelpers).FullName, "TryGetViewId", "Error parsing adx_views JSON: {0}", e); } } // Fall back to the legacy comma-delimited list of IDs. var viewIds = (entityList.GetAttributeValue <string>("adx_view") ?? string.Empty) .Split(',') .Select(s => { Guid id; return(Guid.TryParse(s, out id) ? new Guid?(id) : null); }) .Where(id => id != null); viewId = viewIds.FirstOrDefault() ?? Guid.Empty; return(viewId != Guid.Empty); }
void IUpdatable.SaveChanges() { Tracing.FrameworkInformation("CrmOrganizationServiceContext", "SaveChanges", "Begin"); var results = SaveChanges(); foreach (var result in results) { if (result.Error != null) { Tracing.FrameworkError("CrmOrganizationServiceContext", "SaveChanges", result.Error.Message); } } if (results.HasError) { throw new DataServiceException("An error occured during save."); } Tracing.FrameworkInformation("CrmOrganizationServiceContext", "SaveChanges", "End"); }
public virtual void ProcessRequest(HttpContext context) { try { if (context.Request.ContentType == "application/json") { ProcessJsonRequest(context); return; } var message = GetMessage(context); if (string.Equals("Publish", message, StringComparison.InvariantCultureIgnoreCase) || string.Equals("PublishAll", message, StringComparison.InvariantCultureIgnoreCase)) { foreach (var serviceCache in GetServiceCaches()) { serviceCache.Remove(GetPluginMessage(CacheItemCategory.Metadata)); } // get the default object cache foreach (var cache in GetObjectCaches()) { cache.Remove("xrm:dependency:metadata:*"); } return; } if (string.Equals("InvalidateAll", message, StringComparison.InvariantCultureIgnoreCase)) { foreach (var serviceCache in GetServiceCaches()) { serviceCache.Remove(GetPluginMessage(CacheItemCategory.All)); } // get the default object cache foreach (var cache in GetObjectCaches()) { cache.RemoveAll(); } return; } var entity = GetEntityReference(context); // get the default service cache if (string.Equals("Create", message, StringComparison.InvariantCultureIgnoreCase) || string.Equals("Update", message, StringComparison.InvariantCultureIgnoreCase) || string.Equals("Delete", message, StringComparison.InvariantCultureIgnoreCase)) { foreach (var serviceCache in GetServiceCaches()) { serviceCache.Remove(entity); } return; } } catch (Exception e) { Tracing.FrameworkError(GetType().Name, "ProcessRequest", "Cache invalidation failed. {0}", e.Message); } }
protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments) { Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "Begin"); if (CanSort) { arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort); } if (CanPage) { arguments.AddSupportedCapabilities(DataSourceCapabilities.Page); } if (CanRetrieveTotalRowCount) { arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount); } // merge SelectParameters IOrderedDictionary parameters = SelectParameters.GetValues(Context, Owner); string sortExpression = GetNonNullOrEmpty( arguments.SortExpression, parameters[_sortExpressionParameterName] as string, SortExpression); string entityName = GetNonNullOrEmpty( parameters[_entityNameParameterName] as string, EntityName); string attributeName = GetNonNullOrEmpty( parameters[_attributeNameParameterName] as string, AttributeName); var metadataFlags = MetadataFlags; if (parameters.Contains(_metadataFlagsParameterName)) { metadataFlags = (parameters[_metadataFlagsParameterName] as string).ToEnum <EntityFilters>(); } var entityFlags = EntityFlags; if (parameters.Contains(_entityFlagsParameterName)) { entityFlags = (parameters[_entityFlagsParameterName] as string).ToEnum <EntityFilters>(); } // raise pre-event CrmMetadataDataSourceSelectingEventArgs selectingArgs = new CrmMetadataDataSourceSelectingEventArgs( Owner, arguments, entityName, attributeName, metadataFlags, entityFlags, sortExpression); OnSelecting(selectingArgs); if (selectingArgs.Cancel) { Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "Cancel"); return(null); } // merge event results arguments.RaiseUnsupportedCapabilitiesError(this); sortExpression = selectingArgs.SortExpression; entityName = selectingArgs.EntityName; attributeName = selectingArgs.AttributeName; metadataFlags = selectingArgs.MetadataFlags; entityFlags = selectingArgs.EntityFlags; if (CancelSelectOnNullParameter && string.IsNullOrEmpty(entityName) && string.IsNullOrEmpty(attributeName)) { Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "CancelSelectOnNullParameter"); return(null); } IEnumerable result = null; int rowsAffected = 0; try { if (Owner.CacheParameters.Enabled) { var cacheKey = GetCacheKey(metadataFlags, entityFlags, entityName, attributeName, sortExpression); result = ObjectCacheManager.Get(cacheKey, cache => { var metadata = ExecuteSelect(entityName, attributeName, sortExpression, entityFlags, metadataFlags, out rowsAffected); return(metadata); }, (cache, metadata) => { if (metadata != null) { var dependencies = GetCacheDependencies(metadata); cache.Insert(cacheKey, metadata, dependencies); } }); } else { result = ExecuteSelect(entityName, attributeName, sortExpression, entityFlags, metadataFlags, out rowsAffected); } } catch (System.Web.Services.Protocols.SoapException ex) { Tracing.FrameworkError("CrmMetadataDataSourceView", "ExecuteSelect", "{0}\n\n{1}", ex.Detail.InnerXml, ex); } catch (Exception e) { Tracing.FrameworkError("CrmMetadataDataSourceView", "ExecuteSelect", "Exception: {0}", e); // raise post-event with exception CrmMetadataDataSourceStatusEventArgs selectedExceptionArgs = new CrmMetadataDataSourceStatusEventArgs(0, e); OnSelected(selectedExceptionArgs); if (!selectedExceptionArgs.ExceptionHandled) { throw; } return(result); } // raise post-event CrmMetadataDataSourceStatusEventArgs selectedArgs = new CrmMetadataDataSourceStatusEventArgs(rowsAffected, null); OnSelected(selectedArgs); Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "End"); return(result); }
/// <summary> /// Retrieves the cache key based on the current property values. /// </summary> /// <param name="context"></param> /// <param name="control"></param> /// <param name="container"></param> /// <param name="getDefaultKey"></param> /// <returns></returns> public string GetCacheKey(System.Web.HttpContext context, System.Web.UI.Control control, object container, Converter <string, string> getDefaultKey) { string cacheKey = KeyFormat; if (Parameters != null && Parameters.Count > 0) { // use the parameters collection to build the dependency IOrderedDictionary values = Parameters.GetValues(context, control); if (container != null) { // process CacheItemParameter objects, lookup the value based on the container foreach (Parameter param in Parameters) { if (param is CacheItemParameter) { string format = (param as CacheItemParameter).Format; string propertyName = (param as CacheItemParameter).PropertyName; string result = DataBinder.Eval(container, propertyName, format); if (!string.IsNullOrEmpty(result)) { values[param.Name] = result; } } } } if (!string.IsNullOrEmpty(KeyFormat)) { foreach (DictionaryEntry entry in values) { if (entry.Key != null) { string key = entry.Key.ToString().Trim(); if (!key.StartsWith("@")) { key = "@" + key; } cacheKey = Regex.Replace(cacheKey, key, "{0}".FormatWith(entry.Value), RegexOptions.IgnoreCase); } } } } else if (!string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(PropertyName)) { string result = null; if (container != null) { try { result = DataBinder.Eval(container, PropertyName, "{0}"); } catch (Exception e) { Tracing.FrameworkError("CacheKeyDependency", "GetCacheKey", "Invalid cache parameter settings."); Tracing.FrameworkError("CacheKeyDependency", "GetCacheKey", e.ToString()); } } // use this object to build the dependency string key = Name.Trim(); if (!key.StartsWith("@")) { key = "@" + key; } cacheKey = Regex.Replace(cacheKey, key, result ?? string.Empty, RegexOptions.IgnoreCase); } if (string.IsNullOrEmpty(cacheKey)) { // could not find a suitable cacheKey from the parameters, build a default key cacheKey = "Adxstudio:{0}:ID={1}".FormatWith(control.GetType().FullName, control.ID); // provide an opportunity to override this suggested default if (getDefaultKey != null) { cacheKey = getDefaultKey(cacheKey); } } if (VaryByUser) { IIdentity identity; if (TryGetCurrentIdentity(out identity) && identity.IsAuthenticated) { cacheKey += ":Identity={0}".FormatWith(identity.Name); } } if (!string.IsNullOrEmpty(VaryByParam)) { foreach (string section in VaryByParam.Split(_varySeparator)) { string param = section.Trim(); cacheKey += ":{0}={1}".FormatWith(param, context.Request[param]); } } return(cacheKey); }
protected override IEnumerable EndExecuteSelect(IAsyncResult asyncResult) { Tracing.FrameworkInformation("CrmDataSourceView", "EndExecuteSelect", "Begin"); if (_client == null) { Tracing.FrameworkInformation("CrmDataSourceView", "EndExecuteSelect", "End: _client=null"); return(null); } IEnumerable selectResult = null; int rowsAffected = 0; try { SynchronousAsyncSelectResult syncResult = asyncResult as SynchronousAsyncSelectResult; if (syncResult != null) { Tracing.FrameworkInformation("CrmDataSourceView", "EndExecuteSelect", "syncResult"); selectResult = syncResult.SelectResult; } else { Tracing.FrameworkInformation("CrmDataSourceView", "EndExecuteSelect", "EndExecute"); var response = _execute.EndInvoke(asyncResult); if (response != null) { var entities = response.Entities; rowsAffected = entities.Count; selectResult = ExecuteSelect(entities).ToList(); if (Owner.CacheParameters.Enabled) { var dependencies = GetCacheDependencies(Request.Query, selectResult); string cacheKey = GetCacheKey(Request.Query); // insert into cache ObjectCacheManager.GetInstance().Insert(cacheKey, selectResult, dependencies); } } } } catch (System.Web.Services.Protocols.SoapException ex) { Tracing.FrameworkError("CrmDataSourceView", "EndExecuteSelect", "{0}\n\n{1}", ex.Detail.InnerXml, ex); } catch (Exception e) { Tracing.FrameworkError("CrmDataSourceView", "EndExecuteSelect", "Exception: {0}", e); // raise post-event with exception CrmDataSourceStatusEventArgs selectedExceptionArgs = new CrmDataSourceStatusEventArgs(0, e); OnSelected(selectedExceptionArgs); if (!selectedExceptionArgs.ExceptionHandled) { throw; } return(selectResult); } finally { _client = null; } // raise post-event CrmDataSourceStatusEventArgs selectedArgs = new CrmDataSourceStatusEventArgs(rowsAffected, null); OnSelected(selectedArgs); Tracing.FrameworkInformation("CrmDataSourceView", "EndExecuteSelect", "End"); return(string.IsNullOrEmpty(Owner.StaticEntityWrapperTypeName) ? selectResult : CreateEntities(selectResult)); }
protected override IAsyncResult BeginExecuteSelect( DataSourceSelectArguments arguments, AsyncCallback asyncCallback, object asyncState) { Tracing.FrameworkInformation("CrmDataSourceView", "BeginExecuteSelect", "Begin"); if (CanSort) { arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort); } if (CanPage) { arguments.AddSupportedCapabilities(DataSourceCapabilities.Page); } if (CanRetrieveTotalRowCount) { arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount); } string fetchXml; QueryByAttribute query; InitializeParameters(out fetchXml, out query); // raise pre-event CrmDataSourceSelectingEventArgs selectingArgs = new CrmDataSourceSelectingEventArgs( Owner, arguments, fetchXml, query); OnSelecting(selectingArgs); IEnumerable selectResult = null; if (selectingArgs.Cancel) { Tracing.FrameworkInformation("CrmDataSourceView", "BeginExecuteSelect", "Cancel"); return(new SynchronousAsyncSelectResult(selectResult, asyncCallback, asyncState)); } // merge event results arguments.RaiseUnsupportedCapabilitiesError(this); fetchXml = selectingArgs.FetchXml; if (CancelSelectOnNullParameter && string.IsNullOrEmpty(fetchXml) && query == null) { Tracing.FrameworkInformation("CrmDataSourceView", "BeginExecuteSelect", "CancelSelectOnNullParameter"); return(new SynchronousAsyncSelectResult(selectResult, asyncCallback, asyncState)); } try { _client = OrganizationServiceContextFactory.Create(Owner.CrmDataContextName); if (!string.IsNullOrEmpty(fetchXml)) { Tracing.FrameworkInformation("CrmDataSourceView", "BeginExecuteSelect: fetchXml", fetchXml); var queryExpression = ToFetchExpression(arguments, fetchXml); Tracing.FrameworkInformation("CrmDataSourceView", "BeginExecuteSelect", "End"); return(ExecuteSelect(_client, queryExpression, asyncCallback, asyncState)); } if (query != null) { Tracing.FrameworkInformation("CrmDataSourceView", "BeginExecuteSelect", "QueryByAttribute"); // the SortExpression has high priority, apply it to the query AppendSortExpressionToQuery(arguments.SortExpression, order => query.Orders.Add(order)); Tracing.FrameworkInformation("CrmDataSourceView", "BeginExecuteSelect", "End"); return(ExecuteSelect(_client, query, asyncCallback, asyncState)); } } catch (System.Web.Services.Protocols.SoapException ex) { Tracing.FrameworkError("CrmDataSourceView", "BeginExecuteSelect", "{0}\n\n{1}", ex.Detail.InnerXml, ex); } catch (Exception e) { Tracing.FrameworkError("CrmDataSourceView", "BeginExecuteSelect", "Exception: {0}", e); _client = null; return(new SynchronousAsyncSelectResult(e, asyncCallback, asyncState)); } Tracing.FrameworkInformation("CrmDataSourceView", "BeginExecuteSelect", "End"); return(new SynchronousAsyncSelectResult(selectResult, asyncCallback, asyncState)); }