Advertisement
Guest User

Untitled

a guest
Sep 20th, 2010
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. // DSL for Project Planning
  2. // Copyright (C) Dmitri Nesteruk, dmitri@activemesa.com, 2009
  3. // All rights reserved.
  4.  
  5. open System;
  6. open Microsoft.Office.Interop.MSProject;
  7.  
  8. type Task() =
  9. [<DefaultValue>] val mutable Name : string
  10. [<DefaultValue>] val mutable Duration : string
  11.  
  12. type Resource() =
  13. [<DefaultValue>] val mutable Name : string
  14. [<DefaultValue>] val mutable Position : string
  15. [<DefaultValue>] val mutable Rate : int
  16.  
  17. type Group() =
  18. [<DefaultValue>] val mutable Name : string
  19. [<DefaultValue>] val mutable Person : Resource
  20. [<DefaultValue>] val mutable Tasks : Task list
  21.  
  22. type Project() =
  23. [<DefaultValue>] val mutable Name : string
  24. [<DefaultValue>] val mutable Resources : Resource list
  25. [<DefaultValue>] val mutable StartDate : DateTime
  26. [<DefaultValue>] val mutable Groups : Group list
  27.  
  28. let mutable my_project = new Project()
  29.  
  30. // dsl constructs
  31. let project name startskey start =
  32. my_project <- new Project()
  33. my_project.Name <- name
  34. my_project.Resources <- []
  35. my_project.Groups <- []
  36. my_project.StartDate <- DateTime.Parse(start)
  37.  
  38. let with_rate = -1
  39. let starts = -1
  40. let isa = -1
  41. let done_by = -1
  42. let takes = -1
  43.  
  44. let hours = 1
  45. let hour = 1
  46. let days = 2
  47. let day = 2
  48. let weeks = 3
  49. let week = 3
  50. let months = 4
  51. let month = 4
  52.  
  53. let resource name isakey position ratekey rate =
  54. let r = new Resource()
  55. r.Name <- name
  56. r.Position <- position
  57. r.Rate <- rate
  58. my_project.Resources <- r :: my_project.Resources
  59.  
  60. let group name donebytoken resource =
  61. let g = new Group()
  62. g.Name <- name
  63. g.Person <- my_project.Resources |> List.find(fun f -> f.Name = resource)
  64. g.Tasks <- []
  65. my_project.Groups <- g :: my_project.Groups
  66.  
  67. let task name takestoken count timeunit =
  68. let t = new Task()
  69. t.Name <- name
  70. let dummy = 1 + count
  71. match timeunit with
  72. | 1 -> t.Duration <- String.Format("{0}h", count)
  73. | 2 -> t.Duration <- String.Format("{0}d", count)
  74. | 3 -> t.Duration <- String.Format("{0}wk", count)
  75. | 4 -> t.Duration <- String.Format("{0}mon", count)
  76. | _ -> raise(ArgumentException("only spans of hour(s), day(s), week(s) and month(s) are supported"))
  77. let g = List.head my_project.Groups
  78. g.Tasks <- t :: g.Tasks
  79.  
  80. let prepare (proj:Project) =
  81. let app = new ApplicationClass()
  82. app.Visible <- true
  83. let p = app.Projects.Add()
  84. p.Name <- proj.Name
  85. proj.Resources |> List.iter(fun r ->
  86. let r' = p.Resources.Add()
  87. r'.Name <- r.Position // position, not name :)
  88. let tables = r'.CostRateTables
  89. let table = tables.[1]
  90. table.PayRates.[1].StandardRate <- r.Rate
  91. table.PayRates.[1].OvertimeRate <- (r.Rate + (r.Rate >>> 1)))
  92. // make root task with project name
  93. let root = p.Tasks.Add()
  94. root.Name <- proj.Name
  95. // add groups
  96. proj.Groups |> List.rev |> List.iter(fun g ->
  97. let t = p.Tasks.Add()
  98. t.Name <- g.Name
  99. t.OutlineLevel <- 2s
  100. // who is responsible for this group?
  101. t.ResourceNames <- g.Person.Position
  102. // add tasks
  103. let tasksInOrder = g.Tasks |> List.rev
  104. tasksInOrder |> List.iter(fun t' ->
  105. let t'' = p.Tasks.Add(t'.Name)
  106. t''.Duration <- t'.Duration
  107. t''.OutlineLevel <- 3s
  108. // make task follow previous
  109. let idx = tasksInOrder |> List.findIndex(fun f -> f.Equals(t'))
  110. if (idx > 0) then
  111. t''.Predecessors <- Convert.ToString(t''.Index - 1)
  112. )
  113. )
  114.  
  115. // usage
  116. project "F# DSL Article" starts "01/01/2009"
  117. resource "Dmitri" isa "Writer" with_rate 140
  118. resource "Computer" isa "Dumb Machine" with_rate 0
  119.  
  120. group "DSL Popularization" done_by "Dmitri"
  121. task "Create basic estimation DSL" takes 1 day
  122. task "Write article" takes 1 day
  123. task "Post on CP and wait for comments" takes 1 week
  124.  
  125. group "Infrastructure Support" done_by "Computer"
  126. task "Provide VS2010 and MS Project" takes 1 week
  127. task "Download and deploy TypograFix" takes 1 day
  128. task "Sit idly while owner waits for comments" takes 1 week
  129.  
  130. prepare my_project
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement