示例#1
0
        public CAD2BOM(Innovator getInnovator)
        {
            //System.Diagnostics.Debugger.Break();

            innovator = getInnovator;
            conn      = innovator.getConnection();
            CbwGeneric.bwIOMInnovator = innovator;
            CoCommon = new CGeneric.Common();

            //Modify by kenny 2016/04/01 ------
            string LanCode = innovator.getI18NSessionContext().GetLanguageCode();

            if (LanCode == null)
            {
                LanCode = "";
            }
            LangCode = LanCode;
            LanCode  = LanCode.ToLower();

            if ((LanCode.IndexOf("zt") > -1) || (LanCode.IndexOf("tw") > -1))
            {
                LanCode = "zh-tw";
            }
            else if ((LanCode.IndexOf("zc") > -1) || (LanCode.IndexOf("cn") > -1))
            {
                LanCode = "zh-cn";
            }
            else if ((LanCode.IndexOf("kr") > -1) || (LanCode.IndexOf("ko") > -1))
            {
                LanCode = "ko-kr";
            }
            else
            {
                LanCode = "en";
            }
            CoCommon.SetLanguage   = LanCode;
            CbwGeneric.SetLanguage = LanCode;
            //----------------------------------
        }
示例#2
0
        public string CallAction(string action, string input, IProgressCallback progressReporter)
        {
            XmlNode     fault;
            XmlDocument outputDoc = null;
            var         inputDoc  = new XmlDocument();

            inputDoc.LoadXml(input);
            if (_userInfo == null)
            {
                _userInfo = _inn.applyAML(string.Format("<AML><Item type='User' action='get' select='default_vault' expand='1'><id>{0}</id><Relationships><Item type='ReadPriority' action='get' select='priority, related_id' expand='1' orderBy='priority'/></Relationships></Item></AML>", _inn.getUserID()));
            }

            if (action == "ApplyItem" || action == "ApplyAML")
            {
                var     fileNodes = XPathCache.SelectNodes("descendant-or-self::Item[@type='File' and (@action='add' or @action='update' or @action='create') and actual_filename]", inputDoc.DocumentElement);
                XmlNode locatedNode;
                if (fileNodes.Count > 0)
                {
                    Item fileItem = _inn.newItem();
                    foreach (var fileNode in fileNodes.OfType <XmlElement>())
                    {
                        if (string.IsNullOrEmpty(fileNode.Attribute("id")))
                        {
                            fileNode.Attr("id", _inn.getNewID());
                        }
                        fileNode.Elem("checkedout_path", Path.GetDirectoryName(fileNode.Element("actual_filename", "")));
                        fileNode.Elem("filename", Path.GetFileName(fileNode.Element("actual_filename", "")));
                        locatedNode = XPathCache.SelectSingleNode("Relationships/Item[@type='Located']/related_id", fileNode);
                        if (locatedNode == null)
                        {
                            fileItem.dom      = inputDoc;
                            fileItem.node     = (XmlElement)fileNode;
                            fileItem.nodeList = null;
                            fileItem.attachPhysicalFile(fileNode.Element("actual_filename", ""), _userInfo.getProperty("default_vault"));
                        }
                    }

                    var firstItem = XPathCache.SelectSingleNode("//Item[1]", inputDoc.DocumentElement);
                    IList <XmlElement> items;
                    if (firstItem.ParentNode == null)
                    {
                        items = new XmlElement[] { (XmlElement)firstItem };
                    }
                    else
                    {
                        items = firstItem.Parent().Elements("Item").ToList();
                    }

                    Item       result;
                    XmlElement resultNode = null;

                    for (var i = 0; i < items.Count; i++)
                    {
                        fileItem.dom      = items[i].OwnerDocument;
                        fileItem.node     = items[i];
                        fileItem.nodeList = null;
                        result            = fileItem.apply();
                        fault             = XPathCache.SelectSingleNode(faultXPath, result.dom.DocumentElement);
                        if (fault != null)
                        {
                            fault.AppendChild(result.dom.CreateElement("original_query")).InnerText = input;
                            return(result.dom.DocumentElement.OuterXml);
                        }
                        else if (result.isError())
                        {
                            throw new InvalidOperationException();
                        }

                        if (outputDoc == null)
                        {
                            outputDoc  = result.dom;
                            resultNode = XPathCache.SelectSingleNode("//Item[1]", outputDoc.DocumentElement).Parent() as XmlElement;
                        }
                        else
                        {
                            resultNode.AppendChild(outputDoc.ImportNode(result.node, true));
                        }

                        if (progressReporter != null)
                        {
                            progressReporter.ReportProgress(i + 1, items.Count);
                        }
                    }

                    return(outputDoc.OuterXml);
                }
            }

            outputDoc = new XmlDocument();
            outputDoc.Elem("Empty");
            _inn.getConnection().CallAction(action, inputDoc, outputDoc);
            fault = XPathCache.SelectSingleNode(faultXPath, outputDoc.DocumentElement);
            if (fault != null)
            {
                fault.AppendChild(outputDoc.CreateElement("original_query")).InnerText = input;
            }
            return(outputDoc.DocumentElement.OuterXml);
        }
 public IServerConnection GetConnection()
 {
     return(Innovator.getConnection());
 }