コード例 #1
0
ファイル: MobeelizerModel.cs プロジェクト: mobeelizer/wp7-sdk
 public MobeelizerModel(Type type, string name, Definition.MobeelizerModelCredentialsDefinition credentials, IList<MobeelizerField> fields)
 {
     this.Type = type;
     this.Name = name;
     this.Credentials = credentials;
     this.Fields = fields;
 }
コード例 #2
0
ファイル: PlantObjectHereEx.cs プロジェクト: Robobeurre/NRaas
        public void OnPreLoad()
        {
            Tunings.Inject<GameObject, PlantObjectHere.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #3
0
ファイル: OfferToMakeRealEx.cs プロジェクト: Robobeurre/NRaas
        public void OnPreLoad()
        {
            Tunings.Inject<Sim, OccultImaginaryFriend.OfferToTurnReal.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #4
0
ファイル: ReadSomethingEx.cs プロジェクト: Robobeurre/NRaas
        public void OnPreLoad()
        {
            Tunings.Inject<Bookshelf, Bookshelf_ReadSomething.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #5
0
        public void OnPreLoad()
        {
            Tunings.Inject<Sim, CuddleSeated.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition ();
        }
コード例 #6
0
ファイル: CallThrowPartyEx.cs プロジェクト: Robobeurre/NRaas
        public void OnPreLoad()
        {
            Tunings.Inject<Phone, Phone.CallThrowParty.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #7
0
        public void OnPreLoad()
        {
            if (Common.AssemblyCheck.IsInstalled("NRaasBOGO")) return;

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }        
コード例 #8
0
        public void OnPreLoad()
        {
            Tunings.Inject<IMirror, VanityDresser.ChangeAppearance.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #9
0
ファイル: CreateServobotEx.cs プロジェクト: Robobeurre/NRaas
        public void OnPreLoad()
        {
            Tunings.Inject<BotMakingStation, BotMakingStation.CreateServobot.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #10
0
ファイル: GetMarriedEx.cs プロジェクト: Robobeurre/NRaas
        public void OnPreLoad()
        {
            Tunings.Inject<WeddingArch, WeddingArch.GetMarried.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #11
0
        public void OnPreLoad()
        {
            Tunings.Inject<Phone, Phone.CallMoveVacationHomeLot.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #12
0
        public void OnPreLoad()
        {
            Tunings.Inject<RoutineMachine, RoutineMachine.TeleportToCommunityLot.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #13
0
ファイル: GetSmeltEx.cs プロジェクト: Robobeurre/NRaas
        public void OnPreLoad()
        {
            Tunings.Inject<Metal, Metal.GetSmelt.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #14
0
        public void OnPreLoad()
        {
            Tunings.Inject<Sim, Cheats.TriggerAgeTransition.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #15
0
ファイル: SummonWeatherEx.cs プロジェクト: Robobeurre/NRaas
        public void OnPreLoad()
        {
            Tunings.Inject<WeatherStone, WeatherStone.SummonWeather.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #16
0
        public void OnPreLoad()
        {
            Tunings.Inject<RabbitHole, SchoolRabbitHole.TakeChildOutOfAfterschoolClass.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #17
0
        public void OnPreLoad()
        {
            Tunings.Inject<Sim, MagicWand.SpellcastingDuel.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #18
0
        public void OnPreLoad()
        {
            Tunings.Inject<TattooChair, TattooChair.GiveTattooToSelf.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #19
0
        public void OnPreLoad()
        {
            Tunings.Inject<Sim, Saddle.EditOutfit.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #20
0
        public void OnPreLoad()
        {
            Tunings.Inject<ClothingPedestal, ClothingPedestal.PlanOutfit.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #21
0
ファイル: HaveBabyHomeEx.cs プロジェクト: GnatGoSplat/NRaas
        public void OnPreLoad()
        {
            Tunings.Inject<Sim, Pregnancy.HaveBabyHome.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #22
0
 public string this[Definition definition]
 {
     get
     {
         return _resources[definition];
     }
 }
コード例 #23
0
        public void OnPreLoad()
        {
            Tunings.Inject<Sim, Sim.CustomizeCollarAndCoats.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #24
0
ファイル: HotTubGetOut.cs プロジェクト: Robobeurre/NRaas
        public void OnPreLoad()
        {
            Tunings.Inject<HotTubBase, HotTubBase.GetOut.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #25
0
        public void OnPreLoad()
        {
            Tunings.Inject<Tablet, Tablet.PickUpTabletForAudio.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
        public void OnPreLoad()
        {
            Tunings.Inject<Phone, Phone.CallInviteOverForeignVisitorsFromRelationPanel.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition ();
        }
コード例 #27
0
        public void OnPreLoad()
        {
            Tunings.Inject<Sim, CuddleRelaxingMakeOut.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition ();
        }
コード例 #28
0
ファイル: SellHorseEx.cs プロジェクト: Robobeurre/NRaas
        public void OnPreLoad()
        {
            Tunings.Inject<EquestrianCenter, EquestrianCenter.SellHorse.Definition, Definition>(true);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #29
0
        public void OnPreLoad()
        {
            Tunings.Inject<RabbitHole, GoToSchoolInRabbitHole.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #30
0
ファイル: HotAirBalloonSit.cs プロジェクト: Robobeurre/NRaas
        public void OnPreLoad()
        {
            Tunings.Inject<HotairBalloon, HotairBalloon.SitInBalloon.Definition, Definition>(false);

            sOldSingleton = Singleton;
            Singleton = new Definition();
        }
コード例 #31
0
 public CastSpellBuilder SetSpellCastingOrigin(FeatureDefinitionCastSpell.CastingOrigin origin)
 {
     Definition.SetSpellCastingOrigin(origin);
     return(this);
 }
コード例 #32
0
 public CastSpellBuilder SetSlotsRecharge(RuleDefinitions.RechargeRate slotRecharge)
 {
     Definition.SetSlotsRecharge(slotRecharge);
     return(this);
 }
コード例 #33
0
 public CastSpellBuilder SetSpellPreparationCount(RuleDefinitions.SpellPreparationCount prepCount)
 {
     Definition.SetSpellPreparationCount(prepCount);
     return(this);
 }
コード例 #34
0
 public CastSpellBuilder SetSpellReadyness(RuleDefinitions.SpellReadyness readyness)
 {
     Definition.SetSpellReadyness(readyness);
     return(this);
 }
コード例 #35
0
 public CastSpellBuilder SetSpellKnowledge(RuleDefinitions.SpellKnowledge knowledge)
 {
     Definition.SetSpellKnowledge(knowledge);
     return(this);
 }
コード例 #36
0
 public CastSpellBuilder SetSpellList(SpellListDefinition spellList)
 {
     Definition.SetSpellListDefinition(spellList);
     return(this);
 }
コード例 #37
0
 public CastSpellBuilder SetSpellCastingAbility(string attribute)
 {
     Definition.SetSpellcastingAbility(attribute);
     return(this);
 }
コード例 #38
0
 public async Task DeleteEntryLisAsynct(int storageNo)
 {
     var path = Path.Combine(Definition.EntryDirectory, Definition.EntryFileFormatter(storageNo));
     await fileService.DeleteFileAsync(path);
 }
コード例 #39
0
 public ActorProxyBaseImpl(Definition definition, IAddress address)
     : base(typeof(IProto), Xoom.Actors.Definition.SerializationProxy.From(definition), address)
 {
 }
コード例 #40
0
 public CastSpellBuilder SetGuiPresentation(GuiPresentation gui)
 {
     Definition.SetGuiPresentation(gui);
     return(this);
 }
コード例 #41
0
 public bool IsValidDev2Task()
 {
     return(Definition.IsValidDev2Task());
 }
コード例 #42
0
 public abstract string[] EvaulateOutgoingPaths(Definition definition, IsFlowValid isFlowValid, ProcessVariablesContainer variables);
コード例 #43
0
        private bool AddParameter(Element element)
        {
            bool instanceBindOK = false;

            try
            {
                DefinitionFile  definitionFile = m_app.Application.OpenSharedParameterFile();
                DefinitionGroup defGroup       = definitionFile.Groups.get_Item("HOK BCF");
                if (null == defGroup)
                {
                    defGroup = definitionFile.Groups.Create("HOK BCF");
                }

                foreach (string defName in bcfParameters)
                {
#if RELEASE2015 || RELEASE2016 || RELEASE2017
                    Parameter parameter = element.LookupParameter(defName);
#else
                    Parameter parameter = element.get_Parameter(defName);
#endif
                    if (null != parameter)
                    {
                        continue;
                    }

                    Definition definition = defGroup.Definitions.get_Item(defName);
                    if (null == definition)
                    {
#if RELEASE2015
                        ExternalDefinitonCreationOptions option = new ExternalDefinitonCreationOptions(defName, ParameterType.Text);
                        definition = defGroup.Definitions.Create(option);
#elif RELEASE2016 || RELEASE2017
                        ExternalDefinitionCreationOptions option = new ExternalDefinitionCreationOptions(defName, ParameterType.Text);
                        definition = defGroup.Definitions.Create(option);
#else
                        definition = defGroup.Definitions.Create(defName, ParameterType.Text);
#endif
                    }

                    BindingMap      bindingMap      = m_app.ActiveUIDocument.Document.ParameterBindings;
                    InstanceBinding instanceBinding = bindingMap.get_Item(definition) as InstanceBinding;
                    if (null != instanceBinding)
                    {
                        instanceBinding.Categories.Insert(element.Category);
                        instanceBindOK = bindingMap.ReInsert(definition, instanceBinding);
                    }
                    else
                    {
                        CategorySet categories = m_app.Application.Create.NewCategorySet();
                        categories.Insert(element.Category);
                        instanceBinding = m_app.Application.Create.NewInstanceBinding(categories);
                        instanceBindOK  = bindingMap.Insert(definition, instanceBinding, BuiltInParameterGroup.PG_TEXT);
                    }
                    if (!instanceBindOK)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to add project parameters for element " + element.Name + "\n" + ex.Message, "CommandForm:AddParameter", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                instanceBindOK = false;
            }
            return(instanceBindOK);
        }
コード例 #44
0
 public override object Exec(Definition d, object arg)
 {
     return(d.TypeExpr);
 }
コード例 #45
0
ファイル: CSPGenerator.cs プロジェクト: cnacha/PAT.ADL
        public void parse(SystemConfig config)
        {
            Dictionary <string, Connector> connectorInstanceList = new Dictionary <string, Connector>();

            // get connector instance to the dictionary
            foreach (var define in config.declareList)
            {
                Spec.ConnectorDatabase.TryGetValue(define.RightName, out Connector conn);
                if (conn == null)
                {
                    throw new Exception("At define statement, cannot find connector :" + define.RightName);
                }

                // Console.WriteLine(".......... define: " + define.LeftName + ", conn:" + conn.Name);
                Connector connInst = conn.DeepClone();
                connInst.setConfigName(define.LeftName);
                connectorInstanceList.Add(define.LeftName, connInst);
            }

            // create attach process
            //  Dictionary<string, DefinitionRef> attachMap = new Dictionary<string, DefinitionRef>();
            foreach (var attach in config.attachList)
            {
                Console.WriteLine("##loop on attach: " + attach.LeftName);
                if (!Spec.ComponentDatabase.ContainsKey(attach.LeftName))
                {
                    throw new Exception("No component " + attach.LeftName + " found");
                }
                // find component
                Spec.ComponentDatabase.TryGetValue(attach.LeftName, out Component comp);
                // find internal process associated to the component
                Feature port = comp.getPortByName(attach.LeftFunction.Name);
                Spec.AttachmentDatabase.Add(port.Name, attach);
                Console.WriteLine("attach " + attach.LeftName + "port: " + port.Name + " portproc:" + attach.HeadFunction.getCountEventAfter());

                SysProcess    current     = attach.HeadFunction;
                SysProcess    prevProc    = null;
                Feature       prevRole    = null;
                DefinitionRef atprocRef   = null;
                Process       headprocRef = null;
                // loop through trail of process of attachment
                String         process_prefix    = attach.LeftName + "_";
                List <Feature> linkedRoles       = new List <Feature>();
                Feature        headEmbedProcRole = null;
                SysProcess     headEmbedProc     = null;
                while (current != null)
                {
                    Console.WriteLine("#loop on attach process " + current.getName());
                    atprocRef = new DefinitionRef(process_prefix + current.Super + "_" + current.Name, convertParamValues(current.Parameters));
                    // retrieve connector
                    connectorInstanceList.TryGetValue(current.Super, out Connector conn);

                    if (conn == null)
                    {
                        throw new Exception("At attach statement, " + current.Super + " is not defined");
                    }

                    //  Console.WriteLine("finding role process " + config.Name + "_" + current.Name + ": " + atprocRef.Args);
                    Feature role = conn.getRoleByName(current.Name);
                    if (headprocRef != null)
                    {
                        List <Process> coProcs = new List <Process>();
                        coProcs.Add(headprocRef);

                        if (current.operation == SysProcess.Operation.Interleave)
                        {
                            this.createRoleProcessSpec(role, null, attach.LeftName, port, comp.Name);
                            Spec.DefinitionDatabase.TryGetValue(process_prefix + current.Super + "_" + current.Name, out atprocRef.Def);
                            coProcs.Add(atprocRef);
                            IndexInterleave procs = new IndexInterleave(coProcs);
                            headprocRef = procs;
                        }
                        else if (current.operation == SysProcess.Operation.Parallel)
                        {
                            this.createRoleProcessSpec(role, null, attach.LeftName, port, comp.Name);
                            Spec.DefinitionDatabase.TryGetValue(process_prefix + current.Super + "_" + current.Name, out atprocRef.Def);
                            coProcs.Add(atprocRef);
                            IndexParallel procs = new IndexParallel(coProcs);
                            headprocRef = procs;
                        }

                        else if (current.operation == SysProcess.Operation.Embed)
                        {
                            if (current.next != null && current.next.operation == SysProcess.Operation.Embed)
                            {
                                linkedRoles.Add(role.DeepClone <Feature>());
                            }
                            else
                            {
                                linkedRoles.Add(role.DeepClone <Feature>());
                                Console.WriteLine(" #process: " + process_prefix + headEmbedProcRole.getName() + " headEmbedProc: " + headEmbedProc + " creating...");
                                atprocRef = new DefinitionRef(process_prefix + headEmbedProcRole.ConfigName + "_" + headEmbedProcRole.Name, convertParamValues(headEmbedProc.Parameters));
                                // create embed process

                                this.createRoleProcessSpecWithMultipleLinked(headEmbedProcRole, linkedRoles, attach.LeftName, port, comp.Name);
                                Spec.DefinitionDatabase.TryGetValue(process_prefix + headEmbedProcRole.getName(), out atprocRef.Def);
                                headprocRef = atprocRef;
                            }
                        }
                    }
                    else
                    {
                        if (current.next != null && current.next.operation == SysProcess.Operation.Embed)
                        {
                            // this is head of embeded processs

                            headEmbedProcRole = conn.getRoleByName(current.Name);
                            headEmbedProc     = current;
                        }
                        else
                        {
                            // other process rather than embeded process
                            this.createRoleProcessSpec(role, null, attach.LeftName, port, comp.Name);
                        }

                        Console.WriteLine("     #create first sub process");
                        Spec.DefinitionDatabase.TryGetValue(process_prefix + current.Super + "_" + current.Name, out atprocRef.Def);
                        // first sub process
                        headprocRef = atprocRef;
                    }
                    prevProc = current;
                    prevRole = conn.getRoleByName(current.Name);
                    current  = current.next;
                }

                Definition atprocDef = new Definition(attach.LeftName + "_" + attach.LeftFunction.Name, new String[] { }, headprocRef);
                Spec.DefinitionDatabase.Add(atprocDef.Name, atprocDef);
                //   attachMap.Add(atprocRef.Name, atprocRef);
            }

            // find exec statement and create exec process
            SysProcess subproc = config.Exec;
            //loop through each function in the exec process
            Process head = null;

            while (subproc != null)
            {
                // find attachment process according to what is called in exec process
                DefinitionRef atprocRef = new DefinitionRef(subproc.Super + "_" + subproc.Name, new Expression[] { });
                Spec.DefinitionDatabase.TryGetValue(subproc.Super + "_" + subproc.Name, out atprocRef.Def);
                if (atprocRef.Def == null)
                {
                    throw new Exception("At exec statement, cannot find port" + subproc.Name + " on " + subproc.Super);
                }
                // Process atprocRef = def.Process;
                if (head != null)
                {
                    List <Process> coProcs = new List <Process>();
                    coProcs.Add(head);
                    coProcs.Add(atprocRef);
                    if (subproc.operation == SysProcess.Operation.Interleave)
                    {
                        IndexInterleave interleaveProcs = new IndexInterleave(coProcs);
                        head = interleaveProcs;
                    }
                    else if (subproc.operation == SysProcess.Operation.Parallel)
                    {
                        IndexParallel parallelProcs = new IndexParallel(coProcs);
                        head = parallelProcs;
                    }
                    else if (subproc.operation == SysProcess.Operation.Choice)
                    {
                        IndexChoice choiceProcs = new IndexChoice(coProcs);
                        head = choiceProcs;
                    }
                }
                else
                {
                    // first sub process
                    head = atprocRef;
                }

                // go to next process
                subproc = subproc.next;
            }
            // create exec process
            DefinitionRef execRef = new DefinitionRef(config.Name, new Expression[] { });
            //Console.WriteLine("exec proc: " + head.ToString());
            Definition instanceDef = new Definition(execRef.Name, new String[] { }, head);

            execRef.Def = instanceDef;
            Spec.DefinitionDatabase.Add(instanceDef.Name, instanceDef);
            Spec.ExecProcessDatabase.Add(execRef.Name, execRef);
        }
コード例 #46
0
        //Temporarily store group visibility information for LoadDeck. //bug (google) #20

        public void LoadDeck(IDeck deck)
        {
            Player player  = deck.IsShared ? Player.GlobalPlayer : Player.LocalPlayer;
            var    def     = Program.GameEngine.Definition;
            var    deckDef = deck.IsShared ? def.SharedDeckSections : def.DeckSections;
            int    nCards  = deck.CardCount();
            var    ids     = new int[nCards];
            var    keys    = new ulong[nCards];
            var    cards   = new Card[nCards];
            var    groups  = new Play.Group[nCards];
            var    gtmps   = new List <GrpTmp>(); //for temp groups visibility
            int    j       = 0;

            foreach (ISection section in deck.Sections)
            {
                var sectionDef = deckDef[section.Name];
                if (sectionDef == null)
                {
                    throw new InvalidFileFormatException("Invalid section '" + section.Name + "' in deck file.");
                }
                Play.Group group = player.Groups.First(x => x.Name == sectionDef.Group);

                //In order to make the clients know what the card is (if visibility is set so that they can see it),
                //we have to set the visibility to Nobody, and then after the cards are sent, set the visibility back
                //to what it was. //bug (google) #20
                var gt = new GrpTmp(group, group.Visibility, group.Viewers.ToList());
                if (!gtmps.Contains(gt))
                {
                    gtmps.Add(gt);
                    group.SetVisibility(false, false);
                }
                foreach (IMultiCard element in section.Cards)
                {
                    DataNew.Entities.Card mod = Definition.GetCardById(element.Id);
                    for (int i = 0; i < element.Quantity; i++)
                    { //for every card in the deck, generate a unique key for it, ID for it
                        ulong key = ((ulong)Crypto.PositiveRandom()) << 32 | element.Id.Condense();
                        int   id  = GenerateCardId();
                        ids[j]    = id;
                        keys[j]   = Crypto.ModExp(key);
                        groups[j] = group;
                        var card = new Card(player, id, key, mod, true);
                        cards[j++] = card;
                        group.AddAt(card, group.Count);
                    }

                    // Load images in the background
                    string pictureUri = element.GetPicture();
                    Dispatcher.CurrentDispatcher.BeginInvoke(
                        new Func <string, BitmapImage>(ImageUtils.CreateFrozenBitmap),
                        DispatcherPriority.ApplicationIdle, pictureUri);
                }
            }
            Program.Client.Rpc.LoadDeck(ids, keys, groups);

            //reset the visibility to what it was before pushing the deck to everybody. //bug (google) #20
            foreach (GrpTmp g in gtmps)
            {
                switch (g.Visibility)
                {
                case GroupVisibility.Everybody:
                    g.Group.SetVisibility(true, false);
                    break;

                case GroupVisibility.Nobody:
                    g.Group.SetVisibility(false, false);
                    break;

                default:
                    foreach (Player p in g.Viewers)
                    {
                        g.Group.AddViewer(p, false);
                    }
                    break;
                }
            }
            gtmps.Clear();
            gtmps.TrimExcess();
        }
コード例 #47
0
ファイル: RelIndToken.cs プロジェクト: cmrazek/DkTools
 public RelIndToken(Scope scope, Span span, string text, Definition def)
     : base(scope, span, text)
 {
     ClassifierType   = Classifier.ProbeClassifierType.TableName;
     SourceDefinition = def;
 }
コード例 #48
0
        protected static IDefinition <Assembly> GetAssemblies(Action <IDefinition <Assembly> > defineAssemblies)
        {
            var assemblyDefinition = Definition.CreateAssemblyDefinition(defineAssemblies);

            return(assemblyDefinition);
        }
コード例 #49
0
ファイル: DBDReader.cs プロジェクト: bryanspaulding/WoWDBDefs
        public DBDefinition Read(string file, bool validate = false)
        {
            if (!File.Exists(file))
            {
                throw new FileNotFoundException("Unable to find definitions file: " + file);
            }

            var columnDefinitionDictionary = new Dictionary <string, ColumnDefinition>();

            var lines      = File.ReadAllLines(file);
            var lineNumber = 0;

            if (lines[0].StartsWith("COLUMNS"))
            {
                lineNumber++;
                while (true)
                {
                    var line = lines[lineNumber++];

                    // Column definitions are done after encountering a newline
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        break;
                    }

                    // Create a new column definition to store information in
                    var columnDefinition = new ColumnDefinition();

                    /* TYPE READING */
                    // List of valid types, uint should be removed soon-ish
                    var validTypes = new List <string> {
                        "uint", "int", "float", "string", "locstring"
                    };

                    // Check if line has a space in case someone didn't assign a type to a column name
                    if (!line.Contains(" "))
                    {
                        throw new Exception("Line " + line + " in file " + Path.GetFileNameWithoutExtension(file) + " does not contain a space between type and column name!");
                    }

                    // Read line up to space (end of type) or < (foreign key)
                    var type = line.Substring(0, line.IndexOfAny(new char[] { ' ', '<' }));

                    // Check if type is valid, throw exception if not!
                    if (!validTypes.Contains(type))
                    {
                        throw new Exception("Invalid type: " + type + " on line " + lineNumber);
                    }
                    else
                    {
                        columnDefinition.type = type;
                    }

                    /* FOREIGN KEY READING */
                    // Only read foreign key if foreign key identifier is found right after type (it could also be in comments)
                    if (line.StartsWith(type + "<"))
                    {
                        // Read foreign key info between < and > without < and > in result, then split on :: to separate table and field
                        var foreignKey = line.Substring(line.IndexOf('<') + 1, line.IndexOf('>') - line.IndexOf('<') - 1).Split(new string[] { "::" }, StringSplitOptions.None);

                        // There should only be 2 values in foreignKey (table and col)
                        if (foreignKey.Length != 2)
                        {
                            throw new Exception("Invalid foreign key length: " + foreignKey.Length);
                        }
                        else
                        {
                            columnDefinition.foreignTable  = foreignKey[0];
                            columnDefinition.foreignColumn = foreignKey[1];
                        }
                    }

                    /* NAME READING */
                    var name = "";
                    // If there's only one space on the line at the same locaiton as the first one, assume a simple line like "uint ID", this can be better
                    if (line.LastIndexOf(' ') == line.IndexOf(' '))
                    {
                        name = line.Substring(line.IndexOf(' ') + 1);
                    }
                    else
                    {
                        // Location of first space (after type)
                        var start = line.IndexOf(' ');

                        // Second space (after name)
                        var end = line.IndexOf(' ', start + 1) - start - 1;

                        name = line.Substring(start + 1, end);
                    }

                    // If name ends in ? it's unverified
                    if (name.EndsWith("?"))
                    {
                        columnDefinition.verified = false;
                        name = name.Remove(name.Length - 1);
                    }
                    else
                    {
                        columnDefinition.verified = true;
                    }

                    /* COMMENT READING */
                    if (line.Contains("//"))
                    {
                        columnDefinition.comment = line.Substring(line.IndexOf("//") + 2).Trim();
                    }

                    // Add to dictionary
                    if (columnDefinitionDictionary.ContainsKey(name))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Collision with existing column name while adding new column name! Skipping..");
                        Console.ResetColor();
                    }
                    else
                    {
                        columnDefinitionDictionary.Add(name, columnDefinition);
                    }
                }
            }
            else
            {
                throw new Exception("File does not start with column definitions!");
            }

            // There will be less comments from this point on, stuff used in above code is mostly repeated

            var versionDefinitions = new List <VersionDefinitions>();

            var definitions  = new List <Definition>();
            var layoutHashes = new List <string>();
            var comment      = "";
            var builds       = new List <Build>();
            var buildRanges  = new List <BuildRange>();

            for (var i = lineNumber; i < lines.Length; i++)
            {
                var line = lines[i];

                if (string.IsNullOrWhiteSpace(line))
                {
                    versionDefinitions.Add(
                        new VersionDefinitions()
                    {
                        builds       = builds.ToArray(),
                        buildRanges  = buildRanges.ToArray(),
                        layoutHashes = layoutHashes.ToArray(),
                        comment      = comment,
                        definitions  = definitions.ToArray()
                    }
                        );

                    definitions  = new List <Definition>();
                    layoutHashes = new List <string>();
                    comment      = "";
                    builds       = new List <Build>();
                    buildRanges  = new List <BuildRange>();
                }

                if (line.StartsWith("LAYOUT"))
                {
                    var splitLayoutHashes = line.Remove(0, 7).Split(new string[] { ", " }, StringSplitOptions.None);
                    layoutHashes.AddRange(splitLayoutHashes);
                }

                if (line.StartsWith("BUILD"))
                {
                    var splitBuilds = line.Remove(0, 6).Split(new string[] { ", " }, StringSplitOptions.None);
                    foreach (var splitBuild in splitBuilds)
                    {
                        if (splitBuild.Contains("-"))
                        {
                            var splitRange = splitBuild.Split('-');
                            buildRanges.Add(
                                new BuildRange(new Build(splitRange[0]), new Build(splitRange[1]))
                                );
                        }
                        else
                        {
                            var build = new Build(splitBuild);
                            builds.Add(build);
                        }
                    }
                }

                if (line.StartsWith("COMMENT"))
                {
                    comment = line.Substring(7).Trim();
                }

                if (!line.StartsWith("LAYOUT") && !line.StartsWith("BUILD") && !line.StartsWith("COMMENT") && !string.IsNullOrWhiteSpace(line))
                {
                    var definition = new Definition();

                    // Default to everything being inline
                    definition.isNonInline = false;

                    if (line.Contains("$"))
                    {
                        var annotationStart = line.IndexOf("$");
                        var annotationEnd   = line.IndexOf("$", 1);

                        var annotations = new List <string>(line.Substring(annotationStart + 1, annotationEnd - annotationStart - 1).Split(','));

                        if (annotations.Contains("id"))
                        {
                            definition.isID = true;
                        }

                        if (annotations.Contains("noninline"))
                        {
                            definition.isNonInline = true;
                        }

                        if (annotations.Contains("relation"))
                        {
                            definition.isRelation = true;
                        }

                        line = line.Remove(annotationStart, annotationEnd + 1);
                    }

                    if (line.Contains("<"))
                    {
                        var size = line.Substring(line.IndexOf('<') + 1, line.IndexOf('>') - line.IndexOf('<') - 1);

                        if (size[0] == 'u')
                        {
                            definition.isSigned = false;
                            definition.size     = int.Parse(size.Replace("u", ""));
                        }
                        else
                        {
                            definition.isSigned = true;
                            definition.size     = int.Parse(size);
                        }

                        line = line.Remove(line.IndexOf('<'), line.IndexOf('>') - line.IndexOf('<') + 1);
                    }

                    if (line.Contains("["))
                    {
                        int.TryParse(line.Substring(line.IndexOf('[') + 1, line.IndexOf(']') - line.IndexOf('[') - 1), out definition.arrLength);
                        line = line.Remove(line.IndexOf('['), line.IndexOf(']') - line.IndexOf('[') + 1);
                    }

                    if (line.Contains("//"))
                    {
                        definition.comment = line.Substring(line.IndexOf("//") + 2).Trim();
                        line = line.Remove(line.IndexOf("//")).Trim();
                    }

                    definition.name = line;

                    // Check if this column name is known in column definitions, if not throw exception
                    if (!columnDefinitionDictionary.ContainsKey(definition.name))
                    {
                        throw new KeyNotFoundException("Unable to find " + definition.name + " in column definitions!");
                    }
                    else
                    {
                        // Temporary unsigned format update conversion code
                        if (columnDefinitionDictionary[definition.name].type == "uint")
                        {
                            definition.isSigned = false;
                        }
                    }

                    definitions.Add(definition);
                }

                if (lines.Length == (i + 1))
                {
                    versionDefinitions.Add(
                        new VersionDefinitions()
                    {
                        builds       = builds.ToArray(),
                        buildRanges  = buildRanges.ToArray(),
                        layoutHashes = layoutHashes.ToArray(),
                        comment      = comment,
                        definitions  = definitions.ToArray()
                    }
                        );
                }
            }

            // Validation is optional!
            if (validate)
            {
                var newColumnDefDict = new Dictionary <string, ColumnDefinition>();
                foreach (var column in columnDefinitionDictionary)
                {
                    newColumnDefDict.Add(column.Key, column.Value);
                }

                var seenBuilds       = new List <Build>();
                var seenLayoutHashes = new List <string>();

                foreach (var column in columnDefinitionDictionary)
                {
                    var found = false;

                    foreach (var version in versionDefinitions)
                    {
                        foreach (var definition in version.definitions)
                        {
                            if (column.Key == definition.name)
                            {
                                if (definition.name == "ID" && !definition.isID)
                                {
                                    Console.ForegroundColor = ConsoleColor.Yellow;
                                    Console.WriteLine(Path.GetFileNameWithoutExtension(file) + "." + definition.name + " is called ID and might be a primary key.");
                                    Console.ResetColor();
                                }
                                found = true;
                                break;
                            }
                        }

                        if (found)
                        {
                            break;
                        }
                    }

                    if (!found)
                    {
                        Console.WriteLine("Column definition " + column.Key + " is never used in version definitions!");
                        newColumnDefDict.Remove(column.Key);
                    }
                }

                columnDefinitionDictionary = newColumnDefDict;

                foreach (var version in versionDefinitions)
                {
                    foreach (var build in version.builds)
                    {
                        if (seenBuilds.Contains(build))
                        {
                            throw new Exception("Build " + build.ToString() + " is already defined!");
                        }
                        else
                        {
                            seenBuilds.Add(build);
                        }
                    }

                    foreach (var layoutHash in version.layoutHashes)
                    {
                        if (seenLayoutHashes.Contains(layoutHash))
                        {
                            throw new Exception("Layout hash " + layoutHash + " is already defined!");
                        }
                        else
                        {
                            seenLayoutHashes.Add(layoutHash);
                        }

                        if (layoutHash.Length != 8)
                        {
                            throw new Exception("Layout hash \"" + layoutHash + "\" is wrong length for file " + file);
                        }
                    }

                    // Check if int/uint columns have sizes set
                    foreach (var definition in version.definitions)
                    {
                        if ((columnDefinitionDictionary[definition.name].type == "int" || columnDefinitionDictionary[definition.name].type == "uint") && definition.size == 0)
                        {
                            throw new Exception("Version definition " + definition.name + " is an int/uint but is missing size in file " + file + "!");
                        }
                    }
                }
            }


            return(new DBDefinition
            {
                columnDefinitions = columnDefinitionDictionary,
                versionDefinitions = versionDefinitions.ToArray()
            });
        }
コード例 #50
0
ファイル: CSPGenerator.cs プロジェクト: cnacha/PAT.ADL
        private void createRoleProcessSpec(Feature role, Feature linkedRole, String eventPrefixStr, Feature attachedPort, String componentName)
        {
            if (Spec.DefinitionDatabase.ContainsKey(eventPrefixStr + "_" + role.getName()))
            {
                return;
            }
            //Feature role = conn.getRoleByName(roleName);

            Spec.CompStateDatabase.TryGetValue(componentName, out List <string> statesList);
            if (statesList == null)
            {
                statesList = new List <string>();
                Spec.CompStateDatabase.Add(componentName, statesList);
            }

            // create parameter of role process
            List <Expression> paramsExpr = new List <Expression>();

            if (role.Params.Count > 0)
            {
                foreach (var param in role.Params)
                {
                    paramsExpr.Add(new Variable(param));
                }
            }
            // create main role process
            DefinitionRef process = new DefinitionRef(eventPrefixStr + "_" + role.getName(), paramsExpr.ToArray());
            Process       prev    = null;

            Console.WriteLine(role.process.ElementAt(role.process.Count - 1).Name + "====" + role.getName());
            if (role.process.ElementAt(role.process.Count - 1).getName() == role.getName())
            {
                prev = process;
            }
            else if (role.process.ElementAt(role.process.Count - 1).Name.IndexOf("Skip") != -1)
            {
                prev = new Skip();
            }
            else if (role.process.ElementAt(role.process.Count - 1).Name.IndexOf("Stop") != -1)
            {
                prev = new Stop();
            }
            // copy list of event from the role process
            List <SysEvent> roleProcess = new List <SysEvent>();

            roleProcess.AddRange(role.process);

            // intercept if there is a link to other role
            if (linkedRole != null)
            {
                for (int i = 0; i < roleProcess.Count; i++)
                {
                    if (roleProcess.ElementAt(i).Name.IndexOf("_process") != -1)

                    {
                        // get rid of xxx() in linked role process
                        if (linkedRole.process.ElementAt(linkedRole.process.Count - 1).Name == linkedRole.Name)
                        {
                            linkedRole.process.RemoveAt(linkedRole.process.Count - 1);
                        }
                        Console.WriteLine("##inserting " + roleProcess.ElementAt(i));
                        // combine process at where  _process is
                        roleProcess.InsertRange(i, linkedRole.process);

                        // combine process after where  _process is
                        // roleProcess.InsertRange(i+1, linkedRole.process);
                        break;
                    }
                }
            }

            // insert component internal computation
            if (attachedPort.process.Count != 0)
            {
                for (int i = 0; i < roleProcess.Count; i++)
                {
                    if (roleProcess.ElementAt(i).Name.IndexOf("_process") != -1)

                    {
                        if (attachedPort.process.ElementAt(attachedPort.process.Count - 1).Name == attachedPort.Name)
                        {
                            attachedPort.process.RemoveAt(attachedPort.process.Count - 1);
                        }

                        // insert event trail after process event
                        //  roleProcess.InsertRange(i+1, attachedPort.process);

                        // insert event trail at process event
                        roleProcess.InsertRange(i, attachedPort.process);

                        break;
                    }
                }
            }


            // construct a sequenc for the role process
            // start from the second event
            for (int i = roleProcess.Count - 2; i >= 0; i--)
            {
                var     sysEvent = roleProcess.ElementAt(i);
                Process current  = null;
                if (sysEvent is SysProcess)
                {
                    // it is event
                    current = new EventPrefix(new Common.Classes.LTS.Event(eventPrefixStr + "_" + sysEvent.getName()), prev);
                    Console.WriteLine("   ->" + componentName + "  addEvent " + eventPrefixStr + "_" + sysEvent.getName());
                    statesList.Add(eventPrefixStr + "_" + sysEvent.getName());
                }
                else if (sysEvent is SysChannel)
                {
                    // it is channel
                    SysChannel channel = (SysChannel)sysEvent;
                    // parse channel parameters
                    List <Expression> chparamsExpr = new List <Expression>();
                    if (channel.Parameters.Count > 0)
                    {
                        foreach (var param in channel.Parameters)
                        {
                            chparamsExpr.Add(new Variable(param));
                        }
                    }
                    // add channelqueue to database, if still not exists
                    if (!Spec.ChannelDatabase.ContainsKey(channel.getName()))
                    {
                        ChannelQueue queue = new ChannelQueue(1);
                        Spec.ChannelDatabase.Add(channel.getName(), queue);
                    }
                    if (channel.ChannelType == SysChannel.Type.Input)
                    {
                        current = new ChannelInput(channel.getName(), null, chparamsExpr.ToArray(), prev);
                    }
                    else if (channel.ChannelType == SysChannel.Type.Output)
                    {
                        current = new ChannelOutput(channel.getName(), null, chparamsExpr.ToArray(), prev);
                    }
                }
                prev = current;
            }
            //Spec.CompStateDatabase.Add(componentName, statesList);
            Spec.CompStateDatabase.TryGetValue(componentName, out List <string> outstatesList);
            Console.WriteLine("     -> outstate: " + outstatesList.Count);
            // create process definition
            Definition processDef = new Definition(eventPrefixStr + "_" + role.getName(), role.Params.ToArray(), prev);

            process.Def = processDef;

            // add role process to spec
            Console.WriteLine("............ create role process :" + role.getName());
            Spec.DefinitionDatabase.Add(processDef.Name, processDef);
        }
コード例 #51
0
 public abstract void Execute(Result result, Definition definition);
コード例 #52
0
 public void Post([FromBody] Definition value)
 {
     _service.RegisterNewDefinition(value);
     Response.StatusCode = 204;
 }
コード例 #53
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            if (doc.IsFamilyDocument)
            {
                message = "This command can only be used in a project, not in a family file.";
                return(Result.Failed);
            }

            // get the current shared params definition file
            DefinitionFile sharedParamsFile = LabUtils.GetSharedParamsFile(app.Application);

            if (null == sharedParamsFile)
            {
                message = "Error getting the shared params file.";
                return(Result.Failed);
            }
            // get or create the shared params group
            DefinitionGroup sharedParamsGroup = LabUtils.GetOrCreateSharedParamsGroup(
                sharedParamsFile, LabConstants.ParamGroupName);

            if (null == sharedParamsGroup)
            {
                message = "Error getting the shared params group.";
                return(Result.Failed);
            }
            // visible param
            Definition docParamDefVisible = LabUtils.GetOrCreateSharedParamsDefinition(
                sharedParamsGroup, ParameterType.Integer, LabConstants.ParamNameVisible, true);

            if (null == docParamDefVisible)
            {
                message = "Error creating visible per-doc parameter.";
                return(Result.Failed);
            }
            // invisible param
            Definition docParamDefInvisible = LabUtils.GetOrCreateSharedParamsDefinition(
                sharedParamsGroup, ParameterType.Integer, LabConstants.ParamNameInvisible, false);

            if (null == docParamDefInvisible)
            {
                message = "Error creating invisible per-doc parameter.";
                return(Result.Failed);
            }
            // bind the param
            try
            {
                CategorySet catSet = app.Application.Create.NewCategorySet();

                catSet.Insert(doc.Settings.Categories.get_Item(
                                  BuiltInCategory.OST_ProjectInformation));

                Binding binding = app.Application.Create.NewInstanceBinding(catSet);
                doc.ParameterBindings.Insert(docParamDefVisible, binding);
                doc.ParameterBindings.Insert(docParamDefInvisible, binding);
            }
            catch (Exception e)
            {
                message = "Error binding shared parameter: " + e.Message;
                return(Result.Failed);
            }
            // set the initial values
            // get the singleton project info element
            Element projInfoElem = LabUtils.GetProjectInfoElem(doc);

            if (null == projInfoElem)
            {
                message = "No project info element found. Aborting command...";
                return(Result.Failed);
            }

            // For simplicity, access params by name rather than by GUID
            // and simply the first best one found under that name:

            projInfoElem.LookupParameter(LabConstants.ParamNameVisible).Set(55);
            projInfoElem.LookupParameter(LabConstants.ParamNameInvisible).Set(0);

            return(Result.Succeeded);
        }
 private TimeZoneInfo.AdjustmentRule GetAdjustmentRule(int year, string id)
 {
     return(Definition.GetRule(year, id));
 }
コード例 #55
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            // Open source project

            Document docHasFamily = app.OpenDocumentFile(_source_project_path);

            // Find system family to copy, e.g. using a named wall type

            WallType wallType = null;

            //WallTypeSet wallTypes = docHasFamily.WallTypes; // 2013

            FilteredElementCollector wallTypes
                = new FilteredElementCollector(doc) // 2014
                  .OfClass(typeof(WallType));

            foreach (WallType wt in wallTypes)
            {
                if (wt.Name.Equals(_wall_type_name))
                {
                    wallType = wt;
                    break;
                }
            }

            if (null == wallType)
            {
                message = string.Format(
                    "Cannot find source wall type '{0}'"
                    + " in source document '{1}'. ",
                    _source_project_path,
                    _wall_type_name);

                return(Result.Failed);
            }

            // Create a new wall type in current document

            Transaction t = new Transaction(doc);

            t.Start("Transfer Wall Type");

            WallType newWallType = null;

            //WallTypeSet wallTypes = doc.WallTypes; // 2013

            wallTypes = new FilteredElementCollector(doc)
                        .OfClass(typeof(WallType)); // 2014

            foreach (WallType wt in wallTypes)
            {
                if (wt.Kind == wallType.Kind)
                {
                    newWallType = wt.Duplicate(_wall_type_name)
                                  as WallType;

                    Debug.Print(string.Format(
                                    "New wall type '{0}' created.",
                                    _wall_type_name));

                    break;
                }
            }

            // Assign parameter values from source wall type:

  #if COPY_INDIVIDUAL_PARAMETER_VALUE
            // Example: individually copy the "Function" parameter value:

            BuiltInParameter bip      = BuiltInParameter.FUNCTION_PARAM;
            string           function = wallType.get_Parameter(bip).AsString();
            Parameter        p        = newWallType.get_Parameter(bip);
            p.Set(function);
  #endif // COPY_INDIVIDUAL_PARAMETER_VALUE

            Parameter p = null;

            foreach (Parameter p2 in newWallType.Parameters)
            {
                Definition d = p2.Definition;

                if (p2.IsReadOnly)
                {
                    Debug.Print(string.Format(
                                    "Parameter '{0}' is read-only.", d.Name));
                }
                else
                {
                    p = wallType.get_Parameter(d);

                    if (null == p)
                    {
                        Debug.Print(string.Format(
                                        "Parameter '{0}' not found on source wall type.",
                                        d.Name));
                    }
                    else
                    {
                        if (p.StorageType == StorageType.ElementId)
                        {
                            // Here you have to find the corresponding
                            // element in the target document.

                            Debug.Print(string.Format(
                                            "Parameter '{0}' is an element id.",
                                            d.Name));
                        }
                        else
                        {
                            if (p.StorageType == StorageType.Double)
                            {
                                p2.Set(p.AsDouble());
                            }
                            else if (p.StorageType == StorageType.String)
                            {
                                p2.Set(p.AsString());
                            }
                            else if (p.StorageType == StorageType.Integer)
                            {
                                p2.Set(p.AsInteger());
                            }
                            Debug.Print(string.Format(
                                            "Parameter '{0}' copied.", d.Name));
                        }
                    }
                }

                // Note:
                // If a shared parameter parameter is attached,
                // you need to create the shared parameter first,
                // then copy the parameter value.
            }

            // If the system family type has some other properties,
            // you need to copy them as well here. Reflection can
            // be used to determine the available properties.

            MemberInfo[] memberInfos = newWallType.GetType()
                                       .GetMembers(BindingFlags.GetProperty);

            foreach (MemberInfo m in memberInfos)
            {
                // Copy the writable property values here.
                // As there are no property writable for
                // Walltype, I ignore this process here.
            }

            t.Commit();

            return(Result.Succeeded);
        }
コード例 #56
0
 private static Definition GetDefinition()
 {
     return(Definition
            .WithName(PolicyName)
            .WithExceptionPolicyEntry(GetEntry()));
 }
コード例 #57
0
        public FeedResourceTest(ITestOutputHelper output)
        {
            var converter = new Converter(output);

            Console.SetOut(converter);

            var world = World.StartWithDefaults("test-stream-userResource");

            var testServerPort = ServerPort.IncrementAndGet();

            var properties = new Dictionary <string, string>();

            properties.Add("server.http.port", testServerPort.ToString());
            properties.Add("server.dispatcher.pool", "10");
            properties.Add("server.buffer.pool.size", "100");
            properties.Add("server.message.buffer.size", "65535");
            properties.Add("server.probe.interval", "2");
            properties.Add("server.probe.timeout", "2");
            properties.Add("server.processor.pool.size", "10");
            properties.Add("server.request.missing.content.timeout", "100");

            properties.Add("feed.resource.name.events", FeedURI);
            properties.Add("feed.resource.events.producer.class", "Vlingo.Http.Tests.Resource.Feed.EventsFeedProducerActor");
            properties.Add("feed.resource.events.elements", "5");
            properties.Add("feed.resource.events.pool", "10");

            var httpProperties = HttpProperties.Instance;

            httpProperties.SetCustomProperties(properties);

            var server = ServerFactory.StartWith(world.Stage, httpProperties);

            Assert.True(server.StartUp().Await(TimeSpan.FromMilliseconds(500)));

            _progress = new Progress();
            var consumer = world.ActorFor <IResponseChannelConsumer>(Definition.Has <TestResponseChannelConsumer>(Definition.Parameters(_progress)));

            _client = new BasicClientRequestResponseChannel(Address.From(Host.Of("localhost"), testServerPort, AddressType.None), consumer, 100, 10240, world.DefaultLogger);
        }
コード例 #58
0
        //static public BuiltInCategory Target = BuiltInCategory.OST_Walls;
        //static public string Target = "Drawing1.dwg";
        //static public BuiltInCategory Target = BuiltInCategory.OST_IOSModelGroups; // doc.Settings.Categories.get_Item returns null
        //static public string Target = "Model Groups"; // doc.Settings.Categories.get_Item throws an exception SystemInvalidOperationException "Operation is not valid due to the current state of the object."
        //static public BuiltInCategory Target = BuiltInCategory.OST_Lines; // model lines
        //static public BuiltInCategory Target = BuiltInCategory.OST_SWallRectOpening; // Rectangular Straight Wall Openings, case 1260656 [Add Parameters Wall Opening]

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            Document      doc   = uiapp.ActiveUIDocument.Document;
            Category      cat   = null;

            #region Determine model group category
#if DETERMINE_MODEL_GROUP_CATEGORY
            List <Element> modelGroups = new List <Element>();
            //Filter fType = app.Create.Filter.NewTypeFilter( typeof( Group ) ); // "Binding the parameter to the category Model Groups is not allowed"
            Filter fType     = app.Create.Filter.NewTypeFilter(typeof(GroupType)); // same result "Binding the parameter to the category Model Groups is not allowed"
            Filter fCategory = app.Create.Filter.NewCategoryFilter(BuiltInCategory.OST_IOSModelGroups);
            Filter f         = app.Create.Filter.NewLogicAndFilter(fType, fCategory);
            if (0 < doc.get_Elements(f, modelGroups))
            {
                cat = modelGroups[0].Category;
            }
#endif // DETERMINE_MODEL_GROUP_CATEGORY
            #endregion // Determine model group category

            if (null == cat)
            {
                // The category we are defining the parameter for

                try
                {
                    cat = doc.Settings.Categories.get_Item(Target);
                }
                catch (Exception ex)
                {
                    message = "Error obtaining the shared param document category: "
                              + ex.Message;
                    return(Result.Failed);
                }
                if (null == cat)
                {
                    message = "Unable to obtain the shared param document category.";
                    return(Result.Failed);
                }
            }

            // Get the current shared params definition file

            DefinitionFile sharedParamsFile = LabUtils.GetSharedParamsFile(app);
            if (null == sharedParamsFile)
            {
                message = "Error getting the shared params file.";
                return(Result.Failed);
            }

            // Get or create the shared params group

            DefinitionGroup sharedParamsGroup = LabUtils.GetOrCreateSharedParamsGroup(
                sharedParamsFile, LabConstants.SharedParamsGroupAPI);
            if (null == sharedParamsGroup)
            {
                message = "Error getting the shared params group.";
                return(Result.Failed);
            }

            // Visibility of the new parameter: the
            // Category.AllowsBoundParameters property
            // determines whether a category is allowed to
            // have user-visible shared or project parameters.
            // If it is false, it may not be bound to visible
            // shared parameters using the BindingMap. Note
            // that non-user-visible parameters can still be
            // bound to these categories.

            bool visible = cat.AllowsBoundParameters;

            // Get or create the shared params definition

            Definition fireRatingParamDef = LabUtils.GetOrCreateSharedParamsDefinition(
                sharedParamsGroup, ParameterType.Number, LabConstants.SharedParamsDefFireRating, visible);
            if (null == fireRatingParamDef)
            {
                message = "Error in creating shared parameter.";
                return(Result.Failed);
            }

            // Create the category set for binding and add the category
            // we are interested in, doors or walls or whatever:

            CategorySet catSet = app.Create.NewCategorySet();
            try
            {
                catSet.Insert(cat);
            }
            catch (Exception)
            {
                message = string.Format(
                    "Error adding '{0}' category to parameters binding set.",
                    cat.Name);
                return(Result.Failed);
            }

            // Bind the parameter.

            try
            {
                using (Transaction t = new Transaction(doc))
                {
                    t.Start("Bind Fire Rating Shared Parameter");

                    Binding binding = app.Create.NewInstanceBinding(catSet);

                    // We could check if already bound, but looks
                    // like Insert will just ignore it in that case.

                    doc.ParameterBindings.Insert(fireRatingParamDef, binding);

                    // You can also specify the parameter group here:

                    //doc.ParameterBindings.Insert( fireRatingParamDef, binding, BuiltInParameterGroup.PG_GEOMETRY );

                    t.Commit();
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
            return(Result.Succeeded);
        }
コード例 #59
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIDocument  uidoc = commandData.Application.ActiveUIDocument;
            Application app   = commandData.Application.Application;
            Document    doc   = uidoc.Document;

            // Get the current shared params definition file
            DefinitionFile sharedParamsFile = GetSharedParamsFile(app);

            if (null == sharedParamsFile)
            {
                message = "Error getting the shared params file.";
                return(Result.Failed);
            }

            // Get or create the shared params group
            DefinitionGroup sharedParamsGroup = GetOrCreateSharedParamsGroup(
                sharedParamsFile, kSharedParamsGroupAPI);

            if (null == sharedParamsGroup)
            {
                message = "Error getting the shared params group.";
                return(Result.Failed);
            }

            Category cat = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Doors);

            // Visibility of the new parameter:
            // Category.AllowsBoundParameters property indicates if a category can
            // have shared or project parameters. If it is false, it may not be bound
            // to shared parameters using the BindingMap. Please note that non-user-visible
            // parameters can still be bound to these categories.
            bool visible = cat.AllowsBoundParameters;

            // Get or create the shared params definition
            Definition fireRatingParamDef = GetOrCreateSharedParamsDefinition(
                sharedParamsGroup, ParameterType.Number, kSharedParamsDefFireRating, visible);

            if (null == fireRatingParamDef)
            {
                message = "Error in creating shared parameter.";
                return(Result.Failed);
            }

            // Create the category set for binding and add the category
            // we are interested in, doors or walls or whatever:
            CategorySet catSet = app.Create.NewCategorySet();

            try
            {
                catSet.Insert(cat);
            }
            catch (Exception)
            {
                message = string.Format(
                    "Error adding '{0}' category to parameters binding set.",
                    cat.Name);
                return(Result.Failed);
            }

            // Bind the param
            try
            {
                Binding binding = app.Create.NewInstanceBinding(catSet);
                // We could check if already bound, but looks like Insert will just ignore it in such case
                doc.ParameterBindings.Insert(fireRatingParamDef, binding);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }

            return(Result.Succeeded);
        }
コード例 #60
0
        public string CreateSharedParameter(UIApplication uiApp, Document doc)
        {
            string message = string.Empty;

            AddFileSharedParameter();
            string definitionGroup = "EnTools";

            if (!CreateSharedParameterFile(doc, System.Environment
                                           .GetFolderPath(System.Environment.SpecialFolder.Personal)
                                           + @"\entools\", "EnTools_SharedParameters.txt"))
            {
                ErrorWindow Err = new ErrorWindow("!createSharedParameterFile", "Error");
                Err.ShowDialog();
            }

            List <string> names = new List <string>()
            {
                "_entools1", "_entools2", "_entools3", "_entools4", "_entools5",
                "_entools6", "_entools7", "_entools8", "_entools9", "_entools10",
                "entools_number", "entools_flow", "entools_velocity", "entools_pressure",
                "entools_kvse", "_entools_TD"
            };

            DefinitionFile parafile   = doc.Application.OpenSharedParameterFile();
            CategorySet    categories = doc.Application.Create.NewCategorySet();

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Copy Parameters");

                InstanceBinding binding  = doc.Application.Create.NewInstanceBinding(categories);
                DefinitionGroup apiGroup = parafile.Groups.get_Item(definitionGroup);

                if (apiGroup == null)
                {
                    apiGroup = parafile.Groups.Create(definitionGroup);
                }

                BindingMap bindingMap = doc.ParameterBindings;

                foreach (string name in names)
                {
                    Definition sharedParameterDefinition = apiGroup.Definitions.get_Item(name);
                    if (sharedParameterDefinition == null)
                    {
                        ExternalDefinitionCreationOptions option
                            = new ExternalDefinitionCreationOptions(name, ParameterType.Text);

                        Definition visibleParamDef = apiGroup.Definitions.Create(option);
                        Insert(doc, uiApp, visibleParamDef, bindingMap);
                    }
                    else
                    {
                        Definition visibleParamDef = sharedParameterDefinition;
                        Insert(doc, uiApp, visibleParamDef, bindingMap);
                    }
                    message = message + "Add parameter: " + name + "\n";
                }

                tx.Commit();
            }

            return(message);
        }