Beispiel #1
0
        private static void Logout()
        {
            try
            {
                SDKEnvironment.Logout(new Uri(ServerName));
            }
            catch (Exception ex)
            {
                Program.Log.Error(null, ex);
            }

            try
            {
                if (scs != null)
                {
                    scs.Abort();
                    scs.Dispose();
                    scs = null;
                }

                SDKEnvironment.RemoveAllServers();
            }
            catch (Exception ex)
            {
                Program.Log.Error(null, ex);
            }
        }
Beispiel #2
0
        private static bool Login(Uri uri, bool masterOnly = false)
        {
            try
            {
                SDKEnvironment.Login(uri);
                return(true);
            }
            catch (Exception exception)
            {
                if (exception.Message.Length != 0)
                {
                    Program.Logger.Log.Error(exception.Message);
                }

                SDKEnvironment.RemoveServer(uri);
            }

            try
            {
                SDKEnvironment.Login(uri, true);
                return(true);
            }
            catch (Exception exception)
            {
                if (exception.Message.Length != 0)
                {
                    Program.Logger.Log.Error(exception.Message);
                }

                SDKEnvironment.RemoveServer(uri);
            }

            return(false);
        }
 public void Connect(Uri uri)
 {
     _uri = uri;
     try
     {
         Environment.AddServer(uri, CredentialCache.DefaultNetworkCredentials);
         Environment.Login(uri);
         _configService = new XProtectConfigurationService(uri);
     }
     catch (ServerNotFoundMIPException)
     {
         LastError = $"Login to {_uri} failed. Server not found.";
     }
     catch (InvalidCredentialsMIPException ex)
     {
         LastError = $"Login to {_uri} failed. {ex.Message}";
     }
     catch (LoginFailedInternalMIPException ex)
     {
         LastError = $"Login to {_uri} failed. {ex.Message}";
     }
     catch (Exception e)
     {
         LastError = e.ToString();
     }
 }
        private void LocalStartService()
        {
            Program.Logger.Log.Info("Start the service");

            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
            var appprincipal = Thread.CurrentPrincipal as WindowsPrincipal;

            Program.Logger.Log.Info($"Is in administrators: {appprincipal.IsInRole("Administrators")}");
            Program.Logger.Log.Info($"Windows identity: {WindowsIdentity.GetCurrent().Name}"); //Windows identity: NT AUTHORITY\SYSTEM

            LogSystemInfo();
            WriteExecutingAssemblyVersion();

#if !DEBUG
            using (var impersonation = new Impersonation(BuiltinUser.NetworkService))
            {
#endif
            try
            {
                SDKEnvironment.Initialize();    // General initialize. Always required
                SDKEnvironment.RemoveAllServers();
                TryConnectingToMilestoneServer();
            }
            catch (Exception ex)
            {
                Program.Logger.Log.Error(null, ex);
                Program.Logger.Log.Info($"Windows identity: {WindowsIdentity.GetCurrent().Name}");     //Windows identity: NT AUTHORITY\NETWORK SERVICE
            }
#if !DEBUG
        }
#endif
        }
 public void Dispose()
 {
     try
     {
         if (State.HasFlag(XProtectState.LoggedIn))
         {
             Environment.Logout(_uri);
         }
     }
     catch (Exception e)
     {
         LastError = e.Message;
     }
 }
Beispiel #6
0
        private static bool Login(Uri uri, bool masterOnly = false)
        {
            if (EnvironmentManager.Instance.MasterSite.ServerId.ServerType == VideoOS.Platform.ServerId.EnterpriseServerType)
            {
                Console.WriteLine("Bookmark is not supported on this product.");
                Console.ReadKey();
                return(true);
            }

            try
            {
                SDKEnvironment.Login(uri);
                return(true);
            }
            catch (Exception exception)
            {
                if (exception.Message.Length != 0)
                {
                    Program.Log.Info($"{Environment.NewLine}URI: {uri}{Environment.NewLine}Source: {exception.Source}{Environment.NewLine}Message: {exception.Message}{Environment.NewLine}Exception: {exception.ToString()}");
                    if (exception.InnerException != null)
                    {
                        Program.Log.Info($"{Environment.NewLine}Inner Exception:{Environment.NewLine}Message: {exception.InnerException.Message}{Environment.NewLine}Source: {exception.InnerException.Source}{Environment.NewLine}");
                    }
                }

                SDKEnvironment.RemoveServer(uri);
            }

            try
            {
                SDKEnvironment.Login(uri, true);
                return(true);
            }
            catch (Exception exception)
            {
                if (exception.Message.Length != 0)
                {
                    Program.Log.Info($"{Environment.NewLine}URI (true): {uri}{Environment.NewLine}Source: {exception.Source}{Environment.NewLine}Message: {exception.Message}{Environment.NewLine}Exception: {exception.ToString()}");
                    if (exception.InnerException != null)
                    {
                        Program.Log.Info($"{Environment.NewLine}Inner Exception:{Environment.NewLine}Message: {exception.InnerException.Message}{Environment.NewLine}Source: {exception.InnerException.Source}{Environment.NewLine}");
                    }
                }

                SDKEnvironment.RemoveServer(uri);
            }

            return(false);
        }
Beispiel #7
0
        private static void PrepareToLogin(string serverName, string userName, string password)
        {
            ServerName        = serverName;
            milestoneUserName = userName;
            milestonePassword = password;

            if (string.IsNullOrEmpty(ServerName))
            {
                string msg = "Server address cannot be emnpty";
                Program.Log.Warn(msg);
                Console.WriteLine(msg);
                return;
            }

            Uri               uri    = null;
            CredentialCache   cc     = null;
            NetworkCredential nc     = null;
            bool              logged = false;

            if (!string.IsNullOrEmpty(milestoneUserName))
            {
                // You need this to apply Enterprise "basic" credentials.
                uri = new UriBuilder(ServerName).Uri;
                cc  = Util.BuildCredentialCache(uri, milestoneUserName, milestonePassword, "Negotiate");//"Basic" : "Negotiate"
                SDKEnvironment.AddServer(uri, cc);
                // use the same credentiel as when logge on to the Management Server
                logged = Login(uri);
            }

            if (!logged)
            {
                try
                {
                    uri = new UriBuilder(ServerName).Uri;
                }
                catch (Exception ex)
                {
                    Program.Log.Error(ServerName, ex);
                    Program.Log.Error(ServerName, ex.InnerException);
                    return;
                }

                // This will reuse the Windows credentials you are logged in with
                nc = CredentialCache.DefaultNetworkCredentials;
                SDKEnvironment.AddServer(uri, nc);

                //Pick up the login settings from the management server to be used when logging into the Recording Server.
                loginSettings = LoginSettingsCache.GetLoginSettings(ServerName);

                logged = Login(uri);
            }

            if (!logged)
            {
                uri = new Uri($"http://{Configuration.Instance.ServerFQID.ServerId.ServerHostname}:{Configuration.Instance.ServerFQID.ServerId.Serverport}/");
                SDKEnvironment.AddServer(uri, nc);
                logged = Login(uri);
            }

            if (!logged && loginSettings != null)
            {
                SDKEnvironment.AddServer(uri, nc);
                logged = Login(loginSettings.Uri);
            }

            if (!logged)
            {
                Program.Log.Error("Doesn't logged in.");
                return;
            }

            try
            {
                if (!SDKEnvironment.IsServerConnected(uri))
                {
                    string msg = $"Failed to connect to {uri}";
                    Program.Log.Warn(msg);
                    return;
                }

                scs          = new ServerCommandService();
                scs.Timeout *= 3;                                       // The default is 100,000 milliseconds.

                // use the same credentiel as when logge on to the Management Server
                if (cc != null)
                {
                    scs.Credentials = cc;
                }
                else if (nc != null)
                {
                    scs.Credentials = nc;
                }

                connectedToMilestone = true;
                List <Item> items = Configuration.Instance.GetItems();
                EnumerateElementChildren(items, AllCameras);
                ProductCode = EnvironmentManager.Instance.SystemLicense.ProductCode;
                ServerId    = Configuration.Instance.ServerFQID.ServerId.Id;
            }
            catch (Exception ex)
            {
                Program.Log.Error($"Internal error connecting to: {uri.DnsSafeHost}", ex);
            }

            if (loginSettings != null)
            {
                Token = loginSettings.Token;
            }

            if (connectedToMilestone)
            {
                try
                {
                    string           path             = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    MilestoneVersion milestoneVersion = new MilestoneVersion();
                    milestoneVersion.Connection = connectedToMilestone;

                    File.WriteAllText($"{path}\\Milestone.json", JsonHelper.FromClass(milestoneVersion));
                }
                catch (Exception ex)
                {
                    Program.Log.Error(null, ex);
                }
                scs.Url = $"{ServerName}ServerAPI/ServerCommandService.asmx";
                string msg = $"Connected to Milestone server: {ServerName}";

                MilestoneInfo();

                Console.WriteLine(msg);
                Program.Log.Info(msg);
            }
            else
            {
                Console.WriteLine($"Failed to connect to {ServerName}");
            }
        }
 public XProtectHelper()
 {
     Environment.Initialize();
 }