public static System.Reflection.Assembly GenerateCode(ITextTemplatingEngineHost host, ParsedTemplate pt, 
		                                                       TemplateSettings settings, CodeCompileUnit ccu)
        {
            CompilerParameters pars = new CompilerParameters ();
            pars.GenerateExecutable = false;

            if (settings.Debug) {
                pars.GenerateInMemory = false;
                pars.IncludeDebugInformation = true;
                pars.TempFiles.KeepFiles = true;
            } else {
                pars.GenerateInMemory = true;
                pars.IncludeDebugInformation = false;
            }

            //resolve and add assembly references
            HashSet<string> assemblies = new HashSet<string> ();
            assemblies.UnionWith (settings.Assemblies);
            assemblies.UnionWith (host.StandardAssemblyReferences);
            foreach (string assem in assemblies) {
                string resolvedAssem = host.ResolveAssemblyReference (assem);
                if (!String.IsNullOrEmpty (resolvedAssem)) {
                    pars.ReferencedAssemblies.Add (resolvedAssem);
                } else {
                    pt.LogError ("Could not resolve assembly reference '" + assem + "'");
                    return null;
                }
            }
            CompilerResults results = settings.Provider.CompileAssemblyFromDom (pars, ccu);
            pt.Errors.AddRange (results.Errors);
            if (pt.Errors.HasErrors)
                return null;
            return results.CompiledAssembly;
        }
    static void Main()
    {
        InitializeWordsByChar();

        int textLinesCount = int.Parse(Console.ReadLine().ToLower());
        for (int i = 0; i < textLinesCount; i++)
        {
            GetWords(Console.ReadLine().ToLower());
        }

        int wordsCount = int.Parse(Console.ReadLine());
        for (int i = 0; i < wordsCount; i++)
        {
            string word = Console.ReadLine();
            string wordLowerCase = word.ToLower();
            HashSet<string> currentWords = new HashSet<string>();
            currentWords.UnionWith(wordsByChar[wordLowerCase[0]]);
            for (int j = 1; j < wordLowerCase.Length; j++)
            {
                currentWords.IntersectWith(wordsByChar[wordLowerCase[j]]);
            }

            Console.WriteLine("{0} -> {1}", word, currentWords.Count);
        }
    }
Beispiel #3
0
        /// <summary>
        /// Gather member which provide continuity with the specified member
        /// </summary>
        /// <param name="Member"></param>
        /// <returns></returns>
        public static IEnumerable<Member> GatherParallelMembers(Member Member, Node LastNode = null, bool MoveDownstream = false)
        {
            Node currentNode;
            Member nextMember;
            IEnumerable<Member> connectedParallelMembers;
            HashSet<Member> parallelMembers;

            parallelMembers = new HashSet<Member>();
            if (MoveDownstream)
                parallelMembers.Add(Member);

            // Determine which will be the next node
            currentNode = MemberHelpers.DetermineNextNode(Member, LastNode, MoveDownstream);

            connectedParallelMembers = currentNode.ConnectedBeams.Select(b => b.Member).Where(m => m != null && m != Member && m.DetermineMemberRelation(Member) == MEMBERRELATION.PARALLEL);
            if (connectedParallelMembers.Any())
            {
                nextMember = connectedParallelMembers.First();
                parallelMembers.UnionWith(GatherParallelMembers(nextMember, currentNode, MoveDownstream));
            }
            else
            {
                if (!MoveDownstream)
                    parallelMembers.UnionWith(GatherParallelMembers(Member, currentNode, true));
            }

            return parallelMembers;
        }
 private HashSet<string> GetUserAssemblies(string managedDir)
 {
   HashSet<string> stringSet = new HashSet<string>();
   stringSet.UnionWith(this.FilterUserAssemblies((IEnumerable<string>) this.m_RuntimeClassRegistry.GetUserAssemblies(), new Predicate<string>(this.m_RuntimeClassRegistry.IsDLLUsed), managedDir));
   stringSet.UnionWith(this.FilterUserAssemblies((IEnumerable<string>) Directory.GetFiles(managedDir, "I18N*.dll", SearchOption.TopDirectoryOnly), (Predicate<string>) (assembly => true), managedDir));
   return stringSet;
 }
Beispiel #5
0
        /// <summary>
        /// Gather beams which provide continuity with the specified beam
        /// </summary>
        /// <param name="Beam">The start beam around which to contruct the chain</param>
        /// <returns></returns>
        public static IEnumerable<Beam> GatherParallelBeams(Beam Beam, Node LastNode = null, bool MoveDownstream = false)
        {
            Node currentNode;
            Beam nextBeam;
            IEnumerable<Beam> connectedParallelBeams;
            HashSet<Beam> parallelBeams;

            parallelBeams = new HashSet<Beam>();
            if (MoveDownstream)
                parallelBeams.Add(Beam);

            // Determine which will be the next node depending on the beam orientation and direction of travel
            currentNode = BeamHelpers.DetermineNextNode(Beam, LastNode, MoveDownstream);

            // Check if the are any parallel beams among the connected beams and start gathering the beams depending on the direction of travel
            connectedParallelBeams = currentNode.ConnectedBeams.Where(b => b != null && b != Beam && b.DetermineBeamRelationship(Beam) == BEAMRELATION.PARALLEL);
            if (connectedParallelBeams.Any())
            {
                nextBeam = connectedParallelBeams.First();
                parallelBeams.UnionWith(GatherParallelBeams(nextBeam, currentNode, MoveDownstream));
            }
            else
            {
                if (!MoveDownstream)
                    parallelBeams.UnionWith(GatherParallelBeams(Beam, currentNode, true));
            }

            return parallelBeams;
        }
 public ISet<int> GetNodes()
 {
     var retVal = new HashSet<int>();
     retVal.UnionWith(playerZeroNodes);
     retVal.UnionWith(playerOneNodes);
     return retVal;
 }
        public ICollection<Type> GetControllerTypes(string controllerName, HashSet<string> namespaces) {
            HashSet<Type> matchingTypes = new HashSet<Type>();

            ILookup<string, Type> nsLookup;
            if (_cache.TryGetValue(controllerName, out nsLookup)) {
                // this friendly name was located in the cache, now cycle through namespaces
                if (namespaces != null) {
                    foreach (string requestedNamespace in namespaces) {
                        foreach (var targetNamespaceGrouping in nsLookup) {
                            if (IsNamespaceMatch(requestedNamespace, targetNamespaceGrouping.Key)) {
                                matchingTypes.UnionWith(targetNamespaceGrouping);
                            }
                        }
                    }
                }
                else {
                    // if the namespaces parameter is null, search *every* namespace
                    foreach (var nsGroup in nsLookup) {
                        matchingTypes.UnionWith(nsGroup);
                    }
                }
            }

            return matchingTypes;
        }
 static AssignmentStatementParser()
 {
     COLON_EQUALS_SET = new HashSet<TokenType>();
     COLON_EQUALS_SET.Add(TokenType.COLON_EQUALS);
     COLON_EQUALS_SET.UnionWith(ExpressionParser.EXPR_START_SET);
     COLON_EQUALS_SET.UnionWith(StatementParser.STMT_FOLLOW_SET);
 }
        public static HashSet<string> iu_cs_sinalling_relation_delegate_imsi(List<streamMessagePool._stream_message> ml, string imsi, bool sFlag)
        {

            //哈希表收集关联因子
            HashSet<string> hs = new HashSet<string>();
            hs.Add(imsi);

            //lr关联收集sccp连接串slr
            IEnumerable<string> l_slr_opc =
                    from n in ml
                    where n.message_gsm_a_imsi == imsi & n.message_sccp_slr != null
                    select n.message_sccp_slr + n.message_source
                        into m
                        where m.Contains("0x")
                        select m;
            hs.UnionWith(l_slr_opc);
            if (l_slr_opc.Any())
                foreach (string slr_opc in l_slr_opc)
                    hs.UnionWith(iu_cs_sinalling_relation_delegate_lr(ml, slr_opc, sFlag));

            //lr关联收集sccp连接串dlr
            IEnumerable<string> l_dlr_dpc =
                    from n in ml
                    where n.message_gsm_a_imsi == imsi & n.message_sccp_dlr != null
                    select n.message_sccp_dlr + n.message_destination
                        into m
                        where m.Contains("0x")
                        select m;
            hs.UnionWith(l_dlr_dpc);
            if (l_dlr_dpc.Any())
                foreach (string dlr_dpc in l_dlr_dpc)
                    hs.UnionWith(iu_cs_sinalling_relation_delegate_lr(ml, dlr_dpc, sFlag));

            return hs;
        }
Beispiel #10
0
 public HashSet<Node> getAllEdges()
 {
     HashSet<Node> allEdges = new HashSet<Node>();
     allEdges.UnionWith(_taxiEdges);
     allEdges.UnionWith(_busEdges);
     allEdges.UnionWith(_ugEdges);
     return allEdges;
 }
 public HashSet<KeyCode> getKeysHandled()
 {
     HashSet<KeyCode> keyCodes = new HashSet<KeyCode>();
     keyCodes.UnionWith(getKeyDownHandlers().Keys);
     keyCodes.UnionWith(getKeyUpHandlers().Keys);
     keyCodes.UnionWith(getKeyHandlers().Keys);
     return keyCodes;
 }
 /// <summary>List of cell ids for cells in the same context as the provided cell.</summary>
 /// <remarks>The "context" is the union of the Row, Column, and Shape for the provided cell.</remarks>
 /// <param name="cell">The cell id to find others in the same context.</param>
 /// <returns>The cell ids of all other cells in the same context.</returns>
 public virtual IEnumerable<int> Context(int cell)
 {
     HashSet<Cell> cells = new HashSet<Cell>();
     cells.UnionWith(GetRowRegionForCell(cell).Cells);
     cells.UnionWith(GetColumnRegionForCell(cell).Cells);
     cells.UnionWith(GetShapeRegionForCell(cell).Cells);
     return EnumerateIds(cells, cell);
 }
        public async Task<CodeGenResult> CodeGen(Workspace workspace, Project project)
        {
            CompilationUnitSyntax cu = SF.CompilationUnit();

            var usings = new HashSet<string>();
            bool copyUsings = false;

            foreach (Document document in project.Documents)
            {
                SyntaxTree syntaxTree = await document.GetSyntaxTreeAsync();
                _semanticModel = await document.GetSemanticModelAsync();

                IEnumerable<ClassDeclarationSyntax> classes =
                    syntaxTree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>();

                foreach (var classNode in classes)
                {
                    if (!RoslynUtils.IsPublic(classNode)) continue;

                    ITypeSymbol swmrInterface = FindSwmrInterface(classNode);
                    if (swmrInterface == null)
                    {
                        continue;
                    }

                    var namespaceNode = classNode.Parent as NamespaceDeclarationSyntax;
                    if (namespaceNode == null)
                    {
                        throw new Exception("A grain must be declared inside a namespace");
                    }

                    usings.UnionWith(syntaxTree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().Select(usingDirective => usingDirective.Name.ToString()));

                    int replicaCount = GetReadReplicaCount(swmrInterface);

                    NamespaceDeclarationSyntax namespaceDclr = SF.NamespaceDeclaration(SF.IdentifierName(namespaceNode.Name.ToString())).WithUsings(namespaceNode.Usings);

                    namespaceDclr = namespaceDclr.AddMembers(
                        GenerateWriteGrain(classNode, swmrInterface, replicaCount),
                        GenerateReadGrain(classNode, swmrInterface, replicaCount),
                        GenerateReadReplicaGrain(classNode, swmrInterface)
                        );

                    usings.UnionWith(namespaceNode.Usings.Select(@using => @using.Name.ToString()));

                    cu = cu.AddMembers(namespaceDclr);

                    // only copy the usings if at least one class was generated
                    copyUsings = true;
                }
            }

            if (copyUsings)
            {
                usings.UnionWith(GetCommonUsings());
            }
            return new CodeGenResult(Formatter.Format(cu, workspace).ToString(), usings);
        }
        public HashSet<char> GetVariables()
        {
            HashSet<char> variables = new HashSet<char>();

            variables.UnionWith(baseOfLogarithm.GetVariables());
            variables.UnionWith(number.GetVariables());

            return variables;
        }
 public IEnumerable<PhonebookEntry> Find(string name)
 {
     HashSet<PhonebookEntry> matched = new HashSet<PhonebookEntry>();
     matched.UnionWith(this.byFirstName[name]);
     matched.UnionWith(this.byMiddleName[name]);
     matched.UnionWith(this.byLastName[name]);
     matched.UnionWith(this.byNickname[name]);
     return matched;
 }
 public HashSet<string> MergeAll()
 {
     var results = new HashSet<string>();
     results.UnionWith(OnlyInSource);
     results.UnionWith(OnlyInTarget);
     results.UnionWith(DifferentContents);
     results.UnionWith(IdenticalContents);
     return results;
 } 
 public HashSet<EntityId> GetIds()
 {
     var set = new HashSet<EntityId>();
     set.UnionWith(_phoneDictionary.Select(x=>x.Key));
     set.UnionWith(_businessDictionary.Select(x=>x.Key));
     set.UnionWith(_personDictionary.Select(x=>x.Key));
     set.UnionWith(_locationDictionary.Select(x=>x.Key));
     return set;
 }
        public HashSet<char> GetVariables()
        {
            HashSet<char> variables = new HashSet<char>();

            variables.UnionWith(baseOfPower.GetVariables());
            variables.UnionWith(exponent.GetVariables());

            return variables;
        }
 /// <summary>
 /// Returns a HashSet of the two pockets and all of their contents.
 /// </summary>
 /// <returns>
 /// a HashSet of the two pockets and all of their contents.
 /// </returns>
 public HashSet<Thing> GetRecursiveContents()
 {
     HashSet<Thing> temp = new HashSet<Thing>();
     temp.Add(leftPocket);
     temp.Add(rightPocket);
     temp.UnionWith( leftPocket.GetRecursiveContents());
     temp.UnionWith(rightPocket.GetRecursiveContents());
     return temp;
 }
        public HashSet<char> GetVariables()
        {
            HashSet<char> variables = new HashSet<char>();

            variables.UnionWith(nthRoot.GetVariables());
            variables.UnionWith(baseOfRoot.GetVariables());

            return variables;
        }
        public IEnumerable<IWatcher> Materialize(KeeperState state, EventType type, string clientPath)
        {
            HashSet<IWatcher> result = new HashSet<IWatcher>();

            switch (type) {
                case EventType.None:
                    result.Add(defaultWatcher);
                    foreach (var ws in dataWatches.Values) {
                        result.UnionWith(ws);
                    }
                    foreach (var ws in existWatches.Values) {
                        result.UnionWith(ws);
                    }
                    foreach(var ws in childWatches.Values) {
                        result.UnionWith(ws);
                    }

                    // clear the watches if auto watch reset is not enabled
                    if (ClientConnection.DisableAutoWatchReset &&
                        state != KeeperState.SyncConnected)
                    {
                        dataWatches.Clear();
                        existWatches.Clear();
                        childWatches.Clear();
                    }

                    return result;
                case EventType.NodeDataChanged:
                case EventType.NodeCreated:
                        AddTo(dataWatches.GetAndRemove(clientPath), result);
                        AddTo(existWatches.GetAndRemove(clientPath), result);
                    break;
                case EventType.NodeChildrenChanged:
                        AddTo(childWatches.GetAndRemove(clientPath), result);
                    break;
                case EventType.NodeDeleted:
                        AddTo(dataWatches.GetAndRemove(clientPath), result);
                    // XXX This shouldn't be needed, but just in case
                        HashSet<IWatcher> list = existWatches.GetAndRemove(clientPath);
                        if (list != null) {
                            AddTo(existWatches.GetAndRemove(clientPath), result);
                            #if !NET_CORE
                            LOG.Warn("We are triggering an exists watch for delete! Shouldn't happen!");
                            #endif
                        }
                        AddTo(childWatches.GetAndRemove(clientPath), result);
                    break;
                default:
                    var msg = new StringBuilder("Unhandled watch event type ").Append(type).Append(" with state ").Append(state).Append(" on path ").Append(clientPath).ToString();
                    #if !NET_CORE
                    LOG.Error(msg);
                    #endif
                    throw new InvalidOperationException(msg);
            }

            return result;
        }
Beispiel #22
0
 public IEnumerable<IContact> GetSameContactsAs(IContact c)
 {
     var hash = new HashSet<IContact>();
     hash.UnionWith(GetContactsFor(c.FullName));
     foreach (string email in c.Emails)
     {
         hash.UnionWith(GetContactsFor(email));
     }
     return hash;
 }
        private static IEnumerable<Type> MergeKnownTypesWithDynamicProxyTypes(IEnumerable<Type> knownTypes)
        {
            var tmp = new HashSet<Type>();

            if (knownTypes != null)
                tmp.UnionWith(knownTypes);

            tmp.UnionWith(EfDynamicProxyAssemblies.GetTypes());

            return tmp;
        }
        public IEnumerable<PhonebookEntry> Find(string name, string town)
        {
            HashSet<PhonebookEntry> matchedByName = new HashSet<PhonebookEntry>();
            matchedByName.UnionWith(this.byFirstName[name]);
            matchedByName.UnionWith(this.byMiddleName[name]);
            matchedByName.UnionWith(this.byLastName[name]);
            matchedByName.UnionWith(this.byNickname[name]);

            IEnumerable<PhonebookEntry> matchedByNameAndTown =
                matchedByName.Where(entry => entry.Town == town);
            return matchedByNameAndTown;
        }
        /// <summary>
        /// Find all the possible implementations of the given type.
        /// </summary>
        public IEnumerable<Type> GetAllConcreteTypes(Type serviceType)
        {
            var types = new HashSet<Type>();

            if (mappings.ContainsKey(serviceType))
                types.UnionWith(mappings[serviceType]);

            if(Parent != null)
                types.UnionWith(Parent.GetAllConcreteTypes(serviceType));

            return types;
        }
        public CryptArithmeticProblem(CryptArithmeticInstanceDescription instanceDescriptor)
        {
            this.terms = instanceDescriptor.Terms;
            this.result = instanceDescriptor.Result;

            HashSet<char> charsInExpression = new HashSet<char>();
            foreach (string term in terms) {
                charsInExpression.UnionWith(term.ToCharArray());
            }
            charsInExpression.UnionWith(result.ToCharArray());
            charArray = charsInExpression.ToArray();
        }
Beispiel #27
0
        public static HashSet<CyPhyML.Component> getCyPhyMLComponentSet(CyPhyML.ComponentAssemblies cyPhyMLComponentAssemblies) {

            HashSet<CyPhyML.Component> cyPhyMLComponentSet = new HashSet<CyPhyML.Component>();

            foreach (CyPhyML.ComponentAssemblies childComponentAssembliesFolder in cyPhyMLComponentAssemblies.Children.ComponentAssembliesCollection) {
                cyPhyMLComponentSet.UnionWith(getCyPhyMLComponentSet(childComponentAssembliesFolder));
            }

            foreach (CyPhyML.ComponentAssembly childComponentAssemblyFolder in cyPhyMLComponentAssemblies.Children.ComponentAssemblyCollection) {
                cyPhyMLComponentSet.UnionWith(getCyPhyMLComponentSet(childComponentAssemblyFolder));
            }

            return cyPhyMLComponentSet;
        }
		public void SaveToFile(string suppressionsFilePath)
		{
			HashSet<string> lines = new HashSet<string>();
			lines.Add("[cppcheck]");
			lines.UnionWith(SuppressionLines);
			lines.Add("[cppcheck_files]");
			lines.UnionWith(SkippedFilesMask);
			lines.Add("[cppcheck_includes]");
			lines.UnionWith(SkippedIncludesMask);

			System.IO.FileInfo file = new System.IO.FileInfo(suppressionsFilePath);
			file.Directory.Create(); // If the directory already exists, this method does nothing.
			File.WriteAllLines(suppressionsFilePath, lines);
		}
        public static List<List<String>> OrderByCount(List<List<String>> list)
        {
            list = list.OrderBy(item => item.Count()).ToList();

            HashSet<string> sumAll = new HashSet<string>();
            HashSet<string> listIntersect = new HashSet<string>();
            HashSet<string> listExcept = new HashSet<string>();
            HashSet<string> listEndExc = new HashSet<string>();
            List<List<string>> tmpIntExc = new List<List<string>>(); // List of lists
            int i = 0;
            while (i < list.Count() - 1)
            {

                listIntersect = new HashSet<string>(list[i].Intersect(list[i + 1]));
                listIntersect.ExceptWith(sumAll);
                sumAll.UnionWith(listIntersect);

                listExcept = new HashSet<string>(list[i].Except(list[i + 1]));
                listExcept.ExceptWith(sumAll);
                sumAll.UnionWith(listExcept);

                i++;

                if (i == list.Count() - 1)
                {
                    listEndExc = new HashSet<string>(list[list.Count() - 1]);
                    listEndExc.ExceptWith(sumAll);

                }

                List<string> kkk = new List<string>(listIntersect);// List of Intersect
                List<string> mmm = new List<string>(listExcept);// List of Except
                List<string> nnn = new List<string>(listEndExc);
                if (kkk.Any())
                {
                    tmpIntExc.Add(kkk);
                }
                if (mmm.Any())
                {
                    tmpIntExc.Add(mmm);
                }
                if (nnn.Any())
                {
                    tmpIntExc.Add(nnn);
                }

            }

            return tmpIntExc.OrderBy(l=>l.Count).ThenBy((l=>l.First())).ToList(); //DisplaySet(tmpIntExc);
        }
        /// <summary>
        /// 返回文档所有节点,包括已分配和游离的
        /// </summary>
        /// <param name="document">查找节点的文档</param>
        /// <returns>文档的所有节点</returns>
        public static IEnumerable<IHtmlNode> AllNodes( this IHtmlDocument document )
        {
            if ( document == null )
            throw new ArgumentNullException( "document" );

              var nodes = new HashSet<IHtmlNode>();

              nodes.UnionWith( document.DescendantNodes() );

              var manager = document.FragmentManager;
              if ( manager != null )
            nodes.UnionWith( manager.AllFragments.SelectMany( fragment => fragment.DescendantNodes() ) );

              return nodes;
        }
Beispiel #31
0
        public static HashSet <string> RunHoudini(Program program, bool RobustAgainstEvaluate = false)
        {
            HoudiniStats.Reset();
            HoudiniInlining.RobustAgainstEvaluate = DualHoudini? false : RobustAgainstEvaluate;
            if (DualHoudini && CommandLineOptions.Clo.InlineDepth > 0)
            {
                throw new DualHoudiniFail("InlineDepth not supported");
            }

            // Gather existential constants
            var CandidateConstants = new Dictionary <string, Constant>();

            program.TopLevelDeclarations.OfType <Constant>()
            .Where(c => QKeyValue.FindBoolAttribute(c.Attributes, "existential"))
            .Iter(c => CandidateConstants.Add(c.Name, c));

            // Create a function, one for each impl, for book-keeping
            var CandidateFuncsAssumed  = new Dictionary <string, Function>();
            var CandidateFuncsAsserted = new Dictionary <string, Function>();
            var AssumeToAssert         = new Dictionary <Function, Function>();

            program.TopLevelDeclarations.OfType <Implementation>()
            .Iter(impl =>
            {
                var fassumed  = GetCandidateFunc(CandidateFuncPrefix, impl.Name);
                var fasserted = GetCandidateFunc(CandidateFuncAssertedPrefix, impl.Name);
                CandidateFuncsAssumed.Add(impl.Name, fassumed);
                CandidateFuncsAsserted.Add(impl.Name, fasserted);
                AssumeToAssert.Add(fassumed, fasserted);
            });


            // Tag the ensures so we can keep track of them
            var iterimpls = program.TopLevelDeclarations.OfType <Implementation>().ToList();

            iterimpls.Iter(impl => InstrumentEnsures(program, impl, CandidateFuncsAssumed[impl.Name], CandidateConstants));

            //BoogieUtil.PrintProgram(program, "h2.bpl");

            var RewriteAssumedToAssertedAction = new Action <Implementation>(impl =>
            {
                // Rewrite functions that are asserted
                var rewrite = new RewriteFuncs(AssumeToAssert);
                foreach (var blk in impl.Blocks)
                {
                    foreach (var acmd in blk.Cmds.OfType <AssertCmd>())
                    {
                        acmd.Expr = rewrite.VisitExpr(acmd.Expr);
                    }
                }

                var funcs = new HashSet <Function>(CandidateFuncsAssumed.Values);
                // Move call-site constant to the first argument of CandidateFuncs
                foreach (var blk in impl.Blocks)
                {
                    Expr cv = null;
                    // walk backwards
                    for (int i = blk.Cmds.Count - 1; i >= 0; i--)
                    {
                        var acmd = blk.Cmds[i] as AssumeCmd;
                        if (acmd == null)
                        {
                            continue;
                        }

                        if (QKeyValue.FindBoolAttribute(acmd.Attributes, StratifiedVCGenBase.callSiteVarAttr))
                        {
                            cv = acmd.Expr;
                            continue;
                        }

                        InsertControlVar.Apply(acmd.Expr, funcs, cv);
                    }
                }

                //impl.Emit(new TokenTextWriter(Console.Out), 0);
            });

            program.AddTopLevelDeclarations(CandidateFuncsAssumed.Values);
            program.AddTopLevelDeclarations(CandidateFuncsAsserted.Values);

            var callgraph     = BoogieUtil.GetCallGraph(program);
            var impl2Priority = DeterminePriorityOrder(program, callgraph);
            var impls         = new HashSet <string>(impl2Priority.Keys);

            HoudiniStats.Start("VCGen");

            // VC Gen
            var hi = new HoudiniInlining(program, CommandLineOptions.Clo.SimplifyLogFilePath, CommandLineOptions.Clo.SimplifyLogFileAppend, RewriteAssumedToAssertedAction);

            HoudiniStats.Stop("VCGen");

            var worklist = new SortedSet <Tuple <int, string> >();

            impl2Priority.Iter(tup => worklist.Add(Tuple.Create(tup.Value, tup.Key)));

            // Current assignment: set of true constants
            // Initially: everything is true
            var assignment = new HashSet <string>(CandidateConstants.Keys);

            var prover   = hi.prover;
            var reporter = new EmptyErrorReporter();

            // assert true to flush all one-time axioms, decls, etc
            prover.Assert(VCExpressionGenerator.True, true);

            HoudiniStats.Start("MainLoop");

            // worklist algorithm
            while (worklist.Any())
            {
                var implName = worklist.First().Item2;
                worklist.Remove(worklist.First());

                if (dbg)
                {
                    Console.WriteLine("Processing " + implName);
                }
                prover.LogComment("Processing " + implName);

                prover.Push();

                var hvc           = new HoudiniVC(hi.implName2StratifiedInliningInfo[implName], impls, assignment);
                var openCallSites = new HashSet <StratifiedCallSite>(hvc.CallSites);
                prover.Assert(hvc.vcexpr, true);

                var candidates = !DualHoudini ? new HashSet <string>(hvc.constantToAssertedExpr.Keys.Where(k => assignment.Contains(k))) :
                                 new HashSet <string>(hvc.constantToAssumedExpr.Select(t => t.Item1).Where(k => assignment.Contains(k)));

                var provedTrue  = new HashSet <string>();
                var provedFalse = new HashSet <string>();
                var idepth      = Math.Max(0, CommandLineOptions.Clo.InlineDepth);

                // iterate over idepth
                while (true)
                {
                    // Part 1: over-approximate
                    var proved = ProveCandidates(prover, hvc.constantToAssertedExpr, hvc.constantToAssumedExpr, candidates.Difference(provedTrue.Union(provedFalse)));
                    provedTrue.UnionWith(proved);
                    if (dbg)
                    {
                        Console.WriteLine("Proved {0} candiates at depth {1}", proved.Count, CommandLineOptions.Clo.InlineDepth - idepth);
                    }

                    if (idepth == 0 || openCallSites.Count == 0)
                    {
                        break;
                    }

                    // Part 2: under-approximate
                    prover.Push();
                    foreach (var cs in openCallSites)
                    {
                        prover.Assert(cs.callSiteExpr, false);
                    }

                    var remaining = candidates.Difference(provedTrue.Union(provedFalse));
                    proved = ProveCandidates(prover, hvc.constantToAssertedExpr, hvc.constantToAssumedExpr, remaining);
                    provedFalse.UnionWith(remaining.Difference(proved));
                    if (dbg)
                    {
                        Console.WriteLine("Disproved {0} candiates at depth {1}", remaining.Difference(proved).Count, CommandLineOptions.Clo.InlineDepth - idepth);
                    }

                    prover.Pop();

                    // resolved all?
                    if (candidates.Difference(provedTrue.Union(provedFalse)).Count == 0)
                    {
                        break;
                    }

                    // Inline one level
                    idepth--;
                    var nextOpenCallSites = new HashSet <StratifiedCallSite>();
                    foreach (var cs in openCallSites)
                    {
                        var callee   = new HoudiniVC(hi.implName2StratifiedInliningInfo[cs.callSite.calleeName], impls, assignment);
                        var calleevc = cs.Attach(callee);
                        prover.Assert(prover.VCExprGen.Implies(cs.callSiteExpr, calleevc), true);
                        nextOpenCallSites.UnionWith(callee.CallSites);
                    }
                    openCallSites = nextOpenCallSites;
                }

                prover.Pop();

                var failed = candidates.Difference(provedTrue);
                assignment.ExceptWith(failed);

                if (failed.Count != 0)
                {
                    // add dependencies back into the worklist
                    if (!DualHoudini)
                    {
                        foreach (var caller in callgraph.Predecessors(implName))
                        {
                            worklist.Add(Tuple.Create(impl2Priority[caller], caller));
                        }
                    }
                    else
                    {
                        foreach (var caller in callgraph.Successors(implName))
                        {
                            worklist.Add(Tuple.Create(impl2Priority[caller], caller));
                        }
                    }
                }
            }

            HoudiniStats.Stop("MainLoop");

            hi.Close();

            return(assignment);
        }
Beispiel #32
0
        public Dictionary <string, List <CommentObj> > GetNamedObjects(int N)
        {
            StringBuilder sbAllWords = new StringBuilder();

            foreach (children child in children)
            {
                sbAllWords.Append(child.SubtreeText);
                sbAllWords.Append(" ");
            }
            string[] allWords = GetAllWords(sbAllWords.ToString());
            Dictionary <string, string> stemParentDictionary = GetStemParentDictionary(allWords);
            List <string>         namedObjects = new List <string>();
            children              rootNode     = new children();
            List <HashSet <int> > rootChildIDs = new List <HashSet <int> >();

            foreach (children child in children)
            {
                GetChildIDHashSetList(child);
                HashSet <int> currChildIDs = new HashSet <int>();
                currChildIDs.Add(child.id);
                foreach (var item in child.ChildIDList)
                {
                    currChildIDs.UnionWith(item);
                }
                rootChildIDs.Add(currChildIDs);
            }
            rootNode.ChildIDList = rootChildIDs;
            NodeList             = new List <children>();
            NodeList.Add(rootNode);
            foreach (children child in children)
            {
                PopulateNodeList(child);
            }
            Dictionary <string, HashSet <int> > wordIDMapping = GetWordIDMapping();
            //Dictionary<string, double> WordTreeScore = new Dictionary<string, double>();
            Dictionary <string, List <children> > WordLCAList = new Dictionary <string, List <children> >();

            foreach (var kvp in wordIDMapping)
            {
                List <children> currLCAList = new List <children>();
                int             numLCAs     = 0;
                foreach (children node in NodeList)
                {
                    int numBranchesWithWord = 0;
                    foreach (var childIDBranch in node.ChildIDList)
                    {
                        if (childIDBranch.Intersect(kvp.Value).Count() > 0)
                        {
                            numBranchesWithWord += 1;
                        }
                    }
                    if ((numBranchesWithWord == 1 && node.ChildIDList.Count == 1) || numBranchesWithWord > 1)
                    {
                        currLCAList.Add(node);
                    }
                }
                WordLCAList[stemParentDictionary.ContainsKey(kvp.Key) ? stemParentDictionary[kvp.Key] : kvp.Key] = currLCAList;
            }
            namedObjects = WordLCAList
                           .OrderByDescending(x => x.Value.Count)
                           .Select(x => x.Key)
                           .Where(y => CommonWords.GetFrequency(y) < 1)
                           .Where(a => char.IsUpper(a[0]))
                           .Where(b => b.Length > 1)
                           .Where(z => !(z.EndsWith("n't") || z.EndsWith("'m") || (z.EndsWith("'ll")) || (z.EndsWith("'d")) || z.EndsWith("'ve") || z.EndsWith("'re") || z.EndsWith("'s")))
                           .Take(N)
                           .ToList();
            //namedObjects.Sort();
            Dictionary <string, List <CommentObj> > namedObjectDictionary = new Dictionary <string, List <CommentObj> >();

            foreach (string namedObject in namedObjects)
            {
                List <CommentObj> commentObjsForWord = new List <CommentObj>();
                string            stem        = Stemmer.GetStem(namedObject);
                HashSet <int>     idsWithWord = wordIDMapping[stem];
                foreach (int id in idsWithWord)
                {
                    children   child      = GetNodeById(id);
                    CommentObj commentObj = new CommentObj()
                    {
                        Id = id, Text = child.text
                    };
                    commentObjsForWord.Add(commentObj);
                }
                namedObjectDictionary[namedObject] = commentObjsForWord;
            }
            var ordered = namedObjectDictionary.Keys.OrderByDescending(x => namedObjectDictionary[x].Count).ToList().ToDictionary(x => x, x => namedObjectDictionary[x]);

            return(ordered);
        }
Beispiel #33
0
        internal void PrefetchCompositesRoleRelationTable(HashSet <Reference> associations, IRoleType roleType, HashSet <long> nestedObjectIds, HashSet <long> leafs)
        {
            var references = nestedObjectIds == null?this.FilterForPrefetchRoles(associations, roleType) : this.FilterForPrefetchCompositesRoles(associations, roleType, nestedObjectIds);

            if (references.Count == 0)
            {
                return;
            }

            Command command;

            if (!this.PrefetchCompositesRoleByRoleType.TryGetValue(roleType, out command))
            {
                var sql = this.Database.Mapping.ProcedureNameForPrefetchRoleByRelationType[roleType.RelationType];
                command             = this.Session.Connection.CreateCommand();
                command.CommandText = sql;
                command.CommandType = CommandType.StoredProcedure;
                command.AddObjectTableParameter(references);
                this.prefetchCompositesRoleByRoleType[roleType] = command;
            }
            else
            {
                command.Parameters[Mapping.ParamNameForTableType].Value = this.Database.CreateObjectTable(references);
            }

            var rolesByAssociation = new Dictionary <Reference, List <long> >();

            using (DbDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    var associationId        = reader.GetInt64(0);
                    var associationReference = this.Session.State.ReferenceByObjectId[associationId];

                    var         roleId = reader.GetInt64(1);
                    List <long> roleIds;
                    if (!rolesByAssociation.TryGetValue(associationReference, out roleIds))
                    {
                        roleIds = new List <long>();
                        rolesByAssociation[associationReference] = roleIds;
                    }

                    roleIds.Add(roleId);
                }
            }

            var cache = this.Database.Cache;

            foreach (var reference in references)
            {
                Roles modifiedRoles = null;
                if (this.Session.State.ModifiedRolesByReference != null)
                {
                    this.Session.State.ModifiedRolesByReference.TryGetValue(reference, out modifiedRoles);
                }

                if (modifiedRoles == null || !modifiedRoles.ModifiedRoleByRoleType.ContainsKey(roleType))
                {
                    var cachedObject = cache.GetOrCreateCachedObject(reference.Class, reference.ObjectId, reference.VersionId);

                    List <long> roleIds;
                    if (rolesByAssociation.TryGetValue(reference, out roleIds))
                    {
                        cachedObject.SetValue(roleType, roleIds.ToArray());

                        nestedObjectIds?.UnionWith(roleIds);
                        if (nestedObjectIds == null)
                        {
                            leafs.UnionWith(roleIds);
                        }
                    }
                    else
                    {
                        cachedObject.SetValue(roleType, EmptyObjectIds);
                    }
                }
            }
        }
Beispiel #34
0
        internal ShaderCompilationContext ParseAndAnalyze(ShaderMixinSource shaderMixinSource, Xenko.Shaders.ShaderMacro[] macros, out ShaderMixinParsingResult parsingResult, out HashSet <ModuleMixinInfo> mixinsToAnalyze)
        {
            // Creates a parsing result
            parsingResult = new ShaderMixinParsingResult();

            SiliconStudio.Shaders.Parser.ShaderMacro[] macrosParser;
            if (macros == null)
            {
                macrosParser = new SiliconStudio.Shaders.Parser.ShaderMacro[0];
            }
            else
            {
                macrosParser = new SiliconStudio.Shaders.Parser.ShaderMacro[macros.Length];
                for (var i = 0; i < macros.Length; ++i)
                {
                    macrosParser[i] = new SiliconStudio.Shaders.Parser.ShaderMacro(macros[i].Name, macros[i].Definition);
                }
            }
            //PerformanceLogger.Start(PerformanceStage.Global);

            // ----------------------------------------------------------
            // Load all shaders
            // ----------------------------------------------------------
            lock (shaderLibrary)
            {
                //PerformanceLogger.Start(PerformanceStage.Loading);
                mixinsToAnalyze = shaderLibrary.LoadShaderSource(shaderMixinSource, macrosParser);
                //PerformanceLogger.Stop(PerformanceStage.Loading);
            }

            // Extract all ModuleMixinInfo and check for any errors
            var allMixinInfos = new HashSet <ModuleMixinInfo>();

            foreach (var moduleMixinInfo in mixinsToAnalyze)
            {
                allMixinInfos.UnionWith(moduleMixinInfo.MinimalContext);
            }
            foreach (var moduleMixinInfo in allMixinInfos)
            {
                moduleMixinInfo.Log.CopyTo(parsingResult);

                var ast = moduleMixinInfo.MixinAst;
                var shaderClassSource = moduleMixinInfo.ShaderSource as ShaderClassSource;
                // If we have a ShaderClassSource and it is not an inline one, then we can store the hash sources
                if (ast != null && shaderClassSource != null)
                {
                    parsingResult.HashSources[shaderClassSource.ClassName] = ast.SourceHash;
                }
            }

            // Return directly if there was any errors
            if (parsingResult.HasErrors)
            {
                return(null);
            }

            // ----------------------------------------------------------
            // Perform Type Analysis
            // ----------------------------------------------------------
            //PerformanceLogger.Start(PerformanceStage.TypeAnalysis);
            var context = GetCompilationContext(mixinsToAnalyze, parsingResult);

            //PerformanceLogger.Stop(PerformanceStage.TypeAnalysis);

            // Return directly if there was any errors
            if (parsingResult.HasErrors)
            {
                return(context);
            }

            lock (SemanticAnalyzerLock)
            {
                //PerformanceLogger.Start(PerformanceStage.SemanticAnalysis);
                //SemanticPerformance.Start(SemanticStage.Global);
                foreach (var mixin in mixinsToAnalyze)
                {
                    context.Analyze(mixin);
                }
                //SemanticPerformance.Pause(SemanticStage.Global);
                //PerformanceLogger.Stop(PerformanceStage.SemanticAnalysis);
            }

            return(context);
        }
Beispiel #35
0
        public async Task <IActionResult> PostInputsAsync([FromBody, Required] InputsRequest request)
        {
            // Validate request.
            if (request.RoundId < 0 || !ModelState.IsValid)
            {
                return(BadRequest("Invalid request."));
            }

            if (request.Inputs.Count() > 7)
            {
                return(BadRequest("Maximum 7 inputs can be registered."));
            }

            using (await InputsLock.LockAsync())
            {
                CcjRound round = Coordinator.TryGetRound(request.RoundId);

                if (round is null || round.Phase != CcjRoundPhase.InputRegistration)
                {
                    return(NotFound("No such running round in InputRegistration. Try another round."));
                }

                // Do more checks.
                try
                {
                    uint256[] blindedOutputs        = request.BlindedOutputScripts.ToArray();
                    int       blindedOutputCount    = blindedOutputs.Length;
                    int       maxBlindedOutputCount = round.MixingLevels.Count();
                    if (blindedOutputCount > maxBlindedOutputCount)
                    {
                        return(BadRequest($"Too many blinded output was provided: {blindedOutputCount}, maximum: {maxBlindedOutputCount}."));
                    }

                    if (blindedOutputs.Distinct().Count() < blindedOutputs.Length)
                    {
                        return(BadRequest("Duplicate blinded output found."));
                    }

                    if (round.ContainsAnyBlindedOutputScript(blindedOutputs))
                    {
                        return(BadRequest("Blinded output has already been registered."));
                    }

                    if (request.ChangeOutputAddress.Network != Network)
                    {
                        // RegTest and TestNet address formats are sometimes the same.
                        if (Network == Network.Main)
                        {
                            return(BadRequest($"Invalid ChangeOutputAddress Network."));
                        }
                    }

                    var uniqueInputs = new HashSet <TxoRef>();
                    foreach (InputProofModel inputProof in request.Inputs)
                    {
                        if (uniqueInputs.Contains(inputProof.Input))
                        {
                            return(BadRequest("Cannot register an input twice."));
                        }
                        uniqueInputs.Add(inputProof.Input);
                    }

                    var alicesToRemove    = new HashSet <Guid>();
                    var getTxOutResponses = new List <(InputProofModel inputModel, Task <GetTxOutResponse> getTxOutTask)>();

                    var batch = RpcClient.PrepareBatch();

                    foreach (InputProofModel inputProof in request.Inputs)
                    {
                        if (round.ContainsInput(inputProof.Input.ToOutPoint(), out List <Alice> tr))
                        {
                            alicesToRemove.UnionWith(tr.Select(x => x.UniqueId));                             // Input is already registered by this alice, remove it later if all the checks are completed fine.
                        }
                        if (Coordinator.AnyRunningRoundContainsInput(inputProof.Input.ToOutPoint(), out List <Alice> tnr))
                        {
                            if (tr.Union(tnr).Count() > tr.Count())
                            {
                                return(BadRequest("Input is already registered in another round."));
                            }
                        }

                        OutPoint outpoint   = inputProof.Input.ToOutPoint();
                        var      bannedElem = await Coordinator.UtxoReferee.TryGetBannedAsync(outpoint, notedToo : false);

                        if (bannedElem != null)
                        {
                            return(BadRequest($"Input is banned from participation for {(int)bannedElem.BannedRemaining.TotalMinutes} minutes: {inputProof.Input.Index}:{inputProof.Input.TransactionId}."));
                        }

                        var txoutResponseTask = batch.GetTxOutAsync(inputProof.Input.TransactionId, (int)inputProof.Input.Index, includeMempool: true);
                        getTxOutResponses.Add((inputProof, txoutResponseTask));
                    }

                    // Perform all RPC request at once
                    var waiting = Task.WhenAll(getTxOutResponses.Select(x => x.getTxOutTask));
                    await batch.SendBatchAsync();

                    await waiting;

                    byte[]  blindedOutputScriptHashesByte = ByteHelpers.Combine(blindedOutputs.Select(x => x.ToBytes()));
                    uint256 blindedOutputScriptsHash      = new uint256(Hashes.SHA256(blindedOutputScriptHashesByte));

                    var inputs = new HashSet <Coin>();

                    foreach (var responses in getTxOutResponses)
                    {
                        var(inputProof, getTxOutResponseTask) = responses;
                        var getTxOutResponse = await getTxOutResponseTask;

                        // Check if inputs are unspent.
                        if (getTxOutResponse is null)
                        {
                            return(BadRequest($"Provided input is not unspent: {inputProof.Input.Index}:{inputProof.Input.TransactionId}."));
                        }

                        // Check if unconfirmed.
                        if (getTxOutResponse.Confirmations <= 0)
                        {
                            // If it spends a CJ then it may be acceptable to register.
                            if (!await Coordinator.ContainsCoinJoinAsync(inputProof.Input.TransactionId))
                            {
                                return(BadRequest("Provided input is neither confirmed, nor is from an unconfirmed coinjoin."));
                            }

                            // Check if mempool would accept a fake transaction created with the registered inputs.
                            // This will catch ascendant/descendant count and size limits for example.
                            var result = await RpcClient.TestMempoolAcceptAsync(new[] { new Coin(inputProof.Input.ToOutPoint(), getTxOutResponse.TxOut) });

                            if (!result.accept)
                            {
                                return(BadRequest($"Provided input is from an unconfirmed coinjoin, but a limit is reached: {result.rejectReason}"));
                            }
                        }

                        // Check if immature.
                        if (getTxOutResponse.Confirmations <= 100)
                        {
                            if (getTxOutResponse.IsCoinBase)
                            {
                                return(BadRequest("Provided input is immature."));
                            }
                        }

                        // Check if inputs are native segwit.
                        if (getTxOutResponse.ScriptPubKeyType != "witness_v0_keyhash")
                        {
                            return(BadRequest("Provided input must be witness_v0_keyhash."));
                        }

                        TxOut txout = getTxOutResponse.TxOut;

                        var address = (BitcoinWitPubKeyAddress)txout.ScriptPubKey.GetDestinationAddress(Network);
                        // Check if proofs are valid.
                        if (!address.VerifyMessage(blindedOutputScriptsHash, inputProof.Proof))
                        {
                            return(BadRequest("Provided proof is invalid."));
                        }

                        inputs.Add(new Coin(inputProof.Input.ToOutPoint(), txout));
                    }

                    var acceptedBlindedOutputScripts = new List <uint256>();

                    // Calculate expected networkfee to pay after base denomination.
                    int   inputCount = inputs.Count();
                    Money networkFeeToPayAfterBaseDenomination = (inputCount * round.FeePerInputs) + (2 * round.FeePerOutputs);

                    // Check if inputs have enough coins.
                    Money inputSum     = inputs.Sum(x => x.Amount);
                    Money changeAmount = (inputSum - (round.MixingLevels.GetBaseDenomination() + networkFeeToPayAfterBaseDenomination));
                    if (changeAmount < Money.Zero)
                    {
                        return(BadRequest($"Not enough inputs are provided. Fee to pay: {networkFeeToPayAfterBaseDenomination.ToString(false, true)} BTC. Round denomination: {round.MixingLevels.GetBaseDenomination().ToString(false, true)} BTC. Only provided: {inputSum.ToString(false, true)} BTC."));
                    }
                    acceptedBlindedOutputScripts.Add(blindedOutputs.First());

                    Money networkFeeToPay = networkFeeToPayAfterBaseDenomination;
                    // Make sure we sign the proper number of additional blinded outputs.
                    var moneySoFar = Money.Zero;
                    for (int i = 1; i < blindedOutputCount; i++)
                    {
                        if (!round.MixingLevels.TryGetDenomination(i, out Money denomination))
                        {
                            break;
                        }

                        Money coordinatorFee = denomination.Percentage(round.CoordinatorFeePercent * round.AnonymitySet);                         // It should be the number of bobs, but we must make sure they'd have money to pay all.
                        changeAmount    -= (denomination + round.FeePerOutputs + coordinatorFee);
                        networkFeeToPay += round.FeePerOutputs;

                        if (changeAmount < Money.Zero)
                        {
                            break;
                        }

                        acceptedBlindedOutputScripts.Add(blindedOutputs[i]);
                    }

                    // Make sure Alice checks work.
                    var alice = new Alice(inputs, networkFeeToPayAfterBaseDenomination, request.ChangeOutputAddress, acceptedBlindedOutputScripts);

                    foreach (Guid aliceToRemove in alicesToRemove)
                    {
                        round.RemoveAlicesBy(aliceToRemove);
                    }
                    round.AddAlice(alice);

                    // All checks are good. Sign.
                    var blindSignatures = new List <uint256>();
                    for (int i = 0; i < acceptedBlindedOutputScripts.Count; i++)
                    {
                        var     blindedOutput  = acceptedBlindedOutputScripts[i];
                        var     signer         = round.MixingLevels.GetLevel(i).Signer;
                        uint256 blindSignature = signer.Sign(blindedOutput);
                        blindSignatures.Add(blindSignature);
                    }
                    alice.BlindedOutputSignatures = blindSignatures.ToArray();

                    // Check if phase changed since.
                    if (round.Status != CcjRoundStatus.Running || round.Phase != CcjRoundPhase.InputRegistration)
                    {
                        return(StatusCode(StatusCodes.Status503ServiceUnavailable, "The state of the round changed while handling the request. Try again."));
                    }

                    // Progress round if needed.
                    if (round.CountAlices() >= round.AnonymitySet)
                    {
                        await round.RemoveAlicesIfAnInputRefusedByMempoolAsync();

                        if (round.CountAlices() >= round.AnonymitySet)
                        {
                            await round.ExecuteNextPhaseAsync(CcjRoundPhase.ConnectionConfirmation);
                        }
                    }

                    var resp = new InputsResponse {
                        UniqueId = alice.UniqueId,
                        RoundId  = round.RoundId
                    };
                    return(Ok(resp));
                }
                catch (Exception ex)
                {
                    Logger.LogDebug <ChaumianCoinJoinController>(ex);
                    return(BadRequest(ex.Message));
                }
            }
        }
Beispiel #36
0
        public static void GenerateDependencies(string strippedAssemblyDir, string icallsListFile, RuntimeClassRegistry rcr, bool doStripping, out HashSet <UnityType> nativeClasses, out HashSet <string> nativeModules, IIl2CppPlatformProvider platformProvider)
        {
            if (AssemblyStripper.UseUnityLinkerEngineModuleStripping)
            {
                GenerateDependencies2(strippedAssemblyDir, doStripping, out nativeClasses, out nativeModules);
                return;
            }

            var strippingInfo  = platformProvider == null ? null : StrippingInfo.GetBuildReportData(platformProvider.buildReport);
            var userAssemblies = GetUserAssemblies(strippedAssemblyDir);

            // [1] Extract native classes from scene and scripts
            nativeClasses = doStripping ? GenerateNativeClassList(rcr, strippedAssemblyDir, userAssemblies, strippingInfo) : null;

            // Exclude module managers (GlobalGameManager) if no dependent classes are used.
            if (nativeClasses != null)
            {
                ExcludeModuleManagers(ref nativeClasses);
            }

            // [2] Prepare a list of modules to register
            nativeModules = GetNativeModulesToRegister(nativeClasses, strippingInfo);

            if (nativeClasses != null && icallsListFile != null)
            {
                // Get required modules from icall list file
                var icallModules = GetModulesFromICalls(icallsListFile);

                // Add GameManager classes for modules
                foreach (var module in icallModules)
                {
                    if (!nativeModules.Contains(module))
                    {
                        if (strippingInfo != null)
                        {
                            strippingInfo.RegisterDependency(StrippingInfo.ModuleName(module), StrippingInfo.RequiredByScripts);
                        }
                    }

                    var moduleClasses = ModuleMetadata.GetModuleTypes(module);
                    foreach (var klass in moduleClasses)
                    {
                        if (klass.IsDerivedFrom(GameManagerTypeInfo))
                        {
                            nativeClasses.Add(klass);
                        }
                    }
                }

                nativeModules.UnionWith(icallModules);
            }

            ApplyManualStrippingOverrides(nativeClasses, nativeModules, strippingInfo);

            bool didAdd = true;

            if (platformProvider != null)
            {
                while (didAdd)
                {
                    didAdd = false;
                    foreach (var module in nativeModules.ToList())
                    {
                        var dependecies = ModuleMetadata.GetModuleDependencies(module);
                        foreach (var dependentModule in dependecies)
                        {
                            if (!nativeModules.Contains(dependentModule))
                            {
                                nativeModules.Add(dependentModule);
                                didAdd = true;
                            }
                            if (strippingInfo != null)
                            {
                                var moduleName = StrippingInfo.ModuleName(module);
                                strippingInfo.RegisterDependency(StrippingInfo.ModuleName(dependentModule), "Required by " + moduleName);
                                strippingInfo.SetIcon("Required by " + moduleName, $"package/com.unity.modules.{module.ToLower()}");
                            }
                        }
                    }
                }
            }

            if (nativeClasses != null)
            {
                RemoveClassesFromRemovedModules(nativeClasses, nativeModules);
            }

            AssemblyReferenceChecker checker = new AssemblyReferenceChecker();

            checker.CollectReferencesFromRoots(strippedAssemblyDir, userAssemblies, true, 0.0f, true);

            if (strippingInfo != null)
            {
                foreach (var module in nativeModules)
                {
                    strippingInfo.AddModule(module);
                }
                strippingInfo.AddModule("Core");
            }

            if (nativeClasses != null && strippingInfo != null && platformProvider != null)
            {
                InjectCustomDependencies(platformProvider.target, strippingInfo, nativeClasses, nativeModules);
            }
        }
Beispiel #37
0
		/// <summary>
		/// Get an list of languages that match the given string in some way (code, name, country)
		/// </summary>
		public IEnumerable<LanguageInfo> SuggestLanguages(string searchString)
		{
			if (searchString != null)
				searchString = searchString.Trim();
			if (string.IsNullOrEmpty(searchString))
				yield break;

			if (searchString == "*")
			{
				// there will be duplicate LanguageInfo entries for 2 and 3 letter codes and equivalent tags
				var all_languages = new HashSet<LanguageInfo>(_codeToLanguageIndex.Select(l => l.Value));
				foreach (LanguageInfo languageInfo in all_languages.OrderBy(l => l, new ResultComparer(searchString)))
					yield return languageInfo;
			}
			// if the search string exactly matches a hard-coded way to say "sign", show all the sign languages
			// there will be duplicate LanguageInfo entries for equivalent tags
			else if (new []{"sign", "sign language","signes", "langage des signes", "señas","lenguaje de señas"}.Contains(searchString.ToLowerInvariant()))
			{
				var parallelSearch = new HashSet<LanguageInfo>(_codeToLanguageIndex.AsParallel().Select(li => li.Value).Where(l =>
					l.Names.AsQueryable().Any(n => n.ToLowerInvariant().Contains("sign"))));
				foreach (LanguageInfo languageInfo in parallelSearch)
				{
					yield return languageInfo;
				}
			}
			else
			{
				IEnumerable<LanguageInfo> matchOnCode = from x in _codeToLanguageIndex where x.Key.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase) select x.Value;
				List<LanguageInfo>[] matchOnName = (from x in _nameToLanguageIndex where x.Key.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase) select x.Value).ToArray();
				// Apostrophes can cause trouble in lookup.  Unicode TR-29 inexplicably says to use
				// u2019 (RIGHT SINGLE QUOTATION MARK) for the English apostrophe when it also defines
				// u02BC (MODIFIER LETTER APOSTROPHE) as a Letter character.  Users are quite likely to
				// type the ASCII apostrophe (u0027) which is defined as Punctuation.  The current
				// data appears to use u2019 in several language names, which means that users might
				// end up thinking the language isn't in our database.
				// See https://silbloom.myjetbrains.com/youtrack/issue/BL-6339.
				if (!matchOnName.Any() && searchString.Contains('\''))
				{
					searchString = searchString.Replace('\'','\u2019');
					matchOnName = (from x in _nameToLanguageIndex where x.Key.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase) select x.Value).ToArray();
				}
				List<LanguageInfo>[] matchOnCountry = (from x in _countryToLanguageIndex where x.Key.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase) select x.Value).ToArray();

				if (!matchOnName.Any())
				{
					// look  for approximate matches
					const int kMaxEditDistance = 3;
					var itemFormExtractor = new ApproximateMatcher.GetStringDelegate<KeyValuePair<string, List<LanguageInfo>>>(pair => pair.Key);
					IList<KeyValuePair<string, List<LanguageInfo>>> matches = ApproximateMatcher.FindClosestForms(_nameToLanguageIndex, itemFormExtractor,
						searchString,
						ApproximateMatcherOptions.None,
						kMaxEditDistance);
					matchOnName = (from m in matches select m.Value).ToArray();
				}

				var combined = new HashSet<LanguageInfo>(matchOnCode);
				foreach (List<LanguageInfo> l in matchOnName)
					combined.UnionWith(l);
				foreach (List<LanguageInfo> l in matchOnCountry)
					combined.UnionWith(l);
				var ordered = combined.OrderBy(l => l, new ResultComparer(searchString));
				foreach (LanguageInfo languageInfo in ordered)
					yield return languageInfo;
			}
		}
Beispiel #38
0
        public void UpdateReachableTransitions(string newThing = null, bool item = false, ProgressionManager _pm = null)
        {
            if (_pm != null)
            {
                pm = _pm;
            }
            if (newThing == null)
            {
                newThing = Randomizer.startTransition;
            }

            Queue <string> updates = new Queue <string>();

            if (!item)
            {
                reachableTransitions.Add(newThing);
            }
            pm.Add(newThing);
            updates.Enqueue(newThing);

            while (updates.Any())
            {
                string next = updates.Dequeue();
                if (transitionPlacements.TryGetValue(next, out string next2) && !reachableTransitions.Contains(next2))
                {
                    reachableTransitions.Add(next2);
                    pm.Add(next2);
                    updates.Enqueue(next2);
                }

                HashSet <string> potentialTransitions = LogicManager.GetTransitionsByProgression(recentProgression);

                // update possible vanilla locations
                HashSet <string> potentialLocations = LogicManager.GetLocationsByProgression(recentProgression);
                potentialLocations.IntersectWith(vanillaProgression);
                if (potentialLocations.Any())
                {
                    checkProgression.UnionWith(potentialLocations);
                    vanillaProgression.ExceptWith(checkProgression);
                }

                recentProgression = new HashSet <string>();



                foreach (string transition in potentialTransitions)
                {
                    if (!reachableTransitions.Contains(transition) && pm.CanGet(transition))
                    {
                        reachableTransitions.Add(transition);
                        pm.Add(transition);
                        updates.Enqueue(transition);
                        if (transitionPlacements.TryGetValue(transition, out string transition2))
                        {
                            reachableTransitions.Add(transition2);
                            pm.Add(transition2);
                            updates.Enqueue(transition2);
                        }
                    }
                }

                if (!updates.Any()) // vanilla locations are very unlikely to enter into logic, so we only check them right before the loop ends
                {
                    List <string> iterate = new List <string>();
                    foreach (string loc in checkProgression)
                    {
                        if (pm.CanGet(loc))
                        {
                            pm.Add(loc);
                            iterate.Add(loc); // **Don't**modify**collection**while**iterating**
                            updates.Enqueue(loc);
                        }
                    }
                    checkProgression.ExceptWith(iterate);
                }
            }
        }
        /// <summary>
        ///     Merges the given <paramref name="other" /> CardinalityEstimator instance into this one
        /// </summary>
        /// <param name="other">another instance of CardinalityEstimator</param>
        public void Merge(CardinalityEstimator other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            if (other._m != this._m)
            {
                throw new ArgumentOutOfRangeException(nameof(other),
                                                      "Cannot merge CardinalityEstimator instances with different accuracy/map sizes");
            }

            this.CountAdditions += other.CountAdditions;
            if (this._isSparse && other._isSparse)
            {
                // Merge two sparse instances
                foreach (KeyValuePair <ushort, byte> kvp in other._lookupSparse)
                {
                    ushort index     = kvp.Key;
                    byte   otherRank = kvp.Value;
                    byte   thisRank;
                    this._lookupSparse.TryGetValue(index, out thisRank);
                    this._lookupSparse[index] = Math.Max(thisRank, otherRank);
                }

                // Switch to dense if necessary
                if (this._lookupSparse.Count > this._sparseMaxElements)
                {
                    SwitchToDenseRepresentation();
                }
            }
            else
            {
                // Make sure this (target) instance is dense, then merge
                SwitchToDenseRepresentation();
                if (other._isSparse)
                {
                    foreach (KeyValuePair <ushort, byte> kvp in other._lookupSparse)
                    {
                        ushort index = kvp.Key;
                        byte   rank  = kvp.Value;
                        this._lookupDense[index] = Math.Max(this._lookupDense[index], rank);
                    }
                }
                else
                {
                    for (var i = 0; i < this._m; i++)
                    {
                        this._lookupDense[i] = Math.Max(this._lookupDense[i], other._lookupDense[i]);
                    }
                }
            }

            if (other._directCount != null)
            {
                // Other instance is using direct counter. If this instance is also using direct counter, merge them.
                _directCount?.UnionWith(other._directCount);
            }
            else
            {
                // Other instance is not using direct counter, make sure this instance doesn't either
                this._directCount = null;
            }
        }
Beispiel #40
0
        private ValidationResult ValidateInternal(string[] ruleSets)
        {
            var result = new ValidationResult {
                IsValid = true
            };

            var binderPropsOrFieldsOfT = this.TypeProperties.Keys;

            foreach (var rule in ruleSets)
            {
                if (this.StrictModes.TryGetValue(rule, out var strictMode))
                {
                }
                else
                {
                    strictMode = Faker.DefaultStrictMode;
                }

                //If strictMode is not enabled, skip and move on to the next ruleSet.
                if (!strictMode)
                {
                    continue;
                }

                this.Actions.TryGetValue(rule, out var populateActions);

                var userSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

                if (populateActions != null)
                {
                    userSet.UnionWith(populateActions.Keys);
                }

                //Get the set properties or fields that are only
                //known to the binder, while removing
                //items in userSet that are known to both the user and binder.

                userSet.SymmetricExceptWith(binderPropsOrFieldsOfT);

                //What's left in userSet is the set of properties or fields
                //that the user does not know about + .Rule() methods.

                if (userSet.Count > 0)
                {
                    foreach (var propOrFieldOfT in userSet)
                    {
                        if (populateActions is not null && populateActions.TryGetValue(propOrFieldOfT, out var populateAction))
                        {
                            // Very much a .Rules() action
                            if (populateAction.ProhibitInStrictMode)
                            {
                                result.ExtraMessages.Add(
                                    $"When StrictMode is set to True the Faker<{typeof(T).Name}>.Rules(...) method cannot verify that all properties have rules. You need to use Faker<{typeof(T).Name}>.RuleFor( x => x.Prop, ...) for each property to ensure each property has an associated rule when StrictMode is true; otherwise, set StrictMode to False in order to use Faker<{typeof(T).Name}>.Rules() method.");
                                result.IsValid = false;
                            }
                        }
                        else //The user doesn't know about this property or field. Log it as a validation error.
                        {
                            result.MissingRules.Add(propOrFieldOfT);
                            result.IsValid = false;
                        }
                    }
                }
Beispiel #41
0
        public void BuildNodeSets(TreeNode node)
        {
            if (node == null)
            {
                return;
            }
            node.FollowPos = new HashSet <TreeNode>();
            switch (node.Type)
            {
            case NodeType.Epsilon:
                node.Nullable = true;
                node.FirstPos = new HashSet <TreeNode>();
                node.LastPos  = new HashSet <TreeNode>();
                break;

            case NodeType.Cut:
                BuildNodeSets(node.Left);
                BuildNodeSets(node.Right);
                node.Nullable = node.Left.Nullable && node.Right.Nullable;
                var setcu = new HashSet <TreeNode>(node.Left.FirstPos);
                if (node.Left.Nullable)
                {
                    setcu.UnionWith(node.Right.FirstPos);
                }
                node.FirstPos = setcu;
                setcu         = new HashSet <TreeNode>(node.Right.LastPos);
                if (node.Right.Nullable)
                {
                    setcu.UnionWith(node.Left.LastPos);
                }
                node.LastPos = setcu;
                foreach (var n in node.Right.FirstPos)
                {
                    n.Starts = true;
                }
                foreach (var i in node.Left.LastPos)
                {
                    i.FollowPos.UnionWith(node.Right.FirstPos);
                }
                break;

            case NodeType.Star:
                BuildNodeSets(node.Left);
                node.Nullable = true;
                node.FirstPos = new HashSet <TreeNode>(node.Left.FirstPos);
                node.LastPos  = new HashSet <TreeNode>(node.Left.LastPos);
                foreach (var i in node.Left.LastPos)
                {
                    i.FollowPos.UnionWith(node.FirstPos);
                }
                break;

            case NodeType.Plus:
                BuildNodeSets(node.Left);
                node.Nullable = node.Left.Nullable;
                node.FirstPos = new HashSet <TreeNode>(node.Left.FirstPos);
                node.LastPos  = new HashSet <TreeNode>(node.Left.LastPos);
                foreach (var i in node.Left.LastPos)
                {
                    i.FollowPos.UnionWith(node.FirstPos);
                }

                break;

            case NodeType.Or:
                BuildNodeSets(node.Left);
                BuildNodeSets(node.Right);
                node.Nullable = node.Left.Nullable | node.Right.Nullable;

                var set = new HashSet <TreeNode>(node.Left.FirstPos);
                set.UnionWith(node.Left.FirstPos);
                node.FirstPos = set;

                set = new HashSet <TreeNode>(node.Left.LastPos);
                set.UnionWith(node.Left.LastPos);
                node.LastPos = set;
                break;

            case NodeType.Cat:
                BuildNodeSets(node.Left);
                BuildNodeSets(node.Right);
                node.Nullable = node.Left.Nullable & node.Right.Nullable;
                var setc = new HashSet <TreeNode>(node.Left.FirstPos);
                if (node.Left.Nullable)
                {
                    setc.UnionWith(node.Right.FirstPos);
                }
                node.FirstPos = setc;

                setc = new HashSet <TreeNode>(node.Right.LastPos);
                if (node.Right.Nullable)
                {
                    setc.UnionWith(node.Left.LastPos);
                }
                node.LastPos = setc;

                foreach (var i in node.Left.LastPos)
                {
                    i.FollowPos.UnionWith(node.Right.FirstPos);
                }
                break;

            default:
                // A regular character.
                node.Nullable = false;
                node.FirstPos = new HashSet <TreeNode> {
                    node
                };
                node.LastPos = new HashSet <TreeNode> {
                    node
                };
                break;
            }
        }
        /// <summary>
        ///     Validates property mappings.
        /// </summary>
        /// <param name="model"> The model. </param>
        /// <param name="logger"> The logger to use. </param>
        protected virtual void ValidatePropertyMapping([NotNull] IModel model, [NotNull] IDiagnosticsLogger <DbLoggerCategory.Model.Validation> logger)
        {
            Check.NotNull(model, nameof(model));

            if (!(model is IConventionModel conventionModel))
            {
                return;
            }

            foreach (var entityType in conventionModel.GetEntityTypes())
            {
                var unmappedProperty = entityType.GetProperties().FirstOrDefault(
                    p => (!ConfigurationSource.Convention.Overrides(p.GetConfigurationSource()) ||
                          !p.IsShadowProperty()) &&
                    p.FindTypeMapping() == null);

                if (unmappedProperty != null)
                {
                    throw new InvalidOperationException(
                              CoreStrings.PropertyNotMapped(
                                  entityType.DisplayName(), unmappedProperty.Name, unmappedProperty.ClrType.ShortDisplayName()));
                }

                if (!entityType.HasClrType())
                {
                    continue;
                }

                var clrProperties = new HashSet <string>(StringComparer.Ordinal);

                var runtimeProperties = entityType.AsEntityType().GetRuntimeProperties();

                clrProperties.UnionWith(
                    runtimeProperties.Values
                    .Where(pi => pi.IsCandidateProperty())
                    .Select(pi => pi.GetSimpleMemberName()));

                clrProperties.ExceptWith(entityType.GetProperties().Select(p => p.Name));
                clrProperties.ExceptWith(entityType.GetNavigations().Select(p => p.Name));
                clrProperties.ExceptWith(entityType.GetServiceProperties().Select(p => p.Name));
                clrProperties.RemoveWhere(p => entityType.FindIgnoredConfigurationSource(p) != null);

                if (clrProperties.Count <= 0)
                {
                    continue;
                }

                foreach (var clrProperty in clrProperties)
                {
                    var actualProperty     = runtimeProperties[clrProperty];
                    var propertyType       = actualProperty.PropertyType;
                    var targetSequenceType = propertyType.TryGetSequenceType();

                    if (conventionModel.FindIgnoredConfigurationSource(propertyType.DisplayName()) != null ||
                        targetSequenceType != null &&
                        conventionModel.FindIgnoredConfigurationSource(targetSequenceType.DisplayName()) != null)
                    {
                        continue;
                    }

                    var targetType = FindCandidateNavigationPropertyType(actualProperty);

                    var isTargetWeakOrOwned
                        = targetType != null &&
                          (conventionModel.HasEntityTypeWithDefiningNavigation(targetType) ||
                           conventionModel.IsOwned(targetType));

                    if (targetType?.IsValidEntityType() == true &&
                        (isTargetWeakOrOwned ||
                         conventionModel.FindEntityType(targetType) != null ||
                         targetType.GetRuntimeProperties().Any(p => p.IsCandidateProperty())))
                    {
                        // ReSharper disable CheckForReferenceEqualityInstead.1
                        // ReSharper disable CheckForReferenceEqualityInstead.3
                        if ((!entityType.IsKeyless ||
                             targetSequenceType == null) &&
                            entityType.GetDerivedTypes().All(
                                dt => dt.GetDeclaredNavigations().FirstOrDefault(n => n.Name == actualProperty.GetSimpleMemberName()) == null) &&
                            (!isTargetWeakOrOwned ||
                             (!targetType.Equals(entityType.ClrType) &&
                              (!entityType.IsInOwnershipPath(targetType) ||
                               (entityType.FindOwnership().PrincipalEntityType.ClrType.Equals(targetType) &&
                                targetSequenceType == null)) &&
                              (!entityType.IsInDefinitionPath(targetType) ||
                               (entityType.DefiningEntityType.ClrType.Equals(targetType) &&
                                targetSequenceType == null)))))
                        {
                            if (conventionModel.IsOwned(entityType.ClrType) &&
                                conventionModel.IsOwned(targetType))
                            {
                                throw new InvalidOperationException(
                                          CoreStrings.AmbiguousOwnedNavigation(entityType.ClrType.ShortDisplayName(), targetType.ShortDisplayName()));
                            }

                            throw new InvalidOperationException(
                                      CoreStrings.NavigationNotAdded(
                                          entityType.DisplayName(), actualProperty.Name, propertyType.ShortDisplayName()));
                        }
                        // ReSharper restore CheckForReferenceEqualityInstead.3
                        // ReSharper restore CheckForReferenceEqualityInstead.1
                    }
                    else if (targetSequenceType == null && propertyType.GetTypeInfo().IsInterface ||
                             targetSequenceType?.GetTypeInfo().IsInterface == true)
                    {
                        throw new InvalidOperationException(
                                  CoreStrings.InterfacePropertyNotAdded(
                                      entityType.DisplayName(), actualProperty.Name, propertyType.ShortDisplayName()));
                    }
                    else
                    {
                        throw new InvalidOperationException(
                                  CoreStrings.PropertyNotAdded(
                                      entityType.DisplayName(), actualProperty.Name, propertyType.ShortDisplayName()));
                    }
                }
            }
        }
        private void WatchThread(CancellationToken token)
        {
            for (; ;)
            {
                var searchItems = new List <SearchListViewItemInfo>();

                {
                    var seedInfos = new HashSet <(Seed, Signature)>();

                    var storeMetadatas       = new HashSet <Metadata>();
                    var cacheMetadatas       = new HashSet <Metadata>();
                    var downloadingMetadatas = new HashSet <Metadata>();
                    var downloadedMetadatas  = new HashSet <Metadata>();

                    foreach (var store in _messageManager.GetStores())
                    {
                        var seedHashSet = new HashSet <Seed>();
                        {
                            var boxList = new List <Box>();
                            boxList.AddRange(store.Value.Boxes);

                            for (int i = 0; i < boxList.Count; i++)
                            {
                                boxList.AddRange(boxList[i].Boxes);
                                seedHashSet.UnionWith(boxList[i].Seeds);
                            }
                        }

                        foreach (var seed in seedHashSet)
                        {
                            seedInfos.Add((seed, store.AuthorSignature));
                            storeMetadatas.Add(seed.Metadata);
                        }
                    }

                    {
                        var signature = SettingsManager.Instance.AccountInfo.DigitalSignature.GetSignature();

                        foreach (var seed in _serviceManager.GetCacheContentReports()
                                 .Select(n => new Seed(Path.GetFileName(n.Path), n.Length, n.CreationTime, n.Metadata)).ToArray())
                        {
                            seedInfos.Add((seed, signature));
                            cacheMetadatas.Add(seed.Metadata);
                        }
                    }

                    downloadingMetadatas.UnionWith(_serviceManager.GetDownloadContentReports().Select(n => n.Metadata));

                    {
                        var downloadedSeeds = SettingsManager.Instance.DownloadedSeeds.ToArray();

                        foreach (var seed in SettingsManager.Instance.DownloadedSeeds.ToArray())
                        {
                            if (!storeMetadatas.Contains(seed.Metadata) && !cacheMetadatas.Contains(seed.Metadata))
                            {
                                seedInfos.Add((seed, null));
                            }

                            downloadedMetadatas.Add(seed.Metadata);
                        }
                    }

                    foreach (var(seed, signature) in seedInfos)
                    {
                        var viewModel = new SearchListViewItemInfo();
                        viewModel.Icon         = IconUtils.GetImage(seed.Name);
                        viewModel.Name         = seed.Name;
                        viewModel.Signature    = signature;
                        viewModel.Length       = seed.Length;
                        viewModel.CreationTime = seed.CreationTime;

                        SearchState state = 0;
                        if (storeMetadatas.Contains(seed.Metadata))
                        {
                            state |= SearchState.Store;
                        }
                        if (cacheMetadatas.Contains(seed.Metadata))
                        {
                            state |= SearchState.Cache;
                        }
                        if (downloadingMetadatas.Contains(seed.Metadata))
                        {
                            state |= SearchState.Downloading;
                        }
                        if (downloadedMetadatas.Contains(seed.Metadata))
                        {
                            state |= SearchState.Downloaded;
                        }

                        viewModel.State = state;
                        viewModel.Model = seed;

                        searchItems.Add(viewModel);
                    }
                }

                lock (_cache_SearchItems.LockObject)
                {
                    _cache_SearchItems.Clear();
                    _cache_SearchItems.AddRange(searchItems);
                }

                this.SetCount(this.TabViewModel.Value, searchItems, token);

                if (token.WaitHandle.WaitOne(1000 * 20))
                {
                    return;
                }
            }
        }
        protected override void OnReceive(AbstractMessage message)
        {
            TypeSwitch.On(message)
            .Case((CoordinatorMessage coordinatorMessage) =>
            {
                k_max        = 0;
                partition    = new Dictionary <TNode, int>();
                oldNumBlocks = 0;
                blocks       = new HashSet <int>();
                workers      = coordinatorMessage.Workers;
                state        = new Dictionary <AbstractMachine, WorkerState>();

                foreach (var worker in workers)
                {
                    state.Add(worker, WorkerState.Refining);
                    worker.SendMe(new ClearMessage(this));
                }
            })
            .Case((EstimateRefinedMessage refinedMessage) =>
            {
                state[refinedMessage.Sender] = WorkerState.Waiting;

                if (workers.All(worker => state[worker] == WorkerState.Waiting))
                {
                    // All workers have refined, now perform a share step
                    foreach (var worker in workers)
                    {
                        state[worker] = WorkerState.Sharing;
                        worker.SendMe(new ShareMessage(this));
                    }
                }
            })
            .Case((SharedMessage sharedMessage) =>
            {
                state[sharedMessage.Sender] = WorkerState.Waiting;

                if (workers.All(worker => state[worker] == WorkerState.Waiting))
                {
                    // All workers have shared, now count the number of unqiue blocks
                    oldNumBlocks = blocks.Count;
                    blocks.Clear();
                    foreach (var worker in workers)
                    {
                        state[worker] = WorkerState.Counting;
                        worker.SendMe(new CountMessage(this));
                    }
                }
            })
            .Case((CountedMessage countedMessage) =>
            {
                state[countedMessage.Sender] = WorkerState.Waiting;
                blocks.UnionWith(countedMessage.Blocks);

                if (workers.All(worker => state[worker] == WorkerState.Waiting))
                {
                    if (blocks.Count > oldNumBlocks)
                    {
                        // There was a change, continue refining
                        k_max += 1;
                        foreach (var worker in workers)
                        {
                            state[worker] = WorkerState.Refining;
                            worker.SendMe(new RefineMessage(this));
                        }
                    }
                    else
                    {
                        // We're done, collect global partition
                        k_max -= 1;
                        foreach (var worker in workers)
                        {
                            state[worker] = WorkerState.Collecting;
                            worker.SendMe(new SegmentRequestMessage(this));
                        }
                    }
                }
            })
            .Case((SegmentResponseMessage <TNode> segmentResponseMessage) =>
            {
                state[segmentResponseMessage.Sender] = WorkerState.Waiting;

                foreach (var pair in segmentResponseMessage.Pairs)
                {
                    partition.Add(pair.Key, pair.Value);
                }

                if (workers.All(worker => state[worker] == WorkerState.Waiting))
                {
                    onComplete(k_max, partition);
                }
            });
        }
Beispiel #45
0
        public List <string> GetAnchorWords(int N)
        {
            StringBuilder sbAllWords = new StringBuilder();

            foreach (children child in children)
            {
                sbAllWords.Append(child.SubtreeText);
                sbAllWords.Append(" ");
            }
            string[] allWords = GetAllWords(sbAllWords.ToString());
            Dictionary <string, string> stemParentDictionary = GetStemParentDictionary(allWords);
            List <string>         anchorWords  = new List <string>();
            children              rootNode     = new children();
            List <HashSet <int> > rootChildIDs = new List <HashSet <int> >();

            foreach (children child in children)
            {
                GetChildIDHashSetList(child);
                HashSet <int> currChildIDs = new HashSet <int>();
                currChildIDs.Add(child.id);
                foreach (var item in child.ChildIDList)
                {
                    currChildIDs.UnionWith(item);
                }
                rootChildIDs.Add(currChildIDs);
            }
            rootNode.ChildIDList = rootChildIDs;
            NodeList             = new List <children>();
            NodeList.Add(rootNode);
            foreach (children child in children)
            {
                PopulateNodeList(child);
            }
            Dictionary <string, HashSet <int> > wordIDMapping = GetWordIDMapping();
            //Dictionary<string, double> WordTreeScore = new Dictionary<string, double>();
            Dictionary <string, List <children> > WordLCAList = new Dictionary <string, List <children> >();

            foreach (var kvp in wordIDMapping)
            {
                List <children> currLCAList = new List <children>();
                int             numLCAs     = 0;
                foreach (children node in NodeList)
                {
                    int numBranchesWithWord = 0;
                    foreach (var childIDBranch in node.ChildIDList)
                    {
                        if (childIDBranch.Intersect(kvp.Value).Count() > 0)
                        {
                            numBranchesWithWord += 1;
                        }
                    }
                    if ((numBranchesWithWord == 1 && node.ChildIDList.Count == 1) || numBranchesWithWord > 1)
                    {
                        currLCAList.Add(node);
                    }
                }
                WordLCAList[stemParentDictionary.ContainsKey(kvp.Key)? stemParentDictionary[kvp.Key]:kvp.Key] = currLCAList;
            }
            anchorWords = WordLCAList
                          .OrderByDescending(x => x.Value.Count)
                          .Select(x => x.Key)
                          .Where(y => CommonWords.GetFrequency(y) < 20)
                          .Where(z => !(z.EndsWith("n't") || z.EndsWith("'m") || (z.EndsWith("'ll")) || (z.EndsWith("'d")) || z.EndsWith("'ve") || z.EndsWith("'re") || z.EndsWith("'s")))
                          .Take(N)
                          .ToList();
            return(anchorWords);
        }
Beispiel #46
0
 static LocalNode()
 {
     LocalAddresses.UnionWith(NetworkInterface.GetAllNetworkInterfaces().SelectMany(p => p.GetIPProperties().UnicastAddresses).Select(p => p.Address.MapToIPv6()));
 }
Beispiel #47
0
        // Prove candidates that hold (using an over-approximation, at the current inline depth).
        // Return the set of candidates proved correct
        static HashSet <string> ProveCandidates(ProverInterface prover, Dictionary <string, VCExpr> constantToAssertedExpr, List <Tuple <string, VCExpr, VCExpr> > constantToAssumedExpr, HashSet <string> candidates)
        {
            var remaining = new HashSet <string>(candidates);
            var reporter  = new EmptyErrorReporter();
            var failed    = new HashSet <string>();

            // for dual houdini, we have to iterate once around to the loop
            // even if remaining is empty
            bool secondtry = false;

            while (true)
            {
                remaining.ExceptWith(failed);

                if (remaining.Count == 0 && (!DualHoudini || secondtry))
                {
                    break;
                }

                if (remaining.Count == 0)
                {
                    secondtry = true;
                }
                else
                {
                    secondtry = false;
                }

                HoudiniStats.ProverCount++;
                HoudiniStats.Start("ProverTime");

                prover.Push();

                var nameToCallSiteVar           = new Dictionary <string, VCExprVar>();
                var callSiteVarToConstantToExpr = new Dictionary <string, Dictionary <string, VCExpr> >();

                if (!DualHoudini)
                {
                    // assert post
                    VCExpr toassert = VCExpressionGenerator.True;
                    foreach (var k in remaining)
                    {
                        toassert = prover.VCExprGen.And(toassert, constantToAssertedExpr[k]);
                    }

                    prover.Assert(toassert, false);
                }
                else
                {
                    // assume post of callees
                    foreach (var tup in constantToAssumedExpr)
                    {
                        if (!remaining.Contains(tup.Item1))
                        {
                            continue;
                        }

                        var csVar = tup.Item2 as VCExprVar;
                        Debug.Assert(csVar != null);
                        if (!nameToCallSiteVar.ContainsKey(csVar.ToString()))
                        {
                            nameToCallSiteVar.Add(csVar.ToString(), csVar);
                        }

                        if (!callSiteVarToConstantToExpr.ContainsKey(csVar.ToString()))
                        {
                            callSiteVarToConstantToExpr.Add(csVar.ToString(), new Dictionary <string, VCExpr>());
                        }
                        callSiteVarToConstantToExpr[csVar.ToString()].Add(tup.Item1, tup.Item3);
                    }

                    foreach (var tup in callSiteVarToConstantToExpr)
                    {
                        var expr = VCExpressionGenerator.False;
                        tup.Value.Values.Iter(e => expr = prover.VCExprGen.Or(expr, e));
                        prover.Assert(prover.VCExprGen.Implies(nameToCallSiteVar[tup.Key], expr), true);
                    }
                }

                Dictionary <string, VCExprVar> recordingBool = null;
                if (RobustAgainstEvaluate)
                {
                    recordingBool = new Dictionary <string, VCExprVar>();
                    VCExpr torecord = VCExpressionGenerator.True;
                    foreach (var k in remaining)
                    {
                        var b = prover.VCExprGen.Variable("recordingVar_" + k, Microsoft.Boogie.Type.Bool);
                        recordingBool.Add(k, b);
                        torecord = prover.VCExprGen.And(torecord, prover.VCExprGen.Eq(b, constantToAssertedExpr[k]));
                    }
                    prover.Assert(torecord, true);
                }

                prover.Check();
                var outcome = prover.CheckOutcomeCore(reporter);

                // check which ones failed
                if (outcome == ProverInterface.Outcome.Invalid || outcome == ProverInterface.Outcome.Undetermined)
                {
                    var removed = 0;
                    if (!DualHoudini)
                    {
                        foreach (var k in remaining)
                        {
                            var b = recordingBool == null ? (bool)prover.Evaluate(constantToAssertedExpr[k])
                                : (bool)prover.Evaluate(recordingBool[k]);

                            if (!b)
                            {
                                failed.Add(k);
                                if (dbg)
                                {
                                    Console.WriteLine("Failed: {0}", k);
                                }
                                removed++;
                            }
                        }
                    }
                    else
                    {
                        foreach (var tup in callSiteVarToConstantToExpr)
                        {
                            if (!(bool)prover.Evaluate(nameToCallSiteVar[tup.Key]))
                            {
                                continue;
                            }
                            // call site taken
                            foreach (var tup2 in tup.Value)
                            {
                                if ((bool)prover.Evaluate(tup2.Value))
                                {
                                    failed.Add(tup2.Key);
                                    if (dbg)
                                    {
                                        Console.WriteLine("Failed: {0}", tup2.Key);
                                    }
                                    removed++;
                                }
                            }
                        }
                        if (removed == 0)
                        {
                            throw new DualHoudiniFail("Nothing to drop");
                        }
                    }
                    Debug.Assert(removed != 0);
                    //if(dbg) Console.WriteLine("Query {0}: Invalid, {1} removed", HoudiniStats.ProverCount, removed);
                }

                HoudiniStats.Stop("ProverTime");
                prover.Pop();


                if (outcome == ProverInterface.Outcome.TimeOut || outcome == ProverInterface.Outcome.OutOfMemory)
                {
                    if (DualHoudini)
                    {
                        throw new DualHoudiniFail("Timeout");
                    }
                    failed.UnionWith(remaining);
                    break;
                }

                if (outcome == ProverInterface.Outcome.Valid)
                {
                    //if(dbg) Console.WriteLine("Query {0}: Valid", HoudiniStats.ProverCount);
                    break;
                }
            }

            remaining.ExceptWith(failed);

            return(remaining);
        }
Beispiel #48
0
        static void LoadLegacyExtensionsFromIvyFiles()
        {
            //We can't use the cached native type scanner here since this is called to early for that to be built up.

            HashSet <string> ivyFiles;

            try
            {
                ivyFiles = new HashSet <string>();

                string unityExtensionsFolder = FileUtil.CombinePaths(Directory.GetParent(EditorApplication.applicationPath).ToString(), "Data", "UnityExtensions");
                string playbackEngineFolders = FileUtil.CombinePaths(Directory.GetParent(EditorApplication.applicationPath).ToString(), "PlaybackEngines");

                foreach (var searchPath in new[]
                {
                    FileUtil.NiceWinPath(EditorApplication.applicationContentsPath),
                    FileUtil.NiceWinPath(unityExtensionsFolder),
                    FileUtil.NiceWinPath(playbackEngineFolders)
                })
                {
                    if (!Directory.Exists(searchPath))
                    {
                        continue;
                    }

                    ivyFiles.UnionWith(Directory.GetFiles(searchPath, "ivy.xml", SearchOption.AllDirectories));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error scanning for extension ivy.xml files: {0}", ex);
                return;
            }

            var packages = new Dictionary <string, List <IvyPackageFileData> >();

            var artifactRegex = new Regex(@"<artifact(\s+(name=""(?<name>[^""]*)""|type=""(?<type>[^""]*)""|ext=""(?<ext>[^""]*)""|e:guid=""(?<guid>[^""]*)""))+\s*/>",
                                          RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);

            foreach (var ivyFile in ivyFiles)
            {
                try
                {
                    var ivyFileContent = File.ReadAllText(ivyFile);
                    var artifacts      = artifactRegex.Matches(ivyFileContent).Cast <Match>()
                                         .Select(IvyPackageFileData.CreateFromRegexMatch).ToList();

                    var packageDir = Path.GetDirectoryName(ivyFile);
                    packages.Add(packageDir, artifacts);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error reading extensions from ivy.xml file at {0}: {1}", ivyFile, ex);
                }
            }

            try
            {
                foreach (var packageInfo in packages)
                {
                    var files = packageInfo.Value;
                    foreach (var packageInfoFile in files)
                    {
                        string fullPath = Paths.NormalizePath(Path.Combine(packageInfo.Key, packageInfoFile.filename));

                        if (!File.Exists(fullPath))
                        {
                            Debug.LogWarningFormat(
                                "Missing assembly \t{0} listed in ivy file {1}. Extension support may be incomplete.", fullPath,
                                packageInfo.Key);
                        }

                        if (!packageInfoFile.IsDll)
                        {
                            continue;
                        }

                        if (!string.IsNullOrEmpty(packageInfoFile.guid))
                        {
                            InternalEditorUtility.RegisterExtensionDll(fullPath.Replace('\\', '/'),
                                                                       packageInfoFile.guid);
                        }
                        else
                        {
                            InternalEditorUtility.RegisterPrecompiledAssembly(fullPath, fullPath);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error scanning for extensions. {0}", ex);
            }
        }
        private static void Run(CommandLineApplication cmd, ILogger log)
        {
            cmd.Description = "Remove package dependencies";

            // Filters
            var idFilter             = cmd.Option(Constants.IdFilterTemplate, Constants.IdFilterDesc, CommandOptionType.SingleValue);
            var versionFilter        = cmd.Option(Constants.VersionFilterTemplate, Constants.VersionFilterDesc, CommandOptionType.SingleValue);
            var excludeSymbolsFilter = cmd.Option(Constants.ExcludeSymbolsTemplate, Constants.ExcludeSymbolsDesc, CommandOptionType.NoValue);
            var highestVersionFilter = cmd.Option(Constants.HighestVersionFilterTemplate, Constants.HighestVersionFilterDesc, CommandOptionType.NoValue);

            // Command options
            var frameworkOption    = cmd.Option(Constants.FrameworkOptionTemplate, Constants.FrameworkOptionDesc, CommandOptionType.MultipleValue);
            var dependencyIdOption = cmd.Option(Constants.DependencyIdTemplate, Constants.DependencyIdDesc, CommandOptionType.SingleValue);

            var argRoot = cmd.Argument(
                "[root]",
                Constants.MultiplePackagesRootDesc,
                true);

            cmd.HelpOption(Constants.HelpOption);

            cmd.OnExecute(() =>
            {
                try
                {
                    var inputs = argRoot.Values;

                    if (inputs.Count < 1)
                    {
                        inputs.Add(Directory.GetCurrentDirectory());
                    }

                    var dependencyId = dependencyIdOption.HasValue() ? dependencyIdOption.Value() : null;
                    var type         = dependencyIdOption.HasValue() ? DependenciesUtil.EditType.Remove : DependenciesUtil.EditType.Clear;

                    var editForFrameworks = new HashSet <NuGetFramework>();
                    if (frameworkOption.HasValue())
                    {
                        editForFrameworks.UnionWith(frameworkOption.Values.Select(NuGetFramework.Parse));

                        if (type == DependenciesUtil.EditType.Clear)
                        {
                            log.LogInformation($"removing all dependencies from {string.Join(", ", editForFrameworks.Select(e => e.GetShortFolderName()))}");
                        }
                        else
                        {
                            log.LogInformation($"removing dependency {dependencyId} from {string.Join(", ", editForFrameworks.Select(e => e.GetShortFolderName()))}");
                        }
                    }
                    else
                    {
                        if (type == DependenciesUtil.EditType.Clear)
                        {
                            log.LogInformation($"removing all dependencies");
                        }
                        else
                        {
                            log.LogInformation($"removing dependency {dependencyId} from all frameworks");
                        }
                    }

                    var packages = Util.GetPackagesWithFilter(idFilter, versionFilter, excludeSymbolsFilter, highestVersionFilter, inputs.ToArray());

                    foreach (var package in packages)
                    {
                        log.LogMinimal($"processing {package}");

                        var nuspecXml = Util.GetNuspec(package);

                        DependenciesUtil.Process(nuspecXml, type, editForFrameworks, dependencyId, null, null, null, false, false, log);

                        Util.ReplaceNuspec(package, nuspecXml, log);
                    }

                    return(0);
                }
                catch (Exception ex)
                {
                    log.LogError(ex.Message);
                    log.LogError(ex.ToString());
                }

                return(1);
            });
        }
Beispiel #50
0
        private static IEnumerable <ComposedPartDiagnostic> FindLoops(IEnumerable <ComposedPart> parts)
        {
            Requires.NotNull(parts, nameof(parts));

            var partByPartDefinition  = parts.ToDictionary(p => p.Definition);
            var partByPartType        = parts.ToDictionary(p => p.Definition.TypeRef);
            var partsAndDirectImports = new Dictionary <ComposedPart, IReadOnlyList <KeyValuePair <ImportDefinitionBinding, ComposedPart> > >();

            foreach (var part in parts)
            {
                var directlyImportedParts = (from importAndExports in part.SatisfyingExports
                                             from export in importAndExports.Value
                                             let exportingPart = partByPartDefinition[export.PartDefinition]
                                                                 select new KeyValuePair <ImportDefinitionBinding, ComposedPart>(importAndExports.Key, exportingPart)).ToList();
                partsAndDirectImports.Add(part, directlyImportedParts);
            }

            Func <Func <KeyValuePair <ImportDefinitionBinding, ComposedPart>, bool>, Func <ComposedPart, IEnumerable <ComposedPart> > > getDirectLinksWithFilter =
                filter => (part => partsAndDirectImports[part].Where(filter).Select(ip => ip.Value));
            var visited = new HashSet <ComposedPart>();

            // Find any loops of exclusively non-shared parts.
            var nonSharedPartsInLoops = new HashSet <ComposedPart>();

            foreach (var part in partsAndDirectImports.Keys)
            {
                if (nonSharedPartsInLoops.Contains(part))
                {
                    // Don't check and report parts already detected to be involved in a loop.
                    continue;
                }

                visited.Clear();
                var path = PathExistsBetween(part, part, getDirectLinksWithFilter(ip => !ip.Key.IsExportFactory && (!ip.Value.Definition.IsShared || PartCreationPolicyConstraint.IsNonSharedInstanceRequired(ip.Key.ImportDefinition))), visited);
                if (!path.IsEmpty)
                {
                    path = path.Push(part);
                    nonSharedPartsInLoops.UnionWith(path);
                    yield return(new ComposedPartDiagnostic(path, Strings.LoopBetweenNonSharedParts));
                }
            }

            // Find loops even with shared parts where an importing constructor is involved.
            Func <KeyValuePair <ImportDefinitionBinding, ComposedPart>, bool> importingConstructorFilter = ip => !ip.Key.IsExportFactory && !ip.Key.IsLazy;

            foreach (var partAndImports in partsAndDirectImports)
            {
                var importingPart = partAndImports.Key;
                foreach (var import in partAndImports.Value)
                {
                    var importDefinitionBinding = import.Key;
                    var satisfyingPart          = import.Value;
                    if (importDefinitionBinding.ImportingParameterRef != null && importingConstructorFilter(import))
                    {
                        visited.Clear();
                        var path = PathExistsBetween(satisfyingPart, importingPart, getDirectLinksWithFilter(importingConstructorFilter), visited);
                        if (!path.IsEmpty)
                        {
                            path = path.Push(satisfyingPart).Push(partByPartType[importDefinitionBinding.ComposablePartTypeRef]);
                            yield return(new ComposedPartDiagnostic(path, Strings.LoopInvolvingImportingCtorArgumentAndAllNonLazyImports));
                        }
                    }
                }
            }
        }
Beispiel #51
0
        private static void PushSameDependABToABUnit(IAssetDataQuerier varQuerier, List <string> varRepeatAssets,
                                                     Dictionary <string, List <string> > varAssetBeDep, Dictionary <string, List <string> > varABBeDep, Dictionary <string, List <string> > varABDepABs)
        {
            var tempHashSetHelper = new HashSet <string>();

            for (int iR = 0; iR < varRepeatAssets.Count; ++iR)
            {
                var tempAssetPath = varRepeatAssets[iR];

                var tempAssetBeDeps = varAssetBeDep[tempAssetPath];
                if (tempAssetBeDeps.Count < 2)
                {
                    UDebug.LogErrorFormat("Repeat analysis error.[{0}]", tempAssetPath);
                    iR++;
                    continue;
                }

                tempHashSetHelper.Clear();
                for (int iBD = 0; iBD < tempAssetBeDeps.Count; ++iBD)
                {
                    var tempABName = tempAssetBeDeps[iBD];
                    tempHashSetHelper.UnionWith(varABDepABs[tempABName]);
                    tempHashSetHelper.Add(tempABName);
                }
                var tempAllABDeps = tempHashSetHelper.OrderBy(a => a).ToList();

                for (int iAD = tempAllABDeps.Count - 1; iAD >= 0; --iAD)
                {
                    var tempABName = tempAllABDeps[iAD];

                    if (!varABBeDep.TryGetValue(tempABName, out var tempBeDeps))
                    {
                        continue;
                    }

                    if (tempAssetBeDeps.Count != tempBeDeps.Count)
                    {
                        continue;
                    }

                    bool tempSame = true;
                    for (int iBD = 0; iBD < tempAssetBeDeps.Count; ++iBD)
                    {
                        if (tempAssetBeDeps[iBD] == tempBeDeps[iBD])
                        {
                            continue;
                        }
                        tempSame = false;
                        break;
                    }

                    if (!tempSame)
                    {
                        continue;
                    }

                    varQuerier.SetAssetBundleName(tempAssetPath, tempABName);
                    varRepeatAssets.RemoveAt(iR);
                    iR++;
                    break;
                }
            }
        }
Beispiel #52
0
        internal void PrefetchCompositesAssociationRelationTable(HashSet <Reference> roles, IAssociationType associationType, HashSet <long> nestedObjectIds, HashSet <long> leafs)
        {
            var references = nestedObjectIds == null?this.FilterForPrefetchAssociations(roles, associationType) : this.FilterForPrefetchCompositeAssociations(roles, associationType, nestedObjectIds);

            if (references.Count == 0)
            {
                return;
            }

            Command command;

            if (!this.PrefetchCompositeAssociationByAssociationType.TryGetValue(associationType, out command))
            {
                var roleType = associationType.RoleType;
                var sql      = this.Database.Mapping.ProcedureNameForPrefetchAssociationByRelationType[roleType.RelationType];
                command             = this.Session.Connection.CreateCommand();
                command.CommandText = sql;
                command.CommandType = CommandType.StoredProcedure;
                command.AddObjectTableParameter(roles);
                this.prefetchCompositeAssociationByAssociationType[associationType] = command;
            }
            else
            {
                command.Parameters[Mapping.ParamNameForTableType].Value = this.Database.CreateObjectTable(roles);
            }

            var prefetchedAssociations = new HashSet <long>();

            var prefetchedAssociationByRole = new Dictionary <Reference, List <long> >();

            using (DbDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    var roleId        = reader.GetInt64(1);
                    var roleReference = this.Session.State.ReferenceByObjectId[roleId];

                    List <long> associations;
                    if (!prefetchedAssociationByRole.TryGetValue(roleReference, out associations))
                    {
                        associations = new List <long>();
                        prefetchedAssociationByRole.Add(roleReference, associations);
                    }

                    var associationId = reader.GetInt64(0);
                    associations.Add(associationId);
                    prefetchedAssociations.Add(associationId);
                }
            }

            foreach (var associationId in prefetchedAssociations)
            {
                if (associationType.ObjectType.ExistExclusiveClass)
                {
                    this.Session.State.GetOrCreateReferenceForExistingObject(associationType.ObjectType.ExclusiveClass, associationId, this.Session);
                }
                else
                {
                    this.Session.State.GetOrCreateReferenceForExistingObject(associationId, this.Session);
                }
            }

            var associationsByRole = this.Session.State.GetAssociationsByRole(associationType);

            foreach (var role in roles)
            {
                if (!associationsByRole.ContainsKey(role))
                {
                    List <long> associationIds;
                    if (!prefetchedAssociationByRole.TryGetValue(role, out associationIds))
                    {
                        associationsByRole[role] = EmptyObjectIds;
                    }
                    else
                    {
                        associationsByRole[role] = associationIds.ToArray();

                        nestedObjectIds?.UnionWith(associationIds);
                        if (nestedObjectIds == null)
                        {
                            leafs.UnionWith(associationIds);
                        }
                    }

                    this.Session.FlushConditionally(role.ObjectId, associationType);
                }
            }
        }
Beispiel #53
0
        public Transaction MakeTransaction(List <TransactionAttribute> attributes, IEnumerable <TransferOutput> outputs, UInt160 from = null, UInt160 change_address = null, Fixed8 fee = default(Fixed8))
        {
            var cOutputs = outputs.Where(p => !p.IsGlobalAsset).GroupBy(p => new
            {
                AssetId = (UInt160)p.AssetId,
                Account = p.ScriptHash
            }, (k, g) => new
            {
                k.AssetId,
                Value = g.Aggregate(BigInteger.Zero, (x, y) => x + y.Value.Value),
                k.Account
            }).ToArray();
            Transaction tx;

            if (attributes == null)
            {
                attributes = new List <TransactionAttribute>();
            }
            if (cOutputs.Length == 0)
            {
                tx = new ContractTransaction();
            }
            else
            {
                UInt160[]         accounts    = from == null?GetAccounts().Where(p => !p.Lock && !p.WatchOnly).Select(p => p.ScriptHash).ToArray() : new[] { from };
                HashSet <UInt160> sAttributes = new HashSet <UInt160>();
                using (ScriptBuilder sb = new ScriptBuilder())
                {
                    foreach (var output in cOutputs)
                    {
                        var balances = new List <(UInt160 Account, BigInteger Value)>();
                        foreach (UInt160 account in accounts)
                        {
                            byte[] script;
                            using (ScriptBuilder sb2 = new ScriptBuilder())
                            {
                                sb2.EmitAppCall(output.AssetId, "balanceOf", account);
                                script = sb2.ToArray();
                            }
                            ApplicationEngine engine = ApplicationEngine.Run(script);
                            if (engine.State.HasFlag(VMState.FAULT))
                            {
                                return(null);
                            }
                            balances.Add((account, engine.ResultStack.Pop().GetBigInteger()));
                        }
                        BigInteger sum = balances.Aggregate(BigInteger.Zero, (x, y) => x + y.Value);
                        if (sum < output.Value)
                        {
                            return(null);
                        }
                        if (sum != output.Value)
                        {
                            balances = balances.OrderByDescending(p => p.Value).ToList();
                            BigInteger amount = output.Value;
                            int        i      = 0;
                            while (balances[i].Value <= amount)
                            {
                                amount -= balances[i++].Value;
                            }
                            if (amount == BigInteger.Zero)
                            {
                                balances = balances.Take(i).ToList();
                            }
                            else
                            {
                                balances = balances.Take(i).Concat(new[] { balances.Last(p => p.Value >= amount) }).ToList();
                            }
                            sum = balances.Aggregate(BigInteger.Zero, (x, y) => x + y.Value);
                        }
                        sAttributes.UnionWith(balances.Select(p => p.Account));
                        for (int i = 0; i < balances.Count; i++)
                        {
                            BigInteger value = balances[i].Value;
                            if (i == 0)
                            {
                                BigInteger change = sum - output.Value;
                                if (change > 0)
                                {
                                    value -= change;
                                }
                            }
                            sb.EmitAppCall(output.AssetId, "transfer", balances[i].Account, output.Account, value);
                            sb.Emit(OpCode.THROWIFNOT);
                        }
                    }
                    byte[] nonce = new byte[8];
                    rand.NextBytes(nonce);
                    sb.Emit(OpCode.RET, nonce);
                    tx = new InvocationTransaction
                    {
                        Version = 1,
                        Script  = sb.ToArray()
                    };
                }
                attributes.AddRange(sAttributes.Select(p => new TransactionAttribute
                {
                    Usage = TransactionAttributeUsage.Script,
                    Data  = p.ToArray()
                }));
            }
            tx.Attributes = attributes.ToArray();
            tx.Inputs     = new CoinReference[0];
            tx.Outputs    = outputs.Where(p => p.IsGlobalAsset).Select(p => p.ToTxOutput()).ToArray();
            tx.Witnesses  = new Witness[0];
            if (tx is InvocationTransaction itx)
            {
                ApplicationEngine engine = ApplicationEngine.Run(itx.Script, itx);
                if (engine.State.HasFlag(VMState.FAULT))
                {
                    return(null);
                }
                tx = new InvocationTransaction
                {
                    Version    = itx.Version,
                    Script     = itx.Script,
                    Gas        = InvocationTransaction.GetGas(engine.GasConsumed),
                    Attributes = itx.Attributes,
                    Inputs     = itx.Inputs,
                    Outputs    = itx.Outputs
                };
            }
            tx = MakeTransaction(tx, from, change_address, fee);
            return(tx);
        }
        public void Initialize(bool remote, string[] containRevisons)
        {
            lbChanges.Text       = "";
            LocalBranch.Checked  = !remote;
            Remotebranch.Checked = remote;

            _containRevisons = containRevisons;

            Branches.Items.Clear();
            Branches.Items.AddRange(_containRevisons != null
                ? GetContainsRevisionBranches()
                : LocalBranch.Checked
                    ? GetLocalBranches()
                    : GetRemoteBranches());

            if (_containRevisons != null && Branches.Items.Count == 1)
            {
                Branches.SelectedIndex = 0;
            }
            else
            {
                Branches.Text = null;
            }

            string[] GetLocalBranches()
            {
                if (_localBranches == null)
                {
                    _localBranches = Module.GetRefs(false).Select(b => b.Name).ToArray();
                }

                return(_localBranches);
            }

            string[] GetRemoteBranches()
            {
                if (_remoteBranches == null)
                {
                    _remoteBranches = Module.GetRefs(true, true).Where(h => h.IsRemote && !h.IsTag).Select(b => b.Name).ToArray();
                }

                return(_remoteBranches);
            }

            string[] GetContainsRevisionBranches()
            {
                var result = new HashSet <string>();

                if (_containRevisons.Length > 0)
                {
                    var branches = Module.GetAllBranchesWhichContainGivenCommit(_containRevisons[0], LocalBranch.Checked,
                                                                                !LocalBranch.Checked)
                                   .Where(a => !DetachedHeadParser.IsDetachedHead(a) &&
                                          !a.EndsWith("/HEAD"));
                    result.UnionWith(branches);
                }

                for (int index = 1; index < _containRevisons.Length; index++)
                {
                    var containRevison = _containRevisons[index];
                    var branches       =
                        Module.GetAllBranchesWhichContainGivenCommit(containRevison, LocalBranch.Checked,
                                                                     !LocalBranch.Checked)
                        .Where(a => !DetachedHeadParser.IsDetachedHead(a) &&
                               !a.EndsWith("/HEAD"));
                    result.IntersectWith(branches);
                }

                return(result.ToArray());
            }
        }
        private static void BuildDictionaries(ParsedEvtcLog log, Dictionary <long, Buff> usedBuffs, HashSet <DamageModifier> usedDamageMods, LogDataDto logData, HashSet <string> allDamageMods, List <DamageModifier> commonDamageModifiers, List <DamageModifier> itemDamageModifiers)
        {
            foreach (AbstractSingleActor actor in log.Friendlies)
            {
                allDamageMods.UnionWith(actor.GetPresentDamageModifier(log));
            }
            if (log.DamageModifiers.DamageModifiersPerSource.TryGetValue(Source.Common, out IReadOnlyList <DamageModifier> list))
            {
                foreach (DamageModifier dMod in list)
                {
                    if (allDamageMods.Contains(dMod.Name))
                    {
                        commonDamageModifiers.Add(dMod);
                        logData.DmgModifiersCommon.Add(dMod.ID);
                        usedDamageMods.Add(dMod);
                    }
                }
            }
            if (log.DamageModifiers.DamageModifiersPerSource.TryGetValue(Source.FightSpecific, out list))
            {
                foreach (DamageModifier dMod in list)
                {
                    if (allDamageMods.Contains(dMod.Name))
                    {
                        commonDamageModifiers.Add(dMod);
                        logData.DmgModifiersCommon.Add(dMod.ID);
                        usedDamageMods.Add(dMod);
                    }
                }
            }
            if (log.DamageModifiers.DamageModifiersPerSource.TryGetValue(Source.Item, out list))
            {
                foreach (DamageModifier dMod in list)
                {
                    if (allDamageMods.Contains(dMod.Name))
                    {
                        itemDamageModifiers.Add(dMod);
                        logData.DmgModifiersItem.Add(dMod.ID);
                        usedDamageMods.Add(dMod);
                    }
                }
            }
            if (log.DamageModifiers.DamageModifiersPerSource.TryGetValue(Source.Gear, out list))
            {
                foreach (DamageModifier dMod in list)
                {
                    if (allDamageMods.Contains(dMod.Name))
                    {
                        itemDamageModifiers.Add(dMod);
                        logData.DmgModifiersItem.Add(dMod.ID);
                        usedDamageMods.Add(dMod);
                    }
                }
            }
            StatisticsHelper statistics = log.StatisticsHelper;

            foreach (Buff boon in statistics.PresentBoons)
            {
                logData.Boons.Add(boon.ID);
                usedBuffs[boon.ID] = boon;
            }
            foreach (Buff condition in statistics.PresentConditions)
            {
                logData.Conditions.Add(condition.ID);
                usedBuffs[condition.ID] = condition;
            }
            foreach (Buff offBuff in statistics.PresentOffbuffs)
            {
                logData.OffBuffs.Add(offBuff.ID);
                usedBuffs[offBuff.ID] = offBuff;
            }
            foreach (Buff supBuff in statistics.PresentSupbuffs)
            {
                logData.SupBuffs.Add(supBuff.ID);
                usedBuffs[supBuff.ID] = supBuff;
            }
            foreach (Buff defBuff in statistics.PresentDefbuffs)
            {
                logData.DefBuffs.Add(defBuff.ID);
                usedBuffs[defBuff.ID] = defBuff;
            }
            foreach (Buff debuff in statistics.PresentDebuffs)
            {
                logData.Debuffs.Add(debuff.ID);
                usedBuffs[debuff.ID] = debuff;
            }
            foreach (Buff gearBuff in statistics.PresentGearbuffs)
            {
                logData.GearBuffs.Add(gearBuff.ID);
                usedBuffs[gearBuff.ID] = gearBuff;
            }
            foreach (Buff fractalInstab in statistics.PresentFractalInstabilities)
            {
                logData.FractalInstabilities.Add(fractalInstab.ID);
                usedBuffs[fractalInstab.ID] = fractalInstab;
            }
        }
Beispiel #56
0
        private void SingleStepReduce(IndexToWorkOn index, string[] keysToReduce, AbstractViewGenerator viewGenerator,
                                      List <object> itemsToDelete)
        {
            var needToMoveToSingleStepQueue = new ConcurrentQueue <HashSet <string> >();

            Log.Debug(() => string.Format("Executing single step reducing for {0} keys [{1}]", keysToReduce.Length, string.Join(", ", keysToReduce)));
            var batchTimeWatcher = Stopwatch.StartNew();
            var count            = 0;
            var size             = 0;
            var state            = new ConcurrentQueue <Tuple <HashSet <string>, List <MappedResultInfo> > >();

            BackgroundTaskExecuter.Instance.ExecuteAllBuffered(context, keysToReduce, enumerator =>
            {
                var localNeedToMoveToSingleStep = new HashSet <string>();
                needToMoveToSingleStepQueue.Enqueue(localNeedToMoveToSingleStep);
                var localKeys = new HashSet <string>();
                while (enumerator.MoveNext())
                {
                    localKeys.Add(enumerator.Current);
                }
                transactionalStorage.Batch(actions =>
                {
                    var getItemsToReduceParams = new GetItemsToReduceParams(index: index.IndexName, reduceKeys: localKeys, level: 0,
                                                                            loadData: false,
                                                                            itemsToDelete: itemsToDelete)
                    {
                        Take = int.MaxValue                        // just get all, we do the rate limit when we load the number of keys to reduce, anyway
                    };
                    var scheduledItems = actions.MapReduce.GetItemsToReduce(getItemsToReduceParams).ToList();

                    if (scheduledItems.Count == 0)
                    {
                        if (Log.IsWarnEnabled)
                        {
                            Log.Warn("Found single reduce items ({0}) that didn't have any items to reduce. Deleting level 1 & level 2 items for those keys. (If you can reproduce this, please contact [email protected])",
                                     string.Join(", ", keysToReduce));
                        }
                        // Here we have an interesting issue. We have scheduled reductions, because GetReduceTypesPerKeys() returned them
                        // and at the same time, we don't have any at level 0. That probably means that we have them at level 1 or 2.
                        // They shouldn't be here, and indeed, we remove them just a little down from here in this function.
                        // That said, they might bave smuggled in between versions, or something happened to cause them to be here.
                        // In order to avoid that, we forcibly delete those extra items from the scheduled reductions, and move on
                        foreach (var reduceKey in keysToReduce)
                        {
                            actions.MapReduce.DeleteScheduledReduction(index.IndexName, 1, reduceKey);
                            actions.MapReduce.DeleteScheduledReduction(index.IndexName, 2, reduceKey);
                        }
                    }

                    foreach (var reduceKey in localKeys)
                    {
                        var lastPerformedReduceType = actions.MapReduce.GetLastPerformedReduceType(index.IndexName, reduceKey);

                        if (lastPerformedReduceType != ReduceType.SingleStep)
                        {
                            localNeedToMoveToSingleStep.Add(reduceKey);
                        }

                        if (lastPerformedReduceType != ReduceType.MultiStep)
                        {
                            continue;
                        }

                        Log.Debug("Key {0} was moved from multi step to single step reduce, removing existing reduce results records",
                                  reduceKey);

                        // now we are in single step but previously multi step reduce was performed for the given key
                        var mappedBuckets = actions.MapReduce.GetMappedBuckets(index.IndexName, reduceKey).ToList();

                        // add scheduled items too to be sure we will delete reduce results of already deleted documents
                        mappedBuckets.AddRange(scheduledItems.Select(x => x.Bucket));

                        foreach (var mappedBucket in mappedBuckets.Distinct())
                        {
                            actions.MapReduce.RemoveReduceResults(index.IndexName, 1, reduceKey, mappedBucket);
                            actions.MapReduce.RemoveReduceResults(index.IndexName, 2, reduceKey, mappedBucket / 1024);
                        }
                    }

                    var mappedResults = actions.MapReduce.GetMappedResults(
                        index.IndexName,
                        localKeys,
                        loadData: true
                        ).ToList();

                    Interlocked.Add(ref count, mappedResults.Count);
                    Interlocked.Add(ref size, mappedResults.Sum(x => x.Size));

                    mappedResults.ApplyIfNotNull(x => x.Bucket = 0);

                    state.Enqueue(Tuple.Create(localKeys, mappedResults));
                });
            });

            var reduceKeys = new HashSet <string>(state.SelectMany(x => x.Item1));

            var results = state.SelectMany(x => x.Item2)
                          .Where(x => x.Data != null)
                          .GroupBy(x => x.Bucket, x => JsonToExpando.Convert(x.Data))
                          .ToArray();

            context.ReducedPerSecIncreaseBy(results.Length);

            context.TransactionalStorage.Batch(actions =>
                                               context.IndexStorage.Reduce(index.IndexName, viewGenerator, results, 2, context, actions, reduceKeys, state.Sum(x => x.Item2.Count))
                                               );

            autoTuner.AutoThrottleBatchSize(count, size, batchTimeWatcher.Elapsed);

            var needToMoveToSingleStep = new HashSet <string>();
            HashSet <string> set;

            while (needToMoveToSingleStepQueue.TryDequeue(out set))
            {
                needToMoveToSingleStep.UnionWith(set);
            }

            foreach (var reduceKey in needToMoveToSingleStep)
            {
                string localReduceKey = reduceKey;
                transactionalStorage.Batch(actions =>
                                           actions.MapReduce.UpdatePerformedReduceType(index.IndexName, localReduceKey, ReduceType.SingleStep));
            }
        }
        public static string GenerateDomainCheckMethodContent(IRelationDomain sourceDomain, ISet <IVariable> variablesBindedSoFar, DomainVariablesBindingsResult analysis, List <IObjectTemplateExp> remaining = null, StringBuilder stringBuilder = null, ISet <IPropertyTemplateItem> postPonedPropertiesToCheck = null)
        {
            if (remaining == null)
            {
                remaining = QvtModelExplorer.FindAllObjectTemplates(sourceDomain).Where(o => !o.IsAntiTemplate()).ToList();
            }
            if (stringBuilder == null)
            {
                stringBuilder = new StringBuilder();
            }
            if (postPonedPropertiesToCheck == null)
            {
                postPonedPropertiesToCheck = new HashSet <IPropertyTemplateItem>();
            }

            if (remaining.Count > 0)
            {
                IObjectTemplateExp current = remaining[0];
                remaining.RemoveAt(0);
                string currentVariableName = current.BindsTo.Name;
                variablesBindedSoFar.Add(current.BindsTo);

                // Generate conditional for the object template
                stringBuilder.AppendLine("if (" + currentVariableName + " != null) {");

                // Generate bindings for each non-many free variables
                ISet <IPropertyTemplateItem> managedProps = new HashSet <IPropertyTemplateItem>();
                foreach (IPropertyTemplateItem nonManyProp in current.Part.Where(prop =>
                                                                                 (prop.Value is ObjectTemplateExp || prop.Value is VariableExp) &&
                                                                                 !prop.ReferredProperty.isMany()))
                {
                    IVariable bindedVariable = QvtModelExplorer.FindBindedVariables(nonManyProp).Single();
                    if (bindedVariable != null && !variablesBindedSoFar.Contains(bindedVariable))
                    {
                        managedProps.Add(nonManyProp);
                        stringBuilder.AppendLine(GenerateBindingFreeNonMany(nonManyProp, bindedVariable));
                        variablesBindedSoFar.Add(bindedVariable);
                    }
                }

                // We compute the checks that we can do right now, and the ones that must be post poned because their variables are not binded yet
                // For now we only do checks on single value properties, the many valued one are simply exhaustively explored/binded later
                IEnumerable <IPropertyTemplateItem> candidatesInit = current.Part.Where(prop => !prop.ReferredProperty.isMany() && (prop.Value is CSharpOpaqueExpression || prop.Value is IVariableExp));
                ISet <IPropertyTemplateItem>        candidates     = new HashSet <IPropertyTemplateItem>();
                candidates.UnionWith(candidatesInit);
                candidates.UnionWith(postPonedPropertiesToCheck);
                candidates.ExceptWith(managedProps);
                ISet <IPropertyTemplateItem> propsToCheck = new HashSet <IPropertyTemplateItem>();
                foreach (IPropertyTemplateItem candidate in candidates)
                {
                    if (!variablesBindedSoFar.IsSupersetOf(QvtModelExplorer.FindBindedVariables(candidate)))
                    {
                        propsToCheck.Remove(candidate);
                        postPonedPropertiesToCheck.Add(candidate);
                    }
                    else
                    {
                        propsToCheck.Add(candidate);
                        postPonedPropertiesToCheck.Remove(candidate);
                    }
                }

                // We generate the checks for all the ones that can be made now
                if (propsToCheck.Count > 0)
                {
                    IEnumerable <string> conditions = propsToCheck.Select(u => GenerateConditionnalProperty(u, true));
                    string condition = string.Join(" && ", conditions);
                    stringBuilder.AppendLine("if (" + condition + ") {");
                }

                // We make a recursion for each object template not managed yet
                // - If the ref is many, then we make the binding first using a loop
                // - If the ref is not many, the binding was done before when managing non-many

                List <IPropertyTemplateItem> objectTemplatesManyRemaining = current.Part.Where(p => p.Value is ObjectTemplateExp && p.ReferredProperty.isMany() && remaining.Contains(p.Value)).ToList();
                foreach (IPropertyTemplateItem propWithTemplate in objectTemplatesManyRemaining)
                {
                    // Generate start for each, which binds the variable associated with the object template
                    ObjectTemplateExp objectTemplate = (ObjectTemplateExp)propWithTemplate.Value;
                    stringBuilder.AppendLine("foreach (" + objectTemplate.BindsTo.Type.GetRealTypeName() + " " + objectTemplate.BindsTo.Name + "  in " + currentVariableName + "." + propWithTemplate.ReferredProperty.Name + ".OfType<" + propWithTemplate.ReferredProperty.Type.GetRealTypeName() + ">()) {");
                    variablesBindedSoFar.Add(objectTemplate.BindsTo);
                }

                GenerateDomainCheckMethodContent(sourceDomain, variablesBindedSoFar, analysis, remaining, stringBuilder, postPonedPropertiesToCheck);

                foreach (IPropertyTemplateItem _ in objectTemplatesManyRemaining)
                {
                    // Generate end for each
                    stringBuilder.AppendLine("}");
                }

                // Generate end if checks all c# expressions
                if (propsToCheck.Count > 0)
                {
                    stringBuilder.Append("}");
                }

                // End conditional on the object template
                stringBuilder.AppendLine("}");
            }

            // We stop the recursion if there are no more object templates to manage
            else
            {
                string matchClassName = QvtCodeGeneratorStrings.MatchDomainClassName(sourceDomain);

                // Now we can finally create the Match object
                stringBuilder.AppendLine(matchClassName + " match = new " + matchClassName + "() {");

                foreach (IVariable variable in analysis.VariablesItCanBind)
                {
                    stringBuilder.AppendLine(variable.Name + " = " + variable.Name + ",");
                }

                stringBuilder.AppendLine("};");
                stringBuilder.AppendLine("result.Add(match);");
            }

            return(stringBuilder.ToString());
        }
Beispiel #58
0
        public async Task <IActionResult> PostInputsAsync([FromBody] InputsRequest request)
        {
            // Validate request.
            if (!ModelState.IsValid ||
                request is null ||
                string.IsNullOrWhiteSpace(request.BlindedOutputScriptHex) ||
                string.IsNullOrWhiteSpace(request.ChangeOutputAddress) ||
                request.Inputs is null ||
                !request.Inputs.Any() ||
                request.Inputs.Any(x => x.Input == default(TxoRef) ||
                                   x.Input.TransactionId is null ||
                                   string.IsNullOrWhiteSpace(x.Proof)))
            {
                return(BadRequest("Invalid request."));
            }

            if (request.Inputs.Count() > 7)
            {
                return(BadRequest("Maximum 7 inputs can be registered."));
            }

            using (await InputsLock.LockAsync())
            {
                CcjRound round = Coordinator.GetCurrentInputRegisterableRound();

                // Do more checks.
                try
                {
                    if (round.ContainsBlindedOutputScriptHex(request.BlindedOutputScriptHex, out _))
                    {
                        return(BadRequest("Blinded output has already been registered."));
                    }

                    BitcoinAddress changeOutputAddress;
                    try
                    {
                        changeOutputAddress = BitcoinAddress.Create(request.ChangeOutputAddress, Network);
                    }
                    catch (FormatException ex)
                    {
                        return(BadRequest($"Invalid ChangeOutputAddress. Details: {ex.Message}"));
                    }

                    var inputs = new HashSet <(OutPoint OutPoint, TxOut Output)>();

                    var alicesToRemove = new HashSet <Guid>();

                    foreach (InputProofModel inputProof in request.Inputs)
                    {
                        if (inputs.Any(x => x.OutPoint == inputProof.Input))
                        {
                            return(BadRequest("Cannot register an input twice."));
                        }
                        if (round.ContainsInput(inputProof.Input.ToOutPoint(), out List <Alice> tr))
                        {
                            alicesToRemove.UnionWith(tr.Select(x => x.UniqueId));                             // Input is already registered by this alice, remove it later if all the checks are completed fine.
                        }
                        if (Coordinator.AnyRunningRoundContainsInput(inputProof.Input.ToOutPoint(), out List <Alice> tnr))
                        {
                            if (tr.Union(tnr).Count() > tr.Count())
                            {
                                return(BadRequest("Input is already registered in another round."));
                            }
                        }

                        OutPoint outpoint = inputProof.Input.ToOutPoint();
                        if (Coordinator.UtxoReferee.BannedUtxos.TryGetValue(outpoint, out (int severity, DateTimeOffset timeOfBan)bannedElem))
                        {
                            int maxBan  = (int)TimeSpan.FromHours((long)Global.RoundConfig.DosDurationHours).TotalMinutes;
                            int banLeft = maxBan - (int)(DateTimeOffset.UtcNow - bannedElem.timeOfBan).TotalMinutes;
                            if (banLeft > 0)
                            {
                                return(BadRequest($"Input is banned from participation for {banLeft} minutes: {inputProof.Input.Index}:{inputProof.Input.TransactionId}."));
                            }
                            await Coordinator.UtxoReferee.UnbanAsync(outpoint);
                        }

                        GetTxOutResponse getTxOutResponse = await RpcClient.GetTxOutAsync(inputProof.Input.TransactionId, (int)inputProof.Input.Index, includeMempool : true);

                        // Check if inputs are unspent.
                        if (getTxOutResponse is null)
                        {
                            return(BadRequest($"Provided input is not unspent: {inputProof.Input.Index}:{inputProof.Input.TransactionId}"));
                        }

                        // Check if unconfirmed.
                        if (getTxOutResponse.Confirmations <= 0)
                        {
                            // If it spends a CJ then it may be acceptable to register.
                            if (!Coordinator.ContainsCoinJoin(inputProof.Input.TransactionId))
                            {
                                return(BadRequest("Provided input is neither confirmed, nor is from an unconfirmed coinjoin."));
                            }
                            // After 24 unconfirmed cj in the mempool dont't let unconfirmed coinjoin to be registered.
                            if (await Coordinator.IsUnconfirmedCoinJoinLimitReachedAsync())
                            {
                                return(BadRequest("Provided input is from an unconfirmed coinjoin, but the maximum number of unconfirmed coinjoins is reached."));
                            }
                        }

                        // Check if immature.
                        if (getTxOutResponse.Confirmations <= 100)
                        {
                            if (getTxOutResponse.IsCoinBase)
                            {
                                return(BadRequest("Provided input is immature."));
                            }
                        }

                        // Check if inputs are native segwit.
                        if (getTxOutResponse.ScriptPubKeyType != "witness_v0_keyhash")
                        {
                            return(BadRequest("Provided input must be witness_v0_keyhash."));
                        }

                        TxOut txout = getTxOutResponse.TxOut;

                        var address = (BitcoinWitPubKeyAddress)txout.ScriptPubKey.GetDestinationAddress(Network);
                        // Check if proofs are valid.
                        bool validProof;
                        try
                        {
                            validProof = address.VerifyMessage(request.BlindedOutputScriptHex, inputProof.Proof);
                        }
                        catch (FormatException ex)
                        {
                            return(BadRequest($"Provided proof is invalid: {ex.Message}"));
                        }
                        if (!validProof)
                        {
                            return(BadRequest("Provided proof is invalid."));
                        }

                        inputs.Add((inputProof.Input.ToOutPoint(), txout));
                    }

                    // Check if inputs have enough coins.
                    Money inputSum        = inputs.Select(x => x.Output.Value).Sum();
                    Money networkFeeToPay = (inputs.Count() * round.FeePerInputs) + (2 * round.FeePerOutputs);
                    Money changeAmount    = inputSum - (round.Denomination + networkFeeToPay);
                    if (changeAmount < Money.Zero)
                    {
                        return(BadRequest($"Not enough inputs are provided. Fee to pay: {networkFeeToPay.ToString(false, true)} BTC. Round denomination: {round.Denomination.ToString(false, true)} BTC. Only provided: {inputSum.ToString(false, true)} BTC."));
                    }

                    // Make sure Alice checks work.
                    var alice = new Alice(inputs, networkFeeToPay, changeOutputAddress, request.BlindedOutputScriptHex);

                    foreach (Guid aliceToRemove in alicesToRemove)
                    {
                        round.RemoveAlicesBy(aliceToRemove);
                    }
                    round.AddAlice(alice);

                    // All checks are good. Sign.
                    byte[] blindedData;
                    try
                    {
                        blindedData = ByteHelpers.FromHex(request.BlindedOutputScriptHex);
                    }
                    catch
                    {
                        return(BadRequest("Invalid blinded output hex."));
                    }

                    byte[] signature = RsaKey.SignBlindedData(blindedData);

                    // Check if phase changed since.
                    if (round.Status != CcjRoundStatus.Running || round.Phase != CcjRoundPhase.InputRegistration)
                    {
                        return(base.StatusCode(StatusCodes.Status503ServiceUnavailable, "The state of the round changed while handling the request. Try again."));
                    }

                    // Progress round if needed.
                    if (round.CountAlices() >= round.AnonymitySet)
                    {
                        await round.RemoveAlicesIfInputsSpentAsync();

                        if (round.CountAlices() >= round.AnonymitySet)
                        {
                            await round.ExecuteNextPhaseAsync(CcjRoundPhase.ConnectionConfirmation);
                        }
                    }

                    var resp = new InputsResponse
                    {
                        UniqueId = alice.UniqueId,
                        BlindedOutputSignature = signature,
                        RoundId = round.RoundId
                    };
                    return(Ok(resp));
                }
                catch (Exception ex)
                {
                    Logger.LogDebug <ChaumianCoinJoinController>(ex);
                    return(BadRequest(ex.Message));
                }
            }
        }
Beispiel #59
0
        public void Draw()
        {
            if (World.WorldActor.Disposed)
            {
                return;
            }

            if (debugVis.Value != null && lastDepthPreviewEnabled != debugVis.Value.DepthBuffer)
            {
                lastDepthPreviewEnabled = debugVis.Value.DepthBuffer;
                Game.Renderer.WorldSpriteRenderer.SetDepthPreviewEnabled(lastDepthPreviewEnabled);
            }

            RefreshPalette();

            onScreenActors.UnionWith(World.ScreenMap.RenderableActorsInBox(Viewport.TopLeft, Viewport.BottomRight));
            var renderables = GenerateRenderables();
            var bounds      = Viewport.GetScissorBounds(World.Type != WorldType.Editor);

            Game.Renderer.EnableScissor(bounds);

            if (enableDepthBuffer)
            {
                Game.Renderer.Context.EnableDepthBuffer();
            }

            if (terrainRenderer != null)
            {
                terrainRenderer.RenderTerrain(this, Viewport);
            }

            Game.Renderer.Flush();

            for (var i = 0; i < renderables.Count; i++)
            {
                renderables[i].Render(this);                 //пишет в WorldSpriteRenderer инфу о каждом renderables
            }
            Game.Renderer.Flush();
            if (enableDepthBuffer)
            {
                Game.Renderer.ClearDepthBuffer();
            }

            foreach (var a in World.ActorsWithTrait <IRenderAboveWorld>())
            {
                if (a.Actor.IsInWorld && !a.Actor.Disposed)
                {
                    a.Trait.RenderAboveWorld(a.Actor, this);
                }
            }

            var renderShroud = World.RenderPlayer != null ? World.RenderPlayer.Shroud : null;

            if (enableDepthBuffer)
            {
                Game.Renderer.ClearDepthBuffer();
            }

            foreach (var a in World.ActorsWithTrait <IRenderShroud>())
            {
                a.Trait.RenderShroud(renderShroud, this);
            }

            if (enableDepthBuffer)
            {
                Game.Renderer.Context.DisableDepthBuffer();
            }

            Game.Renderer.DisableScissor();

            var finalOverlayRenderables = GenerateOverlayRenderables();

            // HACK: Keep old grouping behaviour
            var groupedOverlayRenderables = finalOverlayRenderables.GroupBy(prs => prs.GetType());

            foreach (var g in groupedOverlayRenderables)
            {
                foreach (var r in g)
                {
                    r.Render(this);
                }
            }

            if (debugVis.Value != null && debugVis.Value.RenderGeometry)
            {
                for (var i = 0; i < renderables.Count; i++)
                {
                    renderables[i].RenderDebugGeometry(this);
                }

                foreach (var g in groupedOverlayRenderables)
                {
                    foreach (var r in g)
                    {
                        r.RenderDebugGeometry(this);
                    }
                }
            }

            if (debugVis.Value != null && debugVis.Value.ScreenMap)
            {
                foreach (var r in World.ScreenMap.RenderBounds(World.RenderPlayer))
                {
                    Game.Renderer.WorldRgbaColorRenderer.DrawRect(
                        new float3(r.Left, r.Top, r.Bottom),
                        new float3(r.Right, r.Bottom, r.Bottom),
                        1 / Viewport.Zoom, Color.MediumSpringGreen);
                }

                foreach (var r in World.ScreenMap.MouseBounds(World.RenderPlayer))
                {
                    Game.Renderer.WorldRgbaColorRenderer.DrawRect(
                        new float3(r.Left, r.Top, r.Bottom),
                        new float3(r.Right, r.Bottom, r.Bottom),
                        1 / Viewport.Zoom, Color.OrangeRed);
                }
            }

            Game.Renderer.Flush();

            // PERF: Reuse collection to avoid allocations.
            onScreenActors.Clear();
        }
Beispiel #60
0
        /// <summary>
        /// Resolve a relationship stanza (a list of relationships).
        /// This will add modules to be installed, if required.
        /// May recurse back to Resolve for those new modules.
        ///
        /// If `soft_resolve` is true, we warn rather than throw exceptions on mods we cannot find.
        /// If `soft_resolve` is false (default), we throw a ModuleNotFoundKraken if we can't find a dependency.
        ///
        /// Throws a TooManyModsProvideKraken if we have too many choices and
        /// options.without_toomanyprovides_kraken is not set.
        ///
        /// See RelationshipResolverOptions for further adjustments that can be made.
        /// </summary>
        private void ResolveStanza(IEnumerable <RelationshipDescriptor> stanza, SelectionReason reason,
                                   RelationshipResolverOptions options, bool soft_resolve = false, IEnumerable <RelationshipDescriptor> old_stanza = null)
        {
            if (stanza == null)
            {
                return;
            }
            stanza = stanza.Memoize();

            foreach (RelationshipDescriptor descriptor in stanza)
            {
                log.DebugFormat("Considering {0}", descriptor.ToString());

                // If we already have this dependency covered, skip.
                if (descriptor.MatchesAny(modlist.Values, null, null))
                {
                    continue;
                }
                else if (descriptor.ContainsAny(modlist.Keys))
                {
                    CkanModule module = modlist.Values
                                        .FirstOrDefault(m => descriptor.ContainsAny(new string[] { m.identifier }));
                    if (options.proceed_with_inconsistencies)
                    {
                        conflicts.Add(new KeyValuePair <CkanModule, CkanModule>(module, reason.Parent));
                        conflicts.Add(new KeyValuePair <CkanModule, CkanModule>(reason.Parent, module));
                        continue;
                    }
                    else
                    {
                        throw new InconsistentKraken(
                                  $"{descriptor} required, but an incompatible version is in the resolver"
                                  );
                    }
                }

                // If it's already installed, skip.
                if (descriptor.MatchesAny(
                        registry.InstalledModules.Select(im => im.Module),
                        registry.InstalledDlls.ToHashSet(),
                        registry.InstalledDlc))
                {
                    continue;
                }
                else if (descriptor.ContainsAny(registry.InstalledModules.Select(im => im.Module.identifier)))
                {
                    CkanModule module = registry.InstalledModules
                                        .Select(im => im.Module)
                                        .FirstOrDefault(m => descriptor.ContainsAny(new string[] { m.identifier }));
                    if (options.proceed_with_inconsistencies)
                    {
                        conflicts.Add(new KeyValuePair <CkanModule, CkanModule>(module, reason.Parent));
                        conflicts.Add(new KeyValuePair <CkanModule, CkanModule>(reason.Parent, module));
                        continue;
                    }
                    else
                    {
                        throw new InconsistentKraken(
                                  $"{descriptor} required, but an incompatible version is installed"
                                  );
                    }
                }

                // Pass mod list in case an older version of a module is conflict-free while later versions have conflicts
                var descriptor1 = descriptor;
                List <CkanModule> candidates = descriptor
                                               .LatestAvailableWithProvides(registry, kspversion, modlist.Values)
                                               .Where(mod => descriptor1.WithinBounds(mod) && MightBeInstallable(mod))
                                               .ToList();
                if (candidates.Count == 0)
                {
                    // Nothing found, try again without mod list
                    // (conflicts will still be caught below)
                    candidates = descriptor
                                 .LatestAvailableWithProvides(registry, kspversion)
                                 .Where(mod => descriptor1.WithinBounds(mod) && MightBeInstallable(mod))
                                 .ToList();
                }

                if (candidates.Count == 0)
                {
                    if (!soft_resolve)
                    {
                        log.InfoFormat("Dependency on {0} found but it is not listed in the index, or not available for your version of KSP.", descriptor.ToString());
                        throw new DependencyNotSatisfiedKraken(reason.Parent, descriptor.ToString());
                    }
                    log.InfoFormat("{0} is recommended/suggested but it is not listed in the index, or not available for your version of KSP.", descriptor.ToString());
                    continue;
                }
                if (candidates.Count > 1)
                {
                    // Oh no, too many to pick from!
                    // TODO: It would be great if instead we picked the one with the
                    // most recommendations.
                    if (options.without_toomanyprovides_kraken)
                    {
                        continue;
                    }

                    // If we've got a parent stanza that has a relationship on a mod that provides what
                    // we need, then select that.
                    if (old_stanza != null)
                    {
                        List <CkanModule> provide = candidates
                                                    .Where(cand => old_stanza.Any(rel => rel.WithinBounds(cand)))
                                                    .ToList();
                        if (!provide.Any() || provide.Count() > 1)
                        {
                            //We still have either nothing, or too many to pick from
                            //Just throw the TMP now
                            throw new TooManyModsProvideKraken(descriptor.ToString(), candidates);
                        }
                        candidates[0] = provide.First();
                    }
                    else
                    {
                        throw new TooManyModsProvideKraken(descriptor.ToString(), candidates);
                    }
                }

                CkanModule candidate = candidates[0];

                // Finally, check our candidate against everything which might object
                // to it being installed; that's all the mods which are fixed in our
                // list thus far, as well as everything on the system.

                var fixed_mods = new HashSet <CkanModule>(modlist.Values);
                fixed_mods.UnionWith(installed_modules);

                CkanModule conflicting_mod = fixed_mods.FirstOrDefault(mod => mod.ConflictsWith(candidate));
                if (conflicting_mod == null)
                {
                    // Okay, looks like we want this one. Adding.
                    Add(candidate, reason);
                    Resolve(candidate, options, stanza);
                }
                else if (soft_resolve)
                {
                    log.InfoFormat("{0} would cause conflicts, excluding it from consideration", candidate);
                }
                else
                {
                    if (options.proceed_with_inconsistencies)
                    {
                        Add(candidate, reason);
                        conflicts.Add(new KeyValuePair <CkanModule, CkanModule>(conflicting_mod, candidate));
                        conflicts.Add(new KeyValuePair <CkanModule, CkanModule>(candidate, conflicting_mod));
                    }
                    else
                    {
                        throw new InconsistentKraken(
                                  $"{conflicting_mod} conflicts with {candidate}");
                    }
                }
            }
        }