Exemplo n.º 1
0
        public string Export()
        {
            try
            {
                var buffer = new StringBuilder();

                if (_propertytMappings == null)
                {
                    _propertytMappings = new Dictionary <string, string>();
                }

                buffer.Append("{\r\n");
                buffer.Append(String.Format("\t\"DebugPrint\": \"{0}\",\r\n", DebugPrint.ToString()));
                buffer.Append(String.Format("\t\"ProxyGroup\": \"{0}\",\r\n", ProxyGroup));
                buffer.Append(String.Format("\t\"LDAPURI\": \"{0}\",\r\n", LdapURI));
                buffer.Append(String.Format("\t\"RootOU\": \"{0}\",\r\n", RootOU));
                buffer.Append(String.Format("\t\"IdProperty\": \"{0}\",\r\n", IdProperty));
                buffer.Append(String.Format("\t\"EmailProperty\": \"{0}\",\r\n", EmailProperty));
                buffer.Append(String.Format("\t\"ModifiedProperty\": \"{0}\",\r\n", ModifiedProperty));

                buffer.Append("\t\"Properties\":\r\n\t[\r\n");

                var count = PropertyMappings.Count;
                var i     = 0;

                foreach (var mapping in PropertyMappings)
                {
                    buffer.Append(String.Format("\t\t{{\r\n\t\t\t\"Name\": \"{0}\",\r\n\t\t\t\"Source\": \"{1}\",\r\n\t\t\t\"Destination\": \"{2}\"\r\n\t\t}}", mapping.Name, mapping.Source, mapping.Destination));

                    if (++i < count)
                    {
                        buffer.Append(",");
                    }

                    buffer.Append("\r\n");
                }

                buffer.Append("\t],\r\n");

                //sync targets
                buffer.Append("\t\"SyncTargets\":\r\n\t[\r\n");

                count = SyncTargets.Count;
                i     = 0;

                foreach (var target in SyncTargets)
                {
                    buffer.Append(String.Format("\t\t{{\r\n\t\t\t\"Name\": \"{0}\",\r\n\t\t\t\"OU\": \"{1}\"\r\n\t\t}}", target.Name, target.TargetOU));

                    if (++i < count)
                    {
                        buffer.Append(",");
                    }

                    buffer.Append("\r\n");
                }

                buffer.Append("\t],\r\n");

                //sync records

                buffer.Append("\t\"SyncRecords\":\r\n\t[\r\n");

                count = SyncRecords.Count;
                i     = 0;

                foreach (var mapping in SyncRecords)
                {
                    buffer.Append(String.Format("\t\t{{\r\n\t\t\t\"OU\": \"{0}\",\r\n\t\t\t\"LastSync\": \"{1}\"\r\n\t\t}}", mapping.OUName, mapping.SyncTime));

                    if (++i < count)
                    {
                        buffer.Append(",");
                    }

                    buffer.Append("\r\n");
                }

                buffer.Append("\t]\r\n");

                buffer.Append("}");

                return(buffer.ToString());
            }
            catch (Exception ex)
            {
                Logger.WriteLog(Logger.Category.Error, Logger.DiagnosticAreaName, ex.ToString());
                throw;
            }
        }