private static TransformPlug ReadMap(string fileName, Stream mapFile)
        {
            TransformPlug transformPlug = null;

            if (TraceOn)
            {
                Console.WriteLine("Reading map from {0}", fileName);
            }

            transformPlug = (TransformPlug)TransformPlugFactory.CreateTransformPlugFromBTM(mapFile);
            return(transformPlug);
        }
        public static ITransformPlug GenerateTransformPlugFromExcel(ExcelWorksheet current)
        {
            ITransformPlug plug     = new TransformPlug(null, null, null);
            int            rowCount = current.Dimension.End.Row - current.Dimension.Start.Row + 1;

            string previousGroupName = string.Empty;
            string currentGroupName  = string.Empty;

            for (int row = 2; row < rowCount; row++)
            {
                if (current.Cells[row, TargetFieldIndex].Value == null)
                {
                    continue;
                }

                //currentGroupName = current.Cells[row, GroupNameIndex].Value.ToString();
                currentGroupName = string.Empty;
                //if (currentGroupName.Equals(previousGroupName))
                //  continue;
                ITransformGroup group = new TransformGroup(currentGroupName);
                plug.Facets.Add(group);
                CreateTransformLinks(current, ref row, ref group);
                previousGroupName = currentGroupName;
            }
            return(plug);

            /*
             * foreach (ITransformGroup group in plug.Facets)
             * {
             *  foreach (ITransformLink link in group.Links)
             *      f.WriteLine(link.Source.Name+"\t"+link.Target.Name);
             * }
             *
             * f.Close();
             */
        }
Example #3
0
        public MapDetail(string currentFileName, string folderName, TransformPlug transformPlug, string specCertType)
        {
            this.FileName   = currentFileName;
            this.FolderName = folderName;
            this.Map        = transformPlug;

            if (folderName.StartsWith("GCommerce", StringComparison.OrdinalIgnoreCase) || folderName.StartsWith("Maps", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            Console.WriteLine("Extracting metadata from {0}", folderName);

            // Try to get documentType, direction and domainName from folder
            // If documentType is not part of folder name then use map.SourceLocation or TargetLocation
            // based on direction and decide documentType
            string tmpString = folderName;
            int    idx;

            idx = tmpString.LastIndexOf('.');
            string documentTypeStr = tmpString.Substring(idx + 1);

            documentType = -1;
            if (int.TryParse(documentTypeStr, out documentType))
            {
                tmpString = tmpString.Substring(0, idx);
            }
            else
            {
                documentType = -1;
            }

            idx       = tmpString.LastIndexOf('.');
            direction = tmpString.Substring(idx + 1);
            if (string.Equals(direction, "outbound", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(direction, "oubound", StringComparison.OrdinalIgnoreCase))
            {
                direction = "SEND";
            }
            else if (string.Equals(direction, "inbound", StringComparison.OrdinalIgnoreCase))
            {
                direction = "RECEIVE";
            }
            else
            {
                throw new InvalidOperationException("Invalid direction" + direction);
            }
            tmpString = tmpString.Substring(0, idx);
            tmpString = tmpString.Replace(".complex", "");

            domainName = tmpString;
            orgName    = OrganizationMetadata.GetOrganizationName(domainName);
            if (string.IsNullOrWhiteSpace(orgName))
            {
                throw new InvalidOperationException(string.Format("Cannot find organization name for domain {0}", domainName));
            }

            if (documentType == -1 && !string.IsNullOrEmpty(Map.SourceLocation) && !string.IsNullOrEmpty(Map.TargetLocation))
            {
                string location = null;
                if (direction == "SEND")
                {
                    location = Map.TargetLocation;
                }
                else
                {
                    location = Map.SourceLocation;
                }

                location = location.ToLower();

                if (location.Contains(".t810"))
                {
                    documentType = 810;
                }
                else
                if (location.Contains(".t850"))
                {
                    documentType = 850;
                }
                else if (location.Contains(".t856"))
                {
                    documentType = 856;
                }
                else
                if (specCertType == "xml")
                {
                    if (location.Contains("invoice"))
                    {
                        documentType = 810;
                    }
                    else if (location.Contains("purchaseorder"))
                    {
                        documentType = 850;
                    }
                    else if (location.Contains("shipment"))
                    {
                        documentType = 856;
                    }
                }
                else if (specCertType == "flatfile")
                {
                    documentTypeStr = location.Substring(location.Length - 3);
                    if (int.TryParse(documentTypeStr, out documentType) == false)
                    {
                        documentType = -1;
                    }

                    if (documentType == -1)
                    {
                        // try to get document type from file name
                        string tmpStr = Path.GetFileNameWithoutExtension(FileName);
                        documentTypeStr = tmpStr.Substring(tmpStr.Length - 3);
                        if (int.TryParse(documentTypeStr, out documentType) == false)
                        {
                            documentType = -1;
                        }
                    }
                }
            }
        }
        public static List <MapDetail> ReadMap(Stream zipFile, string zipFileName, string specCertType)
        {
            string           currentFileName = string.Empty;
            List <MapDetail> mapDetailList   = new List <MapDetail>();

            //try
            //{
            string extractToFolderName = Path.GetTempPath();

            List <string> filePathList = new List <string>();

            using (ZipArchive zipArchive = new ZipArchive(zipFile, ZipArchiveMode.Read))
            {
                foreach (ZipArchiveEntry archiveEntry in zipArchive.Entries)
                {
                    if (string.IsNullOrWhiteSpace(archiveEntry.Name))
                    {
                        continue;
                    }

                    currentFileName = archiveEntry.Name;
                    string folderName = Path.GetDirectoryName(archiveEntry.FullName);
                    if (folderName.LastIndexOf('\\') != -1)
                    {
                        folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
                    }

                    if (string.Equals(folderName, "deployment", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }
                    if (string.Equals(folderName, "development", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }
                    if (string.Equals(folderName, "bin", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }
                    if (string.Equals(folderName, "debug", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    if (!string.Equals(Path.GetExtension(currentFileName), ".btm", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    if (!(currentFileName.StartsWith("inbound", StringComparison.OrdinalIgnoreCase) ||
                          currentFileName.StartsWith("outbound", StringComparison.OrdinalIgnoreCase) ||
                          currentFileName.StartsWith("oubound", StringComparison.OrdinalIgnoreCase) ||
                          currentFileName.StartsWith("xml", StringComparison.OrdinalIgnoreCase)))
                    {
                        continue;
                    }

                    Console.WriteLine("Reading {0}", currentFileName);
                    string extractToPath = Path.Combine(extractToFolderName, archiveEntry.Name);
                    if (File.Exists(extractToPath) == true)
                    {
                        File.Delete(extractToPath);
                    }

                    archiveEntry.ExtractToFile(extractToPath, true);

                    using (StreamReader sr = new StreamReader(extractToPath))
                    {
                        TransformPlug transformPlug = ReadMap(extractToPath, sr.BaseStream);

                        if (specCertType == "flatfile" || specCertType == "xml")
                        {
                            bool notSupportedBtmFile = false;

                            if (currentFileName.StartsWith("inbound", StringComparison.OrdinalIgnoreCase))
                            {
                                if (transformPlug.SourceLocation.StartsWith("GCommerce") == true ||
                                    transformPlug.TargetLocation.StartsWith("GCommerce") == false)
                                {
                                    notSupportedBtmFile = true;
                                }
                            }
                            else
                            if (currentFileName.StartsWith("outbound", StringComparison.OrdinalIgnoreCase))
                            {
                                if (transformPlug.SourceLocation.StartsWith("GCommerce") == false ||
                                    transformPlug.TargetLocation.StartsWith("GCommerce") == true)
                                {
                                    notSupportedBtmFile = true;
                                }
                            }

                            if (notSupportedBtmFile == true)
                            {
                                transformPlug = null;
                            }
                        }

                        if (transformPlug != null)
                        {
                            mapDetailList.Add(new MapDetail(currentFileName, folderName, transformPlug, specCertType));
                        }
                    }

                    File.Delete(extractToPath);
                }
            }
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(string.Format("Error occured during reading map file. Error: {0}", e.Message));
            //}

            return(mapDetailList);
        }