private void AddDebugFormDataInputs(IEnumerable <IFormDataParameters> conditions)
        {
            var allErrors = new ErrorResultTO();

            try
            {
                var dds  = conditions.GetEnumerator();
                var text = new StringBuilder();
                while (dds.MoveNext())
                {
                    var conditionExpression = dds.Current;

                    text.Append("\n");
                    if (conditionExpression != null)
                    {
                        conditionExpression.RenderDescription(text);
                    }
                }

                var debugItem = new DebugItem();
                var sb        = text.ToString();
                AddDebugItem(new DebugItemStaticDataParams(sb, "Parameters"), debugItem);
                _debugInputs.Add(debugItem);
            }
            catch (JsonSerializationException e)
            {
                Dev2Logger.Warn(e.Message, "Warewolf Warn");
            }
            catch (Exception e)
            {
                allErrors.AddError(e.Message);
            }
            finally
            {
                if (allErrors.HasErrors())
                {
                    var serviceName = GetType().Name;
                    DisplayAndWriteError(_dataObject, serviceName, allErrors);
                }
            }
        }
示例#2
0
 public virtual IList <Guid> ReadSession()
 {
     lock (FileLock)
     {
         var path        = GetEnvironmentsFilePath();
         var tryReadFile = File.Exists(path) ? File.ReadAllText(path) : null;
         var result      = new List <Guid>();
         if (!string.IsNullOrEmpty(tryReadFile))
         {
             try
             {
                 result = ReadSession(tryReadFile, result);
             }
             catch (Exception e)
             {
                 Dev2Logger.Warn(e.Message, "Warewolf Warn");
             }
         }
         return(result);
     }
 }
示例#3
0
        public IList <IIntellisenseResult> ParseDataLanguageForIntellisense(string payload, string dataList, bool addCompleteParts, IIntellisenseFilterOpsTO filterTo, bool isFromIntellisense)
        {
            return(WrapAndClear(() =>
            {
                var key = new Tuple <string, string>(payload, dataList);
                if (string.IsNullOrEmpty(payload))
                {
                    return new List <IIntellisenseResult>();
                }
                if (_payloadCache.ContainsKey(key))
                {
                    return _payloadCache[key];
                }
                var parts = DataListFactory.GenerateIntellisensePartsFromDataList(dataList, filterTo);

                IList <IDev2DataLanguageIntellisensePart> additionalParts = new List <IDev2DataLanguageIntellisensePart>();
                if (filterTo != null && filterTo.FilterType == enIntellisensePartType.RecordsetsOnly)
                {
                    additionalParts = DataListFactory.GenerateIntellisensePartsFromDataList(dataList, new IntellisenseFilterOpsTO {
                        FilterCondition = filterTo.FilterCondition, FilterType = enIntellisensePartType.None
                    });
                }
                var result = PartsGeneration(payload, parts, addCompleteParts, isFromIntellisense, additionalParts);
                if (result != null && result.Count > 0 && result.All(a => a.Type != enIntellisenseResultType.Error))
                {
                    try
                    {
                        _payloadCache.TryAdd(key, result);
                    }

                    catch (Exception e)
                    {
                        Dev2Logger.Warn(e.Message, "Warewolf Warn");
                    }
                }

                return result;
            }, _payloadCache));
        }
示例#4
0
 public ResourceLoadProvider(ConcurrentDictionary <Guid, List <IResource> > workspaceResources, IEnumerable <DynamicService> managementServices = null)
     : this(new FileWrapper())
 {
     try
     {
         _perfCounter = CustomContainer.Get <IWarewolfPerformanceCounterLocater>().GetCounter("Count of requests for workflows which don't exist");
     }
     catch (Exception e)
     {
         Dev2Logger.Warn("Error getting perf counters. " + e.Message, "Warewolf Warn");
     }
     if (managementServices != null)
     {
         foreach (var service in managementServices)
         {
             var resource = new ManagementServiceResource(service);
             ManagementServices.TryAdd(resource.ResourceID, resource);
         }
     }
     _workspaceResources = workspaceResources;
     LoadFrequentlyUsedServices();
 }
示例#5
0
        /// <summary>
        /// Returns true if all conditions are passing
        /// Returns true if there are no conditions
        /// Returns false if any condition is failing
        /// Returns false if any variable does not exist
        /// Returns false if there is an exception of any kind
        /// </summary>
        private bool Passing(int update)
        {
            if (!Conditions.Any())
            {
                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams(nameof(Passing), "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                }
                return(true);
            }

            try
            {
                var res = Conditions.Select(a => a.Eval(GetArgumentsFunc, _dataObject.Environment.HasErrors()));
                return(res.All(o => o));
            }
            catch (Exception e)
            {
                Dev2Logger.Warn("failed checking passing state of gate", e, _dataObject?.ExecutionID?.ToString());
                return(false);
            }
        }
        public QueueWorkerMonitor(IProcessFactory processFactory, IQueueConfigLoader queueConfigLoader, ITriggersCatalog triggersCatalog, IChildProcessTracker childProcessTracker)
        {
            _childProcessTracker = childProcessTracker;
            _processFactory      = processFactory;
            _queueConfigLoader   = queueConfigLoader;

            triggersCatalog.OnChanged += (triggerId) =>
            {
                try
                {
                    var configs = _queueConfigLoader.Configs;
                    var config  = configs.First(o => o.Id == triggerId);
                    WorkerRestart(config);
                }
                catch (Exception e)
                {
                    Dev2Logger.Warn(e.Message, "");
                }
            };

            triggersCatalog.OnDeleted += WorkerDeleted;
            triggersCatalog.OnCreated += WorkerCreated;
        }
示例#7
0
        void PermissionsHaveBeenModified(object sender, PermissionsModifiedEventArgs permissionsModifiedEventArgs)
        {
            if (Context == null)
            {
                return;
            }

            try
            {
                var user            = Context.User;
                var permissionsMemo = new PermissionsModifiedMemo
                {
                    ModifiedPermissions = ServerAuthorizationService.Instance.GetPermissions(user),
                    ServerID            = HostSecurityProvider.Instance.ServerID
                };
                var serializedMemo = _serializer.Serialize(permissionsMemo);
                Clients.Caller.SendPermissionsMemo(serializedMemo);
            }
            catch (Exception e)
            {
                Dev2Logger.Warn($"unable to notify remote client with PermissionsMemo, error: {e.Message}", GlobalConstants.WarewolfWarn);
            }
        }
示例#8
0
        bool IsInRole(IPrincipal principal, WindowsGroupPermission p)
        {
            var isInRole = false;

            if (principal == null)
            {
                return(p.IsBuiltInGuestsForExecution);
            }
            try
            {
                var windowsGroup = p.WindowsGroup;
                if (windowsGroup == WindowsGroupPermission.BuiltInAdministratorsText)
                {
                    var principleName = principal.Identity.Name;
                    if (!string.IsNullOrEmpty(principleName))
                    {
                        return(TryIsInRole(principal, windowsGroup));
                    }
                }
                else
                {
                    isInRole = principal.IsInRole(windowsGroup);
                }
            }
            catch (ObjectDisposedException e)
            {
                Dev2Logger.Warn(e.Message, "Warewolf Warn");
                throw;
            }
            catch (Exception e)
            {
                Dev2Logger.Warn(e.Message, "Warewolf Warn");
            }


            return(isInRole || p.IsBuiltInGuestsForExecution);
        }
示例#9
0
        void Debug(IDSFDataObject dataObject, string firstOrDefault, Dev2Switch ds)
        {
            try
            {
                if (dataObject.IsDebugMode())
                {
                    var result      = new List <DebugItem>();
                    var itemToAdd   = new DebugItem();
                    var debugResult = new DebugItemWarewolfAtomResult(firstOrDefault, "", ds.SwitchVariable, "", "Switch on", "", "=");
                    itemToAdd.AddRange(debugResult.GetDebugItemResult());
                    result.Add(itemToAdd);
                    _debugInputs = result;

                    if (Inner != null)
                    {
                        Inner.SetDebugInputs(_debugInputs);
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Warn(e.Message, GlobalConstants.WarewolfWarn);
            }
        }
示例#10
0
        private void BuildCatalogFromWorkspace(string workspacePath, string[] folders, List <ResourceBuilderTO> streams)
        {
            BuildStream(workspacePath, folders, streams);

            // Use the parallel task library to process file system ;)
            IList <Type> allTypes             = new List <Type>();
            var          connectionTypeName   = typeof(Connection).Name;
            var          dropBoxSourceName    = typeof(DropBoxSource).Name;
            var          sharepointSourceName = typeof(SharepointSource).Name;
            var          dbType = typeof(DbSource).Name;

            try
            {
                var resourceBaseType = typeof(IResourceSource);
                var assemblies       = AppDomain.CurrentDomain.GetAssemblies();
                var types            = assemblies
                                       .SelectMany(s => s.GetTypes())
                                       .Where(p => resourceBaseType.IsAssignableFrom(p));
                allTypes = types as IList <Type> ?? types.ToList();
            }
            catch (Exception e)
            {
                Dev2Logger.Error(ErrorResource.ErrorLoadingTypes, e, GlobalConstants.WarewolfError);
            }
            streams.ForEach(currentItem =>
            {
                try
                {
                    XElement xml = null;
                    try
                    {
                        xml = XElement.Load(currentItem._fileStream);
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Error("Resource [ " + currentItem._filePath + " ] caused " + e.Message,
                                         GlobalConstants.WarewolfError);
                    }

                    var result = xml?.ToStringBuilder();

                    var isValid  = result != null && HostSecurityProvider.Instance.VerifyXml(result);
                    var typeName = xml?.AttributeSafe("Type");
                    if (isValid)
                    {
                        //TODO: Remove this after V1 is released. All will be updated.
                        if (!IsWarewolfResource(xml))
                        {
                            return;
                        }

                        if (typeName == "Unknown")
                        {
                            var servertype = xml.AttributeSafe("ResourceType");
                            if (servertype != null && servertype == dbType)
                            {
                                xml.SetAttributeValue("Type", dbType);
                                typeName = dbType;
                            }
                        }

                        if (typeName == "Dev2Server" || typeName == "Server" || typeName == "ServerSource")
                        {
                            xml.SetAttributeValue("Type", connectionTypeName);
                            typeName = connectionTypeName;
                        }

                        if (typeName == "OauthSource")
                        {
                            xml.SetAttributeValue("Type", dropBoxSourceName);
                            typeName = dropBoxSourceName;
                        }

                        if (typeName == "SharepointServerSource")
                        {
                            xml.SetAttributeValue("Type", sharepointSourceName);
                            typeName = sharepointSourceName;
                        }

                        Type type = null;
                        if (allTypes.Count != 0)
                        {
                            type = allTypes.FirstOrDefault(type1 => type1.Name == typeName);
                        }

                        var resourceType = xml.AttributeSafe("ResourceType");
                        if (type is null && typeName == "" && resourceType == "WorkflowService")
                        {
                            type = typeof(Workflow);
                        }

                        Resource resource;
                        if (type != null)
                        {
                            resource = (Resource)Activator.CreateInstance(type, xml);
                        }
                        else
                        {
                            resource = new Resource(xml);
                        }

                        if (currentItem._filePath.EndsWith(".xml"))
                        {
                            _convertToBiteExtension.Add(currentItem._filePath);
                            resource.FilePath = currentItem._filePath.Replace(".xml", ".bite");
                        }
                        else
                        {
                            resource.FilePath = currentItem._filePath;
                        }

                        xml = _resourceUpgrader.UpgradeResource(xml, Assembly.GetExecutingAssembly().GetName().Version,
                                                                a =>
                        {
                            var fileManager = new TxFileManager();
                            using (TransactionScope tx = new TransactionScope())
                            {
                                try
                                {
                                    var updateXml = a.ToStringBuilder();
                                    var signedXml = HostSecurityProvider.Instance.SignXml(updateXml);
                                    signedXml.WriteToFile(currentItem._filePath, Encoding.UTF8, fileManager);
                                    tx.Complete();
                                }
                                catch
                                {
                                    try
                                    {
                                        Transaction.Current.Rollback();
                                    }
                                    catch (Exception err)
                                    {
                                        Dev2Logger.Error(err, GlobalConstants.WarewolfError);
                                    }

                                    throw;
                                }
                            }
                        });
                        if (resource.IsUpgraded)
                        {
                            // Must close the source stream first and then add a new target stream
                            // otherwise the file will be remain locked
                            currentItem._fileStream.Close();

                            xml = resource.UpgradeXml(xml, resource);

                            var updateXml   = xml.ToStringBuilder();
                            var signedXml   = HostSecurityProvider.Instance.SignXml(updateXml);
                            var fileManager = new TxFileManager();
                            using (TransactionScope tx = new TransactionScope())
                            {
                                try
                                {
                                    signedXml.WriteToFile(currentItem._filePath, Encoding.UTF8, fileManager);
                                    tx.Complete();
                                }
                                catch
                                {
                                    Transaction.Current.Rollback();
                                    throw;
                                }
                            }
                        }

                        lock (_addLock)
                        {
                            AddResource(resource, currentItem._filePath);
                        }
                    }
                    else
                    {
                        Dev2Logger.Debug(string.Format("'{0}' wasn't loaded because it isn't signed or has modified since it was signed.", currentItem._filePath), GlobalConstants.WarewolfDebug);
                    }
                }
                catch
                {
                    Dev2Logger.Warn($"Exception loading resource {currentItem._filePath}", GlobalConstants.WarewolfWarn);
                }
            });
        }
示例#11
0
        string CreateEndPoint(IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args, bool createToFile)
        {
            var result         = ResultOk;
            var activityIOPath = dst.IOPath;
            var dirParts       = MakeDirectoryParts(activityIOPath, dst.PathSeperator());

            var deepestIndex = -1;
            var startDepth   = dirParts.Count - 1;

            var pos = startDepth;

            while (pos >= 0 && deepestIndex == -1)
            {
                var tmpPath = ActivityIOFactory.CreatePathFromString(dirParts[pos], activityIOPath.Username,
                                                                     activityIOPath.Password, true, activityIOPath.PrivateKeyFile);
                try
                {
                    if (dst.ListDirectory(tmpPath) != null)
                    {
                        deepestIndex = pos;
                    }
                }
                catch (Exception e)
                {
                    Dev2Logger.Warn(e.Message, "Warewolf Warn");
                }
                finally
                {
                    pos--;
                }
            }

            pos = deepestIndex + 1;
            var ok = true;

            var origPath = dst.IOPath;

            while (pos <= startDepth && ok)
            {
                var toCreate = ActivityIOFactory.CreatePathFromString(dirParts[pos], dst.IOPath.Username,
                                                                      dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile);
                dst.IOPath = toCreate;
                ok         = CreateDirectory(dst, args);
                pos++;
            }

            dst.IOPath = origPath;

            if (!ok)
            {
                result = ResultBad;
            }
            else
            {
                if (dst.PathIs(dst.IOPath) == enPathType.File && createToFile && !CreateFile(dst, args))
                {
                    result = ResultBad;
                }
            }

            return(result);
        }
示例#12
0
        /// <summary>
        /// Starts up the server with relevant workers.
        /// NOTE: This must return a task as in Windows Server 2008 and Windows Server 2012 there is an issue
        /// with the WMI Performance Adapter that causes it to prevent the Warewolf Server Service to need a double restart.
        /// </summary>
        /// <param name="initWorkers">Initilization Workers</param>
        /// <returns>A Task that starts up the Warewolf Server.</returns>
        public Task Run(IEnumerable <IServerLifecycleWorker> initWorkers)
        {
            void OpenCOMStream(INamedPipeClientStreamWrapper clientStreamWrapper)
            {
                _writer.Write("Opening named pipe client stream for COM IPC... ");
                _ipcClient = _ipcClient.GetIpcExecutor(clientStreamWrapper);
                _writer.WriteLine("done.");
            }

            return(Task.Run(LoadPerformanceCounters)
                   .ContinueWith((t) =>
            {
                // ** Perform Moq Installer Actions For Development ( DEBUG config ) **
#if DEBUG
                try
                {
                    var miq = MoqInstallerActionFactory.CreateInstallerActions();
                    miq.ExecuteMoqInstallerActions();
                }
                catch (Exception e)
                {
                    Dev2Logger.Warn("Mocking installer actions for DEBUG config failed to create Warewolf Administrators group and/or to add current user to it [ " + e.Message + " ]", GlobalConstants.WarewolfWarn);
                }
#endif

                try
                {
                    foreach (var worker in initWorkers)
                    {
                        worker.Execute();
                    }
                    _loggingProcessMonitor.Start();
                    var loggingServerCheckDelay = Task.Delay(TimeSpan.FromSeconds(300));

                    _loadResources = new LoadResources("Resources", _writer, _startUpDirectory, _startupResourceCatalogFactory);
                    LoadHostSecurityProvider();
                    _loadResources.CheckExampleResources();
                    _loadResources.MigrateOldTests();
                    var webServerConfig = _webServerConfiguration;
                    webServerConfig.Execute();
                    new LoadRuntimeConfigurations(_writer).Execute();
                    OpenCOMStream(null);
                    _loadResources.LoadResourceCatalog();
                    _timer = new Timer((state) => GetComputerNames.GetComputerNamesList(), null, 1000, GlobalConstants.NetworkComputerNameQueryFreq);
                    _loadResources.LoadServerWorkspace();
                    _loadResources.LoadActivityCache(_assemblyLoader);
                    LoadTestCatalog();
                    LoadTriggersCatalog();

                    _startWebServer.Execute(webServerConfig, _pauseHelper);
                    _queueProcessMonitor.Start();

                    _hangfireServerMonitor.Start();

                    var checkLogServerConnectionTask = CheckLogServerConnection();
                    var result = Task.WaitAny(new [] { checkLogServerConnectionTask, loggingServerCheckDelay });
                    var isConnectedOkay = !checkLogServerConnectionTask.IsCanceled && !checkLogServerConnectionTask.IsFaulted && checkLogServerConnectionTask.Result == true;
                    var logServerConnectedOkayNoTimeout = result == 0 && isConnectedOkay;
                    if (!logServerConnectedOkayNoTimeout)
                    {
                        _writer.WriteLine("unable to connect to logging server");
                        if (checkLogServerConnectionTask.IsFaulted)
                        {
                            _writer.WriteLine("error: " + checkLogServerConnectionTask.Exception?.Message);
                        }
                        Stop(false, 0, true);
                    }

                    LogWarewolfVersion();
                    if (EnvironmentVariables.IsServerOnline)
                    {
                        SetAsStarted();
                    }
                }
                catch (Exception e)
                {
#pragma warning disable S2228 // Console logging should not be used
                    Console.WriteLine(e);
#pragma warning restore S2228 // Console logging should not be used
                    Dev2Logger.Error("Error Starting Server", e, GlobalConstants.WarewolfError);
                    Stop(true, 0, false);
                }
            }));
        }