private string CreateTask(TaskDescriptor description)
        {
            DeviceHolder holder = GetHolder(description.DeviceId);

            if (holder == null)
            {
                Console.WriteLine("Creating task for non-existing device {0}", description.DeviceId);
                return("");
            }

            AutomationTask task = new AutomationTask(holder.Device);

            if (task.Id == "")
            {
                Console.WriteLine("Couldn't create task for {0}", description.DeviceId);
                return("");
            }

            task.DeviceSensor  = description.Condition.SensorType;
            task.TaskCondition = description.Condition.ComparisonType;
            task.Value         = description.Condition.Target;

            task.ActionType      = description.Action.Type;
            task.ActionParameter = description.Action.Parameter;

            Console.WriteLine("New task for {0}", holder.Device.Id);
            holder.Device.Tasks.Add(task);
            return(task.Id);
        }
示例#2
0
        public static void CreateAutomation(SoapClient soapClient,
                                            string iEmailSendDefinitionName,
                                            string iEmailSendDefinitionCustomerKey,
                                            string iEmailSendDefinitionObjectID)
        {
            Automation automation = new Automation();

            automation.Name = "SOAPAPI Test2_" + Guid.NewGuid().ToString();
            // CustomerKey can be any string value, GUID is only used for example purposes
            automation.CustomerKey    = Guid.NewGuid().ToString();
            automation.Description    = "SOAP API Created Example";
            automation.AutomationType = "scheduled";

            AutomationActivity activityOne = new AutomationActivity();

            activityOne = new AutomationActivity();
            // This is the ObjectID of the Definition Object
            activityOne.ObjectID = iEmailSendDefinitionObjectID;
            // This is the Name of the Definition Object
            activityOne.Name       = iEmailSendDefinitionName;
            activityOne.Definition = new APIObject();
            EmailSendDefinition activityOneDefinition = new EmailSendDefinition();

            // Again this is the ObjectID of the Definition Object
            activityOneDefinition.ObjectID = iEmailSendDefinitionObjectID;
            // Again this is the Name of the Definition Object
            activityOneDefinition.Name        = iEmailSendDefinitionName;
            activityOneDefinition.CustomerKey = iEmailSendDefinitionCustomerKey;

            activityOne.ActivityObject = activityOneDefinition;
            AutomationTask taskOne = new AutomationTask();

            taskOne.Name               = "Task 1";
            taskOne.Activities         = new AutomationActivity[] { activityOne };
            automation.AutomationTasks = new AutomationTask[] { taskOne };

            string RequestID     = String.Empty;
            string OverallStatus = String.Empty;

            CreateResult[] createResults = soapClient.Create(new CreateOptions(), new APIObject[] { automation }, out RequestID, out OverallStatus);

            Console.WriteLine("Status: " + OverallStatus);
            foreach (CreateResult cr in createResults)
            {
                Console.WriteLine("NewObjectID: " + cr.NewObjectID);
                Console.WriteLine("StatusCode: " + cr.StatusCode);
                Console.WriteLine("ErrorCode: " + cr.ErrorCode);
                Console.WriteLine("StatusMessage: " + cr.StatusMessage);
            }
        }
 private void DoAction(AutomationTask task)
 {
     if (task.ActionType == Action.Indication)
     {
         if (task.ActionParameter == "true")
         {
             blinkyLed.Off();
         }
         else
         {
             blinkyLed.On();
         }
     }
 }
        public static void CreateAutomation(SoapClient soapClient,
            string iEmailSendDefinitionName,
            string iEmailSendDefinitionCustomerKey,
            string iEmailSendDefinitionObjectID)
        {
            Automation automation = new Automation();
            automation.Name = "SOAPAPI Test2_" + Guid.NewGuid().ToString();
            // CustomerKey can be any string value, GUID is only used for example purposes
            automation.CustomerKey = Guid.NewGuid().ToString();
            automation.Description = "SOAP API Created Example";
            automation.AutomationType = "scheduled";

            AutomationActivity activityOne = new AutomationActivity();
            activityOne = new AutomationActivity();
            // This is the ObjectID of the Definition Object
            activityOne.ObjectID = iEmailSendDefinitionObjectID;
            // This is the Name of the Definition Object
            activityOne.Name = iEmailSendDefinitionName;
            activityOne.Definition = new APIObject();
            EmailSendDefinition activityOneDefinition = new EmailSendDefinition();

            // Again this is the ObjectID of the Definition Object
            activityOneDefinition.ObjectID = iEmailSendDefinitionObjectID;
            // Again this is the Name of the Definition Object
            activityOneDefinition.Name = iEmailSendDefinitionName;
            activityOneDefinition.CustomerKey = iEmailSendDefinitionCustomerKey;

            activityOne.ActivityObject = activityOneDefinition;
            AutomationTask taskOne = new AutomationTask();
            taskOne.Name = "Task 1";
            taskOne.Activities = new AutomationActivity[] { activityOne };
            automation.AutomationTasks = new AutomationTask[] { taskOne };

            string RequestID = String.Empty;
            string OverallStatus = String.Empty;

            CreateResult[] createResults = soapClient.Create(new CreateOptions(), new APIObject[] { automation }, out RequestID, out OverallStatus);

            Console.WriteLine("Status: " + OverallStatus);
            foreach (CreateResult cr in createResults)
            {
                Console.WriteLine("NewObjectID: " + cr.NewObjectID);
                Console.WriteLine("StatusCode: " + cr.StatusCode);
                Console.WriteLine("ErrorCode: " + cr.ErrorCode);
                Console.WriteLine("StatusMessage: " + cr.StatusMessage);
            }
        }
        private void DigestMessage(TypedMessage msg)
        {
            switch (msg.Type)
            {
            case MessageHeaders.CreateTask:
                TaskDescriptor desc    = ((JObject)msg.Data).ToObject <TaskDescriptor>();
                AutomationTask newTask = new AutomationTask(thisDevice)
                {
                    Id = "0",

                    DeviceSensor  = desc.Condition.SensorType,
                    TaskCondition = desc.Condition.ComparisonType,
                    Value         = desc.Condition.Target,

                    ActionType      = desc.Action.Type,
                    ActionParameter = desc.Action.Parameter,
                };
                asdf = DateTime.Now;
                tasks.Add(newTask);
                break;
            }
        }
示例#6
0
        public async Task Test08_DirectoryFilesHashCompareTest()
        {
            if (Directory.Exists("TestDir1"))
            {
                Directory.Delete("TestDir1", true);
            }
            if (Directory.Exists("TestDir2"))
            {
                Directory.Delete("TestDir2", true);
            }

            //still need a automation sequence object to run this
            AutomationSequence sequence = new AutomationSequence(null, null, null, AutomationRunnerSettings, null, nullToken);

            //still testing these tasks, but they are setup tasks
            //setup
            string testSubDirPath = Path.Combine("TestDir1", "TestSubDir2");

            //create the sub dirs
            sequence.AutomationTasks.Add(new DirectoryCreateTask
            {
                ID            = "dir_setup",
                DirectoryPath = testSubDirPath
            });

            //copy over some sample files
            sequence.AutomationTasks.Add(new FileCopyTask
            {
                ID                  = "copy_0",
                SourceFilePath      = "RelhaxModpack.exe",
                DestinationFilePath = Path.Combine("TestDir1", "RelhaxModpack1.exe")
            });

            sequence.AutomationTasks.Add(new FileCopyTask
            {
                ID                  = "copy_1",
                SourceFilePath      = "RelhaxModpack.exe",
                DestinationFilePath = Path.Combine(testSubDirPath, "RelhaxModpack2.exe")
            });

            sequence.AutomationTasks.Add(new FileCopyTask
            {
                ID                  = "copy_2",
                SourceFilePath      = "RelhaxModpack.xml",
                DestinationFilePath = Path.Combine("TestDir1", "RelhaxModpack1.xml")
            });

            sequence.AutomationTasks.Add(new FileCopyTask
            {
                ID                  = "copy_3",
                SourceFilePath      = "RelhaxModpack.xml",
                DestinationFilePath = Path.Combine(testSubDirPath, "RelhaxModpack2.xml")
            });

            sequence.AutomationTasks.Add(new DirectoryCopyTask
            {
                ID              = "copy_4",
                DirectoryPath   = "TestDir1",
                DestinationPath = "TestDir2",
                Recursive       = true.ToString(),
                SearchPattern   = DirectorySearchTask.SEARCH_ALL
            });

            await RunTasks(sequence, true);

            //these are the tasks we're testing
            sequence.AutomationTasks.Add(new DirectoryCompareTask
            {
                ID = "directory_hash_compare",
                DirectoryComparePathA = "TestDir1",
                DirectoryComparePathB = "TestDir2",
                Recursive             = true.ToString(),
                SearchPattern         = DirectorySearchTask.SEARCH_ALL
            });

            await RunTasks(sequence, false);

            AutomationTask directoryCompareTask = sequence.AutomationTasks[sequence.AutomationTasks.Count - 1];

            foreach (AutomationCompare compare in directoryCompareTask.AutomationCompareTracker.AutomationCompares)
            {
                Assert.IsTrue(compare.CompareResult);
            }

            Directory.Delete("TestDir1", true);
            Directory.Delete("TestDir2", true);
            sequence.AutomationTasks.Clear();
        }
        private void CompleteTask(string taskId)
        {
            DeviceHolder holder = GetTaskHolder(taskId);

            if (holder == null)
            {
                Console.WriteLine("Completing task for non-existing device");
                return;
            }

            if (!holder.Present)
            {
                Console.WriteLine("Completing task for non-present device");
            }

            AutomationTask thisTask = null;

            foreach (var task in holder.Device.Tasks)
            {
                if (task.Id != taskId)
                {
                    continue;
                }

                thisTask = task;
                break;
            }

            if (thisTask == null)
            {
                Console.WriteLine("Task wasn't found the second time!?");
                return;
            }

            Console.WriteLine("Task {0} for {1} completed!", taskId, holder.Device.Id);
            if ((thisTask.ActionType & Action.Indication) == Action.Indication)
            { /* Do Nothing... */
            }

            if ((thisTask.ActionType & Action.Activation) == Action.Activation)
            {
                TaskCompletedMessage data = new TaskCompletedMessage
                {
                    TaskId     = taskId,
                    TaskAction = "activation",
                    Parameter  = (string)thisTask.ActionParameter,
                };
                Broadcast(MessageHeaders.TaskCompleted, data);
            }

            if ((thisTask.ActionType & Action.Facebook) == Action.Facebook)
            {
                Console.WriteLine("Celebrating on facebook (:");
            }

            if ((thisTask.ActionType & Action.Notification) == Action.Notification)
            {
                Console.WriteLine("Sending notification to origin device");
            }

            DeleteTask(taskId);
        }