Welcome to Vortx Community Forum, where you can ask questions and receive answers from the staff at Vortx and other members of the community.

If you had a user account on our previous forums website, you will need to register a new account here.

Learn more about...

AspDotNetStorefront
DotFeed

How to run an admin feed automatically on a time interval?

Hi,

I have a feed (xml.config file) in the Admin that queries dabase and produce an xml file in the image folder.

Does anyone know any method to automatically run the feed on a sepcified time interval, for example run every 6 hours or so?

Related Question: How to remove the number at the end of the file that is saved by the feed?

Thanks for your help,

P.

asked Apr 15, 2014 in MultiStore by Pip (475 points)
edited Apr 15, 2014 by Pip

2 Answers

0 votes
Depending on the feed you can use dotfeed. For all feeds you should be able to use WSI/web services with a client that takes advantage of the windows task scheduler.
answered Apr 16, 2014 by mmcgeachy (5,025 points)
I have been looking for how to use WSI/web services to connect to the admin/database and do some execution, but cannot find a good resource on how to do that. If you know of any sample code please share. Thanks.

It depends on which method you are going with WSI or purely web services.

If you have wsi implamented then http://manual.aspdotnetstorefront.com/p-1455-xmlpackage.aspx is the next step.

If you using your own web service. Then it just a mattter of running a xmlpackage from in a webmethod. Example code for the webmethod would be something like this:

public string XmlPackage(string name, string RuntimeParams)
    {
        if (!HttpContext.Current.Items.Contains("WSIAuthenticateTokenReceived"))
        {            
            throw new ArgumentException("Authentication Failed");
        }
        return AppLogic.RunXmlPackage(name, null, null, 1, "", RuntimeParams, false, false);
    }

Keep in mind that this example code is requires WSE authenication. I highly reccomend having some authenication be it WSE or other wise.

Don't quite understand what you are saying and the code.
Are you famlair with setting up and using WSI? Also are you famlair with web services? WSE is basicly an extension of web services that helps you secure the web service.

Basicly WSI is an implamenation web services with an additonal xml layer to comuicate your site and a client application.

The example code I gave is a for using a stand alone web service that does not depend on WSI to comminacate. The main advantage of this is you don't have to use an addional xml commication layer to run a xmlpackage. The recomendation after was to make sure that you secure web services other wise people that know where to find your serice url can pull the information from your site.
0 votes

This would have to be custom, but one route could be to make a front end page for this which would be in charge of generating the feed/file on load, and then you could just setup a batch file on the Windows Scheduler to simply ping/call that page and that should do it...

Thank you,
Jan
 
Compunix, LLC (Phoenix, AZ)
AspDotNetStorefront Development Partner and Reseller since 2005
------------------------------------------------------------------------------------------------------
 AspDotNetStorefront add-ons and plugins : http://www.ecommercecartmods.com
 Complete Automotive Solution : http://www.autopartsshoppingcart.com
------------------------------------------------------------------------------------------------------
answered Apr 16, 2014 by jsimacek (6,805 points)
Yes a page that would execute an xml.config package on load would work. I can set up Windows scheduler to call that page on an interval and the feed will be executed automatically.

Would you be able to give a sample example of a page that would call a feed/file on load?

Thanks

Sure, here is code for an feed_file.aspx.cs you could use:

(please test etc first, haven't ran it)

 

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using AspDotNetStorefrontCore;
using System.IO;
 
public partial class feed_file : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string path = Server.MapPath("") + "\\feed.xml";
        StreamWriter stream = null;
 
        string feed = AppLogic.RunXmlPackage("feed.XmlPackage.xml.config", null, ((AspDotNetStorefrontPrincipal)Context.User).ThisCustomer, 1, "", "", false, false).ToString(); ;
        try
        {
            using (stream = new StreamWriter(path, false))
            {
                stream.Write(feed);
                stream.Close();
            }
        }
        catch (Exception ex)
        {
        }
 
        long length = (new FileInfo(path)).Length;
        Response.Clear();
        Response.ClearHeaders();
        Response.AppendHeader("Content-Disposition", "attachment; filename=feed_fetchback.xml");
        Response.AppendHeader("Content-Length", "" + length + "");
        Response.ContentType = "text/xml";
        Response.WriteFile(path);
        Response.End();
    }
}
 
 
Thank you,
Jan
 
Compunix, LLC (Phoenix, AZ)
AspDotNetStorefront Development Partner and Reseller since 2005
------------------------------------------------------------------------------------------------------
 AspDotNetStorefront add-ons and plugins : http://www.ecommercecartmods.com
 Complete Automotive Solution : http://www.autopartsshoppingcart.com
------------------------------------------------------------------------------------------------------

 

Thanks a lot for your sample code. I am figuring out how to make it works.

Can you explain what is this one ?

string path = Server.MapPath("") + "\\feed.xml"; 

and this one

Response.AppendHeader("Content-Disposition", "attachment; filename=feed_fetchback.xml"); 

So far cannot figure out how to call and run http://www.domainnamegoeshere.com/images/folder/feed_file.aspx from Windows Task Scheduler?

Any help is appricatied.

Thank you,

 

 

The first is the path to the feed it will create... basically generating into a  feed.xml  file in the root of the site.

The second is adding a header for the response that it's returning a file of that name...sorry should have been  feed.xml

With the feed_file.aspx page, it should be in your root directory too...

See here for the scheduling:  http://stackoverflow.com/questions/1987345/recommended-method-for-loading-a-url-via-a-scheduled-task-on-windows

 
Thank you,
Jan
 
Compunix, LLC (Phoenix, AZ)
AspDotNetStorefront Development Partner and Reseller since 2005
------------------------------------------------------------------------------------------------------
 AspDotNetStorefront add-ons and plugins : http://www.ecommercecartmods.com
 Complete Automotive Solution : http://www.autopartsshoppingcart.com
------------------------------------------------------------------------------------------------------

So I got stuck over an xml package that generates xml file. Can anyone tell me what I need to change so that it generates all the record? Right now, the code generates correct layout, and file but all the data is just a repeat of one record. The query is verified that it generates more than one record.

<?xml version="1.0" encoding="utf-8" ?>
<package displayname="xml feed" version="2.1" debug="false" includeentityhelper="false">
  <query name="Products" rowElementName="Product">
    <sql>
      <![CDATA[            
            SQL statment that returns more than one record. 
        ]]>
    </sql>
  </query>

  <PackageTransform>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" />
      <xsl:template match="/">
        <product_data>
          <products>            
            <xsl:apply-templates select="/root/Products/Product" />
          </products>
        </product_data>
      </xsl:template>
      
      <xsl:template match="/root/Products/Product">
          <product>
            <name>
              <xsl:value-of select="/root/Products/Product/name" />
            </name>
            <url>
              <xsl:value-of select="/root/Products/Product/url" />
            </url>
          </product>
      </xsl:template>
    </xsl:stylesheet>
  </PackageTransform>
</package>

Thanks

I would recommend checking out one of the entity XmlPackages like entity.grid.xml.config and you can practically take it all from there!

 
Thank you,
Jan
 
Compunix, LLC (Phoenix, AZ)
AspDotNetStorefront Development Partner and Reseller since 2005
------------------------------------------------------------------------------------------------------
 AspDotNetStorefront add-ons and plugins : http://www.ecommercecartmods.com
 Complete Automotive Solution : http://www.autopartsshoppingcart.com
------------------------------------------------------------------------------------------------------
...