private string[] GetTagsFromCSVRecord(OneRecord rec)
 {
     string[] s = new string[10];
     s[0] = rec.Tag0;
     s[1] = rec.Tag1;
     s[2] = rec.Tag2;
     s[3] = rec.Tag3;
     s[4] = rec.Tag4;
     s[5] = rec.Tag5;
     s[6] = rec.Tag6;
     s[7] = rec.Tag7;
     s[8] = rec.Tag8;
     s[9] = rec.Tag9;
     return(s);
 }
        public void WriteEntityData(string sFileName)
        {
            LogInfo("Writing CRM metadata to file: " + sFileName);
            iEntityCount    = 0;
            iAttributeCount = 0;
            OneRecord rec = new OneRecord();
            var       csv = new CsvWriter((new System.IO.StreamWriter(sFileName, false, Encoding.UTF8))); //Create csv writer

            csv.Configuration.Delimiter = mySettings.CSVDelimiter;
            csv.Configuration.Quote     = mySettings.TextDelimiter[0];

            csv.WriteHeader <OneRecord>();
            csv.Flush();
            csv.NextRecord();
            foreach (string sKey in CRMEntitySet.entities.Keys)
            {
                LogInfo2("Writing entity row" + sKey);
                clOneEntity ent = CRMEntitySet.entities[sKey];
                //write entity row
                rec.RowType           = "Entity";
                rec.LanguageCode      = mySettings.LanguageCode;
                rec.EntityLogicalName = ent.logicalName;
                rec.EntitySchemaName  = ent.schemaName;
                rec.EntityDescription = ent.description;
                rec.CanBeUpdated      = ent.NotUpdateAble ? "No" : "Yes";
                rec.Tag0 = ent.Tags[0];
                rec.Tag1 = ent.Tags[1];
                rec.Tag2 = ent.Tags[2];
                rec.Tag3 = ent.Tags[3];
                rec.Tag4 = ent.Tags[4];
                rec.Tag5 = ent.Tags[5];
                rec.Tag6 = ent.Tags[6];
                rec.Tag7 = ent.Tags[7];
                rec.Tag8 = ent.Tags[8];
                rec.Tag9 = ent.Tags[9];

                csv.WriteRecord <OneRecord>(rec);
                csv.Flush();
                csv.NextRecord();
                iEntityCount++;
                rec.EntityDescription = ""; //To avoid people updating the wrong one, blank out entity descriptions for attributes
                foreach (string sKey2 in ent.attributes.Keys)
                {
                    LogInfo2("Writing attribute row" + sKey2);
                    rec.RowType = "Attribute";
                    clOneAttribute att = ent.attributes[sKey2];
                    rec.AttributeLogicalName = att.logicalName;
                    rec.AttributeSchemaName  = att.schemaName;
                    rec.AttributeType        = att.attributeTypeDescription;
                    rec.AttributeDescription = att.description;
                    rec.CanBeUpdated         = att.NotUpdateAble ? "No" : "Yes";
                    rec.Tag0 = att.Tags[0];
                    rec.Tag1 = att.Tags[1];
                    rec.Tag2 = att.Tags[2];
                    rec.Tag3 = att.Tags[3];
                    rec.Tag4 = att.Tags[4];
                    rec.Tag5 = att.Tags[5];
                    rec.Tag6 = att.Tags[6];
                    rec.Tag7 = att.Tags[7];
                    rec.Tag8 = att.Tags[8];
                    rec.Tag9 = att.Tags[9];
                    csv.WriteRecord <OneRecord>(rec);
                    csv.Flush();
                    csv.NextRecord();
                    iAttributeCount++;
                }
            }
            csv.Flush();
            csv.Dispose();
        }