Ejemplo n.º 1
0
        public ChoPingServer(IPAddress ipAddress, int timeout = Int32.MinValue, int delay = Int32.MinValue, PingOptions options = null)
        {
            ChoGuard.ArgumentNotNullOrEmpty(ipAddress, "IPAddress");

            if (timeout != Int32.MinValue && timeout <= 0)
            {
                throw new ArgumentException("Timeout should be >= 0");
            }

            if (delay != Int32.MinValue && delay <= 0)
            {
                throw new ArgumentException("Delay should be >= 0");
            }

            if (timeout != Int32.MinValue)
            {
                _timeout = timeout;
            }
            if (delay != Int32.MinValue)
            {
                _delay = delay;
            }
            if (options != null)
            {
                _options = options;
            }
            _buffer     = Encoding.ASCII.GetBytes("Ping_{0}".FormatString(ChoRandom.NextRandom()));
            _pingServer = new Ping();
            _pingServer.PingCompleted += new PingCompletedEventHandler(PingServerPingCompleted);
            _ipAddress = ipAddress;
        }
Ejemplo n.º 2
0
        public void ExecuteAction(params object[] args)
        {
            if (_targetAction == null)
            {
                string className    = "ChoClass_{0}".FormatString(ChoRandom.NextRandom(0, Int32.MaxValue));
                string codeFragment = String.Join(" ", _statements);
                string statement    = null;
                switch (_language)
                {
                case ChoCodeProviderLanguage.VB:
                    statement = String.Format("Public Class {1} {0} Public Sub Execute(ByVal args() As Object) {0} {2} {0} End Sub {0} End Class", Environment.NewLine, className, codeFragment);
                    break;

                default:
                {
                    if (!codeFragment.IsNullOrWhiteSpace())
                    {
                        codeFragment = codeFragment.Replace("@this", "args[0]");
                    }
                    statement = String.Format("public class {0} {{ public void Execute(object[] args) {{ {1}; }} }}", className, codeFragment);
                    break;
                }
                }
                _targetAction = Activator.CreateInstance(CreateType(className, codeFragment, statement));
            }
            _targetAction.Execute(args);
        }
Ejemplo n.º 3
0
        public ChoPingAppServer(IPAddress ipAddress, int portNo, int timeout = Int32.MinValue, int delay = Int32.MinValue)
        {
            ChoGuard.ArgumentNotNullOrEmpty(ipAddress, "IPAddress");

            if (timeout != Int32.MinValue && timeout <= 0)
            {
                throw new ArgumentException("Timeout should be >= 0");
            }

            if (delay != Int32.MinValue && delay <= 0)
            {
                throw new ArgumentException("Delay should be >= 0");
            }

            if (portNo <= 0)
            {
                throw new ArgumentException("Invalid {0} port number passed.".FormatString(portNo));
            }
            _port = portNo;
            if (timeout != Int32.MinValue)
            {
                _timeout = timeout;
            }
            if (delay != Int32.MinValue)
            {
                _delay = delay;
            }

            _ipAddress = ipAddress;
            _buffer    = Encoding.ASCII.GetBytes("Ping_{0}".FormatString(ChoRandom.NextRandom()));
            _result    = _pingServer.BeginConnect(_ipAddress, _port, TcpAsyncCallback, null);
        }
Ejemplo n.º 4
0
        private static string _Translate(string token, string format)
        {
            if (String.IsNullOrEmpty(token))
            {
                return(token);
            }

            switch (token)
            {
            case ApplicationName:
                return(ChoObject.Format(ChoAppSettings.Me.ApplicationId, format));

            case MachineName:
                return(ChoObject.Format(Environment.MachineName, format));

            case ProcessId:
                return(ChoObject.Format(ChoSystemInfo.ProcessId, format));

            case ThreadId:
                return(ChoObject.Format(ChoSystemInfo.GetThreadId(), format));

            case ThreadName:
                return(ChoObject.Format(ChoSystemInfo.GetThreadName(), format));

            case RandomNo:
                return(ChoObject.Format(ChoRandom.NextRandom().ToString(), format));

            case DateTime:
                return(ChoObject.Format(System.DateTime.Now, format));

            case Date:
                if (String.IsNullOrEmpty(format))
                {
                    return(System.DateTime.Today.ToShortDateString());
                }
                else
                {
                    return(ChoObject.Format(System.DateTime.Today, format));
                }

            case Time:
                if (String.IsNullOrEmpty(format))
                {
                    return(System.DateTime.Now.ToShortTimeString());
                }
                else
                {
                    return(ChoObject.Format(System.DateTime.Now, format));
                }

            default:
                return(ChoObject.Format(token, format));
            }
        }
Ejemplo n.º 5
0
        public string Replace(string propertyName, string format)
        {
            if (String.IsNullOrEmpty(propertyName))
            {
                return(propertyName);
            }

            switch (propertyName)
            {
            case ApplicationName:
                return(ChoObject.Format(ChoAppSettings.Me.ApplicationId, format));

            case MachineName:
                return(ChoObject.Format(Environment.MachineName, format));

            case ProcessId:
                return(ChoObject.Format(ChoApplicationInfo.ProcessId, format));

            case ThreadId:
                return(ChoObject.Format(ChoApplicationInfo.GetThreadId(), format));

            case ThreadName:
                return(ChoObject.Format(ChoApplicationInfo.GetThreadName(), format));

            case RandomNo:
                return(ChoObject.Format(ChoRandom.NextRandom().ToString(), format));

            case DateTime:
                return(ChoObject.Format(System.DateTime.Now, format));

            case Date:
                if (String.IsNullOrEmpty(format))
                {
                    return(System.DateTime.Today.ToShortDateString());
                }
                else
                {
                    return(ChoObject.Format(System.DateTime.Today, format));
                }

            case Time:
                if (String.IsNullOrEmpty(format))
                {
                    return(System.DateTime.Now.ToShortTimeString());
                }
                else
                {
                    return(ChoObject.Format(System.DateTime.Now, format));
                }

            default:
                return(ChoObject.Format(propertyName, format));
            }
        }
Ejemplo n.º 6
0
 public ChoIdleTask(string name)
 {
     _idleThread              = new Thread(() => _waitHandle.WaitOne());
     _idleThread.Name         = name.IsNullOrWhiteSpace() ? "ChoIdleTask_{0}".FormatString(ChoRandom.NextRandom()) : name;
     _idleThread.IsBackground = false;
 }
Ejemplo n.º 7
0
 internal ChoPropertyHandlerReplacer(ChoPropertyReplaceHandler propertyReplaceHandler)
 {
     Name     = String.Format("PropertyHandlerReplacer_{0}", ChoRandom.NextRandom().ToString());
     Priority = 0;
     _propertyReplaceHandler = propertyReplaceHandler;
 }
Ejemplo n.º 8
0
        internal ChoBaseProfile(bool condition, string name, string msg, IChoProfile outerProfile, bool delayedStartProfile, string startActions, string stopActions)
        {
            _condition = condition;
            _name      = name.IsNullOrWhiteSpace() || name == ChoProfile.DEFAULT_PROFILE_NAME ? String.Format("Profile_{0}".FormatString(ChoRandom.NextRandom())) : name;
            if (outerProfile != ChoProfile.NULL)
            {
                _outerProfile = outerProfile;
            }
            if (_outerProfile == null)
            {
                _profileBackingStore = ChoProfileBackingStoreManager.GetProfileBackingStore(name, startActions, stopActions);
            }
            _delayedStartProfile = delayedStartProfile;
            if (_condition)
            {
                if (!msg.IsNullOrEmpty())
                {
                    _msg = msg;
                }
                else if (!_name.IsNullOrEmpty())
                {
                    _msg = String.Format(_msg, _name);
                }
                else
                {
                    _msg = ChoProfile.GetDefaultMsg(ChoStackTrace.GetStackFrame(GetType().Namespace));
                }
            }

            if (ChoTraceSettings.Me.IndentProfiling)
            {
                if (outerProfile != null)
                {
                    if (outerProfile.ProfilerName != ChoProfile.GLOBAL_PROFILE_NAME && outerProfile.ProfilerName != ChoProfile.NULL_PROFILE_NAME)
                    {
                        _indent = outerProfile.Indent + 1;
                    }
                }
            }
            if (!_delayedStartProfile)
            {
                StartIfNotStarted();
            }

            if (_outerProfile is ChoProfileContainer)
            {
                ((ChoProfileContainer)_outerProfile).Add(this);
                _parentProfile = outerProfile;
            }

            if (name != ChoProfile.GLOBAL_PROFILE_NAME && name != ChoProfile.NULL_PROFILE_NAME && name != ChoProfile.CURRENT_CONTEXT_PROFILE /* && outerProfile != null */)
            {
                ChoProfile.Register(this);
                _registered = true;
            }
        }
 internal ChoPropertyDictionaryReplacer(IDictionary <string, object> properties)
 {
     Name        = String.Format("PropertyDictionaryReplacer_{0}", ChoRandom.NextRandom().ToString());
     Priority    = 0;
     _properties = properties;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Constructor with Initialize data
        /// </summary>
        /// <param name="initializeData">Semi colon seperated Initialize information</param>
        public ChoTextWriterTraceListener(string name, string initializeData)
        {
            _name = !name.IsNullOrWhiteSpace() ? name : "{0}_{1}".FormatString(GetType().Name, ChoRandom.NextRandom());
            string [] initDatas = initializeData.Split(';');

            foreach (string initData in initDatas)
            {
                string [] nameValues = initData.Split('=');
                if (nameValues.Length == 2)
                {
                    switch (nameValues.GetValue(0).ToString().ToUpper().Trim())
                    {
                    case "CYCLIC":
                        try
                        {
                            _cyclic = Convert.ToBoolean(nameValues.GetValue(1).ToString().Trim());
                        }
                        catch
                        {
                        }
                        break;

                    case "DIRECTORYNAME":
                        _directoryName = nameValues.GetValue(1).ToString().Trim();
                        break;

                    case "BASEFILENAME":
                        _baseFileName = nameValues.GetValue(1).ToString().Trim();
                        break;

                    case "MAXFILECOUNT":
                        try
                        {
                            _maxFileCount = Convert.ToInt32(nameValues.GetValue(1));
                        }
                        catch
                        {
                        }
                        break;

                    case "FILEEXT":
                        FileExt = nameValues.GetValue(1).ToString().Trim();
                        break;

                    case "MAXFILESIZE":
                        try
                        {
                            _maxFileSize = ChoStorageScale.Parse(nameValues.GetValue(1).ToString().Trim());
                        }
                        catch
                        {
                        }
                        break;

                    case "INCLUDE":
                        _includeList = nameValues.GetValue(1).ToString().Trim().Split(',');
                        break;

                    case "EXCLUDE":
                        _excludeList = nameValues.GetValue(1).ToString().Trim().Split(',');
                        break;

                    case "AUTOBACKUP":
                        try
                        {
                            _autoBackup = Convert.ToBoolean(nameValues.GetValue(1).ToString().Trim());
                        }
                        catch
                        {
                        }
                        break;

                    case "ALLOWSPLITMSG":
                        try
                        {
                            _allowSplitMsg = Convert.ToBoolean(nameValues.GetValue(1).ToString().Trim());
                        }
                        catch
                        {
                        }
                        break;

                    case "TIMESTAMP":
                        try
                        {
                            _timeStamp = Convert.ToBoolean(nameValues.GetValue(1).ToString().Trim());
                        }
                        catch
                        {
                        }
                        break;

                    case "PROCESSINFO":
                        try
                        {
                            _processInfo = Convert.ToBoolean(nameValues.GetValue(1).ToString().Trim());
                        }
                        catch
                        {
                        }
                        break;

                    case "CALLERINFO":
                        try
                        {
                            _callerInfo = Convert.ToBoolean(nameValues.GetValue(1).ToString().Trim());
                        }
                        catch
                        {
                        }
                        break;

                    case "SEPERATOR":
                        _seperator = nameValues.GetValue(1).ToString().Trim();
                        break;
                    }
                }
            }

            Init();
        }
Ejemplo n.º 11
0
 internal ChoCustomPropertyHandlerReplacer(ChoCustomPropertyReplaceHandler customPropertyReplaceHandler)
 {
     Name     = String.Format("CustomPropertyHandlerReplacer_{0}", ChoRandom.NextRandom().ToString());
     Priority = 0;
     _customPropertyReplaceHandler = customPropertyReplaceHandler;
 }
Ejemplo n.º 12
0
 public ChoCustomPropertyReplacer(ChoCustomPropertyReplaceHandler customPropertyReplaceHandler)
     : this(String.Format("CustomPropertyReplacer_{0}", ChoRandom.NextRandom().ToString()), customPropertyReplaceHandler)
 {
 }
Ejemplo n.º 13
0
        internal ChoWinRemoteExecState(string remoteMachine, NetworkCredential networkCredential)
        {
            _remoteMachine     = remoteMachine;
            _networkCredential = networkCredential;

            RemoteShareName          = @"\\{0}\admin$".FormatString(remoteMachine);
            RemoteScriptBaseFilePath = @"{0}\{1}".FormatString(RemoteShareName, Math.Abs(ChoRandom.NextRandom()));

            RemoteScriptFilePath       = @"{0}.bat".FormatString(RemoteScriptBaseFilePath);
            RemoteScriptInnerFilePath  = @"{0}_i.bat".FormatString(RemoteScriptBaseFilePath);
            RemoteScriptOutputFilePath = @"{0}.out".FormatString(RemoteScriptBaseFilePath);
            RemoteScriptErrorFilePath  = @"{0}.err".FormatString(RemoteScriptBaseFilePath);
        }