public void Is_Built_Correctly()
    {
        // Arrange
        const int    id                  = 1;
        var          key                 = Guid.NewGuid();
        const bool   useInEditor         = true;
        const int    cacheDuration       = 3;
        const string alias               = "test";
        const string name                = "Test";
        const string source              = "~/script.cshtml";
        const bool   cacheByPage         = false;
        const bool   cacheByMember       = true;
        const bool   dontRender          = true;
        const int    propertyId          = 6;
        const string propertyAlias       = "rewq";
        const string propertyName        = "REWQ";
        const int    propertySortOrder   = 1;
        const string propertyEditorAlias = "asdfasdf";

        var builder = new MacroBuilder();

        // Act
        var macro = builder
                    .WithId(id)
                    .WithKey(key)
                    .WithUseInEditor(useInEditor)
                    .WithCacheDuration(cacheDuration)
                    .WithAlias(alias)
                    .WithName(name)
                    .WithSource(source)
                    .WithCacheByPage(cacheByPage)
                    .WithCacheByMember(cacheByMember)
                    .WithDontRender(dontRender)
                    .AddProperty()
                    .WithId(propertyId)
                    .WithAlias(propertyAlias)
                    .WithName(propertyName)
                    .WithSortOrder(propertySortOrder)
                    .WithEditorAlias(propertyEditorAlias)
                    .Done()
                    .Build();

        // Assert
        Assert.AreEqual(id, macro.Id);
        Assert.AreEqual(key, macro.Key);
        Assert.AreEqual(useInEditor, macro.UseInEditor);
        Assert.AreEqual(cacheDuration, macro.CacheDuration);
        Assert.AreEqual(alias, macro.Alias);
        Assert.AreEqual(name, macro.Name);
        Assert.AreEqual(source, macro.MacroSource);
        Assert.AreEqual(cacheByPage, macro.CacheByPage);
        Assert.AreEqual(cacheByMember, macro.CacheByMember);
        Assert.AreEqual(dontRender, macro.DontRender);
        Assert.AreEqual(1, macro.Properties.Count);
        Assert.AreEqual(propertyId, macro.Properties[0].Id);
        Assert.AreEqual(propertyAlias, macro.Properties[0].Alias);
        Assert.AreEqual(propertyName, macro.Properties[0].Name);
        Assert.AreEqual(propertySortOrder, macro.Properties[0].SortOrder);
        Assert.AreEqual(propertyEditorAlias, macro.Properties[0].EditorAlias);
    }
Beispiel #2
0
        public void OpenDrawingListOfColumns()
        {
            var macroBuilder = new MacroBuilder();

            //open drawing list and show columns
            macroBuilder.ValueChange("main_frame", "sel_all", "0");
            macroBuilder.ValueChange("main_frame", "sel_all", "1");
            macroBuilder.ValueChange("main_frame", "sel_filter", "Steel_Column");
            macroBuilder.Callback("acmdSelectAll", "", "main_frame");
            macroBuilder.Callback("gdr_menu_select_active_draw", "", "main_frame");
            macroBuilder.PushButton("dia_draw_display_all", "Drawing_selection");
            macroBuilder.PushButton("dia_draw_filter_by_parts", "Drawing_selection");

            macroBuilder.Run();

            //recorded macro code for reference

            //akit.ValueChange("main_frame", "sel_all", "0");
            //akit.ValueChange("main_frame", "sel_all", "1");
            //akit.ValueChange("main_frame", "sel_filter", "Steel_Column");
            //akit.Callback("acmdSelectAll", "", "main_frame");
            //akit.Callback("gdr_menu_select_active_draw", "", "main_frame");
            //akit.PushButton("dia_draw_display_all", "Drawing_selection");
            //akit.PushButton("dia_draw_filter_by_parts", "Drawing_selection");
        }
Beispiel #3
0
        private void addMark(string attributeName, bool customAmount, string barNo = null)
        {
            if (!TeklaStructures.Connect())
            {
                return;
            }
            var macroBuilder = new MacroBuilder();

            if (customAmount)
            {
                macroBuilder.Callback("acmd_create_marks_selected", "", "View_10 window_1");
                macroBuilder.ValueChange("rebar_mark_dial", "gr_rebar_mark_get_menu", attributeName);
                macroBuilder.PushButton("gr_rebar_get", "rebar_mark_dial");
                macroBuilder.TableSelect("rebar_mark_dial", "gr_mark_selected_elements", new int[] { 1 });
                macroBuilder.Activate("rebar_mark_dial", "gr_mark_selected_elements");
                macroBuilder.ValueChange("gr_mark_text", "gr_text", barNo);
                macroBuilder.PushButton("gr_mark_prompt_modify", "gr_mark_text");
                macroBuilder.PushButton("rebar_mark_modify", "rebar_mark_dial");
                macroBuilder.Run();
            }
            else
            {
                macroBuilder.Callback("acmd_create_marks_selected", "", "View_10 window_1");
                macroBuilder.ValueChange("rebar_mark_dial", "gr_rebar_mark_get_menu", attributeName);
                macroBuilder.PushButton("gr_rebar_get", "rebar_mark_dial");
                macroBuilder.PushButton("rebar_mark_modify", "rebar_mark_dial");
                macroBuilder.Run();
            }
        }
Beispiel #4
0
        /// <summary>*******************************************************************
        ///
        ///
        /// HELPER METHODS
        ///
        ///
        /// </summary>*******************************************************************

        private void changeDialog(string attributeFileName, dialogType objectType)
        {
            if (!TeklaStructures.Connect())
            {
                return;
            }
            var macroBuilder = new MacroBuilder();

            switch (objectType)
            {
            case dialogType.bar:
                macroBuilder.Callback("acmd_display_selected_drawing_object_dialog", "", "View_10 window_1");
                macroBuilder.ValueChange("rebar_dial", "gr_rebar_get_menu", attributeFileName);
                macroBuilder.PushButton("gr_rebar_get", "rebar_dial");
                macroBuilder.PushButton("rebar_modify", "rebar_dial");
                macroBuilder.Run();
                break;

            case dialogType.coupler:
                macroBuilder.Callback("acmd_display_selected_drawing_object_dialog", "", "View_10 window_1");
                macroBuilder.ValueChange("part_dial", "gr_part_get_menu", attributeFileName);
                macroBuilder.PushButton("gr_part_get", "part_dial");
                macroBuilder.PushButton("part_modify", "part_dial");
                macroBuilder.Run();
                break;

            default:
                break;
            }
        }
Beispiel #5
0
 public static dynamic GetTSObject(MacroBuilder dynObject)
 {
     if (dynObject is null)
     {
         return(null);
     }
     return(dynObject.teklaObject);
 }
 /// <summary>
 /// Determines whether the specified macros are valid.
 /// </summary>
 /// <param name="macros">The macros.</param>
 /// <returns>
 ///   <c>true</c> if the specified macros are valid; otherwise, <c>false</c>.
 /// </returns>
 public bool IsValid(IEnumerable <MacroDto> macros)
 {
     foreach (var macro in macros)
     {
         if (!MacroBuilder.IsValidExpression(macro.Expression))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #7
0
        public void CreateMacro_UsingUnknownMarkups_ExceptionIsThrown()
        {
            var macro   = "Hello $unknown$ $LASTNAME$";
            var patient = new Patient()
            {
                FirstName = "ROBERT", LastName = "DUPONT"
            };

            var builder = new MacroBuilder(patient);

            Assert.Throws <InvalidMacroException>(() => builder.Resolve(macro));
        }
Beispiel #8
0
        public void CreateMacro_UsingUpperCaseMarkups_MarkupsReplacesWithValues()
        {
            var robert = "Robert";
            var dupont = "Dupont";

            var macro    = "Hello $FIRSTNAME$ $LASTNAME$";
            var expected = "Hello " + robert + " " + dupont;

            var patient = new Patient()
            {
                FirstName = robert, LastName = dupont
            };

            var builder = new MacroBuilder(patient);
            var result  = builder.Resolve(macro);

            Assert.AreEqual(expected, result);
        }
Beispiel #9
0
        public void CreateMacro_ReplaceFullName_MarkupsReplacedWithValue()
        {
            var robert = "Robert";
            var dupont = "Dupont";

            var macro    = "Hello $firstname$ $lastname$";
            var expected = "Hello " + robert + " " + dupont;

            var patient = new Patient()
            {
                FirstName = robert, LastName = dupont
            };

            var builder = new MacroBuilder(patient);
            var result  = builder.Resolve(macro);

            Assert.AreEqual(expected, result);
        }
        /// <summary>
        /// Resolves the specified macro with the data of the specified patient.
        /// </summary>
        /// <param name="macro">The macro.</param>
        /// <param name="patient">The patient.</param>
        /// <returns></returns>
        public string Resolve(MacroDto macro, LightPatientDto patient)
        {
            if (macro == null || patient == null)
            {
                return(string.Empty);
            }

            var p = this.Session.Get <Patient>(patient.Id);

            if (p == null)
            {
                throw new EntityNotFoundException(typeof(Patient));
            }

            var builder = new MacroBuilder(p);

            return(builder.Resolve(macro.Expression));
        }
Beispiel #11
0
        public void CreateViewOfAllModelObject()
        {
            var macroBuilder = new MacroBuilder();

            //create view of all model objects
            macroBuilder.Callback("acmdSelectAll", "", "main_frame");
            macroBuilder.Callback("acmdCreateViewBySelectedObjectsExtrema", "", "View_01 window_1");
            macroBuilder.Callback("acmd_set_view_representation", "rendered_joint", "main_frame");
            macroBuilder.Callback("acmd_set_view_representation", "rendered", "main_frame");

            macroBuilder.Run();

            //recorded macro code for reference

            //akit.Callback("acmdSelectAll", "", "main_frame");
            //akit.Callback("acmdCreateViewBySelectedObjectsExtrema", "", "View_02 window_1");
            //akit.Callback("acmd_set_view_representation", "rendered", "main_frame");
            //akit.Callback("acmd_set_view_representation", "rendered_joint", "main_frame");
        }
Beispiel #12
0
 /// <summary>
 /// Updates the specified item.
 /// </summary>
 /// <param name="item">The item.</param>
 public void Update(MacroDto item)
 {
     if (item == null)
     {
         return;
     }
     else if (!MacroBuilder.IsValidExpression(item.Expression))
     {
         throw new InvalidMacroException();
     }
     else
     {
         var entity = this.Session.Get <Macro>(item.Id);
         Mapper.Map <MacroDto, Macro>(item, entity);
         if (entity != null)
         {
             this.Session.Update(entity);
         }
     }
 }
Beispiel #13
0
        public void Can_Export_Macro()
        {
            // Arrange
            IMacroService macroService = GetRequiredService <IMacroService>();
            Macro         macro        = new MacroBuilder()
                                         .WithAlias("test1")
                                         .WithName("Test")
                                         .Build();

            macroService.Save(macro);

            // Act
            XElement element = Serializer.Serialize(macro);

            // Assert
            Assert.That(element, Is.Not.Null);
            Assert.That(element.Element("name").Value, Is.EqualTo("Test"));
            Assert.That(element.Element("alias").Value, Is.EqualTo("test1"));
            Debug.Print(element.ToString());
        }
Beispiel #14
0
        private void changeSelectionFilter(string filterName, bool partOnly)
        {
            if (!TeklaStructures.Connect())
            {
                return;
            }
            var macroBuilder = new MacroBuilder();

            macroBuilder.Callback("acmd_display_gr_select_filter_dialog", "", "main_frame");
            macroBuilder.ValueChange("diaSelDrawingObjectGroupDialogInstance", "get_menu", filterName);
            macroBuilder.PushButton("dia_pa_apply", "diaSelDrawingObjectGroupDialogInstance");
            if (partOnly)
            {
                macroBuilder.ValueChange("main_frame", "gr_sel_all", "0");
                macroBuilder.ValueChange("main_frame", "gr_sel_drawing_part", "1");
            }
            else
            {
                macroBuilder.ValueChange("main_frame", "gr_sel_all", "1");
            }
            macroBuilder.Run();
        }
Beispiel #15
0
        public long Create(MacroDto item)
        {
            Assert.IsNotNull(item, "item");

            if (!MacroBuilder.IsValidExpression(item.Expression))
            {
                throw new InvalidMacroException();
            }

            var exist = (from i in this.Session.Query <MacroDto>()
                         where i.Id == item.Id
                         select i).ToList().Count() > 0;

            if (exist)
            {
                throw new ExistingItemException();
            }

            var entity = Mapper.Map <MacroDto, Macro>(item);

            item.Id = (long)this.Session.Save(entity);
            return(item.Id);
        }
Beispiel #16
0
 public void SetUp() => _builder = new MacroBuilder();
        /// <summary>
        /// Renumbers part that need renumbering.
        /// </summary>
        /// <param name="model">Tekla.Structures.Model model</param>
        public static void RenumberParts(TSM.Model model)
        {
            // check if numberinghistory.txt exists and change its name
            RenameNumberingHistory(model);

            foreach (PartCustom part in partList)
            {
                if (part.NeedsToChange)
                {
                    string partCurrentPosition;
                    partCurrentPosition = part.prefix.ToString() + part.number.ToString();

                    int newNum;
                    string oppositePrefix = ChangeCapitalization(part.Prefix);

                    // checks if a part with same position has already been assigned a new number.
                    // If so, it skips it --> tekla applies the new number from the first part to all of the same parts
                    // all changes are collected in prefixChanges dictionary.
                    if (!prefixChanges.ContainsKey(partCurrentPosition))
                    {
                        bool firstGo = true;
                        string preNumber = string.Empty;
                        string postNumber = string.Empty;

                        do
                        {
                            int maxOppositeNumber = positionsDictionary[oppositePrefix].Max();
                            int maxNumber = positionsDictionary[part.Prefix].Max();

                            newNum = Math.Max(maxNumber, maxOppositeNumber) + 1;

                            // adds new number to prefixChanges dictionary
                            Tuple<string, int> tuple = new Tuple<string, int>(part.prefix, newNum);

                            if (firstGo)
                            {
                                prefixChanges.Add(partCurrentPosition, tuple);
                            }
                            else
                            {
                                prefixChanges.Remove(partCurrentPosition);
                                prefixChanges.Add(partCurrentPosition, tuple);
                            }

                            // select part - clumsy, could it be improved?
                            ArrayList aList = new ArrayList();
                            TSM.Object tPart = model.SelectModelObject(part.Identifier);
                            TSM.UI.ModelObjectSelector selector = new TSM.UI.ModelObjectSelector();
                            aList.Add(tPart);
                            selector.Select(aList);

                            TSM.Part myPart = tPart as TSM.Part;

                            // preNumber and postNumber strings are compared in the 'while' of the do-while loop, to determine if Macrobuilder
                            // macro was succesfully run.
                            // (sometimes Tekla doesn't want to apply certain numbers - e.g.: if they were in use in previous model stages, ... )
                            preNumber = myPart.GetPartMark();

                            // use Macrobuilder dll to change numbering
                            MacroBuilder macroBuilder = new MacroBuilder();
                            macroBuilder.Callback("acmdAssignPositionNumber", "part", "main_frame");
                            macroBuilder.ValueChange("assign_part_number", "Position", newNum.ToString());
                            macroBuilder.PushButton("AssignPB", "assign_part_number");
                            macroBuilder.PushButton("CancelPB", "assign_part_number");
                            macroBuilder.Run();

                            postNumber = myPart.GetPartMark();

                            bool ismacrounning = true;
                            while (ismacrounning)
                            {
                                ismacrounning = TSM.Operations.Operation.IsMacroRunning();
                            }

                            // add newly created part mark to positionsDict
                            positionsDictionary[part.Prefix].Add(newNum);

                            firstGo = false;

                        }
                        //while (!AssignmentSuccesCheck(model));
                        while (preNumber == postNumber);
                    }
                }
            }
        }
 /// <summary>
 /// Determines whether the specified macro is valid.
 /// </summary>
 /// <param name="macro"></param>
 /// <returns>
 ///   <c>true</c> if macro is valid; otherwise, <c>false</c>.
 /// </returns>
 public bool IsValid(MacroDto macro)
 {
     return((macro != null)
         ? MacroBuilder.IsValidExpression(macro.Expression)
         : false);
 }