Ejemplo n.º 1
0
 public SSDsModelView()
 {
     InitializeComponent();
     ImpersonationHelper.Impersonate("CMSB", "mohit", "Password1", delegate
     {
         CompMgr  = new ClsComponentManager();
         CompColl = new ObservableCollection <ClsComponent>();
         LoadSSDsList();
     });
     DataContext = this;
 }
Ejemplo n.º 2
0
        public LaserficheRepository(IAppSettings appSetting)
        {
            var server                 = appSetting.GetString("lf.server");
            var repository             = appSetting.GetString("lf.repository");
            var user                   = appSetting.GetString("lf.user");
            var password               = appSetting.GetString("lf.password");
            var repositoryRegistration = new RepositoryRegistration(server, repository);

            _session = new Session();
            //_session.LogIn(user, password, repositoryRegistration);
            var impersonate = new ImpersonationHelper("ssf", user, password);

            impersonate.Impersonate(() => _session.LogIn(repositoryRegistration));
        }
Ejemplo n.º 3
0
        public bool CheckDuplicate(Ticket ticket)
        {
            string host                     = "";
            string path                     = "";
            string fullFileName             = "";
            string fileNameWithoutExtension = "";
            string extension                = "";
            string cmdRename                = "";
            string cmdCheck                 = "";
            // ticket.RootText e.g. of content  "File already exists: /opt/cloudhost/intbroker/integrations/archive/incoming/BI/FieldGlass-TimeSheet-20170309.csv already exists on the remote filesystem"
            int posPath = ticket.RootText.LastIndexOf("/");

            if (posPath >= 0)
            {
                path = ticket.RootText.Substring(0, posPath);
            }
            // path e.g. of content "File already exists: /opt/cloudhost/intbroker/integrations/archive/incoming/BI"
            path = path.Substring(path.IndexOf("/"), path.Length - path.IndexOf("/"));
            // path e.g. of content  "/opt/cloudhost/intbroker/integrations/archive/incoming/BI"
            int x = 0;

            //exit=true represents a rename applied and will check over the list of affected servers if multiple ( like a cluster )
            while (exit != true && x < ticket.HostArray.Length)
            {
                host         = ticket.HostArray[x];
                fullFileName = ticket.RootText.Substring(ticket.RootText.LastIndexOf("/"), ticket.RootText.Length - ticket.RootText.LastIndexOf("/"));
                fullFileName = fullFileName.Substring(0, fullFileName.IndexOf(" "));
                // fullFileName e.g. of content "/FieldGlass-TimeSheet-20170309.csv"

                //Saves extension of the file if it has to be used later while renaming
                int filePos = fullFileName.IndexOf(".");
                if (filePos >= 0)
                {
                    fileNameWithoutExtension = fullFileName.Substring(0, filePos);
                }
                // fileNameWithoutExtension e.g. of content "/FieldGlass-TimeSheet-20170309"
                if (filePos != -1)
                {
                    extension = fullFileName.Substring(filePos, fullFileName.Length - filePos);
                }
                // extension e.g. of content ".csv"

                //LINUX CONNECTION
                try
                {
                    SshConnection con    = new SshConnection(host, user, passwd);
                    SshClient     sshCon = con.connect();
                    if (path.EndsWith("/"))
                    {
                        path = path.Substring(0, path.Length - 1);
                    }

                    string OS = sshCon.RunCommand("uname").Result;
                    if (OS == "Linux\n")
                    {
                        //Run the commmand to check if file exists and rename if necessary
                        cmdCheck = "/opt/pb/bin/pbrun bash -c 'ls -l " + path + fullFileName + ";'";
                        var command = sshCon.RunCommand(cmdCheck);
                        if (command.ExitStatus == 0)
                        {
                            cmdRename = "/opt/pb/bin/pbrun bash -c 'cd " + path + ";" + "mv " + path + fullFileName + " " + path + fileNameWithoutExtension + "_$(date +%s)" + extension + ";'";
                            if (sshCon.RunCommand(cmdRename).ExitStatus == 0)
                            {
                                exit = true;
                                return(exit);
                            }
                        }
                    }
                    if (OS == "HP-UX\n")
                    {
                        //Run the commmand to check if file exists and rename if necessary
                        cmdCheck = "/opt/pb/bin/pbrun ksh -c 'ls -l " + path + fullFileName + ";'";
                        var command = sshCon.RunCommand(cmdCheck);
                        if (command.ExitStatus == 0)
                        {
                            cmdRename = "/opt/pb/bin/pbrun ksh -c 'cd " + path + ";" + "mv " + path + fullFileName + " " + path + fileNameWithoutExtension + "_$(date +%s)" + extension + ";'";
                            if (sshCon.RunCommand(cmdRename).ExitStatus == 0)
                            {
                                exit = true;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                }
                //WINDOWS CONNECTION
                try
                {
                    string DomainSvcAccount    = "";
                    string winUserSvcAccount   = "";
                    string winPasswdSvcAccount = "";
                    ImpersonationHelper.Impersonate(DomainSvcAccount, winUserSvcAccount, winPasswdSvcAccount, delegate
                    {
                        //Your code here
                        //If connection was done
                        if (File.Exists(@"\\\iten\hpsb.txt"))
                        {
                            string origin      = "\\" + host + path.Replace(@"/", @"\") + fileNameWithoutExtension.Replace(@"/", @"\");
                            string destination = "\\" + host + path.Replace(@"/", @"\") + fileNameWithoutExtension.Replace(@"/", @"\") + "1";
                            File.Move(@"\\hc4w00433\iten\hpsb.txt", @"\\hc4w00433\iten\hpsb.txt1");
                            exit = true;
                        }
                    });
                }
                catch (Exception e)
                {
                }

                x++;
            }
            //Exit contains a vaule True if ticket was SOLVED
            return(exit);
        }
 public static SafeAccessTokenHandle Impersonate([NotNull] this NetworkCredential thisValue, LogonType logonType)
 {
     return(ImpersonationHelper.Impersonate(thisValue, logonType));
 }