RedisRipper.Workbench.WorkbenchFile.CreateWB2File C# (CSharp) Method

CreateWB2File() public method

public CreateWB2File ( ) : string
return string
        public string CreateWB2File()
        {
            StringBuilder sb = new StringBuilder();

            List<CompanionFileType> fileorder = new List<CompanionFileType>()
            {
                CompanionFileType.FGRP, CompanionFileType.MGRP, CompanionFileType.DVIC, CompanionFileType.XMTR,
                CompanionFileType.RCVR, CompanionFileType.ICMD, CompanionFileType.PRND, CompanionFileType.EVNT,
                CompanionFileType.RESP, CompanionFileType.JOBF, CompanionFileType.TEXT, CompanionFileType.DIRC,
                CompanionFileType.TELV, CompanionFileType.ZONE, CompanionFileType.FEMA, CompanionFileType.DIAL,
                CompanionFileType.INPU, CompanionFileType.SCHD, CompanionFileType.TELL, CompanionFileType.ZNAM,
                CompanionFileType.TRAN, CompanionFileType.RNAM, CompanionFileType.JOBX, CompanionFileType.WORK,
                CompanionFileType.NOTE, CompanionFileType.RDAT, CompanionFileType.CWAP, CompanionFileType.IPSH,
                CompanionFileType.IUSR, CompanionFileType.PAGR, CompanionFileType.REMS, CompanionFileType.LTXT
            };

            foreach (CompanionFileType fileType in fileorder)
            {
                sb.AppendLine("// " + fileType.ToString().ToLower() + ".txt");

                // force update znam.shortname ==> zone.name
                switch (fileType)
                {
                    case CompanionFileType.EVNT:
                        break;

                    case CompanionFileType.ZONE:
                        for (int i = 0; i < Files[CompanionFileType.ZNAM].Count; i++)
                        {
                            var zone = Files[CompanionFileType.ZONE][i] as ZONE;
                            var znam = Files[CompanionFileType.ZNAM][i] as ZNAM;

                            if (znam != null && zone != null)
                                zone.Name = znam.ShortName;
                        }
                        break;
                }

                List<CompanionFile> list = Files[fileType];
                bool useAltFormat = (fileType == CompanionFileType.LTXT);
                int iiii = 0;
                foreach (CompanionFile cf in list)
                {
                    if (iiii == 7935)
                    {
                    }
                    iiii++;

                    if (cf != null)
                        sb.Append(cf.FormatFile(useAltFormat));

                    useAltFormat = false; // ltxt 1st record is b64. the rest are s64.
                }
            }

            return sb.ToString();
        }

Usage Example

示例#1
0
        private static void BackupFiles()
        {
            // Use "localhost" when debugging.
            //const string redisUri = "localhost";

            const string redisUri = "cache.silversphere.com";

            var clientManager = new PooledRedisClientManager(1000, 3, redisUri)
            {
                ConnectTimeout = 300,
                IdleTimeOutSecs = 30,
                PoolTimeout = 500
            };

            try
            {
                using (IRedisClient redis = clientManager.GetClient())
                {
                    List<string> data = redis.SearchKeys("Configuration:Workbench:Master:*");

                    if (data.Any())
                    {
                        foreach (string file in data)
                        {
                            // split the string to get the correct property id.
                            char[] delimiter = {':'};
                            string[] elements = file.Split(delimiter);
                            string propertyID = elements[3];

                            try
                            {
                                Console.WriteLine("Getting: " + propertyID);
                                var wbKey = String.Format("Configuration:Workbench:Master:{0}",propertyID);
                                var wbRaw = redis.Get<String>(wbKey);
                                var workbench = new WorkbenchFile(wbRaw);
                                SendOneToS3(elements[3], workbench.CreateWB2File());

                            }
                            catch (Exception e)
                            {
                                MissedProperties.Add(propertyID);
                                LogWriter.LogWrite(" Could not find workbench file for property: " + propertyID);
                            }
                        }
                    }
                }

                try
                {
                    Classes.SiteMailer.BackupError(MissedProperties);

                }
                catch(Exception e)
                {
                    LogWriter.LogWrite(" Could not mail missed properties.");
                }
            }
            catch (Exception e)
            {
                try
                {
                    Classes.SiteMailer.GeneralError(
                        "Could not get configuration!" +
                        Environment.NewLine +
                        "Exception: " +
                        e.ToString() +
                        Environment.NewLine +
                        "Inner Exception:" +
                        e.InnerException.ToString()
                        );
                }
                catch (Exception exc)
                {
                    LogWriter.LogWrite(" Could not mail invalid configuration.");
                }

                string now = DateTime.Now.ToString(CultureInfo.InvariantCulture);
                LogWriter.LogWrite(" Could not get configuration.");
            }
        }