承接MOSS各种工作流开发 联系人:王先生.电话:13691349686 QQ:252385878 MSN:wanghao-3@hotmail.com

寻找网络安全产品代理商(主要产品有:主机审计与监控系统,移动介质管理系统,文件集中管理安全存储系统,硬盘锁等)主要针对内网安全和数据防泄密 联系人:张小姐 电话:13522877350 QQ:419919940

MOSS工作流开发+Email提醒

这几天,忙于MOSS工作流的任务,所以很忙,研究几天工作流,感觉开发MOSS工作流,其实也很简单。不像大家想象的那样的复杂!
一.介绍
MOSS开发工作六
.开发环境&准备工作
 SharePoint Server 2007
 Visual Studio 2005
 .NET Framework 3.0
 Visual Studio 2005 Extensions for Windows Workflow Foundation
 ECM Starter Kit for Visual Studio 2005

工作流中只有一个onWorkflowActivated活劢,所有SharePoint工作流都必须从这个活劢开始.
onWorkflowActivated活劢有一些属性值得我们注意:

 CorrelationToken : Correlation Token 是将若干相关联的活劢映射到同一集合的标识符,其作用不某些编程语言中RadioButtion组件的GroupId属性类似,注意丌要为任务活劢和工作流活劢指定相同的CorrelationToken.

 每一个Task都是一个SequenceActivity(IfElseAcitvity和ParallelActivity的分支也是SequenceActivity), 它依序包含CreateTask,onTaskChanged,CompleteTask和DeleteTask四个活劢,代表了一个任务的一次生命周期.
 同一组Task活劢都必须设置相同的CorrelationToken属性和TaskId属性(在本例中同一组Task活劢都包含在一个SequenceActivity中);而丌同组的Task活劢则需要设置丌同的CorrelationToken属性和TaskId属性.
 Task活劢的OwnerActivityName必须设置为包含它们的SequenceActivity名称.
 将onTaskChanged的afterProperties属性设置为和CreateTask活劢的TaskProperties属性相同的变量(这样做的目的是默认保存用户对Task的修改).
六.部署
关亍部署的文件Feature.xml , Workflow.xml和Install.bat.
6.1 强签名
因为工作流的程序集需要部署到GAC里,所以我们需要为程序集生成一个强签名.

 拷贝并注册工作流表单.
 将程序集添加到GAC.
 安装并激活工作流feature
大家明白上面的理论知识拉,现在开始开工 ,我也不在这里废话拉,
首先跟大家讲讲我这个工作流的流程-〉首先用户提交申请,然后流程启动-〉发送EMAIL-〉通知审批人-〉审批人审批通过-〉然后-〉提交到人事部门list,等待以后察看,流程结束。
程,设计如图:

设计好这样啦,然后,看代码
工作流的后台代码
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Xml.Serialization;
using System.Xml;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WorkflowActions;


namespace LeaveWorkFlow
{
 public sealed partial class Workflow1: SequentialWorkflowActivity
 {
  public Workflow1()
  {
   InitializeComponent();
  }

        public Guid workflowId = default(System.Guid);
        public Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties workflowProperties = new Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties();
        public Guid TaskId = default(System.Guid);
        public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties taskProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
        public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties beforeProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
        public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties afterProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

        private string assignto = default(System.String);

        private string Comment = default(System.String);

        private int currentreviewer = 0;

        private string itemtitle = default(System.String);
        private string itemContent = default(System.String);

        private bool isFinished = false;

       

        private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
        {
            itemtitle = workflowProperties.Item.DisplayName;
            this.isFinished = false;
            this.workflowId = workflowProperties.WorkflowId;

            //XmlSerializer myserializer = new XmlSerializer(typeof(myFields));
            //XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(workflowProperties.InitiationData));
            //myFields myinitf = (myFields)myserializer.Deserialize(reader);

            //assignto = myinitf.ApproveUser;
            assignto = "LHVM\\Administrator";
            Comment =" myinitf.Comment";
           
        }

        private void wordflownotFinished(object sender, ConditionalEventArgs e)
        {
            if (this.assignto.Split(Convert.ToChar(";")).Length < currentreviewer + 1)
            {
                e.Result = false;
            }
            else
            {
                e.Result = true;
            }
        }

        private void taskNotFinished(object sender, ConditionalEventArgs e)
        {
            if (taskProperties.Title == itemtitle + "拒绝!")
            {
                this.isFinished = true;
            }
            e.Result = !isFinished;
        }

        private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)
        {
            this.isFinished = bool.Parse(afterProperties.ExtendedProperties["isFinished"].ToString());
            if (isFinished)
            {
                this.Comment = afterProperties.ExtendedProperties["Conceit"].ToString();
 
            }
            else
            {
                taskProperties.Title = itemtitle + "拒绝!";
                this.isFinished = true;
            }
        }

        private void createTask1_MethodInvoking(object sender, EventArgs e)
        {
            TaskId = Guid.NewGuid();

            taskProperties.Title = "Please Review Say:" + itemtitle;
            taskProperties.AssignedTo = this.assignto.Split(Convert.ToChar(";"))[this.currentreviewer].ToString();
            taskProperties.Description = this.Comment;
            taskProperties.ExtendedProperties["Comment"] = this.Comment;

        }

        private void completeTask1_MethodInvoking(object sender, EventArgs e)
        {
            this.currentreviewer++;
        }

        private void sendEmail1_MethodInvoking(object sender, EventArgs e)
        {
            //this.sendEmail1.To = this.workflowProperties.OriginatorEmail;
            //this.sendEmail1.To = "wanghao-3@tom.com";
            //this.sendEmail1.Subject = "请假申请";
            //this.sendEmail1.Body = "Your request ";
            sendEmail1_Headers1.Add("To", "wanghao-3@tom.com");
            sendEmail1_Headers1.Add("From", "wanghao-3@tom.com");
            sendEmail1_Headers1.Add("Subject", "WorkFlow VS 2005");
            sendEmail1_Body1 = "aa programado " + workflowProperties.Item.DisplayName;
          
           // this.sendEmail1.
        }

        public String sendEmail1_From1 = default(System.String);
        public String sendEmail1_Body1 = default(System.String);
        public String sendEmail1_CC1 = default(System.String);
        public System.Collections.Specialized.StringDictionary sendEmail1_Headers1 = new System.Collections.Specialized.StringDictionary();
        public String sendEmail1_Subject1 = default(System.String);
        public String sendEmail1_To1 = default(System.String);

        private void codeActivity1_ExecuteCode(object sender, EventArgs e)
        {


            SPSite site = new SPSite(@"http://lh-vmpc/personal/test/workflow");
            SPWeb web = site.OpenWeb();
            web.AllowUnsafeUpdates = true;
            SPList list = web.Lists["WorkFlow"];
            SPListItem item = list.Items.Add();
            item["标题"] = this.itemtitle;
            item["请假内容"] = "Content"+this.itemContent;
            item["请假人"] = "lhvm\administrator"+workflowProperties.Web.CurrentUser.Name;
            item["请假时间"] = "1";
            item.Update();
        }
 }

}

feature.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- _lcid="1033" _version="12.0.3111" _dal="1" -->
<!-- _LocalBinding -->

<!-- Insert Feature.xml Code Snippet here.  To do this:
1) Right click on this page and select "Insert Snippet" (or press Ctrl+K, then X)
2) Select Snippets->Windows SharePoint Services Workflow->Feature.xml Code -->
<Feature  Id="{79f5f0c4-3b4e-4a32-addf-9d59b33147dc}"
    Title="AA LeaveWorkFlow"
    Description="AA LeaveWordFlow."
    Version="12.0.0.0"
    Scope="Site"
    ReceiverAssembly="Microsoft.Office.Workflow.Feature, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
    ReceiverClass="Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver"
    xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="workflow.xml" />
  </ElementManifests>
  <Properties>
    <Property Key="GloballyAvailable" Value="true" />

    <!-- Value for RegisterForms key indicates the path to the forms relative to feature file location -->
    <!-- if you don't have forms, use *.xsn -->
    <Property Key="RegisterForms" Value="*.xsn" />
  </Properties>
</Feature>
workflow.xml
  <?xml version="1.0" encoding="utf-8" ?>
<!-- _lcid="1033" _version="12.0.3015" _dal="1"   -->
<!-- _LocalBinding   -->

<!-- Insert Workflow.xml Code Snippet here.  To do this:
1) Right click on this page and select "Insert Snippet" (or press Ctrl+K, then X)
2) Select Snippets->Windows SharePoint Services Workflow->Workflow.xml Code -->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Workflow
   Name="LeaveWorkFlow Show"
   Description="this is LeaveWorkFlow。"
   Id="{44fb0f07-5c96-48ab-8d12-1f99d31620ba}"
   CodeBesideClass="LeaveWorkFlow.Workflow1"
   CodeBesideAssembly="LeaveWorkFlow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e106055d8d054c38"
   TaskListContentTypeId="0x01080100C9C9515DE4E24001905074F980F93160"
   InstantiationUrl="_layouts/IniWrkflIP.aspx"
   ModificationUrl="_layouts/ModWrkflIP.aspx">

    <Categories/>
    <!-- Tags to specify InfoPath forms for the workflow; delete tags for forms that you do not have -->
    <MetaData>

      <Instantiation_FormURN>urn:schemas-microsoft-com:office:infopath:LeaveInit:-myXSD-2007-06-20T18-08-02</Instantiation_FormURN>
      <Association_FormURN>urn:schemas-microsoft-com:office:infopath:LeaveInit:-myXSD-2007-06-20T18-08-02</Association_FormURN>
      <Task0_FormURN>urn:schemas-microsoft-com:office:infopath:LeaveTaskEdit:-myXSD-2007-06-21T01-20-17</Task0_FormURN>
      <StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl>
    </MetaData>
  </Workflow>
</Elements>

Install.bat

:: Before running this file, sign the assembly in Project properties
::
:: To customize this file, find and replace
:: a) "LeaveWorkFlow" with your own feature names
:: b) "feature.xml" with the name of your feature.xml file
:: c) "workflow.xml" with the name of your workflow.xml file
:: d) "http://lh-vmpc/personal/test" with the name of the site you wish to publish to

echo Copying the feature...

rd /s /q "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\LeaveWorkFlow"
mkdir "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\LeaveWorkFlow"

copy /Y feature.xml  "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\LeaveWorkFlow\"
copy /Y workflow.xml "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\LeaveWorkFlow\"
xcopy /s /Y *.xsn "%programfiles%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\LeaveWorkFlow\"


echo Adding assemblies to the GAC...

"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -uf LeaveWorkFlow
"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if bin\Debug\LeaveWorkFlow.dll

:: Note: 64-bit alternative to lines above; uncomment these to install on a 64-bit machine
::"%programfiles% (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -uf LeaveWorkFlow
::"%programfiles% (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if bin\Debug\LeaveWorkFlow.dll

echo Verifying InfoPath Forms...

::Note: Verify InfoPath forms; copy line for each form
::"%programfiles%\common files\microsoft shared\web server extensions\12\bin\stsadm" -o verifyformtemplate -filename [IP_FORM_FILENAME]


echo Activating the feature...

pushd %programfiles%\common files\microsoft shared\web server extensions\12\bin

::Note: Uncomment these lines if you've modified your deployment xml files or IP forms
::stsadm -o deactivatefeature -filename LeaveWorkFlow\feature.xml -url http://lh-vmpc/personal/test
::stsadm -o uninstallfeature -filename LeaveWorkFlow\feature.xml

stsadm -o installfeature -filename LeaveWorkFlow\feature.xml -force
stsadm -o activatefeature -filename LeaveWorkFlow\feature.xml -url http://lh-vmpc/personal/test


echo Doing an iisreset...
popd
iisreset
编译,把DLL放入GAC
程序全部设计开发完成后。直接运行bat文件就OK,结束!

下次介绍MOSS工作流+InfoPath 设计

posted on 2007-06-26 09:42 A A 阅读(4327) 评论(25)  编辑 收藏 所属分类: SharePoint

评论

#1楼  2007-06-26 11:41 大陆响尾蛇      

其实接触MOSS后就一直很喜欢MOSS.只是现在要忙别的事情一直也没在研究MOSS了。楼主辛苦了。。   回复  引用  查看    

#2楼 [楼主] 2007-06-26 12:43 AA(Show)      

大陆响尾蛇 不辛苦.不辛苦.我们一起努力把...
我感觉 未来的发展...MOSS前途确实比较的大噢.   回复  引用  查看    

#3楼  2007-06-26 15:14 分类信息网 [未注册用户]

这几天,忙于MOSS工作流的任务,所以很忙,研究几天工作流,感觉开发MOSS工作流,其实也很简单。不想大家想象的那样的复杂!一.介绍MOSS开发工作六 .开収环境&准备工作   回复  引用    

#4楼  2007-06-26 15:32 ddr888      

收下   回复  引用  查看    

#5楼 [楼主] 2007-06-26 15:53 AA(Show)      

见笑拉..错别字很多!本人比较的马虎!!HOHO..   回复  引用  查看    

#6楼  2007-06-27 08:21 Bruce Lee      

我这几天也在做相关工作。工作流表单是用infopath做,感觉wff是很强大,但infopath的页面编成太痛苦,比如要在infopath内实现个数型菜单,不知道怎么弄,工作流表单用asp.net页面好像也可以,不过没弄过,有例子没?给个,还是对asp.net页面编程比较容易。   回复  引用  查看    

#7楼 [楼主] 2007-06-27 09:29 AA(Show)      

其实,MOSS的工作流开发,他的流程是直接跟任务挂钩的,流程关联与任务.
所以,不管是用InfoPath 还是 asp.net叶面,还是 别的..都一样,流程设计好,就OK.   回复  引用  查看    

#8楼  2007-06-27 09:53 ad [未注册用户]

工作流开发很麻烦的 要有心里准备!

涉及到多分支 和 对任务页面进行控制的时候 很头疼   回复  引用    

#9楼  2007-06-27 10:06 Bruce Lee      

审批需要审批表单的,表单与工作流要有数据交互的。我不是说任务处理。请告诉我怎么用asp.net做审批表单,主要是部署问题,用asp。net做任何效果的界面和后台代码没问题,关键是这些页面怎么和工作流的任务挂起来,进行数据交互。   回复  引用  查看    

#10楼 [楼主] 2007-06-27 10:15 AA(Show)      

OK ,我整理,整理,发出来!   回复  引用  查看    

#11楼  2007-06-27 10:17 Bruce Lee      

主要是部署问题,用asp。net做任何效果的界面和后台代码没问题,关键是这些页面怎么和工作流的任务挂起来,进行数据交互。

十分感谢,能问一下你的其他联系方式码?qq或msn大家以后可以多多交流。
可以发到我的油箱里。brucelee521@hotmail.com   回复  引用  查看    

#12楼  2007-06-27 10:32 ad [未注册用户]

后台代码只能在layout目录下作手脚
另外对工作流的数据收集是通过INFOPATH 来作的
如果用ASP.NET来收集数据的话 那工作流中的任务扩展属性怎么办
头疼阿!   回复  引用    

#13楼 [楼主] 2007-06-27 10:57 AA(Show)      

对 by ad 哥们说的好!
用MOSS扩张创建List Definition aspx模板,做好的WFAssoc,WFInit都要放到layouts下面,
这个是 workflow.xml
AssociationUrl="_layouts/WFAssoc.aspx"
InstantiationUrl="_layouts/WFInit.aspx"
ModificationUrl="_layouts/WFMod.aspx">
至于任务,
大概就是
TaskWorkflowContentType,我们的aspx创建的模板是List Definition 创建的。所以。。可以参考下面代码 :
protected SPList List;
protected SPListItem m_task;
protected SPWorkflow workflow;
protected string m_taskData;
protected string m_taskName;
protected SPWorkflowAssociation assocTemplate;

protected InputFormTextBox Description;
protected InputFormTextBox Comments;
protected Button btnSave;
protected Button btnFeedback;


protected override void OnLoad(EventArgs ea)
{
base.OnLoad(ea);
string strListID = Request.QueryString["List"];

if (strListID != null)
List = Web.Lists[new Guid(strListID)];

m_task = List.GetItemById(Convert.ToInt32(Request.Params["ID"]));
try
{
Guid workflowId = new Guid((string)m_task["WorkflowInstanceID"]);
workflow = new SPWorkflow(Web, workflowId);
}
catch
{
throw new SPException("This list item has not been created by a workflow. You cannot apply this content type");
}

SPList listWF = null;
try
{
listWF = workflow.ParentList;
}
catch
{ }
if (listWF == null)
throw new SPException("The association has no Parent List");

SPWorkflowAssociationCollection wtc = listWF.WorkflowAssociations;
assocTemplate = wtc[workflow.AssociationId];
m_taskName = (string)m_task["Title"];
if (!IsPostBack)
{
FetchTaskInfo();
}
}
#region Helpers
private void FetchTaskInfo()
{
if (m_task["Description"] != "" && m_task["Description"]!= null)
Description.Text = m_task["Description"].ToString();
else
Description.Text = "No instructions were provided for this task.";
Comments.Text = (string)m_task["Comments"];
if (m_task["Status"].ToString() == "Completed")
{
btnFeedback.Enabled = false;
btnSave.Enabled = false;
}
}

  回复  引用  查看    

#14楼 [楼主] 2007-06-27 11:02 AA(Show)      

那样!就在把审批的信息给保存下来拉!   回复  引用  查看    

#15楼  2007-06-27 13:01 Bruce Lee      

有没有具体的例子发个看看,谢谢。   回复  引用  查看    

#16楼 [楼主] 2007-06-27 13:52 AA(Show)      

Bruce Lee 哥们!
你看看MS的SDK 里面 ,workflow里面好像有个列子介绍。。我看来下,,大概就是上面的代码。,不过我没有测试 ,,,
希望你能把结果测试出来!   回复  引用  查看    

#17楼  2007-06-28 07:49 Bruce Lee      

Microsoft Visual Studio 2005 文档里没有介绍啊,有没有wff的sdk?和infopath 2007 的sdk   回复  引用  查看    

#18楼 [楼主] 2007-06-28 09:20 AA(Show)      

Bruce Lee 就是装拉 SharePoint工作流 扩张 然后 自动就帮你在C盘下面装拉。2007 Office System Developer Resources这个 里面扩张好想就有WF的介绍噢   回复  引用  查看    

#19楼  2007-07-05 16:56 Vanke [未注册用户]

不知道仁兄是哪个公司的,我们公司正筹划上线工作流,正寻找合约方,有意联系MSN:xu_jingsong_jrsc@hotmail.com 有这方面的业务的公司均可以联系   回复  引用    

#20楼 [楼主] 2007-07-06 09:05 AA(Show)      

北京 中科软件   回复  引用  查看    

#21楼  2007-08-28 14:11 ken [未注册用户]

有没有实例用INfopath和MOSS实现二级审批?   回复  引用    

#22楼  2007-10-18 13:02 wenanry      

呵呵,发我一份:   回复  引用  查看    

#23楼  2007-10-18 13:02 wenanry      

wenanry@gmail.com
  回复  引用  查看    

#24楼  2008-06-01 11:14 af [未注册用户]



this.createTask1.SpecialPermissions = new System.Collections.Specialized.HybridDictionary();
this.createTask1.SpecialPermissions.Add(taskPerson.LoginName, SPRoleType.Contributor);   回复  引用    


标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2007-09-15 20:38 编辑过
 
另存  打印