public static void Main(string[] args)
        {
            Parser.Default.ParseArguments <CommandLineOptions>(args)
            .WithParsed(o =>
            {
                var lcgHelper = new LCGHelper();
                lcgHelper.LoadSettingsFromFile(o.SettingsFilePath);

                if (o.ConnectionString != null)
                {
                    lcgHelper.ConnectCrm(o.ConnectionString);
                }
                else
                {
                    var credentials = new CrmCredentials
                    {
                        Domain     = o.Domain,
                        OrgUnit    = o.OrgUnit,
                        ServerName = o.ServerName,
                        Password   = o.Password,
                        Protocol   = o.Protocol,
                        User       = o.User
                    };

                    lcgHelper.ConnectCrm(credentials);
                }

                lcgHelper.GenerateConstants();
            });
        }
        public static CrmConnection ConnectCrm(CrmCredentials credentials)
        {
            var organizationServiceUri = $@"{credentials.Protocol}://{credentials.ServerName}/{credentials.OrgUnit}/XRMServices/2011/Organization.svc";
            var serverUri         = new Uri(organizationServiceUri);
            var clientCredentials = new ClientCredentials();

            clientCredentials.Windows.ClientCredential = new NetworkCredential(credentials.User, credentials.Password, credentials.Domain);
            var organizationServiceProxy = new OrganizationServiceProxy(serverUri, null, clientCredentials, null);

            organizationServiceProxy.EnableProxyTypes();
            return(new CrmConnection(organizationServiceProxy, organizationServiceUri));
        }
        public static void Main(string[] args)
        {
            try
            {
                Parser.Default.ParseArguments <CommandLineOptions>(args)
                .WithParsed(o =>
                {
                    Console.WriteLine($"********************** Authorized By Appsurfs {DateTime.Now.Year} Author: Ian Mok **********************");

                    var lcgHelper = new LCGHelper();
                    lcgHelper.LoadSettingsFromFile(o.SettingsFilePath);

                    if (o.ConnectionString != null)
                    {
                        lcgHelper.ConnectCrm(o.ConnectionString);
                    }
                    else
                    {
                        var credentials = new CrmCredentials
                        {
                            Domain     = o.Domain,
                            OrgUnit    = o.OrgUnit,
                            ServerName = o.ServerName,
                            Password   = o.Password,
                            Protocol   = o.Protocol,
                            User       = o.User
                        };

                        lcgHelper.ConnectCrm(credentials);
                    }

                    lcgHelper.GenerateConstants();
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public void ConnectCrm(CrmCredentials credentials)
 {
     this.crmConnection = CrmConnection.ConnectCrm(credentials);
 }