コード例 #1
0
        public FormInstance GetFormMetaDescriptions(int formID)
        {
            Form rootForm = null;
            List <ControlInstance> controlInstances = null;
            ControlInstance        rootControl      = null;

            using (var db = this.CreateContext())
            {
                rootForm         = this._GetFormByID(db, formID);
                controlInstances = this._GetControlInstancesByFormID(db, formID);
            }

            foreach (ControlInstance instance in controlInstances)
            {
                instance.ChildControls = controlInstances
                                         .Where(e => e.Control.ControlIDParent == instance.Control.ControlID)
                                         .ToList();
            }

            rootControl = controlInstances.SingleOrDefault(e => e.Control.ControlIDParent == null);
            if (rootControl == null)
            {
                throw new Exception(String.Format(
                                        "The root element of form not found. (FormID = {0})", formID
                                        ));
            }
            List <FormParameterInstance>    parameters = new ParametersBLL().GetParametersByFormID(formID);
            List <EventWithActionsInstance> events     = new EventsBLL().GetEventsByFormID(formID);

            return(new FormInstance(rootForm, rootControl, parameters, events));
        }
コード例 #2
0
        /// <summary>
        /// Get Dictionary<UniqueID, ControlID>
        /// </summary>
        /// <param name="currentControl"></param>
        /// <param name="db"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        private Dictionary <int, OperandInstance> GetUniqueIDControlIDDictionary(ControlInstance currentControl, WebBuilderEFContext db, DbContextTransaction transaction)
        {
            Dictionary <int, OperandInstance> dictionary = new Dictionary <int, OperandInstance>();

            if (currentControl.Control.UniqueID > 0)
            {
                OperandInstance currentOperand = new OperandInstance()
                {
                    ObjectID  = currentControl.Control.ControlID,
                    UniqueID  = currentControl.Control.UniqueID,
                    OperandID = currentControl.Control.OperandID.GetValueOrDefault()
                };
                dictionary.Add(currentControl.Control.UniqueID, currentOperand);
            }
            if (currentControl.ChildControls != null)
            {
                foreach (ControlInstance childControl in currentControl.ChildControls)
                {
                    {
                        Dictionary <int, OperandInstance> subDictionary = GetUniqueIDControlIDDictionary(childControl, db, transaction);
                        subDictionary.ToList().ForEach(x => dictionary.Add(x.Key, x.Value));
                    }
                }
            }

            return(dictionary);
        }
コード例 #3
0
 public void UpdateProperties(ControlInstance instance)
 {
     instance.Slurp();
     if (isViewShown)
     {
         _view.Hide();
         isViewShown = false;
     }
 }
コード例 #4
0
        public void SetControl(ControlInstance instance)
        {
            _instance = instance;

            if (this.propertyGrid.SelectedObject != instance.UnderlyingControl)
            {
                this.propertyGrid.SelectedObject = instance.UnderlyingControl;
            }
        }
コード例 #5
0
        public void RevertProperties(ControlInstance instance)
        {
            instance.Update();

            if (isViewShown)
            {
                _view.Hide();
                isViewShown = false;
            }
        }
コード例 #6
0
        /// <summary>
        /// Called when a control is selected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ControlSelected(ControlInstance control, object sender, EventArgs e)
        {
            if (_lastSelectedControl != null)
            {
                _lastSelectedControl.IsSelected = false;
                _lastSelectedControl.UnderlyingControl.Refresh();
            }

            (TampaController.GetInstance()).SetSelectedControl(control);

            control.IsSelected = true;
            _lastSelectedControl = control;
            _lastSelectedControl.UnderlyingControl.Refresh();
        }
コード例 #7
0
        /// <summary>
        /// Recursive function - save control events
        /// </summary>
        /// <param name="currentControl"></param>
        /// <param name="db"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        private void SaveControlEvents(Dictionary <int, OperandInstance> controlIDuniqueIDDictionary, ControlInstance currentControl, WebBuilderEFContext db, DbContextTransaction transaction)
        {
            if (currentControl == null)
            {
                return;
            }

            // Save all the control properties
            if (currentControl.Events != null)
            {
                foreach (ControlEventInstance currentEvent in currentControl.Events)
                {
                    currentEvent.Event.ControlID = currentControl.Control.ControlID;

                    // Event actions
                    if (currentEvent.EventActions != null && currentEvent.EventActions.Count > 0)
                    {
                        db.Events.Add(currentEvent.Event);
                        db.SaveChanges();

                        foreach (ControlEventActionInstance currentEventAction in currentEvent.EventActions)
                        {
                            currentEventAction.EventAction.EventID = currentEvent.Event.EventID;
                            db.EventActions.Add(currentEventAction.EventAction);
                            db.SaveChanges();

                            int actionID = currentEventAction.EventAction.ActionID;
                            switch (currentEventAction.ActionTypeID)
                            {
                            // Client action
                            case 1:
                                if (currentEventAction.ClientAction != null)
                                {
                                    currentEventAction.ClientAction.ActionID  = actionID;
                                    currentEventAction.ClientAction.ControlID = controlIDuniqueIDDictionary[currentEventAction.ClientAction.ControlUniqueID].ObjectID;
                                    db.ClientActions.Add(currentEventAction.ClientAction);
                                    db.SaveChanges();
                                }
                                break;

                            case 2:
                                if (currentEventAction.OpenFormAction != null)
                                {
                                    currentEventAction.OpenFormAction.OpenFormAction.ActionID = actionID;
                                    db.OpenFormActions.Add(currentEventAction.OpenFormAction.OpenFormAction);
                                    db.SaveChanges();

                                    if (currentEventAction.OpenFormAction.OpenFormActionParameters != null)
                                    {
                                        foreach (OpenFormActionParameter parameter in currentEventAction.OpenFormAction.OpenFormActionParameters)
                                        {
                                            parameter.OpenFormActionID = actionID;
                                            parameter.OperandIDValue   = controlIDuniqueIDDictionary[parameter.OperandUniqueID].OperandID;
                                            db.OpenFormActionParameters.Add(parameter);
                                            db.SaveChanges();
                                        }
                                    }
                                }
                                break;

                            case 3:
                                if (currentEventAction.PredicateAction != null)
                                {
                                    PredicateAction predicateAction = currentEventAction.PredicateAction.PredicateAction;
                                    predicateAction.ActionID        = actionID;
                                    predicateAction.OperandIDFirst  = controlIDuniqueIDDictionary[predicateAction.FirstOperandUniqueID].OperandID;
                                    predicateAction.OperandIDSecond = controlIDuniqueIDDictionary[predicateAction.SecondOperandUniqueID].OperandID;
                                    db.PredicateActions.Add(predicateAction);
                                    db.SaveChanges();
                                }
                                break;

                            case 5:
                                if (currentEventAction.QueryType != null)
                                {
                                    // Query Type
                                    db.QueryTypes.Add(currentEventAction.QueryType.QueryType);
                                    db.SaveChanges();

                                    // Query Action
                                    QueryAction queryAction = new QueryAction()
                                    {
                                        QueryTypeID = currentEventAction.QueryType.QueryType.QueryTypeID,
                                        ActionID    = actionID
                                    };
                                    db.QueryActions.Add(queryAction);
                                    db.SaveChanges();

                                    // Query Type Tables
                                    if (currentEventAction.QueryType.QueryTypeTables != null)
                                    {
                                        foreach (QueryTypeTableInstance queryTypeTable in currentEventAction.QueryType.QueryTypeTables)
                                        {
                                            queryTypeTable.QueryTypeTable.QueryTypeID = currentEventAction.QueryType.QueryType.QueryTypeID;
                                            db.QueryTypeTables.Add(queryTypeTable.QueryTypeTable);
                                            db.SaveChanges();
                                        }
                                    }

                                    // Query Type Column
                                    if (currentEventAction.QueryType.QueryTypeColumns != null)
                                    {
                                        foreach (QueryTypeColumnInstance queryTypeColumn in currentEventAction.QueryType.QueryTypeColumns)
                                        {
                                            queryTypeColumn.QueryTypeColumn.QueryTypeID = currentEventAction.QueryType.QueryType.QueryTypeID;
                                            db.QueryTypeColumns.Add(queryTypeColumn.QueryTypeColumn);
                                            db.SaveChanges();
                                        }
                                    }

                                    // QueryTypeIn
                                    if (currentEventAction.QueryType.QueryTypeIns != null)
                                    {
                                        foreach (QueryTypeInInstance queryTypeIn in currentEventAction.QueryType.QueryTypeIns)
                                        {
                                            queryTypeIn.QueryTypeIn.QueryTypeID = currentEventAction.QueryType.QueryType.QueryTypeID;
                                            db.QueryTypeIns.Add(queryTypeIn.QueryTypeIn);
                                            db.SaveChanges();

                                            QueryActionIn queryActionIn = new QueryActionIn()
                                            {
                                                QueryActionID  = actionID,
                                                QueryTypeInID  = queryTypeIn.QueryTypeIn.QueryTypeInID,
                                                OperandIDValue = controlIDuniqueIDDictionary[queryTypeIn.QueryTypeIn.UniqueID].OperandID
                                            };
                                            db.QueryActionIns.Add(queryActionIn);
                                            db.SaveChanges();
                                        }
                                    }

                                    // Query Type Out
                                    if (currentEventAction.QueryType.QueryTypeOuts != null)
                                    {
                                        foreach (QueryTypeOutInstance queryTypeOut in currentEventAction.QueryType.QueryTypeOuts)
                                        {
                                            queryTypeOut.QueryTypeOut.QueryTypeID = currentEventAction.QueryType.QueryType.QueryTypeID;
                                            db.QueryTypeOuts.Add(queryTypeOut.QueryTypeOut);
                                            db.SaveChanges();

                                            QueryActionOut queryActionOut = new QueryActionOut()
                                            {
                                                QueryActionID  = actionID,
                                                QueryTypeOutID = queryTypeOut.QueryTypeOut.QueryTypeOutID,
                                                OperandIDValue = controlIDuniqueIDDictionary[queryTypeOut.QueryTypeOut.UniqueID].OperandID
                                            };
                                            db.QueryActionOuts.Add(queryActionOut);
                                            db.SaveChanges();
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }

            if (currentControl.ChildControls != null)
            {
                foreach (ControlInstance childControl in currentControl.ChildControls)
                {
                    SaveControlEvents(controlIDuniqueIDDictionary, childControl, db, transaction);
                }
            }
        }
コード例 #8
0
ファイル: Canvas.cs プロジェクト: ayan/Project-Tampa
 public void RemoveControl(ControlInstance instance)
 {
     ControlInstances.Remove(instance);
     this.Controls.Remove(instance.UnderlyingControl);
 }
コード例 #9
0
        /// <summary>
        /// Recursive function - save control, it's propeties and child controls
        /// </summary>
        /// <param name="currentControl"></param>
        /// <param name="db"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        private ControlInstance SaveControl(ControlInstance currentControl, WebBuilderEFContext db, DbContextTransaction transaction)
        {
            if (currentControl == null)
            {
                return(currentControl);
            }

            // Save current control
            if (currentControl.Control.OperandID == null || currentControl.Control.OperandID <= 0)
            {
                // Get OperandID
                var operand = db.Operands.Add(new Operand());
                db.SaveChanges();
                currentControl.Control.OperandID = operand.OperandID;

                // Add current control
                db.Controls.Add(currentControl.Control);
            }
            else
            {
                // Edit current control
                var originalControl = db.Controls.Find(currentControl.Control.ControlID);
                if (originalControl != null)
                {
                    db.Entry(originalControl).CurrentValues.SetValues(currentControl.Control);
                }
            }
            db.SaveChanges();

            // Save all the control properties
            if (currentControl.Properties != null)
            {
                // Delete old properties
                var oldProperties = db.Properties
                                    .Where(x => x.ControlID == currentControl.Control.ControlID)
                                    .ToList()
                                    .Where(x => !currentControl.Properties.Select(p => p.Property.PropertyID).Contains(x.PropertyID))
                                    .ToList();
                db.Properties.RemoveRange(oldProperties);
                db.SaveChanges();

                foreach (PropertyInstance currentProperty in currentControl.Properties)
                {
                    currentProperty.Property.ControlID = currentControl.Control.ControlID;

                    if (currentProperty.Property.PropertyID <= 0)
                    {
                        // Add property
                        var operand = db.Operands.Add(new Operand());
                        db.Properties.Add(currentProperty.Property);
                    }
                    else
                    {
                        // Edit property
                        var originalProperty = db.Properties.Find(currentProperty.Property.PropertyID);
                        if (originalProperty != null)
                        {
                            db.Entry(originalProperty).CurrentValues.SetValues(currentProperty.Property);
                        }
                    }
                    db.SaveChanges();
                }
            }
            else
            {
                var oldPropertiesList = db.Properties.Where(x => x.ControlID == currentControl.Control.ControlID).ToList();
                db.Properties.RemoveRange(oldPropertiesList);
                db.SaveChanges();
            }

            // Children controls
            if (currentControl.ChildControls != null)
            {
                var oldChildControls = db.Controls
                                       .Where(x => x.ControlIDParent == currentControl.Control.ControlID).ToList()
                                       .Where(x => !currentControl.ChildControls.Select(p => p.Control.ControlID).Contains(x.ControlID)).ToList();
                List <Operand> oldOperandsList = new List <Operand>();
                foreach (int operandID in oldChildControls.Where(x => x.OperandID > 0).Select(x => x.OperandID))
                {
                    var oldOperand = db.Operands.SingleOrDefault(x => x.OperandID == operandID);
                    oldOperandsList.Add(oldOperand);
                }
                List <Property> oldPropertiesList = new List <Property>();
                foreach (var controlID in oldChildControls.Select(x => x.ControlID))
                {
                    var oldProperties = db.Properties.Where(x => x.ControlID == controlID).ToList();
                    oldPropertiesList.AddRange(oldProperties);
                }
                db.Properties.RemoveRange(oldPropertiesList);
                db.SaveChanges();
                db.Controls.RemoveRange(oldChildControls);
                db.SaveChanges();
                db.Operands.RemoveRange(oldOperandsList);
                db.SaveChanges();

                // Recursion: save child controls
                for (int i = 0; i < currentControl.ChildControls.Count; i++)
                {
                    ControlInstance currentChildControl = currentControl.ChildControls[i];
                    currentChildControl.Control.FormID          = currentControl.Control.FormID;
                    currentChildControl.Control.ControlIDParent = currentControl.Control.ControlID;
                    this.SaveControl(currentChildControl, db, transaction);
                }
            }
            else
            {
                var            oldChildControls = db.Controls.Where(x => x.ControlIDParent == currentControl.Control.ControlID).ToList();
                List <Operand> oldOperandsList  = new List <Operand>();
                foreach (int operandID in oldChildControls.Where(x => x.OperandID > 0).Select(x => x.OperandID))
                {
                    var oldOperand = db.Operands.SingleOrDefault(x => x.OperandID == operandID);
                    oldOperandsList.Add(oldOperand);
                }
                List <Property> oldPropertiesList = new List <Property>();
                foreach (var controlID in oldChildControls.Select(x => x.ControlID))
                {
                    var oldProperties = db.Properties.Where(x => x.ControlID == controlID).ToList();
                    oldPropertiesList.AddRange(oldProperties);
                }
                db.Properties.RemoveRange(oldPropertiesList);
                db.SaveChanges();
                db.Controls.RemoveRange(oldChildControls);
                db.SaveChanges();
                db.Operands.RemoveRange(oldOperandsList);
                db.SaveChanges();
            }

            return(currentControl);
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: jondhinkle/Rock
        /// <summary>
        /// Analyze variable names by type and report any prefix violations found.
        /// </summary>
        /// <param name="searchDirectory">The search directory.</param>
        private static int AnalyzeVariableNames( Regex regex, Regex ucRegex, Dictionary<string, string> validPrefixes, Options options )
        {
            int numberFiles = 0;
            int numberControls = 0;
            int violations = 0;
            SortedDictionary<string, List<ControlInstance>> lookup = new SortedDictionary<string, List<ControlInstance>>();
            List<string> sourceFilenames = Directory.GetFiles( options.PathToRockWeb, "*.ascx", SearchOption.AllDirectories ).ToList();

            int idx = options.PathToRockWeb.IndexOf( @"\RockWeb" );

            foreach ( string fileName in sourceFilenames )
            {
                numberFiles++;
                string partialFileName = fileName.Substring( idx + 9 );
                string[] fileContents = File.ReadAllLines( fileName );
                string origFileContents = File.ReadAllText( fileName );

                //string x = @"<h1><asp:Literal id=""lTitle"" runat=""server"" /><div class=""checkin-sub-title""><asp:Literal ID=""lSubTitle"" runat=""server""></asp:Literal></div></h1>";
                foreach ( Match match in regex.Matches( origFileContents ) )
                {
                    string ucString = match.Value;
                    Match m = ucRegex.Match( ucString );
                    if ( m.Success )
                    {
                        numberControls++;
                        string controlType = m.Groups[1].Value;
                        string variable = m.Groups[2].Value;
                        string prefix = ( SplitCase( variable ).Split( ' ' ) )[0];
                        ControlInstance ci = new ControlInstance() { Type = controlType, FileName = partialFileName, FullFilename = fileName, VariableName = variable, Prefix = prefix };

                        // Check if this controlType's prefix is valid
                        if ( !( options.reportEnabled || options.violationsByFile ) && validPrefixes.ContainsKey( controlType ) )
                        {
                            if ( validPrefixes[controlType] != prefix )
                            {
                                violations++;
                                Console.WriteLine( string.Format( "Violation: {0}\t({1})\t{2}", controlType, variable, partialFileName ) );
                            }
                        }

                        if ( lookup.ContainsKey( controlType ) )
                        {
                            lookup[controlType].Add( ci );
                        }
                        else
                        {
                            lookup[controlType] = new List<ControlInstance> { ci };
                        }
                    }
                }
            }

            if ( options.violationsByFile )
            {
                violations = ViolationsByFileName( lookup, validPrefixes );
            }
            else if ( options.reportEnabled )
            {
                BuildReport( lookup, options );
            }

            Console.WriteLine( "\nNumber of Files Checked: {0}", numberFiles );
            Console.WriteLine( "Number of Controls Checked: {0}", numberControls );
            return violations;
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: jondhinkle/Rock
 /// <summary>
 /// Returns a proper variable name for the given control instance
 /// </summary>
 /// <param name="validPrefixes"></param>
 /// <param name="ci"></param>
 /// <returns></returns>
 private static string ProperVariable( Dictionary<string, string> validPrefixes, ControlInstance ci, string varRoot = null )
 {
     varRoot = varRoot != null ? varRoot : ci.VariableName.Substring( ci.Prefix.Length );
     return validPrefixes[ci.Type] + varRoot;
 }
コード例 #12
0
 public void RemoveControl(ControlInstance control)
 {
     _canvasView.RemoveControl(control);
 }
コード例 #13
0
ファイル: Program.cs プロジェクト: fabianoaljava/rockrms
 /// <summary>
 /// Returns a proper variable name for the given control instance
 /// </summary>
 /// <param name="validPrefixes"></param>
 /// <param name="ci"></param>
 /// <returns></returns>
 private static string ProperVariable(Dictionary <string, string> validPrefixes, ControlInstance ci, string varRoot = null)
 {
     varRoot = varRoot != null ? varRoot : ci.VariableName.Substring(ci.Prefix.Length);
     return(validPrefixes[ci.Type] + varRoot);
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: fabianoaljava/rockrms
        /// <summary>
        /// Analyze variable names by type and report any prefix violations found.
        /// </summary>
        /// <param name="searchDirectory">The search directory.</param>
        private static int AnalyzeVariableNames(Regex regex, Regex ucRegex, Dictionary <string, string> validPrefixes, Options options)
        {
            int numberFiles    = 0;
            int numberControls = 0;
            int violations     = 0;
            SortedDictionary <string, List <ControlInstance> > lookup = new SortedDictionary <string, List <ControlInstance> >();
            List <string> sourceFilenames = Directory.GetFiles(options.PathToRockWeb, "*.ascx", SearchOption.AllDirectories).ToList();

            int idx = options.PathToRockWeb.IndexOf(@"\RockWeb");

            foreach (string fileName in sourceFilenames)
            {
                numberFiles++;
                string   partialFileName  = fileName.Substring(idx + 9);
                string[] fileContents     = File.ReadAllLines(fileName);
                string   origFileContents = File.ReadAllText(fileName);

                //string x = @"<h1><asp:Literal id=""lTitle"" runat=""server"" /><div class=""checkin-sub-title""><asp:Literal ID=""lSubTitle"" runat=""server""></asp:Literal></div></h1>";
                foreach (Match match in regex.Matches(origFileContents))
                {
                    string ucString = match.Value;
                    Match  m        = ucRegex.Match(ucString);
                    if (m.Success)
                    {
                        numberControls++;
                        string          controlType = m.Groups[1].Value;
                        string          variable    = m.Groups[2].Value;
                        string          prefix      = (SplitCase(variable).Split(' '))[0];
                        ControlInstance ci          = new ControlInstance()
                        {
                            Type = controlType, FileName = partialFileName, FullFilename = fileName, VariableName = variable, Prefix = prefix
                        };

                        // Check if this controlType's prefix is valid
                        if (!(options.reportEnabled || options.violationsByFile) && validPrefixes.ContainsKey(controlType))
                        {
                            if (validPrefixes[controlType] != prefix)
                            {
                                violations++;
                                Console.WriteLine(string.Format("Violation: {0}\t({1})\t{2}", controlType, variable, partialFileName));
                            }
                        }

                        if (lookup.ContainsKey(controlType))
                        {
                            lookup[controlType].Add(ci);
                        }
                        else
                        {
                            lookup[controlType] = new List <ControlInstance> {
                                ci
                            };
                        }
                    }
                }
            }

            if (options.violationsByFile)
            {
                violations = ViolationsByFileName(lookup, validPrefixes);
            }
            else if (options.reportEnabled)
            {
                BuildReport(lookup, options);
            }

            Console.WriteLine("\nNumber of Files Checked: {0}", numberFiles);
            Console.WriteLine("Number of Controls Checked: {0}", numberControls);
            return(violations);
        }
コード例 #15
0
        public void SetSelectedControl(ControlInstance ci)
        {
            if (SelectedControl != null)
            {
                SelectedControl.ParentControl.Refresh();
            }

            SelectedControl = ci;

            if (ci != null)
            {
                Control c = ci.UnderlyingControl;
                Rectangle controlRectInScreenSpace = c.RectangleToScreen(c.ClientRectangle);

                // Special case forms- in that case, use the bounds instead
                // of the client rectangle
                if (c is Form || c is TextBox)
                {
                    controlRectInScreenSpace = c.Parent.RectangleToScreen(c.Bounds);
                }

                Rectangle r = _parent.RectangleToClient(controlRectInScreenSpace);

                r.Inflate(SelectableControlHelper.GrabHandleLength, SelectableControlHelper.GrabHandleLength);

                this.SelectionBounds = r;
            }

            this.Refresh();
        }
コード例 #16
0
 public void ShowControlProperties(IWin32Window tampaWindow, ControlInstance instance)
 {
     _view.SetControl(instance);
     Show(tampaWindow);
 }
コード例 #17
0
ファイル: TampaController.cs プロジェクト: ayan/Project-Tampa
        public void SetSelectedControl(ControlInstance control)
        {
            SelectionOverlay overlay = (SelectionOverlay)_tampaMainWindow.Controls["selectionOverlay"];

            overlay.SetSelectedControl(control);
        }
コード例 #18
0
ファイル: TampaController.cs プロジェクト: ayan/Project-Tampa
 public void RequestRemoveControl(ControlInstance instance)
 {
     _canvasController.RemoveControl(instance);
 }
コード例 #19
0
ファイル: TampaController.cs プロジェクト: ayan/Project-Tampa
 public void HandleEditControlRequest(ControlInstance instance)
 {
     _propertyDialogController.ShowControlProperties(_tampaMainWindow, instance);
 }