Exemple #1
0
        private void watcher_EventArrived(object sender, EventArrivedEventArgs e)
        {
            string        eventType = e.NewEvent.ClassPath.ClassName;
            Win32_Process proc      = new
                                      Win32_Process(e.NewEvent["TargetInstance"] as ManagementBaseObject);

            switch (eventType)
            {
            case "__InstanceCreationEvent":
                if (ProcessCreated != null)
                {
                    ProcessCreated(proc);
                }
                break;

            case "__InstanceDeletionEvent":
                if (ProcessDeleted != null)
                {
                    ProcessDeleted(proc);
                }
                break;

            case "__InstanceModificationEvent":
                if (ProcessModified != null)
                {
                    ProcessModified(proc);
                }
                break;
            }
        }
Exemple #2
0
        public override bool Execute(out string message)
        {
            string batchFile    = string.Empty;
            string batchFileLog = string.Empty;
            bool   result       = false;

            message = string.Empty;
            try
            { string uniqueName = Guid.NewGuid().ToString();
              batchFile    = Path.Combine(GenericHelper.GetTempFolder(this.ServerName), uniqueName) + ".bat";
              batchFileLog = Path.Combine(GenericHelper.FormatPath(this.ServerName, this.BTDFProjFileDirectory), "DeployResults", "DeployResults.txt");
              string[] btdfProjfiles          = Directory.GetFiles(this.BTDFProjFileDirectory, "*.btdfproj", SearchOption.AllDirectories);
              string[] targetEnvironmentfiles = Directory.GetFiles(this.BTDFProjFileDirectory, this.TargetEnvironment == null ? string.Empty : "*" + this.TargetEnvironment + "*", SearchOption.AllDirectories);
              this.TargetEnvironment = targetEnvironmentfiles.Count() > 0 ? GenericHelper.FormatPath(this.ServerName, targetEnvironmentfiles[0]) : string.Empty;
              this.CreateAndSaveBatchFile(GenericHelper.FormatPath(this.ServerName, btdfProjfiles[0]), batchFile, batchFileLog);
              result = Win32_Process.Create(this.ServerName, batchFile, out message);
              if (File.Exists(batchFileLog))
              {
                  message = message + File.ReadAllText(batchFileLog);
              }
            }
            catch (Exception exe)
            {
                message = exe.Message + "-- FAILED";
            }
            finally
            {
                if (File.Exists(batchFile))
                {
                    File.Delete(batchFile);
                }
            }
            result = (message.Contains("-- FAILED") || message.Contains("Build FAILED.")) ? false : true;
            return(result);
        }
        void ProcWatcher_ProcessCreated(Win32_Process process)
        {
            Debug.WriteLine("process created");
            string name = process.Name;

            AttachToProcess(name);
        }
        public CoreDocument ToDocument(IItemSource itemSource, Win32_Process t)
        {
            var document = new CoreDocument(itemSource, this, ToId(t), ToName(t), ToType(t))
                           .Store("id", t.ProcessId.ToString())
                           .SetItemIdForLearning(ToName(t));

            return(document);
        }
Exemple #5
0
        string Converter(Win32_Process wp, string behavior)
        {
            string ret = string.Empty;

            ret += DateTime.Now.ToString() + "\t" + wp.Name;
            ret += "\t" + wp.ProcessId;
            ret += "\t" + behavior;
            ret += "\t" + wp.ExecutablePath;
            return(ret);
        }
Exemple #6
0
 void pWatcher_ProcessDeleted(Win32_Process proc)
 {
     Dispatcher.Invoke(
         new Action(
             delegate()
     {
         listBox1.Items.Add(Converter(proc, "ProcessDeleted"));
     }
             ), null);
 }
Exemple #7
0
 void pWatcher_ProcessCreated(Win32_Process proc)
 {
     Dispatcher.Invoke(
         new Action(
             delegate()
     {
         listBox1.Items.Add(Converter(proc, "ProcessCreated"));
     }
             ), null);
     //throw new NotImplementedException();
 }
Exemple #8
0
        public override bool Execute(out string message)
        {
            string tempMsiPath = string.Empty;
            string batchFile = string.Empty;
            string batchFileLog = string.Empty;
            bool result = false;
            string exceptionMessage = string.Empty;
            message = string.Empty;
            try
            {
                //tempMsiPath = GenericHelper.FormatPath(this.resourceInfo.ServerName, this.resourceInfo.ResourceName);
                string uniqueName = Guid.NewGuid().ToString();
                batchFile = Path.Combine(GenericHelper.GetTempFolder(this.ServerName), uniqueName) + ".bat";
                batchFileLog = Path.ChangeExtension(batchFile, "txt");
                string[] files = Directory.GetFiles(this.BTDFProjFileDirectory, "*.btdfproj", SearchOption.AllDirectories);

                string[] files1 = Directory.GetFiles(this.BTDFProjFileDirectory, this.TargetEnvironment == null ? string.Empty : "*" + this.TargetEnvironment + "*", SearchOption.AllDirectories);

                this.TargetEnvironment = files1.Count() > 0 ? GenericHelper.FormatPath(this.ServerName, files1[0]) : string.Empty;

                this.CreateAndSaveBatchFile(GenericHelper.FormatPath(this.ServerName, files[0]), batchFile, batchFileLog);
                result = Win32_Process.Create(this.ServerName, batchFile, out message);
                if (File.Exists(batchFileLog))
                {
                    message = message + File.ReadAllText(batchFileLog);
                }
            }
            catch (Exception exe)
            {
                exceptionMessage = exe.Message + "-- FAILED";
            }
            finally
            {
                if (File.Exists(tempMsiPath))
                {
                    File.Delete(tempMsiPath);
                }
                if (File.Exists(batchFile))
                {
                    //File.Delete(batchFile);
                }
                if (File.Exists(batchFileLog))
                {
                    // File.Delete(batchFileLog);
                }
            }
            message = result ? message : exceptionMessage;
            result = (message.Contains("-- FAILED") || message.Contains("Build FAILED.")) ? false : true;
            return result;
        }
Exemple #9
0
        private void ProcessDeleted(Win32_Process proc)
        {
            Log.Debug("Process {0} ({1}) deleted", proc.Name, proc.ProcessId);
            Process process;
            var     storage = _sourceStorageFactory.SourceStorageFor(_source.Id);

            if (_cachedProcesses.TryRemove(proc.ProcessId, out process))
            {
                storage.RemoveItems(_source, process);
            }
            else
            {
                storage.RemoveItems(_source, proc);
            }
        }
Exemple #10
0
        public override bool Execute(out string message)
        {
            string tempAssemblyPath = string.Empty;
            string batchFile        = string.Empty;
            string batchFileLog     = string.Empty;
            bool   result           = false;
            string exceptionMessage = string.Empty;

            message = string.Empty;
            try
            {
                tempAssemblyPath = GenericHelper.CopyToTempFolder(this.resourceInfo.ServerName, this.resourceInfo.ResourceName);
                string uniqueName = Guid.NewGuid().ToString();
                batchFile    = Path.Combine(GenericHelper.GetTempFolder(this.resourceInfo.ServerName), uniqueName) + ".bat";
                batchFileLog = Path.ChangeExtension(batchFile, "txt");
                CreateAndSaveBatchFile(gacUtilLoc.Encode(), tempAssemblyPath, batchFile, batchFileLog);
                result = Win32_Process.Create(this.resourceInfo.ServerName, batchFile, out message);
                if (File.Exists(batchFileLog))
                {
                    message = message + File.ReadAllText(batchFileLog);
                }
            }
            catch (Exception exe)
            {
                exceptionMessage = exe.Message;
            }
            finally
            {
                if (File.Exists(tempAssemblyPath))
                {
                    File.Delete(tempAssemblyPath);
                }
                if (File.Exists(batchFile))
                {
                    File.Delete(batchFile);
                }
                if (File.Exists(batchFileLog))
                {
                    File.Delete(batchFileLog);
                }
            }
            message = result ? message : exceptionMessage;
            return(result);
        }
Exemple #11
0
        public override bool Execute(out string message)
        {
            string tempMsiPath  = string.Empty;
            string batchFile    = string.Empty;
            string batchFileLog = string.Empty;
            bool   result       = false;

            message = string.Empty;
            try
            {
                tempMsiPath = GenericHelper.CopyToTempFolder(this.resourceInfo.ServerName, this.resourceInfo.ResourceName);
                string uniqueName = Guid.NewGuid().ToString();
                batchFile    = Path.Combine(GenericHelper.GetTempFolder(this.resourceInfo.ServerName), uniqueName) + ".bat";
                batchFileLog = Path.ChangeExtension(batchFile, "txt");
                CreateAndSaveBatchFile(tempMsiPath, batchFile, batchFileLog);
                result = Win32_Process.Create(this.resourceInfo.ServerName, batchFile, out message);
                if (File.Exists(batchFileLog))
                {
                    message = message + File.ReadAllText(batchFileLog);
                }
                ExtractSettings(GenericHelper.FormatPath(this.resourceInfo.ServerName, this.TargetDir));
            }
            catch (Exception exe)
            {
                message = exe.Message;
            }
            finally
            {
                if (File.Exists(tempMsiPath))
                {
                    File.Delete(tempMsiPath);
                }
                if (File.Exists(batchFile))
                {
                    File.Delete(batchFile);
                }
                if (File.Exists(batchFileLog))
                {
                    File.Delete(batchFileLog);
                }
            }
            result = (message.Contains("Installation completed successfully") || message.Contains("Configuration completed successfully")) ? true : false;
            return(result);
        }
Exemple #12
0
        public override bool Execute(out string message)
        {
            string batchFile    = string.Empty;
            string batchFileLog = string.Empty;
            bool   result       = false;

            message = string.Empty;
            try
            {
                string uniqueName = Guid.NewGuid().ToString();
                batchFile    = Path.Combine(GenericHelper.GetTempFolder(this.ServerName), uniqueName) + ".bat";
                batchFileLog = Path.ChangeExtension(batchFile, "txt");
                this.CreateAndSaveBatchFile(this.UninstallString, batchFile, batchFileLog);
                result = Win32_Process.Create(this.ServerName, batchFile, out message);
                if (File.Exists(batchFileLog))
                {
                    message = message + File.ReadAllText(batchFileLog);
                }
            }
            catch (Exception exe)
            {
                message = exe.Message;
            }
            finally
            {
                if (File.Exists(batchFile))
                {
                    File.Delete(batchFile);
                }
                if (File.Exists(batchFileLog))
                {
                    File.Delete(batchFileLog);
                }
            }
            result = message.Contains("Removal completed successfully") ? true : false;
            return(result);
        }
Exemple #13
0
        private void ProcessCreated(Win32_Process proc)
        {
            var processId = proc.ProcessId;

            ReIndexProcess((int)processId);
        }
 public string ToType(Win32_Process t)
 {
     return("process");
 }
 public string ToName(Win32_Process t)
 {
     return(t.Name);
 }
 void ProcWatcher_ProcessDeleted(Win32_Process process)
 {
     Debug.WriteLine("process deleted");
 }
 public string ToId(Win32_Process t)
 {
     return(t.ProcessId.ToString());
 }
Exemple #18
0
 private void ProcessModified(Win32_Process proc)
 {
     ProcessCreated(proc);
 }