Beispiel #1
0
 /// <summary>
 /// This method is used for notifying the user about the new version of the application
 /// </summary>
 /// <param name="notification">notification details</param>
 public void NotifyCustomer(EmailNotification notification)
 {
     if (notification != null)
     {
         var content = new JavaScriptSerializer().Serialize(notification);
         if (!string.IsNullOrEmpty(content))
         {
             try
             {
                 var jsonMessage = GetResponseJsonBody(GetCloudRequest("POST", "application/json", "/api/Software/notify", content));
             }
             catch (WebException webEx)
             {
                 GetJSONExceptionMessage(webEx);
             }
             catch (Exception ex)
             {
                 new ExceptionHandler(ex);
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Main method of the schedular
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Add new line to test Git
            try
            {
                Process   runningProcess = Process.GetCurrentProcess();
                Process[] pname          = Process.GetProcessesByName(runningProcess.ProcessName);
                if (pname.Length > 1)
                {
                    return;
                }

                //Getting the security group of active directory whose users needs to be synced with cloud
                string securityGroup = ConfigurationManager.AppSettings["SecurityGroup"];

                string domainPath = ConfigurationManager.AppSettings["LDAPPath"];

                if (string.IsNullOrEmpty(domainPath))
                {
                    new ExceptionHandler("LDAP path is not configured");
                    return;
                }
                DirectoryEntry searchRoot = null;
                searchRoot = new DirectoryEntry(domainPath);
                if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["ADServerName"]))
                {
                    searchRoot.Username = ConfigurationManager.AppSettings["ADServerUserName"];
                    searchRoot.Password = ConfigurationManager.AppSettings["ADServerPassword"];
                }
                //string domainName = (string)searchRoot.Properties["defaultNamingContext"].Value;
                DirectorySearcher search = new DirectorySearcher(searchRoot, "(&(objectCategory=group)(CN=cloudidsyncusers))");
                SearchResult      result = search.FindOne();
                if (result != null)
                {
                    List <SecurityGroupUser> users = new List <SecurityGroupUser>();
                    string adServerName            = ConfigurationManager.AppSettings["ADServerName"];
                    string domainName = GetDomain(domainPath);
                    foreach (var member in result.Properties["member"])
                    {
                        DirectoryEntry userDe = null;
                        if (!string.IsNullOrEmpty(adServerName))
                        {
                            userDe          = new DirectoryEntry(String.Concat("LDAP://", adServerName, "/", member.ToString()));
                            userDe.Username = ConfigurationManager.AppSettings["ADServerUserName"];
                            userDe.Password = ConfigurationManager.AppSettings["ADServerPassword"];
                        }
                        else
                        {
                            userDe = new DirectoryEntry(String.Concat("LDAP://", member.ToString()));
                        }
                        SecurityGroupUser adUser = new SecurityGroupUser();
                        if (userDe.Properties["objectClass"].Contains("user"))
                        {
                            string passwordHash = GetPasswordHash(member.ToString(), ConfigurationManager.AppSettings["ADServerUserName"], ConfigurationManager.AppSettings["ADServerPassword"], domainName, adServerName);
                            if (string.IsNullOrEmpty(passwordHash))
                            {
                                continue;
                            }
                            else
                            {
                                adUser.PasswordHash = passwordHash;
                            }
                            if ((userDe.Properties.Contains("objectSid")) && (userDe.Properties["objectSid"].Count > 0))
                            {
                                SecurityIdentifier siSid = new SecurityIdentifier((byte[])userDe.Properties["objectSid"][0], 0);
                                adUser.Sid = siSid.ToString();
                            }
                            if ((userDe.Properties.Contains("userPrincipalName")) && (userDe.Properties["userPrincipalName"].Count > 0))
                            {
                                adUser.Upn = Convert.ToString(userDe.Properties["userPrincipalName"][0]);
                            }
                            if ((userDe.Properties.Contains("whenChanged")) && (userDe.Properties["whenChanged"].Count > 0))
                            {
                                adUser.TimeStamp = Convert.ToDateTime(userDe.Properties["whenChanged"][0]);
                            }
                            if ((userDe.Properties.Contains("sAMAccountName")) && (userDe.Properties["sAMAccountName"].Count > 0))
                            {
                                adUser.SamAccountName = Convert.ToString(userDe.Properties["sAMAccountName"][0]);
                            }
                            if ((userDe.Properties.Contains("displayName")) && (userDe.Properties["displayName"].Count > 0))
                            {
                                adUser.DisplayName = Convert.ToString(userDe.Properties["displayName"][0]);
                            }
                            if ((userDe.Properties.Contains("sn")) && (userDe.Properties["sn"].Count > 0))
                            {
                                adUser.LastName = Convert.ToString(userDe.Properties["sn"][0]);
                            }
                            if ((userDe.Properties.Contains("givenName")) && (userDe.Properties["givenName"].Count > 0))
                            {
                                adUser.FirstName = Convert.ToString(userDe.Properties["givenName"][0]);
                            }
                            if ((userDe.Properties.Contains("description")) && (userDe.Properties["description"].Count > 0) &&
                                (string.IsNullOrEmpty(ConfigurationManager.AppSettings["description"]) ? true : Convert.ToBoolean(ConfigurationManager.AppSettings["description"])))
                            {
                                adUser.Description = Convert.ToString(userDe.Properties["description"][0]);
                            }
                            if ((userDe.Properties.Contains("l")) && (userDe.Properties["l"].Count > 0) &&
                                (string.IsNullOrEmpty(ConfigurationManager.AppSettings["l"]) ? true : Convert.ToBoolean(ConfigurationManager.AppSettings["l"])))
                            {
                                adUser.City = Convert.ToString(userDe.Properties["l"][0]);
                            }
                            if ((userDe.Properties.Contains("streetAddress")) && (userDe.Properties["streetAddress"].Count > 0) &&
                                (string.IsNullOrEmpty(ConfigurationManager.AppSettings["streetAddress"]) ? true : Convert.ToBoolean(ConfigurationManager.AppSettings["streetAddress"])))
                            {
                                adUser.Street = Convert.ToString(userDe.Properties["streetAddress"][0]);
                            }
                            if ((userDe.Properties.Contains("postalCode")) && (userDe.Properties["postalCode"].Count > 0) &&
                                (string.IsNullOrEmpty(ConfigurationManager.AppSettings["postalCode"]) ? true : Convert.ToBoolean(ConfigurationManager.AppSettings["postalCode"])))
                            {
                                adUser.ZipCode = Convert.ToString(userDe.Properties["postalCode"][0]);
                            }
                            if ((userDe.Properties.Contains("mail")) && (userDe.Properties["mail"].Count > 0) &&
                                (string.IsNullOrEmpty(ConfigurationManager.AppSettings["mail"]) ? true : Convert.ToBoolean(ConfigurationManager.AppSettings["mail"])))
                            {
                                char[]   specialChars = { ',', '/', ';', ':', '-' };
                                string[] arrEmails    = Convert.ToString(userDe.Properties["mail"][0]).Split(specialChars);
                                if (!Regex.IsMatch(arrEmails[0], @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                                                   @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$", RegexOptions.IgnoreCase))
                                {
                                    new ExceptionHandler(new Exception("Invalid Email ID"));
                                }
                                EmailDetail email = new EmailDetail();
                                email.Email           = arrEmails[0];
                                email.IsPrimary       = true;
                                adUser.EmailAddresses = new[] { email };
                            }
                            if ((userDe.Properties.Contains("telephoneNumber")) && (userDe.Properties["telephoneNumber"].Count > 0) &&
                                (string.IsNullOrEmpty(ConfigurationManager.AppSettings["telephoneNumber"]) ? true : Convert.ToBoolean(ConfigurationManager.AppSettings["telephoneNumber"])))
                            {
                                adUser.PhoneNumber = Convert.ToString(userDe.Properties["telephoneNumber"][0]);
                            }
                            if ((userDe.Properties.Contains("mobile")) && (userDe.Properties["mobile"].Count > 0) &&
                                (string.IsNullOrEmpty(ConfigurationManager.AppSettings["mobile"]) ? true : Convert.ToBoolean(ConfigurationManager.AppSettings["mobile"])))
                            {
                                adUser.MobileNumber = Convert.ToString(userDe.Properties["mobile"][0]);
                            }
                        }
                        users.Add(adUser);
                    }
                    result = null;
                    StoreDataLocally(users);
                }

                DateTime dt1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, 30, 0);
                DateTime dt2 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
                TimeSpan ts  = (dt2 - dt1);
                if (ts.TotalSeconds >= 0 && ts.TotalSeconds < 900)
                {
                    var releaseDetails = new CloudOperation().GetReleaseVersion();
                    if (releaseDetails != null && !string.IsNullOrEmpty(releaseDetails.LatestVersion))
                    {
                        string versionFromApi = releaseDetails.LatestVersion;
                        string appVersion     = ConfigurationManager.AppSettings["Version"];
                        if (versionFromApi.CompareTo(appVersion) > 0)
                        {
                            EmailNotification notification = new EmailNotification()
                            {
                                CustomerShortCode = ConfigurationManager.AppSettings["CustomerShortCode"],
                                NotificationEmail = ConfigurationManager.AppSettings["NotificationEmail"],
                                Release           = ConfigurationManager.AppSettings["Version"]
                            };
                            new CloudOperation().NotifyCustomer(notification);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                new ExceptionHandler(ex);
                return;
            }
        }