예제 #1
0
        /// <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);
        }
예제 #2
0
 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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
 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);
 }
예제 #7
0
 /// <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);
 }
예제 #8
0
 public bool ExportFile(string file, ICoreObject parentObject)
 {
     return((bool)TiaStarter.RunInSynchronizer(UsingSynchronizer,
                                               (Func <bool>)(() =>
     {
         return (bool)Reflector.RunInstanceMethodByName(
             TagsTableViewLogic,
             "ExportFile",
             ReflectionWays.SystemReflection,
             file,
             parentObject);
     })));
 }
예제 #9
0
        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);
            }));
        }
예제 #10
0
 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));
 }
예제 #11
0
 public CommandReturnCodes PrepareExport(ICoreObject parentObject, string sourceFile)
 {
     return((CommandReturnCodes)TiaStarter.RunInSynchronizer(UsingSynchronizer,
                                                             (Func <CommandReturnCodes>)(() =>
     {
         return (CommandReturnCodes)Reflector.RunInstanceMethodByName(
             TagsTableViewLogic,
             "PrepareExport",
             ReflectionWays.SystemReflection,
             parentObject,
             sourceFile);
     })));
 }
예제 #12
0
        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);
        }
예제 #13
0
 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);
     });
 }
예제 #14
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);
     }
 }
예제 #15
0
        /// <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);
        }
예제 #16
0
 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);
        }
예제 #18
0
        /// <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);
        }
예제 #19
0
        /// <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);
        }
예제 #20
0
        /// <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>);
        }
예제 #21
0
        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);
        }
예제 #22
0
        /// <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);
        }
예제 #23
0
        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);
        }