I have run into a problem where I need to manually click the clear cache button for a specific product to appear correct on a specific page after it's saved.
I'm wondering how I can go about this with code, but only clear the cache for that product.
clearing complete cache can be done like this:
var _cacheManager = EngineContext.Current.Resolve<ICacheManager>();
_cacheManager.Clear();
I have tried doing it like this but it didn't work.
var product = _productService.GetProductById(productModel.Id);
var productTemplateCacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_TEMPLATE_MODEL_KEY,
productModel.Id);
_cacheManager.Remove(productTemplateCacheKey);
Not sure how to go about this, anyone got any ideas?
Thanks
Related
I am updating an old Outlook.Interop App that moves emails around, downloads attachments, and auto assigns categories to the emails that it moves. In the old app you could do something like...
email.Categories = "Blue Category";
That does not work in EWS. Does anyone have any ideas?
Thanks
I have tried:
email.Categories.Add("Blue Category");
email.Categories.Equals("Blue Category");
and obviously:
email.Categories = "Blue Category";
email.Categories.Add("Blue Category");
is the way to do it you also need to call update on the Item for the change to be saved.I suggest you enable tracing https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-trace-requests-responses-to-troubleshoot-ews-managed-api-applications then you should be able to see if the update is being sent to the server. You can also see if the change has been applied by calling load on the Item after the update and see if the property on the Item has been updated on the server (as you may just be having a client cache issue).
Does anyone know how to remove the renderings from a Sitecore item?
I want to remove all of the sublayouts so I can replace them with a new set.
I have tried this but it does not seem to work. Nothing changes on the item.
I appear to be able to get the renderings like this:
RenderingReference[] renderings = item.Visualization.GetRenderings(Sitecore.Context.Device, true);
But there appears to be no way to then set them.
I can also get the renderings like this (from the link above):
LayoutDefinition layoutDefinition = LayoutDefinition.Parse(LayoutField.GetFieldValue(item.Fields[Sitecore.FieldIDs.LayoutField]));
DeviceDefinition device = layoutDefinition.GetDevice(Sitecore.Context.Device.ID.ToString());
if (device.Layout != null) device.Layout = null;
if (device.Renderings != null) device.Renderings = new ArrayList();
But again this does not work. Clearing the device from the layoutDefinition and setting the modified one has led to this exception: No connection could be made because the target machine actively refused it. And I now cannot view the item at all!
I feel like I'm barking up the wrong tree, any ideas?
Using Sitecore 6.4
UPDATE Re: techphoria414
Code I tried:
layoutDefinition.Devices.Clear();
layoutDefinition.Devices.Add(device);
I think your exception is unrelated. To actually save your changes, you need to edit the item. Be sure you always access and update the value throgh LayoutField.Value.
LayoutField layoutField = new LayoutField(item.Fields[Sitecore.FieldIDs.LayoutField]);
LayoutDefinition layout = LayoutDefinition.Parse(layoutField.Value);
//make your changes to the LayoutDefinition here
item.Editing.BeginEdit();
layoutField.Value = layout.ToXml();
item.Editing.EndEdit();
I'm working with the Audit framework in MOSS 2007, and I've programatically enabled Auditing for 2 specific lists in a bunch of sites in a site collection(meaning the sites all have their own two lists). I've only enabled the update mask, as I only want to know when something's been changed or added.
However, I'm only able to log when something's been added, with my current setup. To allow for seeing changes to the list items, I'm aware that the list item itself has to have auditing enabled. But when adding a new item to the list, how do I automatically enable Auditing for the item? If possible, I'd prefer to avoid creating an event receiver to accomplish this.
*EDIT
The code I use to enable auditing looks something like this:
foreach (SPSite site in webApp.Sites) {
foreach (SPWeb website in site.AllWebs) {
website.Lists["MyList"].Audit.AuditFlags = SPAuditMaskType.Update;
website.Lists["MyList"].Audit.Update();
}
}
And to read it:
SPUserToken sysAdmin = website.Site.SystemAccount.UserToken;
using (SPSite elevatedSite = new SPSite(website.Site.ID,sysAdmin)) {
using (SPWeb elevatedWeb = elevatedSite.OpenWeb(website.ID)) {
SPAuditQuery auditQuery = new SPAuditQuery(elevatedSite);
auditQuery.SetRangeStart(myDatetime);
auditQuery.RestrictToList(elevatedWeb.Lists["MyList"]);
listChanges = elevatedWeb.Lists["MyList"].Audit.GetEntries(auditQuery);
}
}
I realize I'm restricting to list here, but when I didn't I got changes from other lists on the site as well. Even though logically I'd assume I only got the changes from the list I called "GetEntries" on...
Thanks
If the library has auditing enabled, then new items will be audited. I'm not aware of any document-specific auditing
A little late in replying to this, but here is some additional information in case others find this post.
It is possible to track the auditing events at the document level. This link explains how it can be done. They use an event handler to make it work. I know you mention you do not want to do it this way, but this is what is needed to automatically track document events. Setting the audit mask type on the document library appears to only track the DL events, not the individual items.
First of all I am a newbie in C# Programming, and I need to create a simple MRU as fast as i could.
Well the thing is I've tried looking at some online examples but however I found them to be quite a bit too confusing...
So is there anyway that anyone can create a "Recently Used" section in the toolstripmenuitem without going into those complicated codes??
E.g I will not be able to understand this stuff...
Registry key:
KEY_CURRENT_USER\Software\Microsoft\VCExpress\9.0\FileMRUList
Code:
Application.UserAppDataRegistry.DeleteSubKey("MRU", false);
RegistryKey appKey = Application.UserAppDataRegistry.CreateSubKey("MRU");
dictionary
microsoft.win32
I will only need something as simple as shown in this link below http://www.codeproject.com/KB/menus/MRUHandler.aspx
So you want to create a submenu like in the screenshot? For this, you will have to:
Store the list of recently-used files somewhere. This could be the registry, or it could just be a simple textfile, which I’ll do now to keep it simple.
Learn how to generate menu items at runtime instead of in the designer.
1. Store the MRU in a file
You will probably have already declared a private field to contain your MRU, right?
private List<string> _mru = new List<string>();
Every time someone opens a file, you add this file to the beginning of the MRU, right?
_mru.Insert(0, fullFilePath);
Now, of course when the application closes, you need to save this MRU to a file. Let’s do that in the Form’s FormClosed event. Double-click the FormClosed event in the properties and write some code which looks somewhat like this:
var appDataPath = Application.UserAppDataPath;
var myAppDataPath = Path.Combine(appDataPath, "MyApplication");
var mruFilePath = Path.Combine(myAppDataPath, "MRU.txt");
File.WriteAllLines(mruFilePath, _mru);
Now we have saved the MRU in a file. Now obviously when the application starts, we need to load it again, so do something like this in the form’s Load event:
var appDataPath = Application.UserAppDataPath;
var myAppDataPath = Path.Combine(appDataPath, "MyApplication");
var mruFilePath = Path.Combine(myAppDataPath, "MRU.txt");
if (File.Exists(mruFilePath))
_mru.AddRange(File.ReadAllLines(mruFilePath));
2. Create the menu items
Now that _mru contains the file paths that we want in our menu, we need to create a new menu item for each. I’ll be assuming here that you already have a menu item in the File menu (the item called “Most Recently Used” in your screenshot) and that it is called mnuRecentlyUsed, and that we only need to create sub-items:
foreach (var path in _mru)
{
var item = new ToolStripMenuItem(path);
item.Tag = path;
item.Click += OpenRecentFile;
mnuRecentlyUsed.DropDownItems.Add(item);
}
Now all we need is the method that actually opens a file, which I called OpenRecentFile:
void OpenRecentFile(object sender, EventArgs e)
{
var menuItem = (ToolStripMenuItem) sender;
var filepath = (string) menuItem.Tag;
// Proceed to open the file
// ...
}
Disclaimer
Please don’t use any of this code unless you understand it and you are sure that it is written to do what you intended. If it needs to do something slightly different, I’m sure you can make the necessary changes yourself.
Also, I’m sure you will have noticed that the above doesn’t update the sub-menu while the program is running. If you understand how the above code works, then I’m sure you’ll be able to figure out the rest for yourself.
http://www.codeproject.com/Tips/680088/Recent-Items-Tool-Strip-Menu-Item
This project does exactly what you want
I can successfully create an iteration path via:
var commonservice = collection.GetService<ICommonStructureService>();
// create new area path and iteration path
var iterationRoot = commonservice.GetNodeFromPath("\\MyTeamProject\\Iteration");
var newIterationPath = commonservice.CreateNode("my new sprint", iterationRoot.Uri);
However, when I try and assign this path to a work item and save it the field doesn't validate.
If I run the tests again (with the iteration already created) the same code succeeds.
Does anybody know how to make this work?
This fixed it for me:
WorkItemStore wis = (WorkItemStore)tfsTeamProjColl.GetService(typeof(WorkItemStore));
wis.RefreshCache();
wis.SyncToCache();
Maybe it will help someone.
I experienced exactly the same behavior, and unfortunately #JWC answer didn't help. The solution which works for me can be found by this link.
So, this is a quick summary in case the original answer gets lost.
The key point is to use WorkItemServer class. It lives in the Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll assembly.
First of all, you create a WorkItemStore instance:
var store = collection.GetService<WorkItemStore>();
Then, create necessary iteration paths:
var commonservice = collection.GetService<ICommonStructureService>();
var iterationRoot = commonservice.GetNodeFromPath("\\MyTeamProject\\Iteration");
var newIterationPath = commonservice.CreateNode("my sprint", iterationRoot.Uri);
Next, refresh the cache in TFS (I suspect this is similar to pressing F5 in web interface):
var wiServer = collection.GetService<WorkItemServer>();
wiServer.SyncExternalStructures(WorkItemServer.NewRequestId(), commonservice.GetProjectFromName("MyTeamProject").Uri);
store.RefreshCache();
And finally, assign newly created work item to the newly created iteration:
var wi = new WorkItem(store.Projects["MyTeamProject"].WorkItemTypes["Product Backlog Item"]);
wi.Title = "Hello from API";
wi.Description = "This work item was created from API";
wi.Fields["Assigned To"].Value = "Yan Sklyarenko";
wi.IterationPath = FormatPath(commonservice.GetNode(newIterationPath).Path, "Iteration", "MyTeamProject");
wi.Save();
That's it! The method FormatPath translates the iteration path to the form required by the work item IterationPath field, that is from \MyTeamProject\Iteration\my sprint to MyTeamProject\my sprint.
Hope this can save some time.
NOTE: I run this towards TFS 2013.
You are likely running into a caching issue. Try clearing the cache after you create the iteration. A couple things you could try:
Get a new copy of the WorkItemStore.
Disconnect and reconnect to TFS
Check to see if there's a "refresh" method on either the WIS or on the TFS server objects. I've shut down my dev instance of TFS for the night, and I don't recall if there's anything like it.
If that's not quite it, post your code and I'll see if I can reproduce it.
I had the similar issue. I created Areapath and then created a query where the AreaPath was used. I did call store.RefreshCashe() but it did not work. Only in Debugger when I run store.RefreshCashe() two times manually.
Thanks "Yan Sklyarenko". I tried your Suggestion and it works fine (TFS Server 2012).