I have included these files in my project with Build Action set to Content:
\Resources\Myfolder\Myfiles-de-DE.zip
\Resources\Myfolder\Myfiles-en-US.zip
\Resources\Myfolder\Myfiles-sv-SV.zip
\Resources\Myfolder\Myfiles-fr-FR.zip
In my Package.appxmanifest I have tried this [when "Open With..." "XML (Text) Editor"]:
<Resources>
<!-- First = Default -->
<Resource Language="en-US" />
<Resource Language="sv-SV" />
<Resource Language="de-DE" />
<Resource Language="fr-FR" />
</Resources>
and this:
<Resources>
<Resource Language="x-generate" />
</Resources>
In code I am trying to access the file like this:
Dim ZipPath As String = "Resources\Myfolder\Myfiles-.zip"
Dim fs As System.IO.Stream = Await _
Windows.ApplicationModel.Package.Current.InstalledLocation.OpenStreamForReadAsync(ZipPath)
But I get only a FileNotFoundException! What am I doing wrong?
PS: The file loads if I change the code to this:
Dim ZipPath As String = "Resources\Myfolder\Myfiles-en-US.zip"
It isn't fully clear what you're trying to accomplish. But the code should throw that exception unless you have Resources\Myfolder\Myfiles-.zip file loaded in there by default.
I'm guessing you want to load in the specific zip file based on their prefer language, but no where in your code do attempt to get their language.
You can try to do a LocalizedStrings : How to build a localized app for Windows Phone 8
Or you can just get their prefer language and append it to the ZipPath that you have
string ZipPath = "Resources\Myfolder\Myfiles-" + culture_extention + ".zip";
where culture_extention is Windows.System.UserProfile.GlobalizationPreferences.Languages[0]
Related
I'm configuring an embedded instance of ActiveMQ using a WEB-INF/resources.xml file in my Dynamic Web Project that references an external activemq.xml file. ActiveMQ starts & functions as expected using an absolute path to activemq.xml placed in Tomcat's {$CATALINA_HOME}/conf directory. When activemq.xml is placed into the project's WEB-INF directory, Tomcat fails to find the BrokerXmlConfig file using a relative path.
Is it possible to package the activemq.xml file with the project in the WEB-INF directory?
If possible, how is Tomcat parsing the path to the file?
working resources.xml
<resources>
<Resource id="jmsConnectionFactory" type="javax.jms.ConnectionFactory">
connectionMaxIdleTime = 15 Minutes
connectionMaxWaitTime = 5 seconds
poolMaxSize = 10
poolMinSize = 0
resourceAdapter = MyJmsResourceAdapter
transactionSupport = xa
</Resource>
<Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
BrokerXmlConfig = xbean:file:/absolute/path/to/activemq.xml
ServerUrl = tcp://localhost:61616
</Resource>
<resources>
failing resources.xml
<resources>
<Resource id="jmsConnectionFactory" type="javax.jms.ConnectionFactory">
connectionMaxIdleTime = 15 Minutes
connectionMaxWaitTime = 5 seconds
poolMaxSize = 10
poolMinSize = 0
resourceAdapter = MyJmsResourceAdapter
transactionSupport = xa
</Resource>
<Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
BrokerXmlConfig = xbean:file:WEB-INF/activemq.xml
ServerUrl = tcp://localhost:61616
</Resource>
<resources>
Other unsuccessful attempts:
BrokerXmlConfig = xbean:classpath:WEB-INF/activemq.xml
BrokerXmlConfig = xbean:file:WEB-INF/activemq.xml
BrokerXmlConfig = xbean:file:activemq.xml
BrokerXmlConfig = xbean:file:./activemq.xml
BrokerXmlConfig = xbean:file:../activemq.xml
BrokerXmlConfig = xbean:file:conf/activemq.xml
I never solved the xbean relative path problem. Using the absolute path works
BrokerXmlConfig = xbean:file:/absolute/path/to/activemq.xml
Aside from the path problem, I ended up not using a separate activemq.xml file. I just used the connection factory with the Default JMS Resource Adapter.
<resources>
<Resource id="jmsConnectionFactory" type="javax.jms.ConnectionFactory">
connectionMaxIdleTime = 15 Minutes
connectionMaxWaitTime = 5 seconds
poolMaxSize = 10
poolMinSize = 0
resourceAdapter = Default JMS Resource Adapter
transactionSupport = xa
</Resource>
<resources>
I want to change the filenames of the PDF files in Magento 2.
The default names are not clear and I want invoices to be searchable when saved to a location on my pc.
Is it possible to change the filenames of the PDF-files in Magento 2 to a format like "invoice_1000000123.pdf"?
You should never edit core files. Seriously, don't.
Since /vendor/magento/module-sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php is an abstract class you have to use a plugin or preference in your module in order to override it.
What you need to achieve that:
The usual minimum files:
/Vendor/Module/composer.json, /Vendor/Module/registration.php, /Vendor/Module/etc/module.xml
In /Vendor/Module/etc/module.xml you should sequence Magento_Sales
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="1.0.0">
<sequence>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
Then you can either use a plugin or a preference in /Vendor/Module/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction" type="Vendor\Module\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction"/>
</config>
Plugin would look something like this:
<type name="Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction">
<plugin name="Vendor_Module::aroundPrintInvoice" type="Vendor\Module\Block\Class" sortOrder="0"/>
</type>
Now add a PrintAction.php to the path specified in your preference / plugin (Example for preference)
<?php
namespace Vendor\Module\Controller\Adminhtml\Invoice\AbstractInvoice;
class PrintAction extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction
{
/* Write code here */
}
You need override the invoice admin controller.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="\Magento\Sales\Controller\Adminhtml\Order\Invoice"
type="Vendor\Module\Controller\Adminhtml\Order\Invoice" />
</config>
In your custom module admin controller, You need to change the name of Pdf file.
public function execute()
{
$invoiceId = $this->getRequest()->getParam('invoice_id');
return $this->_fileFactory->create(
'invoice_13012020' . $invoiceId . '.pdf', //<== Change the pdf name here.
$pdf->render(),
DirectoryList::VAR_DIR,
'application/pdf'
);
...
}
Reference Link
Yes it is possible to change invoice pdf filename.
Please go to following path:
/vendor/magento/module-sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php
You can change filename from above file.
below is my xml file content -
<?xml version="1.0" encoding="UTF-8"?>
<artifactListing>
<folder id="REPORTMART" path="/Repository Objects" pathAlias="/00"
modifiedBy="Maria" lastUpdated="1480426973000" description="Hyperion Root Folder"/>
<folder id="DATASOURCESFOLD"
path="/Repository Objects/HRInternalFolder/DataSources"
pathAlias="/00/HRInternal/DataSources" modifiedBy="Maria" lastUpdated="1492814854000"/>
<folder id="HRINTERNALFOLD"
path="/Repository Objects/HRInternalFolder"
pathAlias="/00/HRInternal" modifiedBy="Maria" lastUpdated="1492814854000"/>
<folder id="00000158e031595b-0000-0782-0ae57730"
path="/Repository Objects/TRCS" pathAlias="/00/0"
modifiedBy="demoadmin" lastUpdated="1492814854000" description="TRCS"/>
<resource id="JavaScriptUpdateResizeOn_dds_js"
path="/Repository Objects/Administration/Impact Manager/Script Repository"
pathAlias="/00/Administration/0/Script_Repository"
modifiedBy="Maria" lastUpdated="1492814880000"
description="JavaScript Update DDS configuration with Layout Manager"
name="JavaScriptUpdateResizeOn_dds.js" type="text/im-javascript" size="-1"/>
<resource id="449cb46e6b4492f3afb8ef693dffb43a90cdd992"
path="/Security" pathAlias="/02"
description="Shared Services Administrator"
name="epm_default_cloud_admin" type="UserPreferences" size="-1"/>
<resource id="0f62187cf5a8f5aecec7a9879c9e40497d6d8649"
path="/Security" pathAlias="/02" description="" name="Jacob"
type="UserPreferences" size="-1"/>
<resource id="0df02da8548eeef2174c97c2ade67b4c5adc3160"
path="/Security" pathAlias="/02" description="" name="Henry"
type="UserPreferences" size="-1"/>
<resource id="33dca1c0c1c5ae78f67580a76d9c6aba6a172e20"
path="/Security" pathAlias="/02" description="" name="Susan"
type="UserPreferences" size="-1"/>
<resource id="3e182b1ea9376483a38614d916a0b666ef531b6d"
path="/Security" pathAlias="/02" description="" name="Maria"
type="UserPreferences" size="-1"/>
<resource id="0f62187cf5a8f5aecec7a9879c9e40497d6d8649"
path="/Security" pathAlias="/02" description="" name="Jacques"
type="UserPreferences" size="-1"/>
<resource id="0df02da8548eeef2174c97c2ade67b4c5adc3160"
path="/Security" pathAlias="/02" description="" name="Frank"
type="UserPreferences" size="-1"/>
<resource id="PP_3e182b1ea9376483a38614d916a0b666ef531b6d_0"
path="/Product Preferences" pathAlias="/05"
description="This is your default Personal Page."
name="My Personal Page" type="PersonalPageContent" size="-1"/>
</artifactListing>
now using sed I would like to delete entire resource tag if "Susan" string is found within it, other non-Susan resource tag's should not be considered.
In this scenario, it's only 1 line before and after string, I've other cases where there are more line within the resource tag.
Using XML parser is the right way for manipulating XML documents.
xmlstarlet solution:
xmlstarlet ed -d '//resource[#name="Susan"]' yourxmlfile
ed - edit mode
-d - delete action
//resource[#name="Susan"] - xpath expression
For your scenario, try this:
$ sed -ibak -r '/^\s*<resource/!bend;:loop;N;/\/>.*$/{/Susan/d;bend};bloop;:end' filename
Explains:
/^\s*<resource/!bend: if pattern space does NOT start with ^\s*<resource, jump to the label named end to start a new loop.
:loop: set a label named loop to deal with the whole resource tag.
N: use N command to append a \n and next line into pattern space.
/\/>.*$/{/Susan/d}: if current pattern space ends with />$, which means we have got a complete resource tag in pattern space, then we can deal with it; if this complete resource tag contains Susan, which is your pattern, use d command to delete all contents in pattern space and then jump to label named end to start a new loop.
bloop: use a loop to append the remaining lines of current resource tag into pattern space.
use -ibak to backup the origin file.
P.S: It will ALSO work for other cases where there are more lines within the resource tag.
I want to access files (images, text files etc.) from an USB stick on my Raspberry Pi 2 using Windows 10 IoT Core.
So I've added the to the appxmanifest file.
When using this code in my IBackgroundTask I get an access denied error in the second line:
public sealed class StartupTask : IBackgroundTask
{
public async void Run(IBackgroundTaskInstance taskInstance)
{
//...
Windows.Storage.StorageFolder sf = Windows.Storage.KnownFolders.RemovableDevices;
//get list of drives
IReadOnlyList<Windows.Storage.StorageFolder> list = await sf.GetFoldersAsync();
...
}
}
I found that I should add the fileTypeAssociation with the file types I'd like to access in Package.appxmanifest so I did that:
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10" IgnorableNamespaces="uap mp iot">
<Identity Name="test-uwp" Publisher="CN=user" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="8f31dff8-3a2b-4df1-90bb-2c5267f32980" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>test</DisplayName>
<PublisherDisplayName>user</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App">
<uap:VisualElements DisplayName="test" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="test" BackgroundColor="transparent" AppListEntry="none">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
</uap:DefaultTile>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="test.StartupTask">
<BackgroundTasks>
<iot:Task Type="startup" />
</BackgroundTasks>
</Extension>
<uap:Extension Category="windows.fileTypeAssociation">
<uap:FileTypeAssociation Name="myimages">
<uap:SupportedFileTypes>
<uap:FileType ContentType="image/jpeg">.jpg</uap:FileType>
</uap:SupportedFileTypes>
</uap:FileTypeAssociation>
</uap:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<uap:Capability Name="removableStorage" />
</Capabilities>
</Package>
If I want to deploy that, I get the following error:
Severity Code Description Project File Line Suppression State
Error Error : DEP0700 : Registration of the app failed.
AppxManifest.xml(37,10): error 0x80070490: Cannot register the
test-uwp_1.0.0.0_arm__yzekw4x8qxe1g package because the following
error was encountered while parsing the windows.fileTypeAssociation
Extension element: Element not found. . Try again and contact the
package publisher if the problem persists. (0x80073cf6)
As soon as I remove the uap:Extension element, the error goes away (but the access denied is still there).
Did I miss anything? Is it not possible to access files from an USB stick using a background service (I want to run that headless with no user interaction)?
At the moment you can't register a headless app that uses filetypeAssociation.
There is a workaround - see here: https://github.com/ms-iot/ntvsiot/issues/62
Simply add a headed app (project) to your solution (no need for any special code there).
Add a reference to this project in your headless app.
Now change the manifest of the headless (file asso..) and add Executable: YourHeadedApp.exe and EntryPoint: YourHeadedApp.App now with the next deploy the EXE will be included in deployment - so it can be found when the manifest is checked.
I am provisioning a publishing page as part of a feature and placing a single list view web part on the page (see code below). This all works perfectly sp far.
<Elements>
<Module>
<File Path="default.aspx" Url="BulletinBoard.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE">
<Property Name="Title" Value="Bulletin Board" />
<Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/ListNewsletterStyle.aspx" />
<Property Name="ContentType" Value="Page" />
<Property Name="PublishingPageImage" Value="" />
<View List="Lists/BulletinBoard" BaseViewID="2" WebPartZoneID="Main" WebPartOrder="1">
<![CDATA[
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title">Active Announcements</property>
<property name="ChromeType">None</property>
</properties>
</data>
</webPart>
</webParts>
]]>
</View>
</File>
</Module>
</Elements>
The only problem is that each time I redeploy my feature through Visual Studio, the list view web part is duplicated (i.e. another one is added to the web part zone).
This problem only appears to affect web parts with the <View ...> tag. Web parts provisioned with the <AllUsersWebPart ...> tag are not being duplicated.
How do I prevent this?
You can add a feature receiver and add the webpart if it not alreay exists in stead of adding the webpart in XML.
What do you mean by tag?
Check out this blog entry from Waldek Mastykarz. It has the C# code below that should be similar to what you are looking for.
using (SPSite site = new SPSite("http://sharepoint"))
{
SPList list = site.GetCatalog(SPListTemplateType.MasterPageCatalog);
SPListItemCollection items = list.Items;
List<string> webParts = new List<string>();
// find the right Page Layout
foreach (SPListItem item in items)
{
if (item.Name.Equals("CustomPageLayout.aspx",
StringComparison.CurrentCultureIgnoreCase))
{
SPFile file = item.File;
// get the Web Part Manager for the Page Layout
SPLimitedWebPartManager wpm =
file.GetLimitedWebPartManager(PersonalizationScope.Shared);
// iterate through all Web Parts and remove duplicates
while (wpm.WebParts.Count > 0)
{
StringBuilder sb = new StringBuilder();
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
XmlWriter xw = XmlWriter.Create(sb, xws);
System.Web.UI.WebControls.WebParts.WebPart wp =
wpm.WebParts[0];
wpm.ExportWebPart(wp, xw);
xw.Flush();
string md5Hash = getMd5Hash(sb.ToString());
if (webParts.Contains(md5Hash))
wpm.DeleteWebPart(wp);
else
webParts.Add(md5Hash);
}
}
}
}
Note to SharePoint 2013 users. You should add ReplaceContent=True to the tag. The duplicate webpart issue will be resolved.