Beispiel #1
0
        public void IsCorrectLoadOnValues()
        {
            int[,] matrix = new int[4, 4];

            // Define a test input and output value:
            var expectedResult = new int[4, 4];

            //fill the matrix
            expectedResult[0, 0] = 1;
            expectedResult[0, 1] = 0;
            expectedResult[0, 2] = 0;
            expectedResult[0, 3] = 0;
            expectedResult[1, 0] = 0;
            expectedResult[1, 1] = 1;
            expectedResult[1, 2] = 0;
            expectedResult[1, 3] = 0;
            expectedResult[2, 0] = 0;
            expectedResult[2, 1] = 0;
            expectedResult[2, 2] = 1;
            expectedResult[2, 3] = 0;
            expectedResult[3, 0] = 0;
            expectedResult[3, 1] = 0;
            expectedResult[3, 2] = 0;
            expectedResult[3, 3] = 1;
            //
            Level testLevel = new Level();

            testLevel.On      = new int[]  { 0, 5, 10, 15 };
            testLevel.Columns = 4;
            testLevel.Rows    = 4;
            // Run the method under test:
            OperationsHelper.SetOnValues(testLevel, matrix);
            //Verify the result:
            CollectionAssert.AreEqual(expectedResult, matrix);
        }
Beispiel #2
0
        public void IsAllSwitchesOff()
        {
            // Define a test input and output value:
            var matrix = new int[4, 4];

            //fill the matrix
            matrix[0, 0] = 0;
            matrix[0, 1] = 0;
            matrix[0, 2] = 0;
            matrix[0, 3] = 0;
            matrix[1, 0] = 0;
            matrix[1, 1] = 0;
            matrix[1, 2] = 0;
            matrix[1, 3] = 0;
            matrix[2, 0] = 0;
            matrix[2, 1] = 0;
            matrix[2, 2] = 0;
            matrix[2, 3] = 0;
            matrix[3, 0] = 0;
            matrix[3, 1] = 0;
            matrix[3, 2] = 0;
            matrix[3, 3] = 0;
            // Run the method under test:
            OperationsHelper.AllLightsOff(matrix);
            //Verify the result:
            Assert.AreEqual(true, OperationsHelper.AllLightsOff(matrix));
        }
Beispiel #3
0
        public void AddComment(Bug bug)
        {
            var workItemDao = new WorkItemDao
            {
                Id          = bug.Id,
                Description = bug.Description,
            };
            var workItemSql = OperationsHelper.BuildUpdateStatement(workItemDao.GetTableName(), nameof(workItemDao.Id),
                                                                    nameof(workItemDao.Description));

            AddChange(workItemSql, workItemDao, OperationType.UPDATE);

            var bugDao = new BugDao
            {
                Id = bug.Id,
                IntegratedInBuild = bug.IntegratedInBuild,
                FoundInBuild      = bug.FoundInBuild,
                SystemInfo        = bug.SystemInfo
            };
            var bugSql =
                OperationsHelper.BuildUpdateStatement(bugDao.GetTableName(), nameof(bug.Id),
                                                      nameof(bugDao.IntegratedInBuild), nameof(bugDao.FoundInBuild), nameof(bugDao.SystemInfo));

            AddChange(bugSql, bugDao, OperationType.UPDATE);
        }
Beispiel #4
0
        public virtual ActionResult New(ArticleViewModel article)
        {
            ArticleHelper.ValidateArticle(article, ModelState);
            if (ModelState.IsValid)
            {
                var newArticle = article.MapTo(new Article
                {
                    UserId     = this.CorePrincipal() != null ? this.CorePrincipal().PrincipalId : (long?)null,
                    CreateDate = DateTime.Now
                });
                if (articleService.Save(newArticle))
                {
                    permissionService.SetupDefaultRolePermissions(OperationsHelper.GetOperations <ArticleOperations>(), typeof(Article), newArticle.Id);
                    Success(HttpContext.Translate("Messages.Success", String.Empty));
                    return(RedirectToAction(WebContentMVC.Article.Show()));
                }
            }
            else
            {
                Error(HttpContext.Translate("Messages.ValidationError", String.Empty));
            }

            article.AllowManage = true;
            return(View("New", article));
        }
Beispiel #5
0
        public SafeTokenHandle DoLogon(IActivityIOPath path)
        {
            var lpszUsername = OperationsHelper.ExtractUserName(path);
            var lpszDomain   = OperationsHelper.ExtractDomain(path);
            var lpszPassword = path.Password;
            var lpszPath     = path.Path;

            try
            {
                var loggedOn = _loginApi.LogonUser(lpszUsername, lpszDomain, lpszPassword, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out SafeTokenHandle safeToken);
                if (loggedOn)
                {
                    return(safeToken);
                }
                loggedOn = _loginApi.LogonUser(lpszUsername, lpszDomain, lpszPassword, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_WINNT50, out SafeTokenHandle safeTokenHandle);
                if (loggedOn)
                {
                    return(safeTokenHandle);
                }
            }

            catch (Exception ex)
            {
                Dev2Logger.Error(ex.Message, ex, GlobalConstants.WarewolfError);
            }
            finally
            {
                var ex = Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
                Dev2Logger.Info(ex.Message, GlobalConstants.Warewolf);
            }
            throw new Exception(string.Format(ErrorResource.FailedToAuthenticateUser, lpszUsername, lpszPath));
        }
Beispiel #6
0
        public void ModifyEffort(Bug bug)
        {
            var bugDao = new BugDao(bug);
            var bugSql =
                OperationsHelper.BuildUpdateStatement(bugDao.GetTableName(), nameof(bug.Id),
                                                      nameof(bugDao.EffortOriginalEstimate), nameof(bugDao.EffortRemaining),
                                                      nameof(bugDao.EffortCompleted));

            AddChange(bugSql, bugDao, OperationType.UPDATE);
        }
Beispiel #7
0
        public void OperationsHelper_ExtractUserName_With_Domain1()
        {
            const string userName         = "******";
            const string expectedUserName = "******";
            var          mockPathAuth     = new Mock <IPathAuth>();

            mockPathAuth.Setup(pathAuth => pathAuth.Username).Returns(userName);
            var operationsHelper = OperationsHelper.ExtractUserName(mockPathAuth.Object);

            Assert.AreEqual(expectedUserName, operationsHelper);
        }
Beispiel #8
0
        public void OperationsHelper_ExtractDomain()
        {
            const string userName           = "******";
            const string expectedUserName   = "";
            var          mockActivityIOPath = new Mock <IActivityIOPath>();

            mockActivityIOPath.Setup(activityIOPath => activityIOPath.Username).Returns(userName);
            var operationsHelper = OperationsHelper.ExtractDomain(mockActivityIOPath.Object);

            Assert.AreEqual(expectedUserName, operationsHelper);
        }
        /// <summary>
        /// Event handler of the switch buttons
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SwitchHandler(object sender, RoutedEventArgs e)
        {
            var coordinates = (Tuple <int, int>)((Button)sender).CommandParameter;

            //add one click
            ClickCounter++;

            //switch the neighbors states
            OperationsHelper.SetVonNeumannNeighborhood(CurrentLevel, coordinates, LightsMatrix);

            PrintMatrix();
        }
        /// <summary>
        /// Set the current level, set the properties and the On matrix values
        /// </summary>
        /// <param name="levelIndex"></param>
        private void SetLevel(int levelIndex)
        {
            CurrentLevel      = LevelsInput[levelIndex];
            CurrentLevelIndex = levelIndex;

            MatrixRows    = CurrentLevel.Rows;
            MatrixColumns = CurrentLevel.Columns;
            LightsMatrix  = new int[MatrixRows, MatrixColumns];
            OperationsHelper.SetOnValues(CurrentLevel, LightsMatrix);
            lblLevel.Content = CurrentLevel.Name;

            PrintMatrix();
        }
Beispiel #11
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Welcome to the Heroes Table Storage sample!");

            Console.WriteLine("Let's connect to our table");

            string connectionString = AppSettings.LoadAppSettings().ConnectionString;

            CloudTableClient tableClient = TableHelpers.ConnectToClient(connectionString);

            CloudTable cloudTable = tableClient.GetTableReference("HeroesDB");

            List <HeroEntity> heroes = GenerateHeros();

            try
            {
                foreach (var hero in heroes)
                {
                    await OperationsHelper.InsertOrMergeHero(cloudTable, hero);
                }

                Console.WriteLine("Let's see if we can find Superman! Performing a read.");

                var superman = await OperationsHelper.GetHero(cloudTable, "Superman", "Clark Kent");

                Console.WriteLine("Wait, his hometown isn't right! Let's update it.");

                superman.Hometown = "Kryptonopolis";

                await OperationsHelper.InsertOrMergeHero(cloudTable, superman);

                Console.WriteLine("Let's 'snap' Tony Stark out of the Universe (too soon?).");

                HeroEntity tonyStark = await OperationsHelper.GetHero(cloudTable, "Iron Man", "Tony Stark");

                await OperationsHelper.DeleteHero(cloudTable, tonyStark);

                Console.WriteLine("Love you 3000");

                Console.WriteLine("Sample over. Press any key to exit....");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Something went wrong. Exception thrown: {ex.Message}");
                Console.ReadLine();
                throw;
            }
        }
Beispiel #12
0
        public void ChangeState(Bug bug)
        {
            var workItemDao = new WorkItemDao
            {
                Id            = bug.Id,
                StateId       = (int)bug.State,
                StateReasonId = (int)bug.StateReason,
            };

            workItemDao.IncludeDomainEvents(bug.DomainEvents);

            var workItemSql = OperationsHelper.BuildUpdateStatement(workItemDao.GetTableName(), nameof(workItemDao.Id),
                                                                    nameof(workItemDao.StateId), nameof(workItemDao.StateReasonId));

            AddChange(workItemSql, workItemDao, OperationType.UPDATE);
        }
        private void AppendTermToFormula(Term term)
        {
            // If we are processing the first term, and the operation is not Addition, display the implicit first 0 in the results
            if (_formula.Length == 0 && term.Operation != Operations.Addition)
            {
                _formula.Append("0");
            }

            // Append the operation symbol if the current formula has any previous value
            if (_formula.Length > 0)
            {
                _formula.Append(OperationsHelper.GetOperationSymbol(term.Operation));
            }

            // Append the actual value to the formula
            _formula.Append(term.Value.ToString());
        }
Beispiel #14
0
        public void ModifyPlanning(Bug bug)
        {
            var workItemDao = new WorkItemDao
            {
                Id         = bug.Id,
                PriorityId = (int)bug.Priority,
            };
            var workItemSql = OperationsHelper.BuildUpdateStatement(workItemDao.GetTableName(), nameof(workItemDao.Id),
                                                                    nameof(workItemDao.PriorityId));

            AddChange(workItemSql, workItemDao, OperationType.UPDATE);

            var bugDao = new BugDao(bug);
            var bugSql =
                OperationsHelper.BuildUpdateStatement(bugDao.GetTableName(), nameof(bug.Id),
                                                      nameof(bugDao.StoryPoints), nameof(bugDao.SeverityId), nameof(bugDao.ActivityId));

            AddChange(bugSql, bugDao, OperationType.UPDATE);
        }
Beispiel #15
0
        public Term(string termInput)
        {
            var val = termInput;

            Operation = Operations.Addition;

            // To have an operation specified for this Term, there must be a single symbol provided inside parenthesis.
            // This allows subtraction without confusing it for a negative number and gives us more control over this.
            if (termInput.Length > 3 && termInput[0] == '(' && termInput[2] == ')')
            {
                Operation = OperationsHelper.GetOperationFromSymbol(termInput[1]);

                // correct the input for the remaining characters
                val = val.Substring(3);
            }

            // If the input can be parsed, use the out result - otherwise, substitute a 0
            Value = int.TryParse(val, out var termVal) ? termVal : 0;
        }
Beispiel #16
0
        public virtual ActionResult New(FormViewModel form)
        {
            FormsHelper.ValidateForm(form, ModelState);
            if (ModelState.IsValid)
            {
                var newForm = form.MapTo(new Form {
                    UserId = this.CorePrincipal() != null ? this.CorePrincipal().PrincipalId : (long?)null
                });
                if (formsService.Save(newForm))
                {
                    permissionService.SetupDefaultRolePermissions(OperationsHelper.GetOperations <FormOperations>(), typeof(Form), newForm.Id);
                    Success(HttpContext.Translate("Messages.Success", String.Empty));
                    return(RedirectToAction(FormsMVC.Forms.Edit(newForm.Id)));
                }
            }

            Error(HttpContext.Translate("Messages.ValidationError", String.Empty));

            form.AllowManage = true;
            return(View("New", form));
        }
        public virtual ActionResult New(CategoryViewModel category)
        {
            if (ModelState.IsValid)
            {
                var newCategory = category.MapTo(new WebContentCategory {
                    UserId = this.CorePrincipal() != null ? this.CorePrincipal().PrincipalId : (long?)null
                });
                if (categoryService.Save(newCategory))
                {
                    permissionService.SetupDefaultRolePermissions(OperationsHelper.GetOperations <CategoryOperations>(), typeof(WebContentCategory), newCategory.Id);
                    Success(HttpContext.Translate("Messages.Success", String.Empty));
                    return(RedirectToAction(WebContentMVC.WebContentCategory.Show()));
                }
            }
            else
            {
                Error(HttpContext.Translate("Messages.ValidationError", String.Empty));
            }

            category.AllowManage = true;
            return(View("New", category));
        }
Beispiel #18
0
        public virtual ActionResult FormTabs(long formId, bool activeDetails, bool activeElements, bool activePermissions)
        {
            var form = formsService.Find(formId);

            if (form != null)
            {
                var result          = new List <MenuItemModel>();
                var formPermissions = permissionService.GetAccess(OperationsHelper.GetOperations <FormOperations>(), this.CorePrincipal(), typeof(Form), form.Id, IsFormOwner(form));
                if (formPermissions.ContainsKey((int)FormOperations.View) && formPermissions[(int)FormOperations.View])
                {
                    result.Add(new MenuItemModel
                    {
                        Title    = HttpContext.Translate("Tabs.Details", "Forms.Controllers"),
                        IsActive = activeDetails,
                        Url      = Url.Action("Edit", "Forms", new { formId = form.Id, Area = "Forms" })
                    });

                    result.Add(new MenuItemModel
                    {
                        Title    = HttpContext.Translate("Tabs.FormElements", "Forms.Controllers"),
                        IsActive = activeElements,
                        Url      = Url.Action("ShowFormElements", "Forms", new { formId = form.Id, Area = "Forms" })
                    });
                }
                if (formPermissions.ContainsKey((int)FormOperations.Permissions) && formPermissions[(int)FormOperations.Permissions])
                {
                    result.Add(new MenuItemModel
                    {
                        Title    = HttpContext.Translate("Tabs.Permissions", "Forms.Controllers"),
                        IsActive = activePermissions,
                        Url      = Url.Action("ShowPermissions", "Forms", new { formId = form.Id, Area = "Forms" })
                    });
                }

                return(PartialView("FormTabs", result));
            }

            return(Content(String.Empty));
        }
Beispiel #19
0
        public void IsNeighboursStatusOk()
        {
            int[,] matrix = new int[4, 4];

            // Define a test input and output value:
            var expectedResult = new int[4, 4];

            //fill the matrix
            expectedResult[0, 0] = 1;
            expectedResult[0, 1] = 0;
            expectedResult[0, 2] = 0;
            expectedResult[0, 3] = 0;
            expectedResult[1, 0] = 0;
            expectedResult[1, 1] = 1;
            expectedResult[1, 2] = 0;
            expectedResult[1, 3] = 0;
            expectedResult[2, 0] = 0;
            expectedResult[2, 1] = 0;
            expectedResult[2, 2] = 1;
            expectedResult[2, 3] = 0;
            expectedResult[3, 0] = 0;
            expectedResult[3, 1] = 0;
            expectedResult[3, 2] = 0;
            expectedResult[3, 3] = 1;
            //
            Level testLevel = new Level();

            testLevel.On      = new int[] { 0, 5, 10, 15 };
            testLevel.Columns = 4;
            testLevel.Rows    = 4;
            // Run the method under test:
            OperationsHelper.SetVonNeumannNeighborhood(testLevel, new Tuple <int, int>(1, 1), matrix);
            //Verify the result:
            Assert.AreEqual(1, matrix[0, 1]); //upd
            Assert.AreEqual(1, matrix[1, 0]); //left
            Assert.AreEqual(1, matrix[2, 1]); //down
            Assert.AreEqual(1, matrix[1, 2]); //right
        }
 private LanguagesPlugin()
 {
     PermissionTitle = Title;
     Operations      = OperationsHelper.GetOperations <LanguagesPluginOperations>();
 }
Beispiel #21
0
 /// <summary>
 /// The method executes all operations.
 /// </summary>
 /// <param name="operations">List of operations to execute.</param>
 public void ProcessOperations(IList <IConfigurationTestOperation> operations)
 {
     OperationsHelper.ProcessOperations(operations, Document);
 }
 private ProfilesPlugin()
 {
     PermissionTitle = Title;
     Operations      = OperationsHelper.GetOperations <ProfilesPluginOperations>();
 }
 protected BaseWidget()
 {
     Operations = OperationsHelper.GetOperations <BaseWidgetOperations>();
 }
 /// <summary>
 /// reset the current Level to defaults
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnReset_Click(object sender, RoutedEventArgs e)
 {
     OperationsHelper.SetOnValues(CurrentLevel, LightsMatrix);
     ResetControls();
     PrintMatrix();
 }
Beispiel #25
0
 private FormsPlugin()
 {
     PermissionTitle = Title;
     Operations      = OperationsHelper.GetOperations <FormsPluginOperations>();
 }
Beispiel #26
0
 public void OperationsHelper_ExtractUserName_ExpectedException()
 {
     OperationsHelper.ExtractUserName(null);
 }
        /// <summary>
        /// Print the switch buttons
        /// </summary>
        private void PrintMatrix()
        {
            gridPanel.Children.Clear(); //clear children objects
            gridPanel.ColumnDefinitions.Clear();
            gridPanel.RowDefinitions.Clear();

            //add columns dynamically
            for (int i = 0; i < MatrixColumns; i++)
            {
                var newColumn = new ColumnDefinition();
                newColumn.Name  = "column" + i.ToString();
                newColumn.Width = GridLength.Auto;
                this.gridPanel.ColumnDefinitions.Add(newColumn);
            }

            //add rows dynamically
            for (int row = 0; row < MatrixRows; row++)
            {
                var newRows = new RowDefinition();
                newRows.Name   = "row" + row.ToString();
                newRows.Height = GridLength.Auto;


                this.gridPanel.RowDefinitions.Add(newRows);
                for (int col = 0; col < MatrixColumns; col++)
                {
                    UserControl switchBox = new IMAGE_off();

                    if (LightsMatrix[row, col] == 1)
                    {
                        switchBox = new IMAGE_on();
                    }

                    Button btn = new Button();
                    btn.Content          = switchBox;
                    btn.RenderSize       = new Size(20, 20);
                    btn.CommandParameter = Tuple.Create(row, col);
                    btn.Click           += SwitchHandler;
                    btn.Background       = Brushes.DarkRed;

                    btn.HorizontalAlignment = HorizontalAlignment.Center;
                    btn.VerticalAlignment   = VerticalAlignment.Bottom;

                    btn.SetValue(Grid.RowProperty, row);
                    btn.SetValue(Grid.ColumnProperty, col);

                    gridPanel.Children.Add(btn);
                }
            }

            lblCounter.Content = ClickCounter;
            lblTrophy.Content  = WinsCounter;

            //Check if all the switches are in OFF
            if (OperationsHelper.AllLightsOff(LightsMatrix))
            {
                lblYouWin.Visibility = Visibility.Visible;
                WinsCounter++;
                lblTrophy.Content         = WinsCounter;
                gridPanel.IsEnabled       = false;
                btnLevelChange.Visibility = Visibility.Visible;
                lblLevel.Visibility       = Visibility.Hidden;
            }
        }
Beispiel #28
0
 public Plugin()
 {
     PermissionTitle = "Modules";
     Operations      = OperationsHelper.GetOperations <BaseEntityOperations>();
 }
Beispiel #29
0
 public App()
 {
     OperationsHelper.RunParallel(Initialize);
 }
Beispiel #30
0
 public void OperationsHelper_ExtractDomain_ExpectedException()
 {
     OperationsHelper.ExtractDomain(null);
 }