Advertisement
Guest User

Untitled

a guest
May 18th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.86 KB | None | 0 0
  1. public partial class HomePage : Form
  2. {
  3. public void button1_Click(object sender, EventArgs e)
  4. {
  5. //set serviceStop to 0 (false)
  6.  
  7. string connectionString = @"Data Source=FCMONITORAVIDAUTO;Initial Catalog=InterplayWatchFolder;Integrated Security=True";
  8. using (SqlConnection connection = new SqlConnection(connectionString))
  9.  
  10.  
  11. {
  12. SqlCommand setCancelRequest = new SqlCommand("UPDATE SERVICE_STOP SET SERVICE_STOP_REQUESTED = 0");
  13. setCancelRequest.CommandType = CommandType.Text;
  14. setCancelRequest.Connection = connection;
  15. connection.Open();
  16. setCancelRequest.ExecuteNonQuery();
  17. connection.Close();
  18. }
  19.  
  20.  
  21. //start service
  22. initiateThread();
  23.  
  24.  
  25.  
  26.  
  27. }
  28.  
  29. private void initiateThread()
  30. {
  31.  
  32.  
  33. Console.WriteLine("Initiating new check");
  34. System.Threading.Tasks.Task newJobTask = System.Threading.Tasks.Task.Factory.StartNew(() =>
  35. {
  36. repeater();
  37. }
  38.  
  39.  
  40.  
  41. private void repeater()
  42. {
  43.  
  44. while(true)
  45.  
  46. {
  47.  
  48.  
  49. string serviceStop = "False";
  50.  
  51. //check if service stop was requested
  52. string connectionString = @"Data Source=FCMONITORAVIDAUTO;Initial Catalog=InterplayWatchFolder;Integrated Security=True";
  53. using (SqlConnection connection = new SqlConnection(connectionString))
  54.  
  55. {
  56. SqlDataReader stopServiceRequestedReader = null;
  57. SqlCommand getStopServiceRequested = new SqlCommand("SELECT [SERVICE_STOP_REQUESTED] FROM SERVICE_STOP", connection);
  58. getStopServiceRequested.CommandType = CommandType.Text;
  59. connection.Open();
  60. stopServiceRequestedReader = getStopServiceRequested.ExecuteReader();
  61. while (stopServiceRequestedReader.Read())
  62. {
  63. serviceStop = stopServiceRequestedReader["SERVICE_STOP_REQUESTED"].ToString();
  64.  
  65. }
  66. connection.Close();
  67. }
  68.  
  69.  
  70. //check if service was stopped
  71. if (serviceStop == "False")
  72. {
  73. Thread.Sleep(30000);
  74.  
  75.  
  76. System.Threading.Tasks.Task newJobTask = System.Threading.Tasks.Task.Factory.StartNew(() =>
  77. {
  78. executeThreadRunService();
  79. garbage garbage = new garbage();
  80. garbage.Dispose();
  81.  
  82.  
  83.  
  84. }
  85. );
  86. }
  87. else
  88. {
  89. garbage garbage = new garbage();
  90. garbage.Dispose();
  91.  
  92. break;
  93. Thread.CurrentThread.Join();
  94. }
  95.  
  96. }
  97.  
  98. private void executeThreadRunService()
  99. {
  100.  
  101.  
  102. {
  103.  
  104.  
  105.  
  106. //iterate workflow across table
  107. DataTable iterate = (DataTable)interplaySetupView.DataSource;
  108.  
  109. //execute service in parallel
  110.  
  111. {
  112.  
  113.  
  114. Parallel.ForEach(iterate.AsEnumerable(), drow =>
  115.  
  116. {
  117.  
  118.  
  119.  
  120. //Set Variables
  121. string insertDeliniator = "/"; //extra needed to build URI
  122. string insertInterplay = "interplay://"; //extra info needed to build URI
  123.  
  124.  
  125. string interplayEngineHostname = drow["Interplay_Engine_Hostname"].ToString();
  126. string interplayWatchFolder = insertInterplay + drow["Interplay_Engine_Hostname"].ToString() + insertDeliniator + drow["Interplay_Watch_Folder"].ToString();
  127. string safeForTranscodingFolder = insertInterplay + drow["Interplay_Engine_Hostname"].ToString() + insertDeliniator + drow["Interplay_Safe_Folder"].ToString();
  128. string safeForTranscodingSubmitURI = "interplay://Interplay/" + drow["Interplay_Safe_Folder"].ToString();
  129. string transferEngineHostname = drow["Transfer_Engine_Hostname"].ToString();
  130. string transferPlaybackDevice = drow["Transfer_Profile"].ToString();
  131. string transcodingProfile = drow["Transcoding_Profile"].ToString();
  132. string storeInterplayUsername = interplayUsername.Text.ToString();
  133. string storeInterplayPassword = interplayPasswordInput.Text.ToString();
  134. string workflowName = drow["Workflow_Name"].ToString();
  135. string catDVEnabled = drow["CATDV_ENABLED"].ToString();
  136. string catDVXMLDumpLocation = drow["CATDV_XML_DUMP_LOCATION"].ToString();
  137. string xmlMetadataDumpLocation = drow["METADATA_XML_DUMP_LOCATION"].ToString();
  138. string rewriteSequenceMetadata = drow["REWRITE_SEQUENCE_METADATA"].ToString();
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. System.Threading.Tasks.Task newWatchTask = System.Threading.Tasks.Task.Factory.StartNew
  146. (
  147. () =>
  148.  
  149.  
  150.  
  151. runService.executeWatchService
  152. (
  153. interplayEngineHostname,
  154. interplayWatchFolder,
  155. safeForTranscodingFolder,
  156. safeForTranscodingSubmitURI,
  157. transcodingProfile,
  158. transferEngineHostname,
  159. transferPlaybackDevice,
  160. interplayUsernameInput.Text.ToString(),
  161. interplayPasswordInput.Text.ToString(),
  162. workflowName,
  163. catDVEnabled,
  164. catDVXMLDumpLocation,
  165. xmlMetadataDumpLocation,
  166. rewriteSequenceMetadata
  167.  
  168.  
  169.  
  170.  
  171. ) );
  172.  
  173. garbage garbage = new garbage();
  174. garbage.Dispose();
  175.  
  176. Thread.CurrentThread.Join();
  177. }
  178. }
  179.  
  180.  
  181. //another class where the runService method is
  182.  
  183. public class runService
  184. {
  185.  
  186. public static void executeWatchService(
  187. string interplayEngineHostname,
  188. string interplayWatchFolder,
  189. string safeForTranscodingFolder,
  190. string safeForTranscodingSubmitURI,
  191. string transcodingProfile,
  192. string transferEngineHostname,
  193. string transferPlaybackDevice,
  194. string interplayUsername,
  195. string interplayPassword,
  196. string workflowName,
  197. string catDVEnabled,
  198. string catDVXMLDumpLocation,
  199. string xmlMetadataDumpLocation,
  200. string rewriteSequenceMetadata
  201.  
  202. )
  203.  
  204.  
  205. {
  206.  
  207. {
  208.  
  209. {
  210.  
  211.  
  212.  
  213.  
  214.  
  215. //Find if there is a new sequence
  216. //If none, method exits
  217. WatchForNewSequence watchForNewSequence = new WatchForNewSequence();
  218. WatchForNewSequence.returnMOBIDandJobName MOBIDandJobNameResults = watchForNewSequence.searchForNewSequence(
  219. interplayWatchFolder,
  220. interplayUsername,
  221. interplayPassword,
  222. workflowName,
  223. safeForTranscodingFolder);
  224. string returnOriginalSequenceMOBID = MOBIDandJobNameResults.returnOriginalSequenceMOBID;
  225. string returnJobName = MOBIDandJobNameResults.returnJobName;
  226.  
  227.  
  228. //another class where the WatchForNewSequence method is
  229.  
  230. class WatchForNewSequence
  231. {
  232.  
  233. public struct returnMOBIDandJobName
  234. {
  235. public string returnOriginalSequenceMOBID;
  236. public string returnJobName;
  237. }
  238.  
  239.  
  240. public returnMOBIDandJobName searchForNewSequence(
  241. string interplayWatchFolder,
  242. string interplayUsername,
  243. string interplayPassword,
  244. string workflowName,
  245. string safeForTranscodingFolder
  246. )
  247.  
  248. {
  249.  
  250.  
  251. string originalSequenceMOBID = "empty";
  252. string jobName = "empty";
  253.  
  254. Console.WriteLine("Checking for new sequence for " + interplayWatchFolder);
  255. AssetsPortTypeClient port = new AssetsPortTypeClient();
  256. UserCredentialsType creds = new UserCredentialsType();
  257. creds.Username = interplayUsername;
  258. creds.Password = interplayPassword;
  259.  
  260. //parameters currenlty set for sequences only
  261. //masterclip do not send in this verison
  262. SearchType param = new SearchType();
  263. param.MaxResults = 1;
  264. param.InterplayPathURI = interplayWatchFolder;
  265. param.SearchGroup = new SearchGroupType();
  266. param.SearchGroup.Operator = "AND";
  267. param.SearchGroup.AttributeCondition = new AttributeConditionType[1];
  268. param.SearchGroup.AttributeCondition[0] = new AttributeConditionType();
  269. param.SearchGroup.AttributeCondition[0].Condition = "EQUALS";
  270. param.SearchGroup.AttributeCondition[0].Attribute = new AttributeType();
  271. param.SearchGroup.AttributeCondition[0].Attribute.Name = "Type";
  272. param.SearchGroup.AttributeCondition[0].Attribute.Group = "SYSTEM";
  273. param.SearchGroup.AttributeCondition[0].Attribute.Value = "sequence";
  274.  
  275.  
  276. //send request
  277. SearchRequest request = new SearchRequest();
  278. request.UserCredentials = creds;
  279. request.Search = param;
  280.  
  281. garbage garbage = new garbage();
  282. garbage.Dispose();
  283. GC.Collect();
  284. GC.WaitForFullGCComplete();
  285.  
  286.  
  287. SearchResponseType response = port.Search(creds, param);
  288.  
  289. //check if there is any sequences
  290. if (response.Results.Length > 0)
  291. {
  292.  
  293. //designate that we want the MOB ID to be returned as a result of this method
  294. foreach (AssetDescriptionType ad in response.Results)
  295. {
  296. foreach (AttributeType att in ad.Attributes)
  297. {
  298. if (att.Name == "MOB ID")
  299. {
  300. originalSequenceMOBID = att.Value;
  301.  
  302. }
  303. if (att.Name == "Display Name")
  304. {
  305. jobName = att.Value;
  306.  
  307. //The original sequence MOBID is found and returned from the WatchForNewSequence Class
  308. Console.WriteLine(originalSequenceMOBID + "...." + jobName);
  309.  
  310. }
  311. garbage garbage2 = new garbage();
  312. garbage.Dispose();
  313.  
  314. }
  315. }
  316. }
  317. else
  318. {
  319. originalSequenceMOBID = "No_Sequence";
  320. Console.WriteLine("No new sequence for " + interplayWatchFolder + " -- exiting");
  321.  
  322. garbage garbage3 = new garbage();
  323. garbage.Dispose();
  324. Thread.CurrentThread.Join();
  325.  
  326.  
  327.  
  328.  
  329. }
  330. //no new sequence, methods exit and program ends
  331. if (response.Errors != null)
  332. {
  333. foreach (ErrorType watchForNewSequenceError in response.Errors)
  334. {
  335. Console.WriteLine("ERROR: " + watchForNewSequenceError.Message + watchForNewSequenceError.Details + "at" + watchForNewSequenceError.InterplayURI);
  336. }
  337. }
  338.  
  339.  
  340. returnMOBIDandJobName returnMOBIDandJobName = new returnMOBIDandJobName();
  341. returnMOBIDandJobName.returnOriginalSequenceMOBID = originalSequenceMOBID;
  342. returnMOBIDandJobName.returnJobName = jobName;
  343.  
  344. return returnMOBIDandJobName;
  345.  
  346. //return originalSequenceMOBID to Program
  347. //return originalSequenceMOBID;
  348.  
  349.  
  350.  
  351.  
  352.  
  353. }
  354.  
  355.  
  356. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement