he sandboxed code execution request was refused because the Sandboxed Code Host Service was too busy to handle the request - sharepoint-2013

I have a event receiver in my project and in the event receiver I have following code. It is bound to custom list.
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
// Get the web where the event was raised
SPWeb spCurrentSite = properties.OpenWeb();
//Get the name of the list where the event was raised
String curListName = properties.ListTitle;
//If the list is our list named SubSites the create a new subsite directly below the current site
if (curListName == "Customers")
{
//Get the SPListItem object that raised the event
SPListItem curItem = properties.ListItem;
//Get the Title field from this item. This will be the name of our new subsite
String curItemSiteName = properties.AfterProperties["Title"].ToString();
//Get the Description field from this item. This will be the description for our new subsite
string curItemDescription = properties.AfterProperties["Description"].ToString();
//Update the SiteUrl field of the item, this is the URL of our new subsite
properties.AfterProperties["SiteUrl"] = spCurrentSite.Url + "/" + curItemSiteName;
//Create the subsite based on the template from the Solution Gallery
SPWeb newSite = spCurrentSite.Webs.Add(curItemSiteName, curItemSiteName, curItemDescription, Convert.ToUInt16(1033), "WIKI#0", false, false);
//Set the new subsite to inherit it's top navigation from the parent site, Usefalse if you do not want this.
newSite.Navigation.UseShared = true;
CreateList(newSite);
newSite.Close();
}
}
This code works fine for farm solutions. For sandbox solutions it gives exception at :
SPWeb newSite = spCurrentSite.Webs.Add(curItemSiteName, curItemSiteName, curItemDescription, Convert.ToUInt16(1033), "WIKI#0", false, false);
Says "he sandboxed code execution request was refused because the Sandboxed Code Host Service was too busy to handle the request."
Any suggestion??

Related

Uploaded media files 404 on production but show up hours later

We've built a custom front end for users to post threads and upload images on top of Sitecore 9. Recently, we moved the user generated content to it's own database, so the media files are no longer in the proper sitecore 'media gallery'. Also, file storage is on a networked share. Uploading images works just fine. It's immediately after where the problem lies.
Upon image upload, our rest api returns the media url from the MediaManager.GetMediaUrl(itemId). This also works. It returns a valid url, it is formatted correctly and should resolve. Unfortunately, for some time after, the url does the sitecore dance an 302s to our 404 page.
I can see the image through the content editor and our custom content handler injects the image folder node into both master and web databases.
Why would the link manager be able to find the url, but the image is not available? I uploaded something yesterday afternoon, an when I checked this morning, the image is now available on the site. Any information or suggestions are appreciated.
I have tried saving the image multiple times hoping that this might trigger whatever mystical Sitecore event that causes images to show. Since there isn't a publish due to the separate database, I can't try that. I've removed all versions thinking it couldn't default to a particular language. Nothing. Only time seems to make the images visible. The code below works just fine. I'm just putting it here to to show some work.
public MediaItem UploadSimpleMedia(MediaGallerySimpleUploadRequest request)
{
try
{
var destinationFolder = request.ParentItemId != null
? _content.GetItem<Item>(request.ParentItemId.Value)
: _content.GetItem<Item>(_publicLibraryPath + "/embeded");
var name = !string.IsNullOrEmpty(request.Name)
? ItemUtil.ProposeValidItemName(request.Name)
: ItemUtil.ProposeValidItemName(request.Files[0].FileName);
var creator = new MediaCreator();
var tags = request.Tags != null ? request.Tags.Split(',') : new string[0];
var tagIds = _tagService.GetTagIds(tags);
var tagIdString = string.Join(",", tagIds);
var options = new MediaCreatorOptions()
{
AlternateText = request.Name,
FileBased = true,
IncludeExtensionInItemName = false,
Versioned = false,
Destination = $"{destinationFolder.Paths.Path}/{name}",
Database = Factory.GetDatabase("content")
};
using (new SecurityDisabler())
using (new DatabaseCacheDisabler())
{
MediaItem item = creator.CreateFromStream(request.Files[0].InputStream, request.Files[0].FileName, options);
item.BeginEdit();
item.InnerItem["Title"] = request.Name;
item.InnerItem["Description"] = request.Description;
item.InnerItem["__Semantics"] = tagIdString;
// Sitecore won't calculate MIME Type or File Size automatically unless you upload directly
// to the Sitecore Media Library. We're uploading in-place for private groups for permission inheritance
// and now because of indexing, they are getting uploaded to /Community/Gallery/Files if not private.
item.InnerItem["Size"] = request.Files[0].ContentLength.ToString();
item.InnerItem["Mime Type"] = request.Files[0].ContentType;
item.EndEdit();
// Just pausing here to reflect on why Sitecore is so sexily complicated
// that it takes time to display an image on the CD, but has no problem giving
// up the media url
CacheManager.GetHtmlCache(Sitecore.Context.Site);
_searchService.RefreshIndex(item.ID.Guid);
var fromDatabase = _content.GetItem<Item>(item.ID.Guid);
return fromDatabase;
}
}
catch (Exception ex)
{
_logger.Error(this.GetType().AssemblyQualifiedName, ex);
_logger.Trace(ex.StackTrace);
}
return null;
}
I don't get any error messages either in our custom logs or the default sitecore logs. Images just aren't resolving. Is it caching? I've even nuked all caches by calling CacheManager.ClearAllCaches().

Sitecore EXM 3.2(ECM) Assign goal to the triggered message

I need to do a simple newsletter form. This form should work like this:
User inputs an email and presses to the submit button
User recieves message on email with confirm link
After user clicks on the link his email is added to Recipient list
This form should be work with help EXM
I've created Triggered message in the EXM with link for subscription.
And I wrote this code for the Submit button for trigger the Newsletter Goal
[HttpPost]
public ActionResult NewsletterSubscribe(NewsletterViewBag model)
{
var goal = Context.Database.GetItem(newsletterGoal);
if (goal == null)
{
continue;
}
var registerGoal = new Sitecore.Analytics.Data.Items.PageEventItem(goal);
var eventData = Tracker.Current.CurrentPage.Register(registerGoal);
eventData.Data = goal[DateTime.Now.ToString(CultureInfo.InvariantCulture)];
Tracker.Submit();
}
How I can assign my triggered message to the newsletterGoal?
Also I try manually send message this way:
MessageItem message = Sitecore.Modules.EmailCampaign.Factory.GetMessage(new ID(messageId));
Sitecore.Modules.EmailCampaign.AsyncSendingManager manager = new AsyncSendingManager(message);
var contactId = ClientApi.GetAnonymousIdFromEmail(email);
var recipientId = (RecipientId) new XdbContactId(contactId);
manager.SendStandardMessage(recipientId);
And I see error in the log: The recipient 'xdb:857bbea1-1f18-4621-a798-178399cd0b54' does not exist. But Triggered Message haven't any recipient list
Goals are not assigned directly to messages. You can, however, assign engagement plans and campaigns. Each message has its own engagement plan to handle tracking the contacts actions with the message. If you create a campaign that triggers a goal, you can assign that to the message and it will be associated with the contact when they receive the message. You can also leverage the message engagement plan to trigger events as the contact proceeds through those states.
Also, you're missing some details while recording the contact data.
Look at the newsletter signup control that is included in the EXM module. The important part in there is this:
protected virtual RecipientId RecipientId
{
get
{
RecipientId recipientId = null;
var contactId = ContactId;
if (contactId != (ID)null)
{
recipientId = new XdbContactId(contactId);
}
return recipientId;
}
}
protected virtual ID ContactId
{
get
{
if (!Email.Visible || string.IsNullOrEmpty(Email.Text))
{
return new ID(Tracker.Current.Contact.ContactId);
}
var anonymousId = ClientApi.GetAnonymousIdFromEmail(Email.Text);
return anonymousId.HasValue ? new ID(anonymousId.Value) : new ID(Tracker.Current.Contact.ContactId);
}
}
protected virtual void UpdateEmailInXdb()
{
_recipientRepository.UpdateRecipientEmail(RecipientId, Email.Text);
}
It will write the email address directly to Mongo, rather than waiting for the session to end. Include this and the related RecipientId and ContactId properties in your signup code.
Once they are signed up you can register the goal programmatically or send them to a Thank You page where the goal can be registered (Advanced - Tracking), or send the message and let that register the goal. Or create an engagement plan with states for each step of the process (this is the best way).
You'll also want to add the recipient to a list that the newsletter message can use later. Actually, it looks to me like the example Subscription Form does everything you need.

How to get Display name of user profile manager property

When I was writing custom display template for SharePoint people search, I wanted to display the manager of the searched user. When I display the manager value returned from SharePoint people search, it displays as follows:
i:0#.f|membership|lpalmer#xyz.com
I want to show the display instead of the account name in my SharePoint display template. Let me know if this can be done either using JavaScript or just by doing some configurations on SharePoint user profile property change.
This cannot be done using just configurations. You will need to query the User Profile Service and get the Display Name using the login name the search service returns.
For obtaining any property you can use something like this:
function getProfilePropertyValueFromLoginName(loginName, propertyName, success, error) {
// Get the current client context and PeopleManager instance.
var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
// Get user properties for the target user.
// To get the PersonProperties object for the current user, use the
// getMyProperties method.
var personProperties = peopleManager.getPropertiesFor(loginName);
// Load the PersonProperties object and send the request.
clientContext.load(personProperties);
clientContext.executeQueryAsync(
function () {
if (success) {
success(loginName, personProperties.get_userProfileProperties()[propertyName]);
}
}, function (sender, args) {
if (error) {
error(sender, args);
}
});
}
-Hope it helps

How to call processing page via web service

I have a processing page and I want to run function process all via web service (add web reference into my C# window form app). My code below:
var context = new ModuleABCService.Screen() // limk web services: http://localhost:8686/soap/DMSBL009.asmx
{
CookieContainer = new CookieContainer(),
AllowAutoRedirect = true,
EnableDecompression = true,
Timeout = 60000
};
var loginResult = context.Login(string.Format("{0}#{1}", val.UserName, company), val.Password);
if (loginResult.Code != ErrorCode.OK)
{
throw new Exception(string.Format("Can not login {0}", company));
}
Content content = context.GetSchema();
context.Clear();
context.Submit(
new Command[]
{
content.Actions.ProcessAll
}
);
And I got an exception message:
System.Web.Services.Protocols.SoapExceptio:n Server was unable to process request. ---> PX.Data.PXUndefinedCompanyException: Unable determine proper company id for the request. at PX.Data.PXDatabaseProviderBase.getCompanyID(String tableName, companySetting& setting) in c:\Builders\4_10-2014_4_28-21_21_17-Full\Scripts\BuildTemp\NetTools\PX.Data\Database\Common\DbProviderBaseCompanies.cs:line 471...
Have you ever got this error before? Could you please give me any suggestion? Thank you so much!
Ok, I found out, because Acumatica's license

Sitecore publishing to webcm database hangs

I have customized the publishing process of a sitecore content item by making sure its related media items in /sitecore/media library/ directory are published whenever the content item itself is published. The problem is, the related media items publish fine to web database, but hang when being published to webcm database. Any reason for this?
here's my code for publishing a content item's related media item to web and webcm database:
private void PublishItemAsynchronously(ref Item sourceItem, ref Item mediaItem, PublishItemContext context)
{
String databaseName = "webCM";
try
{
if (Sitecore.Configuration.Factory.GetDatabase(databaseName) != null)
{
PublishOptions options = new PublishOptions(mediaItem.Database, Factory.GetDatabase(databaseName),
PublishMode.Smart, mediaItem.Language, DateTime.Now);
options.RootItem = mediaItem;
options.Deep = false;
new Publisher(options).PublishAsync();
Sitecore.Diagnostics.Log.Info("___________ Inside PublishRelationsAction::PublishItemAsynchronously(...), just published from webCM ", this);
}
databaseName = "web";
PublishOptions options2 = new PublishOptions(mediaItem.Database, Factory.GetDatabase(databaseName),
PublishMode.Smart, mediaItem.Language, DateTime.Now);
options2.RootItem = mediaItem;
options2.Deep = false;
new Publisher(options2).PublishAsync();
Sitecore.Diagnostics.Log.Info("___________ Inside PublishRelationsAction::PublishItemAsynchronously(...), just published from web ", this);
}
catch (Exception ex)
{
....
}
}
Any idea why webcm database publishes hang, while all publishes to web database work fine? Both of the above logging statements appear in my log file.
Disabling publishing status manager resolves this issue.
You can disable it by commenting out the content of
/App_Config/Include/Sitecore.SharedSource.AdvancedPublishDialog.config