Beispiel #1
0
        public void TickWithDefaultContinueOperator_ExpectedBehavior()
        {
            var ctx = new MyContext();

            ctx.Init();
            var planner = new Planner <MyContext>();
            var domain  = new Domain <MyContext>("Test");
            var task1   = new Selector()
            {
                Name = "Test"
            };
            var task2 = new PrimitiveTask()
            {
                Name = "Sub-task"
            };

            task2.SetOperator(new FuncOperator <MyContext>((context) => TaskStatus.Continue));
            domain.Add(domain.Root, task1);
            domain.Add(task1, task2);

            planner.Tick(domain, ctx);
            var currentTask = planner.GetCurrentTask();

            Assert.IsTrue(currentTask != null);
            Assert.IsTrue(planner.LastStatus == TaskStatus.Continue);
        }
Beispiel #2
0
        public void OnNewTask_ExpectedBehavior()
        {
            bool test = false;
            var  ctx  = new MyContext();

            ctx.Init();
            var planner = new Planner <MyContext>();

            planner.OnNewTask = (t) => { test = t.Name == "Sub-task"; };
            var domain = new Domain <MyContext>("Test");
            var task1  = new Selector()
            {
                Name = "Test"
            };
            var task2 = new PrimitiveTask()
            {
                Name = "Sub-task"
            };

            task2.SetOperator(new FuncOperator <MyContext>((context) => TaskStatus.Continue));
            domain.Add(domain.Root, task1);
            domain.Add(task1, task2);

            planner.Tick(domain, ctx);

            Assert.IsTrue(test);
        }
Beispiel #3
0
        public void OnCurrentTaskExecutingConditionFailed_ExpectedBehavior()
        {
            bool test = false;
            var  ctx  = new MyContext();

            ctx.Init();
            var planner = new Planner <MyContext>();

            planner.OnCurrentTaskExecutingConditionFailed = (t, c) => { test = t.Name == "Sub-task" && c.Name == "TestCondition"; };
            var domain = new Domain <MyContext>("Test");
            var task1  = new Selector()
            {
                Name = "Test"
            };
            var task2 = new PrimitiveTask()
            {
                Name = "Sub-task"
            };

            task2.SetOperator(new FuncOperator <MyContext>((context) => TaskStatus.Continue));
            task2.AddExecutingCondition(new FuncCondition <MyContext>("TestCondition", context => context.Done));
            domain.Add(domain.Root, task1);
            domain.Add(task1, task2);

            planner.Tick(domain, ctx);

            Assert.IsTrue(test);
        }
Beispiel #4
0
        public void FindPlanIfMTRsAreEqualThenReturnNullPlan_ExpectedBehavior()
        {
            var ctx = new MyContext();
            ctx.Init();
            ctx.LastMTR.Add(1);

            // Root is a Selector that branch off into task1 selector or task2 sequence.
            // MTR only tracks decomposition of compound tasks, so our MTR is only 1 layer deep here,
            // Since both compound tasks decompose into primitive tasks.
            var domain = new Domain<MyContext>("Test");
            var task1 = new Sequence() { Name = "Test1" };
            var task2 = new Selector() { Name = "Test2" };
            var task3 = new PrimitiveTask() { Name = "Sub-task1" }.AddCondition(new FuncCondition<MyContext>("TestCondition", context => context.Done == true));
            var task4 = new PrimitiveTask() { Name = "Sub-task1" };
            var task5 = new PrimitiveTask() { Name = "Sub-task2" }.AddCondition(new FuncCondition<MyContext>("TestCondition", context => context.Done == true));
            var task6 = new PrimitiveTask() { Name = "Sub-task3" };
            domain.Add(domain.Root, task1);
            domain.Add(domain.Root, task2);
            domain.Add(task1, task3);
            domain.Add(task2, task4);
            domain.Add(task2, task5);
            var status = domain.FindPlan(ctx, out var plan);

            Assert.IsTrue(status == DecompositionStatus.Rejected);
            Assert.IsTrue(plan == null);
            Assert.IsTrue(ctx.MethodTraversalRecord.Count == 1);
            Assert.IsTrue(ctx.MethodTraversalRecord[0] == ctx.LastMTR[0]);
        }
Beispiel #5
0
        public void FindPlanClearsStateChangeWhenPlanIsNull_ExpectedBehavior()
        {
            var ctx = new MyContext();
            ctx.Init();
            var domain = new Domain<MyContext>("Test");
            var task1 = new Sequence() { Name = "Test" };
            var task2 = new PrimitiveTask() { Name = "Sub-task1" }.AddEffect(new ActionEffect<MyContext>("TestEffect1", EffectType.PlanOnly, (context, type) => context.SetState(MyWorldState.HasA, true, type)));
            var task3 = new PrimitiveTask() { Name = "Sub-task2" }.AddEffect(new ActionEffect<MyContext>("TestEffect2", EffectType.PlanAndExecute, (context, type) => context.SetState(MyWorldState.HasB, true, type)));
            var task4 = new PrimitiveTask() { Name = "Sub-task3" }.AddEffect(new ActionEffect<MyContext>("TestEffect3", EffectType.Permanent, (context, type) => context.SetState(MyWorldState.HasC, true, type)));
            var task5 = new PrimitiveTask() { Name = "Sub-task4" }.AddCondition(new FuncCondition<MyContext>("TestCondition", context => context.Done == true));
            domain.Add(domain.Root, task1);
            domain.Add(task1, task2);
            domain.Add(task1, task3);
            domain.Add(task1, task4);
            domain.Add(task1, task5);
            var status = domain.FindPlan(ctx, out var plan);

            Assert.IsTrue(status == DecompositionStatus.Rejected);
            Assert.IsTrue(ctx.WorldStateChangeStack[(int) MyWorldState.HasA].Count == 0);
            Assert.IsTrue(ctx.WorldStateChangeStack[(int) MyWorldState.HasB].Count == 0);
            Assert.IsTrue(ctx.WorldStateChangeStack[(int) MyWorldState.HasC].Count == 0);
            Assert.IsTrue(ctx.WorldState[(int) MyWorldState.HasA] == 0);
            Assert.IsTrue(ctx.WorldState[(int) MyWorldState.HasB] == 0);
            Assert.IsTrue(ctx.WorldState[(int) MyWorldState.HasC] == 0);
            Assert.IsTrue(plan == null);
        }
        public void PausePlan_ExpectedBehavior()
        {
            var ctx = new MyContext();

            ctx.Init();
            var domain = new Domain <MyContext>("Test");
            var task   = new Sequence()
            {
                Name = "Test"
            };

            domain.Add(domain.Root, task);
            domain.Add(task, new PrimitiveTask()
            {
                Name = "Sub-task1"
            });
            domain.Add(task, new PausePlanTask());
            domain.Add(task, new PrimitiveTask()
            {
                Name = "Sub-task2"
            });

            var status = domain.FindPlan(ctx, out var plan);

            Assert.IsTrue(status == DecompositionStatus.Partial);
            Assert.IsTrue(plan != null);
            Assert.IsTrue(plan.Count == 1);
            Assert.AreEqual("Sub-task1", plan.Peek().Name);
            Assert.IsTrue(ctx.HasPausedPartialPlan);
            Assert.IsTrue(ctx.PartialPlanQueue.Count == 1);
            Assert.AreEqual(task, ctx.PartialPlanQueue.Peek().Task);
            Assert.AreEqual(2, ctx.PartialPlanQueue.Peek().TaskIndex);
        }
Beispiel #7
0
        public void TickWithPrimitiveTaskWithoutOperator_ExpectedBehavior()
        {
            var ctx = new MyContext();

            ctx.Init();
            var planner = new Planner <MyContext>();
            var domain  = new Domain <MyContext>("Test");
            var task1   = new Selector()
            {
                Name = "Test"
            };
            var task2 = new PrimitiveTask()
            {
                Name = "Sub-task"
            };

            domain.Add(domain.Root, task1);
            domain.Add(task1, task2);

            planner.Tick(domain, ctx);
            var currentTask = planner.GetCurrentTask();

            Assert.IsTrue(currentTask == null);
            Assert.IsTrue(planner.LastStatus == TaskStatus.Failure);
        }
Beispiel #8
0
        public void NestedPausePlan_ExpectedBehavior()
        {
            var ctx = new MyContext();

            ctx.Init();

            var domain = new Domain <MyContext, byte>("Test");
            var task   = new Sequence <byte>()
            {
                Name = "Test"
            };
            var task2 = new Selector <byte>()
            {
                Name = "Test2"
            };
            var task3 = new Sequence <byte>()
            {
                Name = "Test3"
            };

            domain.Add(domain.Root, task);
            domain.Add(task, task2);
            domain.Add(task, new PrimitiveTask <byte>()
            {
                Name = "Sub-task4"
            });

            domain.Add(task2, task3);
            domain.Add(task2, new PrimitiveTask <byte>()
            {
                Name = "Sub-task3"
            });

            domain.Add(task3, new PrimitiveTask <byte>()
            {
                Name = "Sub-task1"
            });
            domain.Add(task3, new PausePlanTask <byte>());
            domain.Add(task3, new PrimitiveTask <byte>()
            {
                Name = "Sub-task2"
            });

            var status = domain.FindPlan(ctx, out var plan);

            Assert.IsTrue(status == DecompositionStatus.Partial);
            Assert.IsTrue(plan != null);
            Assert.IsTrue(plan.Count == 1);
            Assert.AreEqual("Sub-task1", plan.Peek().Name);
            Assert.IsTrue(ctx.HasPausedPartialPlan);
            Assert.IsTrue(ctx.PartialPlanQueue.Count == 2);
            var queueAsArray = ctx.PartialPlanQueue.ToArray();

            Assert.AreEqual(task3, queueAsArray[0].Task);
            Assert.AreEqual(2, queueAsArray[0].TaskIndex);
            Assert.AreEqual(task, queueAsArray[1].Task);
            Assert.AreEqual(1, queueAsArray[1].TaskIndex);
        }
Beispiel #9
0
        public void OnNewTaskConditionFailed_ExpectedBehavior()
        {
            bool test = false;
            var  ctx  = new MyContext();

            ctx.Init();
            var planner = new Planner <MyContext>();

            planner.OnNewTaskConditionFailed = (t, c) => { test = t.Name == "Sub-task1"; };
            var domain = new Domain <MyContext>("Test");
            var task1  = new Selector()
            {
                Name = "Test1"
            };
            var task2 = new Selector()
            {
                Name = "Test2"
            };
            var task3 = (IPrimitiveTask) new PrimitiveTask()
            {
                Name = "Sub-task1"
            }.AddCondition(new FuncCondition <MyContext>("TestCondition", context => context.Done == false));
            var task4 = new PrimitiveTask()
            {
                Name = "Sub-task2"
            };

            task3.SetOperator(new FuncOperator <MyContext>((context) => TaskStatus.Success));
            // Note that one should not use AddEffect on types that's not part of WorldState unless you
            // know what you're doing. Outside of the WorldState, we don't get automatic trimming of
            // state change. This method is used here only to invoke the desired callback, not because
            // its correct practice.
            task3.AddEffect(new ActionEffect <MyContext>("TestEffect", EffectType.PlanAndExecute, (context, type) => context.Done = true));
            task4.SetOperator(new FuncOperator <MyContext>((context) => TaskStatus.Continue));
            domain.Add(domain.Root, task1);
            domain.Add(domain.Root, task2);
            domain.Add(task1, task3);
            domain.Add(task2, task4);

            ctx.Done = true;
            planner.Tick(domain, ctx);

            ctx.Done    = false;
            ctx.IsDirty = true;
            planner.Tick(domain, ctx);

            Assert.IsTrue(test);
        }
Beispiel #10
0
        public void FindPlan_ExpectedBehavior()
        {
            var ctx = new MyContext();
            ctx.Init();
            var domain = new Domain<MyContext>("Test");
            var task1 = new Selector() { Name = "Test" };
            var task2 = new PrimitiveTask() { Name = "Sub-task" };
            domain.Add(domain.Root, task1);
            domain.Add(task1, task2);
            var status = domain.FindPlan(ctx, out var plan);

            Assert.IsTrue(status == DecompositionStatus.Succeeded);
            Assert.IsTrue(plan != null);
            Assert.IsTrue(plan.Count == 1);
            Assert.IsTrue(plan.Peek().Name == "Sub-task");
        }
        public SemesterScore(JHSemesterScoreRecord record)
            : this(record.SchoolYear, record.Semester)
        {
            RawScore = record;

            foreach (SubjectScore eachSubject in RawScore.Subjects.Values)
            {
                string subjName = eachSubject.Subject.Trim();

                if (!Subject.Contains(subjName))
                {
                    Subject.Add(subjName, new SemesterSubjectScore(eachSubject));
                }
            }

            foreach (DomainScore eachDomian in RawScore.Domains.Values)
            {
                string domainName = eachDomian.Domain;

                if (!Domain.Contains(domainName))
                {
                    Domain.Add(domainName, new SemesterDomainScore(eachDomian));
                }
            }

            CourseLearnScore = RawScore.CourseLearnScore;
            LearnDomainScore = RawScore.LearnDomainScore;
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            Domain d = new Domain(new InMemoryStorage());

            d.OnFailedSend += D_OnFailedSend;
            d.OnSuccesSend += D_OnSuccesSend;
            d.SendReminder  = SendReminder;
            //var hors = new HorsTextParser();
            //var result = hors.Parse("через 30 секунд начать отладку", DateTime.Now);
            //
            //var text = result.Text;
            //var date = result.Dates[0].DateFrom; // ->

            d.Add(new Reminder.Storage.Domain.Models.AddReminderItemModel()
            {
                contactId = 123231243,
                Message   = "Позвонить другу",
                date      = DateTime.Now + TimeSpan.FromSeconds(3)
            });

            d.Display();


            while (true)
            {
                d.CheckAwaitingReminders();
                d.SendReadyRemiders();
                Thread.Sleep(10);
            }
        }
Beispiel #13
0
        public void OnApplyEffect_ExpectedBehavior()
        {
            bool test = false;
            var  ctx  = new MyContext();

            ctx.Init();
            var planner = new Planner <MyContext>();

            planner.OnApplyEffect = (e) => { test = e.Name == "TestEffect"; };
            var domain = new Domain <MyContext>("Test");
            var task1  = new Selector()
            {
                Name = "Test1"
            };
            var task2 = new Selector()
            {
                Name = "Test2"
            };
            var task3 = (IPrimitiveTask) new PrimitiveTask()
            {
                Name = "Sub-task1"
            }.AddCondition(new FuncCondition <MyContext>("TestCondition", context => !context.HasState(MyWorldState.HasA)));
            var task4 = new PrimitiveTask()
            {
                Name = "Sub-task2"
            };

            task3.SetOperator(new FuncOperator <MyContext>((context) => TaskStatus.Success));
            task3.AddEffect(new ActionEffect <MyContext>("TestEffect", EffectType.PlanAndExecute, (context, type) => context.SetState(MyWorldState.HasA, true, type)));
            task4.SetOperator(new FuncOperator <MyContext>((context) => TaskStatus.Continue));
            domain.Add(domain.Root, task1);
            domain.Add(domain.Root, task2);
            domain.Add(task1, task3);
            domain.Add(task2, task4);

            ctx.ContextState = ContextState.Executing;
            ctx.SetState(MyWorldState.HasA, true, EffectType.Permanent);
            planner.Tick(domain, ctx);

            ctx.ContextState = ContextState.Executing;
            ctx.SetState(MyWorldState.HasA, false, EffectType.Permanent);
            planner.Tick(domain, ctx);

            Assert.IsTrue(test);
        }
Beispiel #14
0
 public void AddSubtaskToParent_ExpectedBehavior()
 {
     var domain = new Domain<MyContext>("Test");
     var task1 = new Selector() { Name = "Test" };
     var task2 = new PrimitiveTask() { Name = "Test" };
     domain.Add(task1, task2);
     Assert.IsTrue(task1.Subtasks.Contains(task2));
     Assert.IsTrue(task2.Parent == task1);
 }
Beispiel #15
0
        public void OnCurrentTaskCompletedSuccessfully_ExpectedBehavior()
        {
            bool test = false;
            var  ctx  = new MyContext();

            ctx.Init();
            var planner = new Planner <MyContext>();

            planner.OnCurrentTaskCompletedSuccessfully = (t) => { test = t.Name == "Sub-task1"; };
            var domain = new Domain <MyContext>("Test");
            var task1  = new Selector()
            {
                Name = "Test1"
            };
            var task2 = new Selector()
            {
                Name = "Test2"
            };
            var task3 = (IPrimitiveTask) new PrimitiveTask()
            {
                Name = "Sub-task1"
            }.AddCondition(new FuncCondition <MyContext>("TestCondition", context => context.Done == false));
            var task4 = new PrimitiveTask()
            {
                Name = "Sub-task2"
            };

            task3.SetOperator(new FuncOperator <MyContext>((context) => TaskStatus.Success));
            task4.SetOperator(new FuncOperator <MyContext>((context) => TaskStatus.Continue));
            domain.Add(domain.Root, task1);
            domain.Add(domain.Root, task2);
            domain.Add(task1, task3);
            domain.Add(task2, task4);

            ctx.Done = true;
            planner.Tick(domain, ctx);

            ctx.Done    = false;
            ctx.IsDirty = true;
            planner.Tick(domain, ctx);

            Assert.IsTrue(test);
        }
Beispiel #16
0
        public void OnReplacePlan_ExpectedBehavior()
        {
            bool test = false;
            var  ctx  = new MyContext();

            ctx.Init();
            var planner = new Planner <MyContext>();

            planner.OnReplacePlan = (op, ct, p) => { test = op.Count == 0 && ct != null && p.Count == 1; };
            var domain = new Domain <MyContext>("Test");
            var task1  = new Selector()
            {
                Name = "Test1"
            };
            var task2 = new Selector()
            {
                Name = "Test2"
            };
            var task3 = (IPrimitiveTask) new PrimitiveTask()
            {
                Name = "Sub-task1"
            }.AddCondition(new FuncCondition <MyContext>("TestCondition", context => context.Done == false));
            var task4 = new PrimitiveTask()
            {
                Name = "Sub-task2"
            };

            task3.SetOperator(new FuncOperator <MyContext>((context) => TaskStatus.Continue));
            task4.SetOperator(new FuncOperator <MyContext>((context) => TaskStatus.Continue));
            domain.Add(domain.Root, task1);
            domain.Add(domain.Root, task2);
            domain.Add(task1, task3);
            domain.Add(task2, task4);

            ctx.Done = true;
            planner.Tick(domain, ctx);

            ctx.Done    = false;
            ctx.IsDirty = true;
            planner.Tick(domain, ctx);

            Assert.IsTrue(test);
        }
Beispiel #17
0
        public HttpResponseMessage add(Domain post)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }
            else if (Country.MasterPostExists(post.country_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The country does not exist"));
            }
            else if (Language.MasterPostExists(post.front_end_language) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The front end language does not exist"));
            }
            else if (Language.MasterPostExists(post.back_end_language) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The back end language does not exist"));
            }
            else if (Currency.MasterPostExists(post.currency) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The currency does not exist"));
            }
            else if (Company.MasterPostExists(post.company_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The company does not exist"));
            }
            else if (post.custom_theme_id != 0 && CustomTheme.MasterPostExists(post.custom_theme_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The theme does not exist"));
            }
            else if (Domain.GetOneByDomainName(post.domain_name) != null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The domain name is not unique"));
            }

            // Make sure that the data is valid
            post.webshop_name          = AnnytabDataValidation.TruncateString(post.webshop_name, 100);
            post.domain_name           = AnnytabDataValidation.TruncateString(post.domain_name, 100);
            post.web_address           = AnnytabDataValidation.TruncateString(post.web_address, 100);
            post.analytics_tracking_id = AnnytabDataValidation.TruncateString(post.analytics_tracking_id, 50);
            post.facebook_app_id       = AnnytabDataValidation.TruncateString(post.facebook_app_id, 50);
            post.facebook_app_secret   = AnnytabDataValidation.TruncateString(post.facebook_app_secret, 50);
            post.google_app_id         = AnnytabDataValidation.TruncateString(post.google_app_id, 100);
            post.google_app_secret     = AnnytabDataValidation.TruncateString(post.google_app_secret, 50);

            // Add the post
            Domain.Add(post);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added"));
        } // End of the add method
Beispiel #18
0
        public void FindPlanTrimsNonPermanentStateChange_ExpectedBehavior()
        {
            var ctx = new MyContext();

            ctx.Init();
            var domain = new Domain <MyContext, byte>("Test");
            var task1  = new Sequence <byte>()
            {
                Name = "Test"
            };
            var task2 = new PrimitiveTask <byte>()
            {
                Name = "Sub-task1"
            }.AddEffect(new ActionEffect <MyContext, byte>("TestEffect1", EffectType.PlanOnly, (context, type) => context.SetState(MyWorldState.HasA, true, type)));
            var task3 = new PrimitiveTask <byte>()
            {
                Name = "Sub-task2"
            }.AddEffect(new ActionEffect <MyContext, byte>("TestEffect2", EffectType.PlanAndExecute, (context, type) => context.SetState(MyWorldState.HasB, true, type)));
            var task4 = new PrimitiveTask <byte>()
            {
                Name = "Sub-task3"
            }.AddEffect(new ActionEffect <MyContext, byte>("TestEffect3", EffectType.Permanent, (context, type) => context.SetState(MyWorldState.HasC, true, type)));

            domain.Add(domain.Root, task1);
            domain.Add(task1, task2);
            domain.Add(task1, task3);
            domain.Add(task1, task4);
            var status = domain.FindPlan(ctx, out var plan);

            Assert.IsTrue(status == DecompositionStatus.Succeeded);
            Assert.IsTrue(ctx.WorldStateChangeStack[(int)MyWorldState.HasA].Count == 0);
            Assert.IsTrue(ctx.WorldStateChangeStack[(int)MyWorldState.HasB].Count == 0);
            Assert.IsTrue(ctx.WorldStateChangeStack[(int)MyWorldState.HasC].Count == 0);
            Assert.IsTrue(ctx.WorldState[(int)MyWorldState.HasA] == 0);
            Assert.IsTrue(ctx.WorldState[(int)MyWorldState.HasB] == 0);
            Assert.IsTrue(ctx.WorldState[(int)MyWorldState.HasC] == 1);
            Assert.IsTrue(plan.Count == 3);
        }
Beispiel #19
0
        public void ReminderDelegate_Calls_Test()
        {
            var    storage = new InMemoryStorage();
            Domain d       = new Domain(storage);

            bool completed = false;
            bool isCalled  = false;

            d.OnFailedSend += (o, e) =>
            {
                completed = true;
            };

            d.OnSuccesSend += (o, e) =>
            {
                completed = true;
            };

            d.SendReminder = (model) =>
            {
                isCalled = true;
                Assert.IsNotNull(model);
            };

            Assert.IsNotNull(d.SendReminder);

            d.Add(new Models.AddReminderItemModel()
            {
                contactId = 123,
                Message   = "Test",
                date      = DateTime.Now + TimeSpan.FromSeconds(3)
            });

            while (!completed)
            {
                d.CheckAwaitingReminders();
                d.SendReadyRemiders();
                Thread.Sleep(10);
            }

            Assert.AreEqual(isCalled, true);
        }
Beispiel #20
0
        public void SendingFailed_Event_Test()
        {
            var    storage   = new InMemoryStorage();
            Domain d         = new Domain(storage);
            bool   completed = false;
            bool   isFailed  = false;

            d.OnFailedSend += (o, e) =>
            {
                isFailed  = true;
                completed = true;
                Assert.IsNotNull(e.exception);
            };

            d.OnSuccesSend += (o, e) =>
            {
                Assert.Fail();
            };

            d.SendReminder = (model) => { };

            d.Add(new Models.AddReminderItemModel()
            {
                contactId = 123,
                Message   = "Test",
                date      = DateTime.Now + TimeSpan.FromSeconds(3)
            });

            while (!completed)
            {
                d.CheckAwaitingReminders();
                d.SendReadyRemiders();
                Thread.Sleep(10);
            }

            var list  = storage.Get(Core.ReminderStatus.Failed);
            var count = list.Count;

            Assert.AreEqual(isFailed, true);
            Assert.AreEqual(count, 1);
        }
Beispiel #21
0
        public ActionResult edit(FormCollection collection)
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get query parameters
            string returnUrl = collection["returnUrl"];
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("index");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Get all the form values
            Int32 id = Convert.ToInt32(collection["txtId"]);
            string website_name = collection["txtWebsiteName"];
            string domain_name = collection["txtDomainName"];
            string web_address = collection["txtWebAddress"];
            Int32 front_end_language_id = Convert.ToInt32(collection["selectFrontEndLanguage"]);
            Int32 back_end_language_id = Convert.ToInt32(collection["selectBackEndLanguage"]);
            Int32 custom_theme_id = Convert.ToByte(collection["selectTemplate"]);
            string analytics_tracking_id = collection["txtAnalyticsTrackingId"];
            string facebook_app_id = collection["txtFacebookAppId"];
            string facebook_app_secret = collection["txtFacebookAppSecret"];
            string google_app_id = collection["txtGoogleAppId"];
            string google_app_secret = collection["txtGoogleAppSecret"];
            bool noindex = Convert.ToBoolean(collection["cbNoindex"]);

            // Get the default admin language id
            Int32 adminLanguageId = currentDomain.back_end_language;

            // Get translated texts
            KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC");

            // Get the domain
            Domain domain = Domain.GetOneById(id);
            bool postExists = true;

            // Check if the domain exists
            if (domain == null)
            {
                // Create an empty domain
                domain = new Domain();
                postExists = false;
            }

            // Check if we should remove the theme cache
            if (custom_theme_id != domain.custom_theme_id)
            {
                CustomTheme.RemoveThemeCache(domain.custom_theme_id);
            }

            // Update values
            domain.website_name = website_name;
            domain.domain_name = domain_name.TrimEnd('/');
            domain.web_address = web_address.TrimEnd('/');
            domain.front_end_language = front_end_language_id;
            domain.back_end_language = back_end_language_id;
            domain.custom_theme_id = custom_theme_id;
            domain.analytics_tracking_id = analytics_tracking_id;
            domain.facebook_app_id = facebook_app_id;
            domain.facebook_app_secret = facebook_app_secret;
            domain.google_app_id = google_app_id;
            domain.google_app_secret = google_app_secret;
            domain.noindex = noindex;

            // Get the domain on domain name
            Domain domainOnName = Domain.GetOneByDomainName(domain.domain_name);

            // Create a error message
            string errorMessage = string.Empty;

            // Check for errors in the domain
            if (domain.domain_name.ToLower().Contains("http://") || domain.domain_name.ToLower().Contains("https://")
                || domain.domain_name.ToLower().Contains("www") || domain.domain_name.Length > 100)
            {
                errorMessage += "&#149; " + tt.Get("error_domain_name") + "<br/>";
            }
            if (domainOnName != null && domain.id != domainOnName.id)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_unique"), tt.Get("domain_name")) + "<br/>";
            }
            if (domain.website_name.Length > 100)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "100") + "<br/>";
            }
            if (domain.web_address.Length > 100)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("web_address"), "100") + "<br/>";
            }
            if (domain.front_end_language == 0)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_select_value"), tt.Get("front_end_language").ToLower()) + "<br/>";
            }
            if (domain.back_end_language == 0)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_select_value"), tt.Get("back_end_language").ToLower()) + "<br/>";
            }
            if (domain.analytics_tracking_id.Length > 50)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("analytics_tracking_id"), "50") + "<br/>";
            }
            if (domain.facebook_app_id.Length > 50)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), "Facebook app id", "50") + "<br/>";
            }
            if (domain.facebook_app_secret.Length > 50)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), "Facebook app secret", "50") + "<br/>";
            }
            if (domain.google_app_id.Length > 100)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), "Google app id", "100") + "<br/>";
            }
            if (domain.google_app_secret.Length > 50)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), "Google app secret", "50") + "<br/>";
            }

            // Check if there is errors
            if (errorMessage == string.Empty)
            {
                // Check if we should add or update the static text
                if (postExists == false)
                {
                    // Add the domain
                    Domain.Add(domain);
                }
                else
                {
                    // Update the domain
                    Domain.Update(domain);
                }

                // Redirect the user to the list
                return Redirect(returnUrl);
            }
            else
            {
                // Set form values
                ViewBag.ErrorMessage = errorMessage;
                ViewBag.Languages = Language.GetAll(adminLanguageId, "name", "ASC");
                ViewBag.Domain = domain;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

                // Return the edit view
                return View("edit");
            }

        } // End of the edit method
Beispiel #22
0
        public void ContinueMultipleNestedPausePlan_ExpectedBehavior()
        {
            var ctx = new MyContext();

            ctx.Init();
            var domain = new Domain <MyContext>("Test");

            var task = new Sequence()
            {
                Name = "Test"
            };
            var task2 = new Selector()
            {
                Name = "Test2"
            };
            var task3 = new Sequence()
            {
                Name = "Test3"
            };
            var task4 = new Sequence()
            {
                Name = "Test4"
            };

            domain.Add(domain.Root, task);

            domain.Add(task3, new PrimitiveTask()
            {
                Name = "Sub-task1"
            });
            domain.Add(task3, new PausePlanTask());
            domain.Add(task3, new PrimitiveTask()
            {
                Name = "Sub-task2"
            });

            domain.Add(task2, task3);
            domain.Add(task2, new PrimitiveTask()
            {
                Name = "Sub-task3"
            });

            domain.Add(task4, new PrimitiveTask()
            {
                Name = "Sub-task5"
            });
            domain.Add(task4, new PausePlanTask());
            domain.Add(task4, new PrimitiveTask()
            {
                Name = "Sub-task6"
            });

            domain.Add(task, task2);
            domain.Add(task, new PrimitiveTask()
            {
                Name = "Sub-task4"
            });
            domain.Add(task, task4);
            domain.Add(task, new PrimitiveTask()
            {
                Name = "Sub-task7"
            });

            var plan = domain.FindPlan(ctx);

            Assert.IsTrue(plan != null);
            Assert.IsTrue(plan.Count == 1);
            Assert.AreEqual("Sub-task1", plan.Dequeue().Name);
            Assert.IsTrue(ctx.HasPausedPartialPlan);
            Assert.IsTrue(ctx.PartialPlanQueue.Count == 2);
            var queueAsArray = ctx.PartialPlanQueue.ToArray();

            Assert.AreEqual(task3, queueAsArray[0].Task);
            Assert.AreEqual(2, queueAsArray[0].TaskIndex);
            Assert.AreEqual(task, queueAsArray[1].Task);
            Assert.AreEqual(1, queueAsArray[1].TaskIndex);

            plan = domain.FindPlan(ctx);

            Assert.IsTrue(plan != null);
            Assert.IsTrue(plan.Count == 3);
            Assert.AreEqual("Sub-task2", plan.Dequeue().Name);
            Assert.AreEqual("Sub-task4", plan.Dequeue().Name);
            Assert.AreEqual("Sub-task5", plan.Dequeue().Name);

            plan = domain.FindPlan(ctx);

            Assert.IsTrue(plan != null);
            Assert.IsTrue(plan.Count == 2);
            Assert.AreEqual("Sub-task6", plan.Dequeue().Name);
            Assert.AreEqual("Sub-task7", plan.Dequeue().Name);
        }