コード例 #1
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             EasyUpdator eu = context.Instance as EasyUpdator;
             if (eu == null)
             {
                 object   pointer;
                 IClassId ic = context.Instance as IClassId;
                 if (ic != null)
                 {
                     pointer = ic.ObjectInstance;
                 }
                 else
                 {
                     pointer = context.Instance;
                 }
                 if (pointer != null)
                 {
                     eu = VPLUtil.GetObject(pointer) as EasyUpdator;
                 }
             }
             if (eu != null)
             {
                 SQLNoneQuery sq = value as SQLNoneQuery;
                 if (sq == null)
                 {
                     sq = new SQLNoneQuery();
                 }
                 sq.SetConnection(eu.DatabaseConnection);
                 bool bOK = eu.DatabaseConnection.ConnectionObject.IsConnectionReady;
                 if (!bOK)
                 {
                     DlgConnectionManager dlgC = new DlgConnectionManager();
                     dlgC.UseProjectScope = true;
                     if (edSvc.ShowDialog(dlgC) == System.Windows.Forms.DialogResult.OK)
                     {
                         eu.DatabaseConnection = dlgC.SelectedConnection;
                         sq.SetConnection(dlgC.SelectedConnection);
                         bOK = true;
                     }
                 }
                 if (bOK)
                 {
                     dlgPropSQLNonQuery dlg = new dlgPropSQLNonQuery();
                     dlg.LoadData(sq);
                     if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                     {
                         value = dlg.objRet;
                     }
                 }
             }
         }
     }
     return(value);
 }
コード例 #2
0
        /// <summary>
        ///     FilteredAgentIdsByClassKey with an exclusion list
        /// </summary>
        /// <param name="classKey"></param>
        /// <param name="excludeIds"></param>
        /// <returns></returns>
        public List <IAgentId> GetFilteredAgentIdsWithExclusionList(IClassId classKey, ICollection <IAgentId> excludeIds)
        {
            var actors = FilteredAgentIdsByClassId(classKey).ToList();

            if (excludeIds != null)
            {
                actors.RemoveAll(excludeIds.Contains);
            }

            return(actors);
        }
コード例 #3
0
ファイル: Database.cs プロジェクト: lmorisse/Symu
        public Database(GraphMetaNetwork metaNetwork, MainOrganizationModels models, CommunicationTemplate medium,
                        IClassId classId) : base(metaNetwork, classId)
        {
            if (metaNetwork is null)
            {
                throw new ArgumentNullException(nameof(metaNetwork));
            }

            if (models is null)
            {
                throw new ArgumentNullException(nameof(models));
            }

            SetCognitiveArchitecture(medium);
            // There is no random level for database
            _learningModel = new LearningModel(EntityId, models, MetaNetwork.Knowledge, MetaNetwork.ResourceKnowledge,
                                               CognitiveArchitecture, models.Generator, 0);
            _forgettingModel =
                new ForgettingModel(EntityId, MetaNetwork.ResourceKnowledge, CognitiveArchitecture, models, 0);
        }
コード例 #4
0
 /// <summary>
 ///     Returns a list with the names of all the agents that contain a certain string.
 /// </summary>
 /// <returns>The name fragment that the agent names should contain</returns>
 public ushort FilteredStoppedAgentsByClassIdCount(IClassId classId)
 {
     return((ushort)StoppedAgents.Count(a => a.AgentId.Equals(classId)));
 }
コード例 #5
0
 /// <summary>
 ///     Returns a list with the names of all the agents that contain a certain string.
 /// </summary>
 /// <returns>The name fragment that the agent names should contain</returns>
 public IEnumerable <CognitiveAgent> FilteredCognitiveAgentsByClassId(IClassId classId)
 {
     return(Agents.FilteredByClassId(classId).OfType <CognitiveAgent>());
 }
コード例 #6
0
 /// <summary>
 ///     Returns a list with the names of all the agents that contain a certain string.
 /// </summary>
 /// <returns>The name fragment that the agent names should contain</returns>
 public IEnumerable <ReactiveAgent> FilteredAgentsByClassId(IClassId classId)
 {
     return(Agents.FilteredByClassId(classId));
 }
コード例 #7
0
 /// <summary>
 ///     Returns a list with the names of all the agents that contain a certain string.
 /// </summary>
 /// <returns>The name fragment that the agent names should contain</returns>
 public IEnumerable <IAgentId> FilteredAgentIdsByClassId(IClassId classId)
 {
     return(Agents.FilteredKeysByClassId(classId));
 }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             ConnectionItem       ci  = value as ConnectionItem;
             DlgConnectionManager dlg = new DlgConnectionManager();
             dlg.UseProjectScope = true;
             dlg.SetSelection(ci);
             if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
             {
                 if (dlg.SelectedConnection != null)
                 {
                     PropertyDescriptorCollection ps = TypeDescriptor.GetProperties(context.Instance);
                     PropertyDescriptor           p;
                     p = ps["Reserved"];
                     if (p != null)
                     {
                         p.SetValue(context.Instance, Guid.NewGuid().GetHashCode());
                     }
                     p = ps["ConnectionID"];
                     if (p != null)
                     {
                         p.SetValue(context.Instance, new Guid(dlg.SelectedConnection.Filename));
                     }
                     value = dlg.SelectedConnection;
                     if (VPLUtil.CurrentProject != null)
                     {
                         dlg.SelectedConnection.UpdateUsage(VPLUtil.CurrentProject.ProjectFile);
                     }
                     else
                     {
                         dlg.SelectedConnection.UpdateUsage(Application.ExecutablePath);
                     }
                     IDevClassReferencer dcr = context.Instance as IDevClassReferencer;
                     if (dcr == null)
                     {
                         IClassId classPointer = context.Instance as IClassId;
                         if (classPointer != null)
                         {
                             dcr = classPointer.ObjectInstance as IDevClassReferencer;
                         }
                     }
                     if (dcr == null)
                     {
                         ICustomEventMethodType cemt = context.Instance as ICustomEventMethodType;
                         if (cemt != null)
                         {
                             dcr = cemt.ObjectValue as IDevClassReferencer;
                         }
                     }
                     if (dcr == null)
                     {
                         IDevClassReferencerHolder dcrh = context.Instance as IDevClassReferencerHolder;
                         if (dcrh != null)
                         {
                             dcr = dcrh.DevClass;
                         }
                     }
                     if (dcr != null)
                     {
                         IDevClass dc = dcr.GetDevClass();
                         if (dc != null)
                         {
                             dc.NotifyChange(context.Instance, "SqlQuery");
                         }
                     }
                 }
             }
         }
     }
     return(value);
 }
コード例 #9
0
ファイル: ConcurrentAgents.cs プロジェクト: lmorisse/Symu
 /// <summary>
 ///     Returns a list with the names of all the agents that contain a certain string.
 /// </summary>
 /// <returns>The name fragment that the agent names should contain</returns>
 public IEnumerable <IAgentId> FilteredKeysByClassId(IClassId classId)
 {
     return(_list.Keys.Where(a => a.ClassId.Equals(classId)));
 }
コード例 #10
0
ファイル: ConcurrentAgents.cs プロジェクト: lmorisse/Symu
        internal ushort CountByClassId(IClassId classId)
        {
            var count = _list.Values.Count(a => a.AgentId.ClassId.Equals(classId));

            return(Convert.ToUInt16(count));
        }
コード例 #11
0
ファイル: ConcurrentAgents.cs プロジェクト: lmorisse/Symu
 /// <summary>
 ///     Returns a list with the names of all the agents that contain a certain string.
 /// </summary>
 /// <returns>The name fragment that the agent names should contain</returns>
 public IEnumerable <T> FilteredByClassId(IClassId classId)
 {
     return(GetValues().Where(a => a.AgentId.ClassId.Equals(classId)));
 }
コード例 #12
0
ファイル: ReactiveAgent.cs プロジェクト: lmorisse/Symu
 /// <summary>
 ///     Constructor with standard agent template
 ///     and without an existing AgentId
 ///     The constructor will set the AgentId based on the classId
 /// </summary>
 /// <param name="classId"></param>
 /// <param name="environment"></param>
 protected ReactiveAgent(IClassId classId, SymuEnvironment environment) : this(
         environment?.AgentNetwork.NextAgentId(classId), environment)
 {
 }
コード例 #13
0
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    IQuery qry = context.Instance as IQuery;
                    if (qry == null)
                    {
                        IClassId classPointer = context.Instance as IClassId;
                        if (classPointer != null)
                        {
                            qry = VPLUtil.GetObject(classPointer.ObjectInstance) as IQuery;
                        }
                    }
                    if (qry == null)
                    {
                        ICustomEventMethodType cemt = context.Instance as ICustomEventMethodType;
                        if (cemt != null)
                        {
                            qry = cemt.ObjectValue as IQuery;
                        }
                    }
                    if (qry != null)
                    {
                        IDatabaseAccess da = qry as IDatabaseAccess;
                        if (da != null)
                        {
                            if (da.OnBeforeSetSQL())
                            {
                                if (context.PropertyDescriptor != null)
                                {
                                    da.SetSqlContext(context.PropertyDescriptor.Name);
                                }
                            }
                            else
                            {
                                return(value);
                            }
                        }
                        bool bOK = qry.IsConnectionReady;
                        if (!bOK)
                        {
                            DlgConnectionManager dlgC = new DlgConnectionManager();
                            dlgC.UseProjectScope = true;
                            if (edSvc.ShowDialog(dlgC) == System.Windows.Forms.DialogResult.OK)
                            {
                                qry.DatabaseConnection = dlgC.SelectedConnection;
                                bOK = true;
                            }
                        }
                        if (bOK)
                        {
                            if (qry.IsConnectionReady)
                            {
                                dlgQueryBuilder dlg = new dlgQueryBuilder();
                                QueryParser     qp  = new QueryParser();
                                qp.LoadData(qry.QueryDef);
                                dlg.LoadData(qp);
                                if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                                {
                                    IDevClassReferencer dcr = qry as IDevClassReferencer;
                                    if (dcr != null)
                                    {
                                        IDevClass dc = dcr.GetDevClass();
                                        if (dc != null)
                                        {
                                            dc.NotifyBeforeChange(context.Instance, "SqlQuery");
                                        }
                                    }
                                    qp.checkQueryreadOnly(qp.query);
                                    qry.CopyFrom(qp.query);
                                    if (da != null && !(da is EasyGrid))
                                    {
                                        da.Query();                                        //make the query and get SQL
                                    }
                                    value = qp.query.SQL.Clone();                          //qry.SQL.Clone();

                                    if (context.PropertyDescriptor.IsReadOnly)
                                    {
                                        IDatabaseAccess eq = qry as IDatabaseAccess;
                                        if (eq != null)
                                        {
                                            if (eq.NeedDesignTimeSQL)
                                            {
                                                eq.SQL = (SQLStatement)value;
                                            }
                                            else
                                            {
                                                PropertyDescriptorCollection ps = TypeDescriptor.GetProperties(qry);
                                                ISqlUser eds = qry as ISqlUser;
                                                if (eds != null)
                                                {
                                                }
                                                else
                                                {
                                                    //SQL property is read-only and will not get designer notified
                                                    //For EasyGrid it will cause other properties changes.
                                                    eq.SQL = (SQLStatement)value;
                                                }
                                            }
                                        }

                                        if (dcr != null)
                                        {
                                            IDevClass dc = dcr.GetDevClass();
                                            if (dc != null)
                                            {
                                                dc.NotifyChange(context.Instance, "SqlQuery");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(value);
        }
コード例 #14
0
 /// <summary>
 ///     Use this method to get the next unique AgentId.
 ///     Use Organization.MetaNetwork.[The good OneModeNetwork].NextEntityId if agent has an entity stored in the
 ///     metaNetwork
 /// </summary>
 public IAgentId NextAgentId(IClassId classId)
 {
     return(new AgentId(AgentIndex++, classId));
 }
コード例 #15
0
ファイル: TimeStampedMessages.cs プロジェクト: lmorisse/Symu
 public bool Exists(MessageAction action, byte content, IClassId senderClassId, IClassId receiverClassId)
 {
     return(_messages.Any(m => m.Value.Exists(v => v.Action == action && v.Subject == content &&
                                              v.Sender.Equals(senderClassId) &&
                                              v.Receiver.Equals(receiverClassId))));
 }
コード例 #16
0
ファイル: Database.cs プロジェクト: lmorisse/Symu
 public static Database CreateInstance(GraphMetaNetwork metaNetwork, MainOrganizationModels models, CommunicationTemplate medium,
                                       IClassId classId)
 {
     return(new Database(metaNetwork, models, medium, classId));
 }
コード例 #17
0
 /// <summary>
 ///     The number of agents in the environment
 /// </summary>
 public ushort FilteredAgentsByClassCount(IClassId classKey)
 {
     return(Agents.CountByClassId(classKey));
 }
コード例 #18
0
 /// <summary>
 ///     Constructor with specific agentTemplate
 /// </summary>
 /// <param name="classId"></param>
 /// <param name="environment"></param>
 /// <param name="template"></param>
 /// <remarks> Make constructor private and create a factory method to create an agent that call the Initialize method</remarks>
 protected CognitiveAgent(IClassId classId, SymuEnvironment environment, CognitiveArchitectureTemplate template)
     : this(environment?.AgentNetwork.NextAgentId(classId), environment, template)
 {
     _cognitiveTemplate = template;
 }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             Type scopeType    = null;
             Type scopeTypeWeb = null;
             if (context.PropertyDescriptor.Attributes != null)
             {
                 foreach (Attribute a in context.PropertyDescriptor.Attributes)
                 {
                     ComponentReferenceSelectorTypeAttribute cr = a as ComponentReferenceSelectorTypeAttribute;
                     if (cr != null)
                     {
                         scopeType = cr.ScopeType;
                     }
                     else
                     {
                         ComponentReferenceSelectorTypeWebAttribute crw = a as ComponentReferenceSelectorTypeWebAttribute;
                         if (crw != null)
                         {
                             scopeTypeWeb = crw.ScopeType;
                         }
                     }
                 }
             }
             if (scopeType != null || scopeTypeWeb != null)
             {
                 bool       bForName = false;
                 IComponent ic       = context.Instance as IComponent;
                 if (ic == null)
                 {
                     IClassId icid = context.Instance as IClassId;
                     if (icid != null)
                     {
                         ic = icid.ObjectInstance as IComponent;
                     }
                 }
                 if (ic == null)
                 {
                     CollectionComponentNames cc = context.Instance as CollectionComponentNames;
                     if (cc != null)
                     {
                         ic       = cc.Owner;
                         bForName = true;
                     }
                 }
                 if (ic != null && ic.Site != null)
                 {
                     ComponentList list = new ComponentList(edSvc);
                     list.Items.Add(string.Empty);
                     foreach (IComponent c in ic.Site.Container.Components)
                     {
                         Type t = c.GetType();
                         if (scopeType != null && scopeType.IsAssignableFrom(t))
                         {
                             list.Items.Add(c);
                         }
                         else if (scopeTypeWeb != null && scopeTypeWeb.IsAssignableFrom(t))
                         {
                             list.Items.Add(c);
                         }
                     }
                     if (list.Items.Count > 0)
                     {
                         edSvc.DropDownControl(list);
                         if (list.SelectedObj != null)
                         {
                             if (typeof(string).Equals(list.SelectedObj.GetType()))
                             {
                                 value = null;
                             }
                             else
                             {
                                 if (bForName)
                                 {
                                     IComponent ic2 = list.SelectedObj as IComponent;
                                     if (ic2 != null && ic2.Site != null)
                                     {
                                         value = ic2.Site.Name;
                                     }
                                 }
                                 else
                                 {
                                     value = list.SelectedObj;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return(value);
 }