public static void Process(ActionArgs args, ControllerConfiguration config)
 {
     if ((args.CommandName == "Update") || (args.CommandName == "Insert"))
     {
         EventTracker tracker = new EventTracker();
         tracker.InternalProcess(args, config);
     }
 }
 public HeaterController(Controller controller)
     : base (controller)
 {
     if (string.IsNullOrEmpty(controller.Configuration))
     {
         configuration = ControllerConfiguration.Default;
         controller.SetConfiguration(configuration);
     }
     else
         configuration = controller.GetConfiguration(typeof(ControllerConfiguration));
 }
 public WemosScheduledSwitchController(WemosController controller)
     : base (controller)
 {
     if (string.IsNullOrEmpty(controller.Configuration))
     {
         configuration = ControllerConfiguration.Default;
         controller.SerializeConfiguration(configuration);
     }
     else
         configuration = controller.DeserializeConfiguration<ControllerConfiguration>();
 }
예제 #4
0
파일: Blob.cs 프로젝트: Ashrafnet/XIOT
        private List <FieldValue> CreateActionValues(Stream stream, string contentType, string fileName, int contentLength)
        {
            bool                    deleting         = (((contentType == "application/octet-stream") && (contentLength == 0)) && String.IsNullOrEmpty(fileName));
            List <string>           keyValues        = CreateKeyValues();
            int                     keyValueIndex    = 0;
            List <FieldValue>       actionValues     = new List <FieldValue>();
            ControllerConfiguration config           = Controller.CreateConfigurationInstance(typeof(Controller), DataController);
            XPathNodeIterator       keyFieldIterator = config.Select("/c:dataController/c:fields/c:field[@isPrimaryKey=\'true\']");

            while (keyFieldIterator.MoveNext())
            {
                FieldValue v = new FieldValue(keyFieldIterator.Current.GetAttribute("name", String.Empty));
                if (keyValueIndex < keyValues.Count)
                {
                    v.OldValue = keyValues[keyValueIndex];
                    v.Modified = false;
                    keyValueIndex++;
                }
                actionValues.Add(v);
            }
            if (stream != null)
            {
                XPathNavigator lengthField = config.SelectSingleNode("/c:dataController/c:fields/c:field[@name=\'{0}Length\']", ControllerFieldName);
                if (lengthField != null)
                {
                    actionValues.Add(new FieldValue(lengthField.GetAttribute("name", String.Empty), contentLength));
                    if (deleting)
                    {
                        ClearLastFieldValue(actionValues);
                    }
                }
                XPathNavigator contentTypeField = config.SelectSingleNode("/c:dataController/c:fields/c:field[@name=\'{0}ContentType\']", ControllerFieldName);
                if (contentTypeField != null)
                {
                    actionValues.Add(new FieldValue(contentTypeField.GetAttribute("name", String.Empty), contentType));
                    if (deleting)
                    {
                        ClearLastFieldValue(actionValues);
                    }
                }
                XPathNavigator fileNameField = config.SelectSingleNode("/c:dataController/c:fields/c:field[@name=\'{0}FileName\']", ControllerFieldName);
                if (fileNameField != null)
                {
                    actionValues.Add(new FieldValue(fileNameField.GetAttribute("name", String.Empty), Path.GetFileName(fileName)));
                    if (deleting)
                    {
                        ClearLastFieldValue(actionValues);
                    }
                }
                actionValues.Add(new FieldValue(ControllerFieldName, stream));
            }
            return(actionValues);
        }
예제 #5
0
        protected void Application_Start()
        {
            IContainer container = DependencyResolution.IoC.Initialize();

            AutoMapperConfiguration.Configure(container);
            ControllerConfiguration.Configure(container);
            FluentValidationConfiguration.Configure();

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
예제 #6
0
        private bool InitiateMesh()
        {
            if (openConnection != null && openConnection.isConnected() && ControllerManager.IsControllerConnected(SelectedController) &&
                UsingSelectedController && mesher == null)
            {
                //start the mesh

                //read what type of configuration to use from saved properties.
                ControllerConfiguration config = ControllerManager.GetConfiguration(SelectedController);
                mesher = new ConnectionControllerMesher(openConnection, config);
                mesher.StartMesh();
                return(true);
            }
            return(false);
        }
예제 #7
0
 public virtual void MapControllers(ControllerConfiguration controllerConfig)
 {
     this.ConfigureServices(services =>
     {
         if (controllerConfig?.Controllers?.Count > 0)
         {
             var mvcBuilder = services.AddMvc();
             foreach (var controllerAssemblyName in controllerConfig.Controllers)
             {
                 Assembly controllerAssembly = Assembly.Load(controllerAssemblyName);
                 mvcBuilder.AddApplicationPart(controllerAssembly);
             }
             mvcBuilder.AddControllersAsServices();
         }
     });
 }
예제 #8
0
        public static void SoftDeleteFolders(ControllerConfiguration context, IEnumerable<string> folders)
        {
            if (context == null)
                throw new ArgumentNullException("context", "Context cannot be null.");
            if (folders == null)
                throw new ArgumentNullException("folders", "Folders cannot be null.");

            using (var client = new AmazonS3Client(context.AwsAccessKeyId, context.AwsSecretAccessKey))
            {
                foreach (var folder in folders)
                {
                    int maxResults = 100;
                    int lastCount = maxResults;
                    while (maxResults == lastCount)
                    {
                        using (var listResponse = client.ListObjects(new ListObjectsRequest()
                        {
                            BucketName = context.BucketName,
                            Prefix = folder,
                        }))
                        {
                            lastCount = listResponse.S3Objects.Count;

                            Parallel.ForEach(listResponse.S3Objects, folderObject =>
                                {
                                    using (var copyResponse = client.CopyObject(new CopyObjectRequest()
                                    {
                                        SourceBucket = context.BucketName,
                                        DestinationBucket = context.BucketName,
                                        SourceKey = folderObject.Key,
                                        DestinationKey = ".recycled/" + folderObject.Key,
                                    })) { }
                                });

                            Parallel.ForEach(listResponse.S3Objects, folderObject =>
                                {
                                    using (var deleteReponse = client.DeleteObject(new DeleteObjectRequest()
                                    {
                                        BucketName = context.BucketName,
                                        Key = folderObject.Key,
                                    })) { }
                                });
                        }
                    }
                }
            }
        }
예제 #9
0
        public static void Run(ControllerConfiguration context, Guid instanceKey)
        {
            var logsController = new Logs(context);

            var searchEmpty = logsController.GetLogEntryPage(instanceKey);
            Debug.Assert(searchEmpty.LogEntries.Count() == 0);
            Debug.Assert(searchEmpty.InstanceKey == instanceKey);

            var logEntry1 = new LogEntry() { InstanceKey = instanceKey, LogContent = "Now this is the story all about how\r\nMy life got flipped, turned upside down\r\nAnd I'd like to take a minute just sit right there\r\nI'll tell you how I became the prince of a town called Bel-air" };
            logsController.AddLogEntry(logEntry1);

            var createdLogEntry1 = logsController.GetLogEntry(instanceKey, logEntry1.Timestamp, logEntry1.Status);
            Debug.Assert(createdLogEntry1.Timestamp == logEntry1.Timestamp);
            Debug.Assert(createdLogEntry1.InstanceKey == logEntry1.InstanceKey);
            Debug.Assert(createdLogEntry1.Status == logEntry1.Status);
            Debug.Assert(createdLogEntry1.LogContent == logEntry1.LogContent);

            var searchSingle = logsController.GetLogEntryPage(instanceKey);
            Debug.Assert(searchSingle.LogEntries.Count() == 1);
            Debug.Assert(searchSingle.LogEntries.ElementAt(0).Timestamp == logEntry1.Timestamp);
            Debug.Assert(searchSingle.LogEntries.ElementAt(0).Status == LogStatus.Ok);

            var logEntry2 = new LogEntry() { InstanceKey = instanceKey, Status = LogStatus.Warning, LogContent = "In west Philadelphia born and raised\r\nOn the playground where I spent most of my days\r\nChilling out, maxing, relaxing all cool\r\nAnd all shooting some b-ball outside of the school\r\nWhen a couple of guys, they were up to no good\r\nStarted making trouble in my neighbourhood\r\nI got in one little fight and my mom got scared\r\nAnd said \"You're moving with your auntie and uncle in Bel-air\"" };
            logsController.AddLogEntry(logEntry2);

            var createdLogEntry2 = logsController.GetLogEntry(instanceKey, logEntry2.Timestamp, logEntry2.Status);
            Debug.Assert(createdLogEntry2.Timestamp == logEntry2.Timestamp);
            Debug.Assert(createdLogEntry2.InstanceKey == logEntry2.InstanceKey);
            Debug.Assert(createdLogEntry2.Status == logEntry2.Status);
            Debug.Assert(createdLogEntry2.LogContent == logEntry2.LogContent);

            var search2 = logsController.GetLogEntryPage(instanceKey);
            Debug.Assert(search2.LogEntries.Count() == 2);
            Debug.Assert(search2.LogEntries.ElementAt(0).Timestamp == logEntry2.Timestamp);
            Debug.Assert(search2.LogEntries.ElementAt(0).Status == LogStatus.Warning);
            Debug.Assert(search2.LogEntries.ElementAt(1).Timestamp == logEntry1.Timestamp);

            var searchFirst = logsController.GetLogEntryPage(instanceKey, pageSize: 1);
            Debug.Assert(searchFirst.PageSize == 1);
            Debug.Assert(searchFirst.LogEntries.Count() == 1);
            Debug.Assert(searchFirst.LogEntries.ElementAt(0).Timestamp == logEntry2.Timestamp);

            var searchNext = logsController.GetLogEntryPage(instanceKey, searchFirst.NextMarker);
            Debug.Assert(searchNext.StartMarker == searchFirst.NextMarker);
            Debug.Assert(searchNext.LogEntries.Count() == 1);
            Debug.Assert(searchNext.LogEntries.ElementAt(0).Timestamp == logEntry1.Timestamp);
        }
예제 #10
0
        public static Instance Run(ControllerConfiguration context, Guid targetKey)
        {
            var instancesController = new Instances(context);

            var searchEmpty = instancesController.SearchInstances(targetKey);
            Debug.Assert(searchEmpty.TotalCount == 0);
            Debug.Assert(searchEmpty.Instances.Count() == 0);

            var testInstance = new Instance() { TargetKey = targetKey };
            instancesController.CreateInstance(testInstance);
            var createdInstance = instancesController.GetInstance(testInstance.Key);
            Debug.Assert(testInstance.Key == createdInstance.Key);
            Debug.Assert(testInstance.Name == createdInstance.Name);
            Debug.Assert(testInstance.TargetKey == createdInstance.TargetKey);

            var searchSingle = instancesController.SearchInstances(targetKey);
            Debug.Assert(searchSingle.TotalCount == 1);
            Debug.Assert(searchSingle.Instances.Count() == 1);
            Debug.Assert(searchSingle.Instances.First().Key == createdInstance.Key);
            Debug.Assert(searchSingle.Instances.First().Name == createdInstance.Name);

            createdInstance.Tags.Add("Foo", "Bar");
            instancesController.UpdateInstance(createdInstance);

            var taggedInstance = instancesController.GetInstance(createdInstance.Key);
            Debug.Assert(taggedInstance.Tags.Count == 1);
            Debug.Assert(taggedInstance.Tags.ContainsKey("Foo"));
            Debug.Assert(taggedInstance.Tags["Foo"] == "Bar");

            taggedInstance.Name = "Updated Test Instance";
            instancesController.UpdateInstance(taggedInstance);

            var renamedInstance = instancesController.GetInstance(taggedInstance.Key);
            Debug.Assert(renamedInstance.Name == taggedInstance.Name);

            var searchRenamed = instancesController.SearchInstances(targetKey);
            Debug.Assert(searchRenamed.TotalCount == 1);
            Debug.Assert(searchRenamed.Instances.First().Name == renamedInstance.Name);

            taggedInstance.Name = "Test Instance";
            instancesController.UpdateInstance(taggedInstance);

            SearchAndDelete(targetKey, instancesController, taggedInstance);

            return testInstance;
        }
        public override bool RequiresAuthentication(HttpRequest request)
        {
            bool result = base.RequiresAuthentication(request);

            if (result)
            {
                return(true);
            }
            Match m = AppServicesRegex.Match(request.Path);

            if (m.Success)
            {
                ControllerConfiguration config = null;
                try
                {
                    string controllerName = m.Groups["Controller"].Value;
                    if ((controllerName == "_authenticate") || (controllerName == "saas"))
                    {
                        return(false);
                    }
                    if (!(DynamicResourceRegex.IsMatch(controllerName)))
                    {
                        config = DataControllerBase.CreateConfigurationInstance(GetType(), controllerName);
                    }
                }
                catch (Exception)
                {
                }
                if (config == null)
                {
                    return(!(DynamicWebResourceRegex.IsMatch(request.Path)));
                }
                return(RequiresRESTAuthentication(request, config));
            }
            return(false);
        }
 public virtual bool RequiresRESTAuthentication(HttpRequest request, ControllerConfiguration config)
 {
     return(UriRestConfig.RequiresAuthentication(request, config));
 }
예제 #13
0
        public static string Serialise(ControllerConfiguration config)
        {
            if (config == null)
                throw new ArgumentNullException("config", "Configuration cannot be null.");

            var values = new List<KeyValuePair<string, string>>()
            {
                new KeyValuePair<string,string>("AwsAccessKeyId", config.AwsAccessKeyId),
                new KeyValuePair<string,string>("AwsSecretAccessKey", config.AwsSecretAccessKey),
                new KeyValuePair<string,string>("BucketName", config.BucketName),
            };

            using (var reader = new StreamReader(Utils.Serialisation.Serialise(values)))
            {
                return reader.ReadToEnd();
            }
        }
        protected virtual void InternalEnsureTrackingFields(ViewPage page, ControllerConfiguration config)
        {
            bool hasCreatedByUserId    = false;
            bool hasCreatedByUserName  = false;
            bool hasCreatedOn          = false;
            bool hasModifiedByUserId   = false;
            bool hasModifiedByUserName = false;
            bool hasModifiedOn         = false;

            // detect missing tracking fields
            foreach (DataField field in page.Fields)
            {
                if (!(field.ReadOnly))
                {
                    if (IsCreatedByUserIdPattern(field.Name))
                    {
                        hasCreatedByUserId = true;
                    }
                    if (IsCreatedByUserNamePattern(field.Name))
                    {
                        hasCreatedByUserName = true;
                    }
                    if (IsCreatedOnPattern(field.Name))
                    {
                        hasCreatedOn = true;
                    }
                    if (IsModifiedByUserIdPattern(field.Name))
                    {
                        hasModifiedByUserId = true;
                    }
                    if (IsModifiedByUserNamePattern(field.Name))
                    {
                        hasModifiedByUserName = true;
                    }
                    if (IsModifiedOnPattern(field.Name))
                    {
                        hasModifiedOn = true;
                    }
                }
            }
            // Create DataField instances for missing tracking fields
            XPathNodeIterator fieldIterator = config.Select("/c:dataController/c:fields/c:field[not(@readOnly=\'true\')]");

            while (fieldIterator.MoveNext())
            {
                string fieldName = fieldIterator.Current.GetAttribute("name", String.Empty);
                // ensure that missing "created" data fields are declared
                if (!(hasCreatedByUserId) && IsCreatedByUserIdPattern(fieldName))
                {
                    page.Fields.Add(new DataField(fieldIterator.Current, config.Resolver));
                    hasCreatedByUserId = true;
                }
                if (!(hasCreatedByUserName) && IsCreatedByUserNamePattern(fieldName))
                {
                    page.Fields.Add(new DataField(fieldIterator.Current, config.Resolver));
                    hasCreatedByUserName = true;
                }
                if (!(hasCreatedOn) && IsCreatedOnPattern(fieldName))
                {
                    page.Fields.Add(new DataField(fieldIterator.Current, config.Resolver));
                    hasCreatedOn = true;
                }
                // ensure that missing "modified" data fields are declared
                if (!(hasModifiedByUserId) && IsModifiedByUserIdPattern(fieldName))
                {
                    page.Fields.Add(new DataField(fieldIterator.Current, config.Resolver));
                    hasModifiedByUserId = true;
                }
                if (!(hasModifiedByUserName) && IsModifiedByUserNamePattern(fieldName))
                {
                    page.Fields.Add(new DataField(fieldIterator.Current, config.Resolver));
                    hasModifiedByUserName = true;
                }
                if (!(hasModifiedOn) && IsModifiedOnPattern(fieldName))
                {
                    page.Fields.Add(new DataField(fieldIterator.Current, config.Resolver));
                    hasModifiedOn = true;
                }
            }
        }
        public static void EnsureTrackingFields(ViewPage page, ControllerConfiguration config)
        {
            EventTracker tracker = new EventTracker();

            tracker.InternalEnsureTrackingFields(page, config);
        }
        protected virtual void InternalProcess(ActionArgs args, ControllerConfiguration config)
        {
            bool hasCreatedByUserId    = false;
            bool hasCreatedByUserName  = false;
            bool hasCreatedOn          = false;
            bool hasModifiedByUserId   = false;
            bool hasModifiedByUserName = false;
            bool hasModifiedOn         = false;

            // assign tracking values to field values passed from the client
            foreach (FieldValue v in args.Values)
            {
                if (!(v.ReadOnly))
                {
                    if (!(hasCreatedByUserId) && IsCreatedByUserIdPattern(v.Name))
                    {
                        hasCreatedByUserId = true;
                        if (v.Value == null)
                        {
                            v.NewValue = UserId;
                            v.Modified = true;
                        }
                    }
                    else
                    if (!(hasCreatedByUserName) && IsCreatedByUserNamePattern(v.Name))
                    {
                        hasCreatedByUserName = true;
                        if (v.Value == null)
                        {
                            v.NewValue = UserName;
                            v.Modified = true;
                        }
                    }
                    else
                    if (!(hasCreatedOn) && IsCreatedOnPattern(v.Name))
                    {
                        hasCreatedOn = true;
                        if (v.Value == null)
                        {
                            v.NewValue = DateTime.Now;
                            v.Modified = true;
                        }
                    }
                    else
                    if (!(hasModifiedByUserId) && IsModifiedByUserIdPattern(v.Name))
                    {
                        hasModifiedByUserId = true;
                        v.NewValue          = UserId;
                        v.Modified          = true;
                    }
                    else
                    if (!(hasModifiedByUserName) && IsModifiedByUserNamePattern(v.Name))
                    {
                        hasModifiedByUserName = true;
                        v.NewValue            = UserName;
                        v.Modified            = true;
                    }
                    else
                    if (!(hasModifiedOn) && IsModifiedOnPattern(v.Name))
                    {
                        hasModifiedOn = true;
                        v.NewValue    = DateTime.Now;
                        v.Modified    = true;
                    }
                }
            }
            // assign missing tracking values
            List <FieldValue> values        = new List <FieldValue>(args.Values);
            XPathNodeIterator fieldIterator = config.Select("/c:dataController/c:fields/c:field[not(@readOnly=\'true\')]");

            while (fieldIterator.MoveNext())
            {
                string fieldName = fieldIterator.Current.GetAttribute("name", String.Empty);
                // ensure that missing "created" values are provided
                if (args.CommandName == "Insert")
                {
                    if (!(hasCreatedByUserId) && IsCreatedByUserIdPattern(fieldName))
                    {
                        hasCreatedByUserId = true;
                        FieldValue v = new FieldValue(fieldName, UserId);
                        values.Add(v);
                    }
                    else
                    if (!(hasCreatedByUserName) && IsCreatedByUserNamePattern(fieldName))
                    {
                        hasCreatedByUserName = true;
                        FieldValue v = new FieldValue(fieldName, UserName);
                        values.Add(v);
                    }
                    else
                    if (!(hasCreatedOn) && IsCreatedOnPattern(fieldName))
                    {
                        hasCreatedOn = true;
                        FieldValue v = new FieldValue(fieldName, DateTime.Now);
                        values.Add(v);
                    }
                }
                // ensure that missing "modified" values are provided
                if (!(hasModifiedByUserId) && IsModifiedByUserIdPattern(fieldName))
                {
                    hasModifiedByUserId = true;
                    FieldValue v = new FieldValue(fieldName, UserId);
                    values.Add(v);
                }
                else
                if (!(hasModifiedByUserName) && IsModifiedByUserNamePattern(fieldName))
                {
                    hasModifiedByUserName = true;
                    FieldValue v = new FieldValue(fieldName, UserName);
                    values.Add(v);
                }
                else
                if (!(hasModifiedOn) && IsModifiedOnPattern(fieldName))
                {
                    hasModifiedOn = true;
                    FieldValue v = new FieldValue(fieldName, DateTime.Now);
                    values.Add(v);
                }
            }
            args.Values = values.ToArray();
        }
예제 #17
0
        /// <summary>
        /// Loads the configuration for the system.
        /// </summary>
        private void Load()
        {
            foreach (string resourceName in Assembly.GetExecutingAssembly().GetManifestResourceNames())
            {
                if (resourceName.EndsWith(".SystemConfiguration.xml"))
                {
                    using (Stream istrm = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(Configuration));
                        m_configuration = (Configuration)serializer.Deserialize(istrm);
                    }
                }
            }

            if (m_configuration.Controllers != null)
            {
                for (int ii = 0; ii < m_configuration.Controllers.Length; ii++)
                {
                    ControllerConfiguration controller = m_configuration.Controllers[ii];

                    int blockAddress = m_position;
                    int offset       = m_position - blockAddress;

                    BlockConfiguration data = new BlockConfiguration()
                    {
                        Address    = blockAddress,
                        Name       = controller.Name,
                        Type       = controller.Type,
                        Properties = new List <BlockProperty>()
                    };

                    if (controller.Properties != null)
                    {
                        for (int jj = 0; jj < controller.Properties.Length; jj++)
                        {
                            ControllerProperty property   = controller.Properties[jj];
                            NodeId             dataTypeId = NodeId.Parse(property.DataType);
                            string             value      = property.Value;
                            Range range = null;

                            if (!String.IsNullOrEmpty(property.Range))
                            {
                                try
                                {
                                    NumericRange nr = NumericRange.Parse(property.Range);
                                    range = new Range()
                                    {
                                        High = nr.End, Low = nr.Begin
                                    };
                                }
                                catch (Exception)
                                {
                                    range = null;
                                }
                            }

                            data.Properties.Add(new BlockProperty()
                            {
                                Offset    = offset,
                                Name      = controller.Properties[jj].Name,
                                DataType  = dataTypeId,
                                Writeable = controller.Properties[jj].Writeable,
                                Range     = range
                            });

                            switch ((uint)dataTypeId.Identifier)
                            {
                            case DataTypes.Int32:
                            {
                                Write(blockAddress, offset, (int)TypeUtils.Cast(value, BuiltInType.Int32));
                                offset += 4;
                                break;
                            }

                            case DataTypes.Double:
                            {
                                Write(blockAddress, offset, (double)TypeUtils.Cast(value, BuiltInType.Double));
                                offset += 4;
                                break;
                            }
                            }
                        }
                    }

                    m_position            += offset;
                    m_blocks[blockAddress] = data;
                }
            }
        }
예제 #18
0
        private static void ParseArguments(string[] args, out string comment, out string directoryPath, out Guid appKey, out ControllerConfiguration context)
        {
            comment = null;
            directoryPath = Directory.GetCurrentDirectory();
            Guid? tempAppKey = null;
            string awsAccessKeyId = null;
            string awsSecretAccessKey = null;
            string bucketName = null;

            if (args.Length == 2)
            {
                // Just parse for a comment.
                if (args[1].StartsWith("-"))
                    PushSyntaxError();
                comment = args[1];
            }
            else if (args.Length > 2)
            {
                // Read named parameters.
                for (int i = 1; i < args.Length; i++)
                {
                    if (i > args.Length - 2)
                        PushSyntaxError();

                    switch (args[i].ToLower())
                    {
                        case "-a":
                        case "--app-key":
                            Guid parsedAppKey;
                            if (!Guid.TryParse(args[++i], out parsedAppKey))
                                PushSyntaxError();
                            tempAppKey = parsedAppKey;
                            break;
                        case "-b":
                        case "--bucket-name":
                            bucketName = args[++i];
                            break;
                        case "-c":
                        case "--comment":
                            comment = args[++i];
                            break;
                        case "-d":
                        case "--directory":
                            directoryPath = args[++i];
                            break;
                        case "-k":
                        case "--aws-access-key-id":
                            awsAccessKeyId = args[++i];
                            break;
                        case "-s":
                        case "--aws-secret-access-key":
                            awsSecretAccessKey = args[++i];
                            break;
                        default:
                            break;
                    }
                }
            }
            else
            {
                PushSyntaxError();
            }

            // Verify comment.
            if (string.IsNullOrWhiteSpace(comment))
            {
                Console.WriteLine("Comment must be specified and cannot be blank.");
                throw new HandledCliException();
            }

            // Verify directory.
            DirectoryInfo directory;
            try
            {
                directory = new DirectoryInfo(directoryPath);
            }
            catch
            {
                Console.WriteLine("Invalid directory.");
                throw new HandledCliException();
            }
            if (!directory.Exists)
            {
                Console.WriteLine("Directory does not exist.");
                throw new HandledCliException();
            }

            // Verify app key.
            if (!tempAppKey.HasValue)
            {
                try
                {
                    using (var stream = File.Open(directory.FullName + @"\.appkey", FileMode.Open))
                    {
                        tempAppKey = Utils.Serialisation.ParseKey(stream);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("No app key specified and failed loading key from .appkey file.");
                    throw new HandledCliException();
                }
            }
            appKey = tempAppKey.Value;

            // Verify configuration.
            if (awsAccessKeyId == null || awsSecretAccessKey == null || bucketName == null)
            {
                // Try loading from file.
                try
                {
                    using (var stream = File.Open(directory.FullName + @"\.config", FileMode.Open))
                    {
                        var fileConfig = Utils.Serialisation.ParseControllerConfiguration(stream);
                        if (awsAccessKeyId == null)
                            awsAccessKeyId = fileConfig.AwsAccessKeyId;
                        if (awsSecretAccessKey == null)
                            awsSecretAccessKey = fileConfig.AwsSecretAccessKey;
                        if (bucketName == null)
                            bucketName = fileConfig.BucketName;
                    }
                }
                catch
                {
                    Console.WriteLine("Missing controller configuration properties and failed loading from .config file.");
                    throw new HandledCliException();
                }
            }
            if (awsAccessKeyId.Length != 20)
            {
                Console.WriteLine("Invalid AWS Access Key ID.");
                throw new HandledCliException();
            }
            if (awsSecretAccessKey.Length != 40)
            {
                Console.WriteLine("Invalid AWS Secret Access Key.");
                throw new HandledCliException();
            }
            if (string.IsNullOrWhiteSpace(bucketName))
            {
                Console.WriteLine("Bucket name cannot be blank.");
                throw new HandledCliException();
            }
            context = new ControllerConfiguration()
            {
                AwsAccessKeyId = awsAccessKeyId,
                AwsSecretAccessKey = awsSecretAccessKey,
                BucketName = bucketName,
            };
        }
예제 #19
0
        protected string PreparePrefetch(string content)
        {
            string output = null;

            if (!(String.IsNullOrEmpty(Request.Url.Query)) || (Request.Headers["X-Cot-Manifest-Request"] == "true"))
            {
                return(output);
            }
            JToken        token = ApplicationServices.TryGetJsonProperty(ApplicationServices.Current.DefaultSettings, "ui.history.dataView");
            bool          supportGridPrefetch = ((token == null) || !(Regex.IsMatch(((string)(token)), "\\b(search|sort|group|filter)\\b")));
            List <string> prefetches          = new List <string>();
            bool          prefetch            = false;
            List <Tuple <string, AttributeDictionary> > dataViews = new List <Tuple <string, AttributeDictionary> >();

            foreach (Match m in Regex.Matches(content, "<div\\s+(id=\"(?\'Id\'\\w+)\")\\s+(?\'Props\'data-controller.*?)>"))
            {
                dataViews.Add(new Tuple <string, AttributeDictionary>(m.Groups["Id"].Value, new AttributeDictionary(m.Groups["Props"].Value)));
            }
            if (dataViews.Count == 1)
            {
                prefetch = true;
            }
            else
            {
                // LEGACY MASTER DETAIL PAGE SUPPORT
                //
                //
                // 1. convert text of containers into single container with single dataview referring to virtual dashboard controller
                //
                // <div data-flow="row">
                //   <div id="view1" data-controller="Dashboards" data-view="form1" data-show-action-buttons="none"></div>
                //
                // </div>
                //
                // 2. produce response for this controller.
                // a. standalone data views become data view fields of the virtual controller
                // b. the layout of the page is optionally converted into form1 layout of the virtual controller
                // c. render json response of virtual controller with layout in it
                //
            }
            if (prefetch)
            {
                for (int i = 0; (i < dataViews.Count); i++)
                {
                    Tuple <string, AttributeDictionary> dataView = dataViews[i];
                    string dataViewId         = dataView.Item1;
                    AttributeDictionary attrs = dataView.Item2;
                    foreach (string p in UnsupportedDataViewProperties)
                    {
                        if (attrs.ContainsKey(p))
                        {
                            return(output);
                        }
                    }
                    string controllerName = attrs["data-controller"];
                    string viewId         = null;
                    string tags           = null;
                    attrs.TryGetValue("data-tags", out tags);
                    ControllerConfiguration c = Controller.CreateConfigurationInstance(GetType(), controllerName);
                    if (!(attrs.TryGetValue("data-view", out viewId)))
                    {
                        viewId = ((string)(c.Evaluate("string(/c:dataController/c:views/c:view[1]/@id)")));
                    }
                    XPathNavigator viewNav = c.SelectSingleNode("/c:dataController/c:views/c:view[@id=\'{0}\']", viewId);
                    if (!(Context.User.Identity.IsAuthenticated) && !((viewNav.GetAttribute("access", String.Empty) == "Public")))
                    {
                        return(output);
                    }
                    string roles = null;
                    if (attrs.TryGetValue("data-roles", out roles) && !(new ControllerUtilities().UserIsInRole(roles.Split(','))))
                    {
                        return(output);
                    }
                    tags = (tags
                            + (" " + viewNav.GetAttribute("tags", String.Empty)));
                    bool isForm = (viewNav.GetAttribute("type", String.Empty) == "Form");
                    if (isForm)
                    {
                        _summaryDisabled = true;
                    }
                    if ((String.IsNullOrEmpty(tags) || !(Regex.IsMatch(tags, "\\bprefetch-data-none\\b"))) && (supportGridPrefetch || isForm))
                    {
                        PageRequest request = new PageRequest(-1, 30, null, null);
                        request.Controller      = controllerName;
                        request.View            = viewId;
                        request.Tag             = tags;
                        request.ContextKey      = dataViewId;
                        request.SupportsCaching = true;
                        if (attrs.ContainsKey("data-search-on-start"))
                        {
                            request.DoesNotRequireData = true;
                        }
                        ViewPage response = ControllerFactory.CreateDataController().GetPage(request.Controller, request.View, request);
                        string   result   = String.Format("{{ \"d\": {0} }}", ApplicationServices.CompressViewPageJsonOutput(JsonConvert.SerializeObject(response)));
                        prefetches.Add(String.Format("<script type=\"application/json\" id=\"_{0}_prefetch\">{1}</script>", dataViewId, Regex.Replace(result, "(<(/?\\s*script)(\\s|>))", "]_[$2$3]^[", RegexOptions.IgnoreCase)));
                        if (isForm)
                        {
                            foreach (DataField field in response.Fields)
                            {
                                if (String.IsNullOrEmpty(field.DataViewFilterSource) && (field.Type == "DataView"))
                                {
                                    AttributeDictionary fieldAttr = new AttributeDictionary(String.Empty);
                                    fieldAttr.Add("data-controller", field.DataViewController);
                                    fieldAttr.Add("data-view", field.DataViewId);
                                    fieldAttr.Add("data-tags", field.Tag);
                                    if (field.DataViewSearchOnStart)
                                    {
                                        fieldAttr.Add("data-search-on-start", "true");
                                    }
                                    dataViews.Add(new Tuple <string, AttributeDictionary>(String.Format("{0}_{1}", dataViewId, field.Name), fieldAttr));
                                }
                            }
                        }
                    }
                }
            }
            if (prefetches.Count > 0)
            {
                output = string.Join(String.Empty, prefetches);
            }
            return(output);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationControlCommand"/> class.
 /// </summary>
 public ConfigurationControlCommand()
     : base(DataType.Configuration, ControlCommandAction.None)
 {
     Configuration = new ControllerConfiguration();
 }
예제 #21
0
 public Indexes(ControllerConfiguration context)
     : base(context)
 {
 }
예제 #22
0
        public string GetNetxtView(string forwardName)
        {
            ControllerConfiguration config = (ControllerConfiguration)Context.Items["ControllerConfig"];

            return(config.GetForwardAction(this.CurrentRouter.CurrentView, forwardName));
        }
 public ConnectionControllerMesher(ConnectionContext connection, ControllerConfiguration configuration, int PollRate = 100)
 {
     conn         = connection;
     config       = configuration;
     PollInterval = PollRate;
 }
 public override void SetConfiguration(string config)
 {
     configuration = (ControllerConfiguration)Extensions.FromJson(typeof(ControllerConfiguration), config);
     controller.SetConfiguration(configuration);
     SaveToDB();
 }
예제 #25
0
 public static void SoftDeleteFolders(ControllerConfiguration context, string folder)
 {
     SoftDeleteFolders(context, new List<string>() { folder });
 }