Ejemplo n.º 1
0
        public HttpResponseMessage Run(string databaseName, Guid taskGuid, [FromBody] IDictionary <string, string> properties)
        {
            using (var context = new DynacomDataContext(DynacomDataContext.GetConnectionString(databaseName)))
            {
                var task = context.DynaAutoTasks.Where(t => t.GUID == taskGuid).SingleOrDefault();
                if (task == null)
                {
                    return(Request.CreateResponse <string>(HttpStatusCode.NotFound, $"Task {taskGuid} does not exist."));
                }
                else
                {
                    try
                    {
                        var errors   = new List <Models.Error>();
                        var messages = new List <Models.Message>();

                        var principal = Request.GetRequestContext().Principal as DynacomPrincipal;
                        Dynacom.Helper.RunAutoTask(Properties.Settings.Default.DataSource, databaseName, principal.Username, principal.Password, task.ID, properties, errors, messages);
                        return(Request.CreateResponse <Models.RunTaskResponse>(errors.Count > 0 ? HttpStatusCode.InternalServerError : HttpStatusCode.OK, new Models.RunTaskResponse {
                            Errors = errors, Messages = messages
                        }));
                    }
                    catch (Exception ex)
                    {
                        return(Request.CreateResponse <string>(HttpStatusCode.InternalServerError, ex.Message));
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public IEnumerable <Models.AutoTask> List(string databaseName)
 {
     using (var context = new DynacomDataContext(DynacomDataContext.GetConnectionString(databaseName)))
     {
         foreach (var task in context.DynaAutoTasks.Where(t => (t.IsSystem == false || t.IsSystem == null) && t.AvailableToAutoMan == true))
         {
             yield return(new Models.AutoTask()
             {
                 TaskGuid = task.GUID, Name = task.Name
             });
         }
     }
 }
        private bool ValidateCredentials(string databaseName, AuthenticationHeaderValue authenticationHeaderVal)
        {
            if (authenticationHeaderVal != null && !String.IsNullOrEmpty(authenticationHeaderVal.Parameter))
            {
                string[] decodedCredentials = Encoding.ASCII.GetString(Convert.FromBase64String(authenticationHeaderVal.Parameter)).Split(new[] { ':' });
                string   decodedUsername    = decodedCredentials[0];
                string   decodedPassword    = decodedCredentials[1];

                using (var context = new DynacomDataContext(DynacomDataContext.GetConnectionString(databaseName)))
                {
                    var user = context.DynaUsers.Where(u => u.UserName == decodedUsername).SingleOrDefault();
                    if (user != null && user.Password.SequenceEqual(HashUserPassword(decodedUsername, decodedPassword)))
                    {
                        var principal = new DynacomPrincipal(decodedUsername, decodedPassword);
                        Thread.CurrentPrincipal  = principal;
                        HttpContext.Current.User = principal;
                        return(true);
                    }
                }
            }

            return(false);
        }