private static string MatchViewRootProperties(object view, string output)
        {
            var sb = new StringBuilder(output);
            // Normal access properties
            var matcher = new Regex(@"<%([\.a-zA-Z]+)>");
            var match = matcher.Match(sb.ToString());

            while (match.Success)
            {
                var listProperties = match.Groups[1].Value;
                var propCallStack = new Stack<string>(listProperties.Split('.'));

                var value = view;
                foreach (var prop in propCallStack.Reverse())
                {
                    var pinfo = value.GetType().GetProperty(prop);
                    //Try to Map invalid Data
                    if (pinfo == null)
                        throw new InvalidDataBindViewException(listProperties, prop, value.GetType().Name, "Master");
                    value = pinfo.GetValue(value, new object[] { });
                }
                //MustEscapeData
                sb.Replace(match.Value, SecurityElement.Escape(value.ToString()));
                match = match.NextMatch();
            }
            return sb.ToString();
        }
Exemplo n.º 2
0
        private IPath BuildPath(Stack<Tuple<JProperty, bool>> propertyStack, JProperty jProperty, JToken root)
        {
            var path = new JsonPath();

            path.ActualPath = string.Join(JsonPath.SeperatorSymbol,
                propertyStack.Reverse().Select(p => path.CreatePathSegment(p.Item1).ToString(p.Item2)));

            List<Tuple<IPathSegment, bool>> displayPathSegments =
                propertyStack.Reverse()
                    .Select(p => new Tuple<IPathSegment, bool>(path.CreatePathSegment(p.Item1), p.Item2))
                    .ToList();
            bool recordsetEncountered = false;

            for (int i = displayPathSegments.Count - 1; i >= 0; i--)
            {
                Tuple<IPathSegment, bool> pathSegment = displayPathSegments[i];
                if (recordsetEncountered)
                {
                    pathSegment.Item1.IsEnumarable = false;
                }

                if (pathSegment.Item1.IsEnumarable && pathSegment.Item2) recordsetEncountered = true;
            }

            path.DisplayPath = string.Join(JsonPath.SeperatorSymbol,
                displayPathSegments.Select(p => p.Item1.ToString(p.Item2)));

            if (path.ActualPath != string.Empty)
            {
                path.ActualPath += JsonPath.SeperatorSymbol;
            }

            if (path.DisplayPath != string.Empty)
            {
                path.DisplayPath += JsonPath.SeperatorSymbol;
            }

            path.ActualPath += path.CreatePathSegment(jProperty).ToString();
            path.DisplayPath += path.CreatePathSegment(jProperty).ToString();
            path.SampleData += GetSampleData(root, path);

            return path;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Trys to get an instance from the instance store, creating it if it doesnt exist
        /// </summary>
        /// <param name="requestType">The requested type</param>
        /// <param name="instanceStore"></param>
        /// <param name="tempInstanceStore"></param>
        /// <param name="buildStack"></param>
        /// <returns></returns>
        IEnumerable GetOrCreateInstances(Type requestType, IInstanceStore instanceStore, IInstanceStore tempInstanceStore, Stack<Type> buildStack)
        {
            var typesToCreate = GetTypesToCreate(requestType, buildStack);

            var instances = new List<Tuple<Registration, object>>();

            if (tempInstanceStore != null && tempInstanceStore.ContainsInstancesFor(requestType))
                instances.AddRange(tempInstanceStore.GetInstances(requestType).Cast<Tuple<Registration, object>>());
            else if (instanceStore.ContainsInstancesFor(requestType))
                instances.AddRange(instanceStore.GetInstances(requestType).Cast<Tuple<Registration, object>>());

            foreach (var registration in typesToCreate)
            {
                if(!instances.Any(i => i != null && i.Item1 == registration))
                {
                    var newinstance = this.GetInstance(registration, tempInstanceStore, new Stack<Type>(buildStack.Reverse()));

                    instanceStore.Insert(registration, requestType, newinstance);

                    instances.Add(new Tuple<Registration, object>(registration, newinstance));
                }
            }

            return instances.Select(i => i.Item2).ToArray();
        }
Exemplo n.º 4
0
        object GetInstance(Registration registration, IInstanceStore tempInstanceStore, Stack<Type> buildStack)
        {
            if (buildStack.Contains(registration.ConcreteType))
                throw new ContainerException("Cyclic dependency detected when trying to construct `" + registration.ConcreteType.AssemblyQualifiedName + "`", buildStack);

            buildStack.Push(registration.ConcreteType);

            var constructor = registration.Ctor ??
                               (container =>
                                    {
                                        var constructors = registration.ConcreteType.GetConstructors();
                                        var ctorsWithParams = constructors.Select(c => new {ctor = c, parameters = c.GetParameters()});
                                        var orderedEnumerable = ctorsWithParams.OrderBy(x => x.parameters.Length);
                                        foreach (var ctor in orderedEnumerable)
                                        {
                                            var parameterInfos = ctor.parameters.Select(p => p.ParameterType);

                                            this.CheckDependencies(registration.ConcreteType, parameterInfos, registration.Lifecycle, tempInstanceStore, buildStack);

                                            var parameters = new object[ctor.parameters.Length];
                                            for (var i = 0; i < ctor.parameters.Length; i++)
                                            {
                                                var newBuildStack = new Stack<Type>(buildStack.Reverse());
                                                if (ctor.parameters[i].ParameterType.IsGenericType && ctor.parameters[i].ParameterType.GetGenericTypeDefinition() == typeof (IEnumerable<>))
                                                {
                                                    var genericArgument = ctor.parameters[i].ParameterType.GetGenericArguments()[0];
                                                    parameters[i] = this.ResolveAll(genericArgument, newBuildStack);
                                                }
                                                else
                                                {
                                                    parameters[i] = this.Resolve(ctor.parameters[i].ParameterType, tempInstanceStore, newBuildStack);
                                                }
                                            }

                                            try
                                            {
                                                return ctor.ctor.Invoke(parameters);
                                            }
                                            catch(Exception e)
                                            {
                                                throw new ContainerException("Cannot create type `" + ctor.ctor.DeclaringType.FullName + "`", buildStack, e);
                                            }
                                        }

                                        throw new ContainerException("Unable to construct `" + registration.ConcreteType.AssemblyQualifiedName + "`", buildStack);
                                    });

            return constructor(this);
        }
Exemplo n.º 5
0
        private bool createListBoxItems ( string path, Stack<string> subDirectories )
        {
            if(!isMatch(path))
            {
                return false;
            }
            
            subDirectories.Push( Path.GetFileName( path ));

            var subPaths = Directory.GetDirectories( path );
            foreach ( var subPath in subPaths )
            {
                if ( !createListBoxItems( subPath, subDirectories ) )
                {
                    var internalData = new InternalDataItem( path, subDirectories.Reverse().ToArray() );
                    var lvItem = new ListViewItem();
                    lvItem.Text = internalData.ToString();
                    lvItem.Tag = internalData;
                    lv_Directories.Items.Add( lvItem );
                    subDirectories.Pop();
                    break;
                }
            }

            return true;
        }
        private static string MatchViewProperties(object view, string filePath)
        {
            if (!File.Exists(RootFolder + filePath + ".txt"))
                throw new TemplateViewNotFoundViewException(
                    view.GetType().Name, RootFolder + filePath + ".txt");

            var sb = new StringBuilder();

            using (TextReader reader = File.OpenText(RootFolder + filePath + ".txt"))
            {
                sb.Append(reader.ReadToEnd());
            }

            // Normal access properties
            var matcher = new Regex(@"<\$([\.a-zA-Z]+)>");
            var match = matcher.Match(sb.ToString());

            while (match.Success)
            {
                var listProperties = match.Groups[1].Value;
                var propCallStack = new Stack<string>(listProperties.Split('.'));
                
                var value = view;
                foreach (var prop in propCallStack.Reverse())
                {
                    var pinfo = value.GetType().GetProperty(prop);
                    //Try to Map invalid Data
                    if (pinfo == null)
                        throw new InvalidDataBindViewException(listProperties, prop, value.GetType().Name, filePath);
                    value = pinfo.GetValue(value, new object[] { });
                }
                //MustEscapeData
                sb.Replace(match.Value, SecurityElement.Escape(value.ToString()));
                match = match.NextMatch();
            }


            matcher = new Regex(@"<@([\.a-zA-Z]+)>");
            var matchList = matcher.Match(sb.ToString());

            while (matchList.Success)
            {
                var listProperties = matchList.Groups[1].Value;
                var propCallStack = new Stack<string>(listProperties.Split('.'));

                var value = view;
                var propIndex = propCallStack.Count;
                foreach (var prop in propCallStack.Reverse())
                {
                    --propIndex;
                    var pinfo = value.GetType().GetProperty(prop);

                    //Try to Map invalid Data
                    if (pinfo == null)
                        throw new InvalidDataBindViewException(listProperties, prop, value.GetType().Name, filePath);

                    value = pinfo.GetValue(value, new object[] { });

                    //Is enumerable and it's the last callstack it can be usefull to use fom .Count on collections
                    if (value is IEnumerable && propIndex == 0)
                    {
                        // the enumerable
                        var listsb = new StringBuilder();
                        foreach (var item in (IEnumerable)value)
                        {
                            listsb.Append(MatchViewProperties(item, filePath + "." + pinfo.Name));
                        }

                        value = listsb.ToString();
                    }
                }
                //MustEscapeData
                sb.Replace(matchList.Value, value.ToString());

                matchList = matchList.NextMatch();
            }
            return sb.ToString();
        }
Exemplo n.º 7
0
        public SwarmMemory InitializeThePeer(string data, string myIPPort)
        {
            XDocument doc = XDocument.Parse(data);
            var q = from x in doc.Elements().Descendants("Pid") select x;
            string Pid = q.ElementAt(0).Value.ToString();
            
             SwarmMemory  sm = new SwarmMemory(Pid,myIPPort);            
            
            q = from x in doc.Elements().Descendants("stack").Descendants("value") select x;
            Stack<string> newProgramStack = new Stack<string>();

            foreach (var item in q)
            {
                newProgramStack.Push(item.Value.ToString());
            }
            newProgramStack.Reverse();
            sm.setProgramStack(newProgramStack);
            ////////////////////////////////////////////////////////
            q = from x in doc.Elements().Descendants("partialResults").Descendants("Result").Descendants("IPPort") select x;
            List<string> ResultIPorts = new List<string>();
            foreach (var item in q)
            {
                ResultIPorts.Add(item.Value.ToString());
            }
            q = from x in doc.Elements().Descendants("partialResults").Descendants("Result").Descendants("ResultValue") select x;
            List<string> ResultVal = new List<string>();
            foreach (var item in q)
            {
                ResultVal.Add(item.Value.ToString());
            }
            q = from x in doc.Elements().Descendants("partialResults").Descendants("Result").Descendants("done") select x;
            List<string> _done = new List<string>();
            foreach (var item in q)
            {
                _done.Add(item.Value.ToString());
            }
            Hashtable newPartialResults = new Hashtable();
            for (int i = 0; i < ResultIPorts.Count; i++)
            {
                string[] temp = { ResultVal[i].ToString(), _done[i].ToString() };
                newPartialResults.Add(ResultIPorts[i].ToString(), temp);
            }
            sm.setpartialResults(newPartialResults);
            /////////////////////////////
            q = from x in doc.Elements().Descendants("permissions").Descendants("permit").Descendants("IPPort") select x;
            List<string> IPorts = new List<string>();
            foreach (var item in q)
            {
                IPorts.Add(item.Value.ToString());
            }
            q = from x in doc.Elements().Descendants("permissions").Descendants("permit").Descendants("read") select x;
            List<string> reads = new List<string>();
            foreach (var item in q)
            {
                reads.Add(item.Value.ToString());
            }
            q = from x in doc.Elements().Descendants("permissions").Descendants("permit").Descendants("write") select x;
            List<string> writes = new List<string>();
            foreach (var item in q)
            {
                writes.Add(item.Value.ToString());
            }

            Hashtable newPermissions = new Hashtable();
            for (int i = 0; i < IPorts.Count; i++)
            {
                string[] temp = { reads[i].ToString(), writes[i].ToString() };
                newPermissions.Add(IPorts[i].ToString(), temp);
            }
            sm.setPermissions(newPermissions);
            //////////////////////////////
            q = from x in doc.Elements().Descendants("programVariables").Descendants("variable").Descendants("name") select x;
            List<string> varnames = new List<string>();
            foreach (var item in q)
            {
                varnames.Add(item.Value.ToString());
            }
            q = from x in doc.Elements().Descendants("programVariables").Descendants("variable").Descendants("value") select x;
            List<string> varvalues = new List<string>();
            foreach (var item in q)
            {
                varvalues.Add(item.Value.ToString());
            }
            Hashtable newProgramVariables = new Hashtable();
            for (int i = 0; i < varnames.Count; i++)
            {
                newProgramVariables.Add(varnames[i].ToString(), varvalues[i].ToString());
            }
            sm.setProgramVariables(newProgramVariables);
            ///////////////////////////////////////////
            q = from x in doc.Elements().Descendants("Replies").Descendants("Reply").Descendants("IPPort") select x;
            List<string> ports = new List<string>();
            foreach (var item in q)
            {
                ports.Add(item.Value.ToString());
            }
            q = from x in doc.Elements().Descendants("Replies").Descendants("Reply").Descendants("ReplyValue") select x;
            List<string> repVal = new List<string>();
            foreach (var item in q)
            {
                repVal.Add(item.Value.ToString());
            }
            Hashtable newReplies = new Hashtable();
            for (int i = 0; i < ports.Count; i++)
            {
                newReplies.Add(ports[i].ToString(), repVal[i].ToString());
            }
            sm.setReply(newReplies);
            ///////////////////////////////
            q = from x in doc.Elements().Descendants("Owner") select x;
            string owner = q.ElementAt(0).Value.ToString();
            sm.setOwner(owner);
            return sm;
            /*
            //////////////////////////////////////////////////////
            //this part belongs to TEST2
            string TestID = Pid;
            Stack<string> TestStack = sm.getStack();
            Hashtable TestPartialResults = sm.getPartialResults();
            Hashtable TestPermissions = sm.getPermissions();
            Hashtable TestVariables = sm.getProgramVariables();
            Hashtable TestReplies = sm.getReplies();
            string TestOwner = sm.getOwner();
            Console.WriteLine("========STACK=======");
            foreach (string item in TestStack)
            {
                Console.WriteLine(item.ToString());
            }
            Console.WriteLine("========PartialResults=======");
            foreach (DictionaryEntry item in TestPartialResults)
            {
                string[] temp = (string[])item.Value;
                Console.WriteLine("IP={0}  Value={1}  Done={2}", item.Key.ToString(), temp[0].ToString(), temp[1].ToString());
            }
            Console.WriteLine("========Permissions=======");
            foreach (DictionaryEntry item in TestPermissions)
            {
                string[] temp = (string[])item.Value;
                Console.WriteLine("IP={0}  read={1}  write={2}", item.Key.ToString(), temp[0].ToString(), temp[1].ToString());
            }
            Console.WriteLine("========Variables=======");
            foreach (DictionaryEntry item in TestVariables)
            {
                Console.WriteLine("name={0}  value={1}",item.Key.ToString(),item.Value.ToString());
            }
            Console.WriteLine("========Replies=======");
            foreach (DictionaryEntry item in TestReplies)
            {
                Console.WriteLine("IP={0}  Reply={1}", item.Key.ToString(), item.Value.ToString());
            }
            Console.WriteLine("========Owner=======");
            Console.WriteLine("Owner={0}",TestOwner);
             * */
        }
 public ContextAwareObjectVisitor(Stack<string> previousContext = null)
 {
     this.context = previousContext == null
         ? new Stack<string>()
         : new Stack<string>(previousContext.Reverse());
 }
Exemplo n.º 9
0
 private static String GetName(Stack<Field> fields)
 {
     return String.Join(".", fields.Reverse().Select(f => f.Name));
 }