Timer job-update SAP data to the list database

Source: Internet
Author: User
Tags biztalk
Preliminary work: SAP data is published as WebServices through BizTalk connection. Design the list library structure and save it as a template
To achieve quick updates, you can directly Delete the entire list database and create new data entries.

New Class

Using system;
Using system. Collections. Generic;
Using system. text;
Using Microsoft. SharePoint;
Using Microsoft. Sharepoint. administration;
Using system. collections;
// Web reference
Using saptimer. BizTalk;
Namespace saptimer
{
Public class sapdatatimer: spjobdefinition
{
Public sapdatatimer (): Base (){}

/// <Summary>
/// Initialize eventchecktimer
/// For more constructors, see SDK
/// </Summary>
/// <Param name = "_ timername"> timer name </param>
/// <Param name = "_ WP"> Web Application name </param>
Public sapdatatimer (string _ timername, spwebapplication _ WP)
: Base (_ timername, _ WP, null, spjoblocktype. contentdatabase)
{
This. Title = "saptimer ";
}

/// <Summary>
/// This method is called by the system, and contentdbid is also passed by the System
/// </Summary>
/// <Param name = "_ contentdbid"> ID of the content database </param>
Public override void execute (guid targetinstanceid)
{

Spwebapplication webapplication = This. Parent as spwebapplication;
Spcontentdatabase contentdb = webapplication. contentdatabases [targetinstanceid];
// Portal site
Spsite = new spsite ("... ");
// Subwebsite
Spweb = spsite. openweb ("/");

Splist list1 = spweb. Lists ["wbsinfo"];
Splist list2 = spweb. Lists ["staffinfo"];
Splist list3 = spweb. Lists ["deptinfo"];

Webservice_bizforoa wsbfoa = new webservice_bizforoa ();

Wbsinfo WBS = new wbsinfo ();
Wbscollection [] wbscollections = wsbfoa. getwbsinfo (WBS );

Staffinfo Si = new staffinfo ();
Staffcollection [] staffcollections = wsbfoa. getstaffinfo (SI );

Deptinfo de = new deptinfo ();
Deptcollection [] deptcollections = wsbfoa. getdeptlist (de );

// Delete the permission
Spweb. allowunsafeupdates = true;

# Region update wbsinfo
// Clear the document library list1
Spweb. Lists. Delete (list1.id );
Splisttemplatecollection listtemplatecollection = spsite. getcustomlisttemplates (spweb );
// List library template: You can save a specific list library as a template file in Moss, which is located in the site.
Splisttemplate template = listtemplatecollection ["WBS"];
Guid listlibguid = spweb. Lists. Add ("wbsinfo", "", template );
List1 = spweb. Lists [listlibguid];

// Add
Foreach (wbscollection wwbs in wbscollections)
{
Splistitem Item1 = list1.items. Add ();
Item1 ["WBS element number"] = wwbs. WBS element number;
Item1 ["contract name"] = wwbs. Contract name;
Item1 ["concise identifier"] = wwbs. Concise identifier;
Item1 ["place of contract signing"] = wwbs. Place of contract signing;
Item1 ["code of the place where the contract is signed"] = wwbs. Code of the place where the contract is signed;
Item1 ["profit center"] = wwbs. profit center;
Item1 ["profit center code"] = wwbs. Profit Center Code;
Item1 ["project owner"] = wwbs. project owner;
Item1 ["project owner code"] = wwbs. project owner code;
Item1.update ();
}
# Endregion

# Region update staffinfo
// Clear list2
Spweb. Lists. Delete (list2.id );
Listtemplatecollection = spsite. getcustomlisttemplates (spweb );
// List library template: You can save a specific list library as a template file in Moss, which is located in the site.
Template = listtemplatecollection ["staff"];
Listlibguid = spweb. Lists. Add ("staffinfo", "", template );
List2 = spweb. Lists [listlibguid];
// Add
Foreach (staffcollection ST in staffcollections)
{
Splistitem Item1 = list2.items. Add ();
Item1 ["employee ID"] = ST. ID;
Item1 ["name"] = ST. Name;
Item1 ["Login Name"] = ST. login name;
Item1 ["email"] = ST. Email;
Item1 ["position"] = ST. position;
Item1 ["Job Code"] = ST. Job Code;
Item1 ["department"] = ST. Department;
Item1 ["department code"] = ST. Department Code;
Item1 ["Mobile Phone"] = ST. Mobile phone;
Item1 ["landline"] = ST. Landline;
Item1.update ();
}
# Endregion

# Region update deptinfo
// Clear list3
Spweb. Lists. Delete (list3.id );
Listtemplatecollection = spsite. getcustomlisttemplates (spweb );
// List library template: You can save a specific list library as a template file in Moss, which is located in the site.
Template = listtemplatecollection ["Dept"];
Listlibguid = spweb. Lists. Add ("deptinfo", "", template );
List3 = spweb. Lists [listlibguid];
// Add
Foreach (deptcollection dept in deptcollections)
{
Splistitem Item1 = list3.items. Add ();
Item1 ["department ID"] = Dept. ID;
Item1 ["department name"] = Dept. Name;
Item1 ["Owner ID"] = Dept. Owner ID;
Item1 ["owner name"] = Dept. Owner name;
Item1 ["owner login name"] = Dept. owner login name;
Item1 ["Owner email"] = Dept. Owner email;
Item1.update ();
}
# Endregion
}

}
}
----------------------------------------------------
Using system;
Using system. Collections. Generic;
Using system. text;
Using Microsoft. SharePoint;
Using Microsoft. Sharepoint. administration;
Namespace saptimer
{
Class sapdatatimerinstaller: spfeaturereceiver
{
Const string my_task = "sapdatatimer ";

/// <Summary>
/// Called after the function is installed
/// </Summary>
Public override void featureinstalled (spfeaturereceiverproperties properties)
{
}

/// <Summary>
/// Called when the function is uninstalled
/// </Summary>
Public override void featureuninstalling (spfeaturereceiverproperties properties)
{
}

/// <Summary>
/// Called when the function is activated
/// </Summary>
Public override void featureactivated (spfeaturereceiverproperties properties)
{
// Obtain the scope of the current site
Spsite site = properties. feature. Parent as spsite;

Spweb web = site. rootweb;

// Ensure that the system is not called before this function is installed
Foreach (spjobdefinition job in site. webapplication. jobdefinitions)
{
If (job. Name = my_task)
Job. Delete ();
}

// Install timerjob
Sapdatatimer timer = new sapdatatimer (my_task, site. webapplication );
// Set the notebook schedule, which is started once a day and runs from to. For more timer information, see the SDK. The minimum task is to run only once a day.
Spdailyschedule schedule = new spdailyschedule ();
Schedule. beginhour = 0;
Schedule. endhour = 1;

// Per minute
// Spminuteschedule schedule = new spminuteschedule ();
// Schedule. beginsecond = 0;
// Schedule. endsecond = 59;
// Schedule. interval = 1;

// Hourly
// Sphourlyschedule schedule = new sphourlyschedule ();
// Schedule. beginminute = 40;
// Schedule. endminute = 45;

Timer. Schedule = schedule;
Timer. Update ();
}

/// <Summary>
/// Called when the function is frozen
/// </Summary>
Public override void featuredeactivating (spfeaturereceiverproperties properties)
{
Spsite site = properties. feature. Parent as spsite;

// Delete this function
Foreach (spjobdefinition job in site. webapplication. jobdefinitions)
{
If (job. Name = my_task)
Job. Delete ();
}
}
}
}
Create a new folder with the same name as the project under the features folder on drive C, and create a new feature. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Feature id = "DC421BF5-6EAE-4d2b-A1E3-CF3B987DEC10"
Title = "saptimer ;"
Description = "sapimerinstaller ;"
Version = "12.0.0.0"
Scope = "Site"
Xmlns = "http://schemas.microsoft.com/sharepoint"
Receiverassembly = "saptimer, version = 1.0.0.0, culture = neutral, publickeytoken = a17149b5e6de8152"
Receiverclass = "saptimer. sapdatatimerinstaller">
</Feature>
After testing, the update time for a total of more than 2000 records in the three list databases is 58 seconds.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.