/// <summary> /// 取得或创建变量表 /// </summary> /// <param name="cpu">控制器</param> /// <param name="Path">变量表路径</param> public static ICoreObject GetOrCreateTagTable( this ICoreObject cpu, string Path, ISynchronizeInvoke synchronizer = null) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = cpu.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, (Func <ICoreObject>) (() => { ICoreObject tagFolder = cpu.GetTagsFolder(); ICoreObject table = GetTagTableByName(tagFolder, Path); if (table == null) { table = CreateTagTable(tagFolder, Path); } return table; })) as ICoreObject); }
public XLSXImporterProxy( ICoreObject cpu, ISynchronizeInvoke synchronizer = null) { if (synchronizer == null) { Synchronizer = cpu.GetSynchronizer(); } else { Synchronizer = synchronizer; } TiaStarter.RunInSynchronizer(Synchronizer, () => { XLSXImporter = new XLSXImporter(cpu.GetTagService(), MassDataHandler.CreateWorkbook(null), cpu.GetDefaultTagTable(Synchronizer), XLSXImportExportOptions.IncludeTags | XLSXImportExportOptions.IncludeConstants, cpu.GetFolderService(), cpu.GetCommandProcessor(), null, null, cpu.GetNameService(), cpu.GetRangeCheck()); }); }
public static BlockEditorLogicBase GetPLBlockEditorLogic(this ICoreObject block, IWorkingContext ViewWorkingContext = null, LanguageServiceContainer serviceContainer = null, ISynchronizeInvoke synchronizer = null) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = block.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, () => { PLBlockEditorLogic pl = new PLBlockEditorLogic(); IWorkingContext iwc = block.GetWorkingContext(); pl.Attach(iwc); pl.PostAttach(); EditorPayload ep = new EditorPayload(block, ViewWorkingContext, serviceContainer); pl.SetPayload(ep); OnlineManagerBase OnlineManager = pl.OnlineManager; return pl; }) as BlockEditorLogicBase); }
public static BlockEditorControlBase GetGraphView(this ICoreObject block, IWorkingContext ViewWorkingContext = null, ISynchronizeInvoke synchronizer = null) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = block.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, () => { GraphBlockEditorControl pl = new GraphBlockEditorControl(); IWorkingContext iwc = block.GetWorkingContext(); pl.Attach(iwc); BlockEditorLogicBase logic = block.GetGraphBlockEditorLogic(); pl.SetDomainLogic(logic); pl.SetPayload(block); pl.InitializationFinished(); pl.CreateVisuals(); return pl; }) as BlockEditorControlBase); }
/// <summary> /// 按地址查找变量 /// </summary> /// <param name="cpu">控制器</param> /// <param name="address">地址</param> public static IBLTag FindRootTagByAddress(this ICoreObject cpu, string address, ISynchronizeInvoke synchronizer = null) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = cpu.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, (p_cpu, p_address, p_synchronizer) => { ITagService tagService = p_cpu.GetTagService(); RootTagCollectionProxy rtcp = p_cpu.FindRootTags(p_synchronizer); List <IBLTag> tags = rtcp.Tags; foreach (IBLTag tag in tags) { if (tag.LogicalAddress == p_address) { return tag; } } return null; }, cpu, address, UsingSynchronizer) as IBLTag); }
public ICoreObject ResolveTagTableFromProperties(IDictionary <string, string> properties) { return(TiaStarter.RunInSynchronizer(Synchronizer, (p_properties) => { return Reflector.RunInstanceMethodByName(XLSXImporter, "ResolveTagTableFromProperties", ReflectionWays.SystemReflection, p_properties) as ICoreObject; }, properties) as ICoreObject); }
/// <summary> /// 取得或创建变量表 /// </summary> public ICoreObject GetOrCreateTagTable(string tagTablePath) { return(TiaStarter.RunInSynchronizer(Synchronizer, (p_tagTablePath) => { ICoreObject tagTable = Reflector.RunInstanceMethodByName(XLSXImporter, "GetOrCreateTagTable", ReflectionWays.SystemReflection, p_tagTablePath) as ICoreObject; return tagTable; }, tagTablePath) as ICoreObject); }
public bool ExportFile(string file, ICoreObject parentObject) { return((bool)TiaStarter.RunInSynchronizer(UsingSynchronizer, (Func <bool>)(() => { return (bool)Reflector.RunInstanceMethodByName( TagsTableViewLogic, "ExportFile", ReflectionWays.SystemReflection, file, parentObject); }))); }
public bool ImportXML(ICoreObject controller, string path) { XmlReader xmlReader = XmlReader.Create(path); return(TiaStarter.RunInSynchronizer(UsingSynchronizer, () => { return (bool)Reflector.RunInstanceMethodByName(FM, "ImportXML", ReflectionWays.SystemReflection, controller, xmlReader); })); }
public bool UpdateTag(IBLTag tag, Dictionary <string, string> properties, bool isConstant, int rowNumber) { return((bool)TiaStarter.RunInSynchronizer(Synchronizer, (p_tag, p_properties, p_isConstant) => { return Reflector.RunInstanceMethodByName(XLSXImporter, "UpdateTag", ReflectionWays.SystemReflection, p_tag, p_properties, p_isConstant); }, tag, properties, isConstant)); }
public CommandReturnCodes PrepareExport(ICoreObject parentObject, string sourceFile) { return((CommandReturnCodes)TiaStarter.RunInSynchronizer(UsingSynchronizer, (Func <CommandReturnCodes>)(() => { return (CommandReturnCodes)Reflector.RunInstanceMethodByName( TagsTableViewLogic, "PrepareExport", ReflectionWays.SystemReflection, parentObject, sourceFile); }))); }
public static IBLTag UpdateOrCreateTag( this ICoreObject cpu, string Name, string Path, string DataType, string address, string Comment, bool isConstant = false, ISynchronizeInvoke synchronizer = null) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = cpu.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, (Func <ICoreObject, string, string, string, string, string, bool, IBLTag>) ((p_cpu, p_Name, p_Path, p_DataType, p_address, p_Comment, p_isConstant) => { string[] values = new string[] { p_Name, p_Path, p_DataType, p_address, p_Comment, "True", "True" }; Dictionary <string, string> properties = CreateTagProperties(values); IBLTag findTag = FindRootTagByName(p_cpu, p_Name, UsingSynchronizer); ICoreObject tagTable = GetOrCreateTagTable(p_cpu, p_Path, UsingSynchronizer); IBLTag newTag = null; if (findTag == null) { newTag = CreateRootTagInTagTable(p_cpu, tagTable, properties, isConstant); } else { newTag = UpdateTag(tagTable, findTag, properties, isConstant, UsingSynchronizer); } return newTag; }), cpu, Name, Path, DataType, address, Comment, isConstant) as IBLTag); }
public void AddUpdateTagOrConstant2TagTable( string[] propertyValues, string[] propertyNames, int typeIndex, bool isConstant ) { TiaStarter.RunInSynchronizer(Synchronizer, () => { Reflector.RunInstanceMethodByName(XLSXImporter, "AddUpdateTagOrConstant2TagTable", ReflectionWays.SystemReflection, propertyValues, propertyNames, typeIndex, isConstant, 0); }); }
public ICoreObject this[int index] { get { return(TiaStarter.RunInSynchronizer(UsingSynchronizer, () => { if (index <= ICOC.Count - 1) { return ICOC[index] as ICoreObject; } else { return null; } }) as ICoreObject); } }
/// <summary> /// 创建变量 /// </summary> /// <param name="cpu">控制器</param> /// <param name="tagTable">变量表</param> /// <param name="properties">变量数据</param> /// <param name="isConstant">是否静态变量</param> public static IBLTag CreateRootTagInTagTable( this ICoreObject cpu, ICoreObject tagTable, Dictionary <string, string> properties, bool isConstant = false, ISynchronizeInvoke synchronizer = null ) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = cpu.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, () => { IObjectTypeInfo iot = null; if (isConstant) { iot = tagTable.GetConstantType(); } else { iot = tagTable.GetTagType(); } ITagService tagService = cpu.GetTagService(); using (new ObjectFrameBulkOperationMode(tagTable)) { return tagService.CreateRootTag( cpu, iot, Enumerable.ToDictionary(properties, kvp => kvp.Key, (Func <KeyValuePair <string, string>, object>)(kvp => kvp.Value))) as IBLTag; } }) as IBLTag); }
public bool ImportFile(ITagService TagService, string file, ICoreObject parentObject) { return((bool)TiaStarter.RunInSynchronizer(UsingSynchronizer, (Func <bool>)(() => { TagService.SuspendCollectionEvents(); using (OnDispose.Invoke(() => TagService.ResumeCollectionEvents())) { using (new ObjectFrameBulkOperationMode(parentObject)) { return (bool)Reflector.RunInstanceMethodByName( TagsTableViewLogic, "ImportFile", ReflectionWays.SystemReflection, file, parentObject); } } }))); }
public static BlockEditorLogicBase GetGraphBlockEditorLogic(this ICoreObject block, IWorkingContext ViewWorkingContext = null, LanguageServiceContainer serviceContainer = null, ISynchronizeInvoke synchronizer = null) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = block.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, () => { GraphBlockEditorLogic pl = new GraphBlockEditorLogic(); if (ViewWorkingContext == null) { IWorkingContext iwc = block.GetWorkingContext(); pl.Attach(iwc); } else { pl.Attach(ViewWorkingContext); } pl.PostAttach(); try { pl.SetPayload(block); } catch (Exception ex) { Console.WriteLine(ex); } return pl; }) as BlockEditorLogicBase); }
/// <summary> /// 取得变量表文件夹 /// </summary> /// <param name="cpu">控制器</param> public static ICoreObject GetTagsFolder(this ICoreObject cpu, ISynchronizeInvoke synchronizer = null) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = cpu.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, (c) => { IFolderService folderService = cpu.GetFolderService(); IObjectTypeInfo tagTableType = GetTagTableType(cpu); return folderService.GetAppropriateFolder(cpu, tagTableType, false); }, cpu) as ICoreObject); }
/// <summary> /// 按名称查找变量 /// </summary> /// <param name="cpu">控制器</param> /// <param name="tagName">变量名称</param> public static IBLTag FindRootTagByName( this ICoreObject cpu, string tagName, ISynchronizeInvoke synchronizer = null) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = cpu.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, (p_cpu, p_tagName) => { ITagService tagService = cpu.GetTagService(); return tagService.FindRootTagByName(p_tagName, p_cpu, "InverseTarget", true); }, cpu, tagName) as IBLTag); }
/// <summary> /// 取得指定文件夹下所有变量表 /// </summary> public static IDictionary <string, ICoreObject> GetTagTables(this ICoreObject tagsFolder, ISynchronizeInvoke synchronizer = null) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = tagsFolder.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, (folder) => { return Reflector.RunStaticMethodByName( XLSXImporterType, "GetTagTables", ReflectionWays.SystemReflection, tagsFolder) as IDictionary <string, ICoreObject>; }, tagsFolder) as IDictionary <string, ICoreObject>); }
public static ICoreObject GetTagTableByName(this ICoreObject tagsFolder, string Name, ISynchronizeInvoke synchronizer = null) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = tagsFolder.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, (p_tagsFolder, p_Name) => { IDictionary <string, ICoreObject> tables = GetTagTables(tagsFolder, UsingSynchronizer); ICoreObject table; tables.TryGetValue(p_Name, out table); return table; }, tagsFolder, Name) as ICoreObject); }
/// <summary> /// 取得控制器所有变量 /// </summary> public static RootTagCollectionProxy FindRootTags(this ICoreObject cpu, ISynchronizeInvoke synchronizer = null) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = cpu.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, (p_cpu) => { ITagService tagService = cpu.GetTagService(); IList list = tagService.FindRootTags(p_cpu, cpu.GetTagType(), "InverseTarget", true); RootTagCollectionProxy rtcp = new RootTagCollectionProxy(list, UsingSynchronizer); return rtcp; }, cpu) as RootTagCollectionProxy); }
public static BlockEditorControlBase GetPLView(this ICoreObject block, BlockEditorLogicBase logic, IWorkingContext ViewWorkingContext = null, LanguageServiceContainer serviceContainer = null, ISynchronizeInvoke synchronizer = null) { ISynchronizeInvoke UsingSynchronizer; if (synchronizer == null) { UsingSynchronizer = block.GetSynchronizer(); } else { UsingSynchronizer = synchronizer; } return(TiaStarter.RunInSynchronizer(UsingSynchronizer, () => { PLBlockEditorControlElement pl = new PLBlockEditorControlElement(); if (ViewWorkingContext == null) { IWorkingContext iwc = block.GetWorkingContext(); pl.Attach(iwc); } else { pl.Attach(ViewWorkingContext); } EditorPayload ep = new EditorPayload(block, ViewWorkingContext, serviceContainer); pl.SetPayload(ep); pl.SetDomainLogic(logic); logic.SetView(pl); logic.InitializationFinished(); return pl; }) as BlockEditorControlBase); }