示例#1
0
        public static void Save(string path, IEnumerable <ConnectionEntry> list)
        {
            var computers   = new List <ComputerInfo>();
            var credentials = new List <CredentialsInfo>();
            var webServices = new List <WebServiceInfo>();

            var usedCredentials = new Dictionary <CredentialsInfo, int>();
            var usedWebServices = new Dictionary <WebServiceInfo, int>();

            foreach (var item in list)
            {
                var cred = new CredentialsInfo()
                {
                    userName = item.UserName
                };
                var ws = new WebServiceInfo()
                {
                    url = item.WebServiceURL
                };

                if (!usedCredentials.ContainsKey(cred))
                {
                    credentials.Add(cred);
                    usedCredentials.Add(cred, usedCredentials.Count);
                }

                if (!usedWebServices.ContainsKey(ws))
                {
                    webServices.Add(ws);
                    usedWebServices.Add(ws, usedWebServices.Count);
                }

                var comp = new ComputerInfo()
                {
                    displayName      = item.Description,
                    hostName         = item.HostName,
                    authentication   = item.UseCredSSP ? 4 : 0,
                    executionPolicy  = item.ExecutionPolicy,
                    group            = item.GroupName,
                    startupScript    = item.StartupScript,
                    showAvailability = item.ShowAvailability,
                    credentialsIndex = usedCredentials[cred],
                    webServiceIndex  = usedWebServices[ws]
                };

                computers.Add(comp);
            }

            var data = new WinRMXFileStruct()
            {
                version     = "1.9", // compatible version
                computers   = computers,
                credentials = credentials,
                webServices = webServices
            };

            var plist = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.SerializeObject(data));

            File.WriteAllBytes(path, Compress(Encoding.UTF8.GetBytes(Plist.writeXml(plist))));
        }
        public ActionResult <CredentialsInfo> Login(Credentials credentials)
        {
            User user = Program.MedialynxData.userDBAPI.GetByEmail(credentials.UserEmail);

            if (user == null)
            {
                return(NotFound("User " + credentials.UserEmail + " not found."));
            }

            Program.MedialynxData.historyDBAPI.Add(
                new HistoryItem(
                    user.Id,
                    user.Id,
                    this.GetType().ToString(),
                    "Try to login " + credentials.UserEmail
                    )
                );

            string passwordHash = Utils.GetHashString(credentials.Password);

            if (user.Password == passwordHash)   // OK!!!
            {
                CredentialsInfo credentialsInfo = this.GetCredentialsInfo(user);
                Program.MedialynxData.historyDBAPI.Add(
                    new HistoryItem(
                        user.Id,
                        credentialsInfo.Session.Id,
                        this.GetType().ToString(),
                        "Login Success " + credentials.UserEmail
                        )
                    );
                return(credentialsInfo);
            }
            return(null);
        }
        private CredentialsInfo GetCredentialsInfo(User user)
        {
            // login success. Session required.
            Session         existsSession   = Program.MedialynxData.sessionDBAPI.GetByUser(user.Id);
            CredentialsInfo credentialsInfo = new CredentialsInfo();

            if (existsSession != null)   // session exists
            {
                credentialsInfo.Session = existsSession;
            }
            else
            {
                Session newSession = new Session();
                newSession.Id           = Guid.NewGuid().ToString("B");;
                newSession.UserId       = user.Id;
                newSession.CreationDate = DateTime.UtcNow;
                newSession.LastUpdate   = newSession.CreationDate;
                Program.MedialynxData.sessionDBAPI.Add(newSession);
                credentialsInfo.Session = newSession;
            }
            credentialsInfo.User = user;
            return(credentialsInfo);
        }
 public void SetCredentialsInfo(CredentialsInfo credentialsInfo)
 {
     this.currentCredentialsInfo = credentialsInfo;
 }