public virtual InternalModelBuilder Apply(InternalModelBuilder modelBuilder)
        {
            Check.NotNull(modelBuilder, nameof(modelBuilder));

            foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
            {
                var unmappedProperty = entityType.GetProperties().FirstOrDefault(p => !IsMappedPrimitiveProperty(((IProperty)p).ClrType));
                if (unmappedProperty != null)
                {
                    throw new InvalidOperationException(CoreStrings.PropertyNotMapped(unmappedProperty.Name, entityType.Name));
                }

                if (entityType.HasClrType())
                {
                    var clrProperties = new HashSet<string>();
                    clrProperties.UnionWith(entityType.ClrType.GetRuntimeProperties()
                        .Where(pi => pi.IsCandidateProperty())
                        .Select(pi => pi.Name));

                    clrProperties.ExceptWith(entityType.GetProperties().Select(p => p.Name));

                    clrProperties.ExceptWith(entityType.GetNavigations().Select(p => p.Name));

                    var entityTypeBuilder = modelBuilder.Entity(entityType.ClrType, ConfigurationSource.Convention);

                    clrProperties.RemoveWhere(p => entityTypeBuilder.IsIgnored(p, ConfigurationSource.Convention));

                    if (clrProperties.Count > 0)
                    {
                        foreach (var clrProperty in clrProperties)
                        {
                            var actualProperty = entityType.ClrType.GetRuntimeProperty(clrProperty);
                            var targetType = FindCandidateNavigationPropertyType(actualProperty);
                            if (targetType != null)
                            {
                                if (!modelBuilder.IsIgnored(targetType.DisplayName(), ConfigurationSource.Convention))
                                {
                                    throw new InvalidOperationException(CoreStrings.NavigationNotAdded(actualProperty.Name, entityType.Name));
                                }
                            }
                            else
                            {
                                throw new InvalidOperationException(CoreStrings.PropertyNotAdded(actualProperty.Name, entityType.Name));
                            }
                        }
                    }
                }
            }

            return modelBuilder;
        }
        public void onProductListReceived (string productListString) {

            Hashtable response = (Hashtable)MiniJSON.jsonDecode (productListString);

            if (response.Count == 0) {
                callback.logError (UnibillError.AMAZONAPPSTORE_GETITEMDATAREQUEST_NO_PRODUCTS_RETURNED);
                callback.onSetupComplete (false);
                return;
            }

            HashSet<PurchasableItem> productsReceived = new HashSet<PurchasableItem>();
            foreach (var identifier in response.Keys) {
                var item = remapper.getPurchasableItemFromPlatformSpecificId(identifier.ToString());
                Hashtable details = (Hashtable) response[identifier];
                
                PurchasableItem.Writer.setLocalizedPrice(item, (string) details["price"]);
                PurchasableItem.Writer.setLocalizedTitle(item, (string) details["localizedTitle"]);
                PurchasableItem.Writer.setLocalizedDescription(item, (string) details["localizedDescription"]);
                productsReceived.Add(item);
            }
            
            HashSet<PurchasableItem> productsNotReceived = new HashSet<PurchasableItem> (db.AllPurchasableItems);
            productsNotReceived.ExceptWith (productsReceived);
            if (productsNotReceived.Count > 0) {
                foreach (PurchasableItem product in productsNotReceived) {
                    this.unknownAmazonProducts.Add(remapper.mapItemIdToPlatformSpecificId(product));
                    callback.logError(UnibillError.AMAZONAPPSTORE_GETITEMDATAREQUEST_MISSING_PRODUCT, product.Id, remapper.mapItemIdToPlatformSpecificId(product));
                }
            }

            callback.onSetupComplete(true);
        }
 public EntityJoinOperation(Process process, Relationship rel)
     : base(process) {
     _rel = rel;
     var rightFields = new HashSet<string>(rel.RightEntity.OutputFields().Aliases());
     rightFields.ExceptWith(rel.LeftEntity.OutputFields().Aliases());
     _fields = rightFields.ToArray();
 }
Exemple #4
0
        private async Task DeleteInDestination(HashSet<Tuple<string, string, string>> src,
                                               HashSet<Tuple<string, string, string>> dst)
        {
            dst.ExceptWith(src);

            int n = 0;

            // group by table + partition
            foreach (var batch1 in dst.GroupBy(x => x.Item1 + x.Item2))
            {
                CloudTable dstTable = _dstClient.GetTableReference(batch1.First().Item1);

                if (_token.IsCancellationRequested)
                    return;

                foreach (var batch2 in batch1.Batch(100))
                {
                    if (_token.IsCancellationRequested)
                        return;

                    var op = new TableBatchOperation();

                    foreach (var tuple in batch2)
                    {
                        op.Delete(new TableEntity(tuple.Item2, tuple.Item3) {ETag = "*"});
                    }

                    await dstTable.ExecuteBatchAsync(op, _token);

                    n += Math.Min(op.Count, 100);
                    Console.WriteLine("deleted {0} rows", n);
                }
            }
        }
Exemple #5
0
        public override void Visit(AST.MethodDeclNode node)
        {
            MethodBeingVisited = ClassBeingVisited.Methods.Lookup(node.methodName.name);

            if (node.paramDeclList != null)
                foreach (AST.ParamDeclNode paramDecl in node.paramDeclList)
                    paramDecl.Accept(this);

            if (node.variableDeclList != null)
                foreach (AST.VariableDeclNode variableDecl in node.variableDeclList)
                    variableDecl.Accept(this);

            if (node.statementList != null)
            {
                var reverseList = node.statementList.statementList;
                reverseList.Reverse();

                HashSet<AST.IdentifierNode> afterLiveness = new HashSet<AST.IdentifierNode>();

                foreach (AST.StatementNode statement in reverseList)
                {
                    m_R.Clear();
                    m_W.Clear();
                    statement.Accept(this);
                    afterLiveness.ExceptWith(m_W);
                    afterLiveness.UnionWith(m_R);

                    m_livenessAtNode[statement] = new HashSet<AST.IdentifierNode>(afterLiveness);
                }
            }
        }
Exemple #6
0
		public void onProductListReceived(string productListString) {
			Dictionary<string, object> response = (Dictionary<string, object>)Unibill.Impl.MiniJSON.jsonDecode(productListString);

			if (response.Count == 0) {
				callback.logError (UnibillError.SAMSUNG_APPS_NO_PRODUCTS_RETURNED);
				callback.onSetupComplete (false);
				return;
			}

			HashSet<PurchasableItem> productsReceived = new HashSet<PurchasableItem>();
			foreach (var identifier in response.Keys) {
				if (remapper.canMapProductSpecificId(identifier.ToString())) {
					var item = remapper.getPurchasableItemFromPlatformSpecificId(identifier.ToString());
					Dictionary<string, object> details = (Dictionary<string, object>)response[identifier];

					PurchasableItem.Writer.setLocalizedPrice(item,  details["price"].ToString());
					PurchasableItem.Writer.setLocalizedTitle(item, (string) details["localizedTitle"]);
					PurchasableItem.Writer.setLocalizedDescription(item, (string) details["localizedDescription"]);
					productsReceived.Add(item);
				} else {
					logger.LogError("Warning: Unknown product identifier: {0}", identifier.ToString());
				}
			}

			HashSet<PurchasableItem> productsNotReceived = new HashSet<PurchasableItem> (config.AllPurchasableItems);
			productsNotReceived.ExceptWith (productsReceived);
			if (productsNotReceived.Count > 0) {
				foreach (PurchasableItem product in productsNotReceived) {
					this.unknownSamsungProducts.Add(remapper.mapItemIdToPlatformSpecificId(product));
					callback.logError(UnibillError.SAMSUNG_APPS_MISSING_PRODUCT, product.Id, remapper.mapItemIdToPlatformSpecificId(product));
				}
			}

			callback.onSetupComplete (true);
		}
Exemple #7
0
        public void onProductListReceived (string productListString) {
            if (productListString.Length == 0) {
                biller.logError (UnibillError.STOREKIT_RETURNED_NO_PRODUCTS);
                biller.onSetupComplete (false);
                return;
            }

            Dictionary<string, object> response = (Dictionary<string, object>)Unibill.Impl.MiniJSON.jsonDecode(productListString);
            HashSet<PurchasableItem> productsReceived = new HashSet<PurchasableItem>();
            foreach (var identifier in response.Keys) {
                var item = remapper.getPurchasableItemFromPlatformSpecificId(identifier.ToString());
                Dictionary<string, object> details = (Dictionary<string, object>)response[identifier];

                PurchasableItem.Writer.setLocalizedPrice(item, details["price"].ToString());
                PurchasableItem.Writer.setLocalizedTitle(item, details["localizedTitle"].ToString());
                PurchasableItem.Writer.setLocalizedDescription(item, details["localizedDescription"].ToString());
                productsReceived.Add(item);
            }

            HashSet<PurchasableItem> productsNotReceived = new HashSet<PurchasableItem> (products);
            productsNotReceived.ExceptWith (productsReceived);
            if (productsNotReceived.Count > 0) {
                foreach (PurchasableItem product in productsNotReceived) {
                    biller.logError(UnibillError.STOREKIT_REQUESTPRODUCTS_MISSING_PRODUCT, product.Id, remapper.mapItemIdToPlatformSpecificId(product));
                }
            }

            this.productsNotReturnedByStorekit = new HashSet<string>(productsNotReceived.Select(x => remapper.mapItemIdToPlatformSpecificId(x)));

            // We should complete so long as we have at least one purchasable product.
            biller.onSetupComplete(true);
        }
            public override void WalkGrammar(Grammar grammar)
            {
                var rules = grammar.Rules.ToDictionary(r => r.Identifier.Name, r => r);

                var startRule = grammar.Settings.Where(s => s.Key.Name == "start").Select(s => s.Value.ToString()).SingleOrDefault() ?? grammar.Rules[0].Identifier.Name;
                this.usedRules.Add(startRule);
                this.rulesToVisit.Enqueue(startRule);

                var publicRules = grammar.Rules.Where(r => r.Flags.Any(f => f.Name == "public" || f.Name == "export"));
                foreach (var rule in publicRules)
                {
                    if (this.usedRules.Add(rule.Identifier.Name))
                    {
                        this.rulesToVisit.Enqueue(rule.Identifier.Name);
                    }
                }

                while (this.rulesToVisit.Count > 0)
                {
                    var ruleName = this.rulesToVisit.Dequeue();
                    this.WalkRule(rules[ruleName]);
                }

                var unusedRules = new HashSet<string>(grammar.Rules.Select(r => r.Identifier.Name));
                unusedRules.ExceptWith(this.usedRules);

                foreach (var ruleName in unusedRules)
                {
                    var rule = rules[ruleName];
                    this.result.AddCompilerError(rule.Identifier.Start, () => Resources.PEG0017_WARNING_UnusedRule, rule.Identifier.Name);
                }
            }
 static void Main(string[] args)
 {
     var letters = new HashSet<char>("the quick brown fox");
     Console.WriteLine(letters.Contains('t')); // true
     Console.WriteLine(letters.Contains('j')); // false
     foreach (char c in letters)
     {
         Console.Write(c); // the quickbrownfx
     }
     letters.IntersectWith("aeiou");
     foreach (char c in letters)
     {
         Console.Write(c); // euio
     }
     var letters2 = new HashSet<char>("the quick brown fox");
     letters2.ExceptWith("aeiou");
     foreach (char c in letters2)
     {
         Console.Write(c); // th qckbrwnfx
     }
     var letters3 = new HashSet<char>("the quick brown fox");
     letters3.SymmetricExceptWith("the lazy brown fox");
     foreach (char c in letters3)
     {
         Console.Write(c); // quicklazy
     }
 }
Exemple #10
0
        /// <summary>
        /// start
        /// </summary>
        public override void Start()
        {
            if (this._config.Discovery != null &&
                this._config.Discovery.Zookeeper != null &&
                !string.IsNullOrEmpty(this._config.Discovery.Zookeeper.ConfigPath) &&
                !string.IsNullOrEmpty(this._config.Discovery.Zookeeper.ConfigName) &&
                !string.IsNullOrEmpty(this._config.Discovery.Zookeeper.ZNode))
            {
                this._zkDiscovery = new ZoomkeeperDiscovery(this._config.Client,
                    this._config.Discovery.Zookeeper.ConfigPath,
                    this._config.Discovery.Zookeeper.ConfigName,
                    this._config.Discovery.Zookeeper.ZNode, endpoints =>
                    {
                        lock (this._lockObj)
                        {
                            var set = new HashSet<string>(this.GetAllRegisteredEndPoint().Select(c => c.Key).Distinct().ToArray());
                            set.ExceptWith(endpoints.Select(p =>
                                string.Concat(p.Address.ToString(), ":", p.Port.ToString())).Distinct().ToArray());
                            if (set.Count > 0)
                            {
                                foreach (var name in set) this.UnRegisterEndPoint(name);
                            }

                            foreach (var p in endpoints)
                                this.TryRegisterEndPoint(string.Concat(p.Address.ToString(), ":", p.Port.ToString()), new EndPoint[] { p });
                        }
                    });
            }
            base.Start();
        }
        /// <summary>
        /// start
        /// </summary>
        public void Start()
        {
            if (this._config == null || this._config.Discovery == null ||
                this._config.Discovery.Zookeeper == null || string.IsNullOrEmpty(this._config.Discovery.Zookeeper.ZNode)) return;

            var keeperConfig = this._config.Discovery.Zookeeper;
            var zk = ZookClientPool.Get(keeperConfig.ConfigPath, "zookeeper", keeperConfig.ConfigName);

            //ensure root node...
            var nodes = new NodeInfo[2];
            nodes[0] = new NodeInfo(string.Concat("/", keeperConfig.ZNode), null, IDs.OPEN_ACL_UNSAFE, CreateModes.Persistent);
            nodes[1] = new NodeInfo(string.Concat("/", keeperConfig.ZNode, "/consumers"), null, IDs.OPEN_ACL_UNSAFE, CreateModes.Persistent);
            NodeFactory.TryEnsureCreate(zk, nodes, () =>
            {
                var currProcess = Process.GetCurrentProcess();
                var path = string.Concat("/", keeperConfig.ZNode, "/consumers/", Uri.EscapeDataString(string.Format(
                    "consumer://{0}/{1}?application={2}&category=consumers&check=false&dubbo=2.5.1&interface={1}&methods={6}&owner={3}&pid={4}&revision=0.0.2-SNAPSHOT&side=consumer&timestamp={5}",
                    IPUtility.GetLocalIntranetIP().ToString(),
                    keeperConfig.ZNode,
                    currProcess.ProcessName,
                    string.Empty,
                    currProcess.Id.ToString(),
                    Date.ToMillisecondsSinceEpoch(DateTime.UtcNow).ToString(),
                    this._methods)));
                this._sessionNode = new SessionNode(zk, path, null, IDs.OPEN_ACL_UNSAFE);
            });

            this._watcher = new ChildrenWatcher(zk, string.Concat("/", keeperConfig.ZNode, "/providers"), (names) =>
            {
                //已存在的servers
                var arrExistServers = this._thriftClient.GetAllNodeNames();
                //当前从zk获取到servers
                var arrNowServers = names.Select(s =>
                {
                    var t = Uri.UnescapeDataString(s);
                    t = t.Substring(t.IndexOf(":") + 3);
                    return t.Substring(0, t.IndexOf("/"));
                }).ToArray();

                var set = new HashSet<string>(arrExistServers);
                set.ExceptWith(arrNowServers);
                if (set.Count > 0)
                {
                    foreach (var child in set) this._thriftClient.UnRegisterServerNode(child);
                }

                set = new HashSet<string>(arrNowServers);
                set.ExceptWith(arrExistServers);
                if (set.Count > 0)
                {
                    foreach (var child in set)
                    {
                        int index = child.IndexOf(":");
                        this._thriftClient.RegisterServerNode(child,
                            new IPEndPoint(IPAddress.Parse(child.Substring(0, index)), int.Parse(child.Substring(index + 1))));
                    }
                }
            });
        }
Exemple #12
0
 public IEnumerable<string> GetCommands(string profile)
 {
     var commands = new HashSet<string>(_requirements.SelectMany(x => x.Commands));
     var removeCommands = _remove.Where(x => x.Profile == profile)
         .SelectMany(x => x.Commands).ToArray();
     commands.ExceptWith(removeCommands);
     return commands;
 }
Exemple #13
0
 /// <summary>
 /// Returns all Edges that connect the two nodes (which are assumed to be different).
 /// </summary>
 /// <param name="node0"></param>
 /// <param name="node1"></param>
 /// <returns></returns>
 public static IList<DirectedEdge> GetEdgesBetween(Node node0, Node node1)
 {
     IList<Edge> edges0 = DirectedEdge.ToEdges(node0.OutEdges.Edges);
     var commonEdges = new HashSet<DirectedEdge>(Utilities.Caster.Cast<DirectedEdge>(edges0));
     IList<Edge> edges1 = DirectedEdge.ToEdges(node1.OutEdges.Edges);
     commonEdges.ExceptWith(Utilities.Caster.Cast<DirectedEdge>(edges1));
     return new List<DirectedEdge>(commonEdges);
 }
		protected void SynchronizeModelChildren()
		{
			HashSet<object> set = new HashSet<object>(ModelChildren);
			Children.RemoveAll(n => !set.Contains(n.Model));
			set.ExceptWith(Children.Select(n => n.Model));
			InsertChildren(set);
			if (IsSpecialNode())
				InsertSpecialNodes();
		}
Exemple #15
0
 public Cell[] GetSurroundingCells()
 {
     HashSet<Cell> surrounding = new HashSet<Cell>();
     foreach (var member in members)
         foreach (var move in MoveTypeExt.LinearMoves)
             surrounding.Add(member.Move(move));
     surrounding.ExceptWith(members);
     return surrounding.ToArray();
 }
 public IEnumerable<IStylingRule> GetUnusedRules()
 {
     lock (_sync)
     {
         var unusedRules = new HashSet<IStylingRule>(GetAllRules());
         unusedRules.ExceptWith(_ruleUsages.Select(x => x.Rule).Distinct());
         return unusedRules.Where(x => !UsageRegistry.IsAProtectedClass(x)).ToList();
     }
 }
        /// <summary>
        /// Determines whether the interpreter factory contains the specified
        /// modules.
        /// </summary>
        /// <returns>The names of the modules that were found.</returns>
        public static async Task<HashSet<string>> FindModulesAsync(this IPythonInterpreterFactory factory, params string[] moduleNames) {
            var finding = new HashSet<string>(moduleNames);
            var found = new HashSet<string>();
            var withPackages = factory.PackageManager;
            if (withPackages != null) {
                foreach (var m in finding) {
                    if ((await withPackages.GetInstalledPackageAsync(new PackageSpec(m), CancellationToken.None)).IsValid) {
                        found.Add(m);
                    }
                }
                finding.ExceptWith(found);
                if (!finding.Any()) {
                    // Found all of them, so stop searching
                    return found;
                }
            }

            var withDb = factory as PythonInterpreterFactoryWithDatabase;
            if (withDb != null && withDb.IsCurrent) {
                var db = withDb.GetCurrentDatabase();
                found.UnionWith(finding.Where(m => db.GetModule(m) != null));

                // Always stop searching after this step
                return found;
            }

            if (withDb != null) {
                try {
                    var paths = await PythonTypeDatabase.GetDatabaseSearchPathsAsync(withDb);
                    found.UnionWith(PythonTypeDatabase.GetDatabaseExpectedModules(withDb.Configuration.Version, paths)
                        .SelectMany()
                        .Select(g => g.ModuleName)
                        .Where(m => finding.Contains(m)));
                } catch (InvalidOperationException) {
                }

                finding.ExceptWith(found);
                if (!finding.Any()) {
                    // Found all of them, so stop searching
                    return found;
                }
            }

            return await Task.Run(() => {
                foreach (var mp in ModulePath.GetModulesInLib(factory.Configuration)) {
                    if (finding.Remove(mp.ModuleName)) {
                        found.Add(mp.ModuleName);
                    }

                    if (!finding.Any()) {
                        break;
                    }
                }
                return found;
            });
        }
Exemple #18
0
 public override void Process(IEnumerable<string> expected, IEnumerable<string> result)
 {
     d++;
     HashSet<string> delta = new HashSet<string>(expected);
     delta.UnionWith(result);
     HashSet<string> section = new HashSet<string>(expected);
     section.IntersectWith(result);
     delta.ExceptWith(section);
     score += (double) delta.Count;
 }
Exemple #19
0
 static HashSet<string> GetWaitingURLs(HashSet<string> crawled_urls)
 {
     HashSet<string> ret = new HashSet<string>();
     for(int idx = 0; idx < seed_category_urls_fmt.Length; idx++)
     {
         ret.UnionWith(GetURLsByCategory(idx));
     }
     ret.ExceptWith(crawled_urls);
     return ret;
 }
Exemple #20
0
 public static HashSet<int> Func(HashSet<int> X1, HashSet<int> X2, HashSet<int> X3)
 {
     HashSet<int> Y1 = new HashSet<int>(X2);
       Y1.ExceptWith(X3);
       HashSet<int> Y2 = new HashSet<int>(X1);
       Y2.ExceptWith(X3);
       HashSet<int> Y = new HashSet<int>(Y1);
       Y.UnionWith(Y2);
       return Y;
 }
 public override void SetExpandedWithChildren(TreeViewItem item, bool expand)
 {
   HashSet<int> source = new HashSet<int>((IEnumerable<int>) this.expandedIDs);
   HashSet<int> parentsBelow = this.GetParentsBelow(item.id);
   if (expand)
     source.UnionWith((IEnumerable<int>) parentsBelow);
   else
     source.ExceptWith((IEnumerable<int>) parentsBelow);
   this.SetExpandedIDs(source.ToArray<int>());
 }
 public double GetDistance(string a, string b)
 {
     HashSet<string> ta = new HashSet<string>(StringUtils.GetLuceneTokens(a));
     HashSet<string> tb = new HashSet<string>(StringUtils.GetLuceneTokens(b));
     HashSet<string> xor = new HashSet<string>(ta);
     xor.UnionWith(tb);
     HashSet<string> intersec = new HashSet<string>(ta);
     intersec.IntersectWith(tb);
     xor.ExceptWith(intersec);
     return Math.Sqrt(xor.Count);
 }
Exemple #23
0
        public static ushort GetFreePort()
        {
            var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
            var tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();

            var usedPorts = new HashSet<ushort>(tcpConnInfoArray.Select(x => (ushort)x.LocalEndPoint.Port));
            var availablePorts = new HashSet<ushort>(Enumerable.Range(1024, 65535 - 1024).Select(x => (ushort)x));
            availablePorts.ExceptWith(usedPorts);

            return availablePorts.Skip(new Random().Next(availablePorts.Count - 1)).First();
        }
		public void TestExceptWith ()
		{
			var aSet = new HashSet<int> { 1, 2 };  
			var bSet = new HashSet<int> { 1 };  

			aSet.ExceptWith (bSet);

			Assert.IsTrue (aSet.Contains (2));
			Assert.IsFalse (aSet.Contains (1));
			Assert.AreEqual (1, aSet.Count);
		}
Exemple #25
0
 public IEnumerable<int> find(int i)
 {
     var finder = new HashSet<int>(full_digit);
     HashSet<int> existed_digits=new HashSet<int>();
     foreach (char digit in i.ToString())
     {
         existed_digits.Add(int.Parse(digit.ToString()));
     }
     finder.ExceptWith(existed_digits);
     return finder;
 }
        public static IEnumerable<IEnumerable<Vertex>> GetConnectedComponents(
            this IGraph graph)
        {
            HashSet<Vertex> remainingVertices = new HashSet<Vertex>(graph.Vertices());

            while (remainingVertices.Count > 0)
            {
                IEnumerable<Vertex> componentVertices = graph.BreadthFirstTreeTraversal(remainingVertices.First());
                remainingVertices.ExceptWith(componentVertices);
                yield return componentVertices;
            }
        }
Exemple #27
0
        private HashSet<IProjectEntry> GetNewDependencies(HashSet<IProjectEntry> oldDependencies) {
            HashSet<IProjectEntry> deps;
            lock (_dependencies) {
                deps = new HashSet<IProjectEntry>(_dependencies);
            }

            if (oldDependencies != null) {
                deps.ExceptWith(oldDependencies);
            }

            return deps;
        }
 public void SyncAll()
 {
     bool started = false;
     var cloudBlobs = container.ListBlobs(new BlobRequestOptions() { UseFlatBlobListing = true, BlobListingDetails = BlobListingDetails.Metadata }).OfType<CloudBlob>();
     var cloudBlobNames = new HashSet<string>(cloudBlobs.Select(b => b.Uri.ToString()));
     var localBlobNames = new HashSet<string>(localBlobs.Keys);
     localBlobNames.ExceptWith(cloudBlobNames);
     foreach (var name in localBlobNames)
     {
         started = true;
         if (!started && SyncStarted != null)
         {
             SyncStarted(this);
         }
         File.Delete(GetLocalPath(name));
         localBlobs.Remove(name);
     }
     foreach (var blob in cloudBlobs)
     {
         if (!localBlobs.ContainsKey(blob.Uri.ToString()) ||
             blob.Attributes.Properties.ETag != localBlobs[blob.Uri.ToString()])
         {
             if (!started)
             {
                 started = true;
                 if (SyncStarted != null)
                 {
                     SyncStarted(this);
                 }
             }
             var path = GetLocalPath(blob.Uri.ToString());
             var args = new UpdatingFileEventArgs(blob, path);
             if (UpdatingFile != null)
             {
                 UpdatingFile(this, args);
             }
             if (!args.Cancel)
             {
                 Directory.CreateDirectory(Path.GetDirectoryName(path));
                 using (var stream = File.Create(GetLocalPath(blob.Uri.ToString())))
                 {
                     blob.DownloadToStream(stream);
                 }
             }
             localBlobs[blob.Uri.ToString()] = blob.Properties.ETag;
         }
     }
     if (started && SyncCompleted != null)
     {
         SyncCompleted(this);
     }
 }
Exemple #29
0
        public static void CopyDirectory(string sourceDir, string destDir) {
            sourceDir = sourceDir.TrimEnd('\\');
            destDir = destDir.TrimEnd('\\');
            try {
                Directory.CreateDirectory(destDir);
            } catch (IOException) {
            }

            var newDirectories = new HashSet<string>(from d in Directory.EnumerateDirectories(sourceDir, "*", SearchOption.AllDirectories)
                                                     where d.StartsWith(sourceDir)
                                                     select d.Substring(sourceDir.Length + 1), StringComparer.OrdinalIgnoreCase);
            newDirectories.ExceptWith(from d in Directory.EnumerateDirectories(destDir, "*", SearchOption.AllDirectories)
                                      where d.StartsWith(destDir)
                                      select d.Substring(destDir.Length + 1));

            foreach (var newDir in newDirectories.OrderBy(i => i.Length).Select(i => Path.Combine(destDir, i))) {
                try {
                    if (newDir.Length < NativeMethods.MAX_FOLDER_PATH) {
                        Directory.CreateDirectory(newDir);
                    }
                } catch {
                    Debug.WriteLine("Failed to create directory " + newDir);
                }
            }

            var newFiles = new HashSet<string>(from f in Directory.EnumerateFiles(sourceDir, "*", SearchOption.AllDirectories)
                                               where f.StartsWith(sourceDir)
                                               select f.Substring(sourceDir.Length + 1), StringComparer.OrdinalIgnoreCase);
            newFiles.ExceptWith(from f in Directory.EnumerateFiles(destDir, "*", SearchOption.AllDirectories)
                                where f.StartsWith(destDir)
                                select f.Substring(destDir.Length + 1));

            foreach (var newFile in newFiles) {
                var copyFrom = Path.Combine(sourceDir, newFile);
                var copyTo = Path.Combine(destDir, newFile);
                try {
                    if (copyTo.Length < NativeMethods.MAX_PATH && copyFrom.Length < NativeMethods.MAX_PATH) {
                        var copyToDir = Path.GetDirectoryName(copyTo);
                        if (copyToDir.Length < NativeMethods.MAX_FOLDER_PATH) {
                            File.Copy(copyFrom, copyTo);
                            File.SetAttributes(copyTo, FileAttributes.Normal);
                        } else {
                            Debug.WriteLine("Failed to copy " + copyFrom + " to " + copyTo + " due to max path limit");
                        }
                    } else {
                        Debug.WriteLine("Failed to copy " + copyFrom + " to " + copyTo + " due to max path limit");
                    }
                } catch {
                    Debug.WriteLine("Failed to copy " + copyFrom + " to " + copyTo + " for unknown reason");
                }
            }
        }
 public IDictionary<string, SDProgramImageResponse> GetImages(ISet<string> imageIDs)
 {
     ISet<string> imagesNeeded = new HashSet<string>(imageIDs.Except(imageCache_.Keys));
     IDictionary<string, SDProgramImageResponse> dbImages = DBManager.instance.GetImagesByIds(imagesNeeded);
     foreach (var kv in dbImages)
         imageCache_[kv.Key] = kv.Value;
     imagesNeeded.ExceptWith(dbImages.Keys);
     foreach(var imageResponse in DownloadProgramImages(imagesNeeded))
     {
         imageCache_[imageResponse.programID] = imageResponse;
     }
     return imageCache_;
 }
Exemple #31
0
        /// <summary>
        /// Main entry point for the BuildGraph command
        /// </summary>
        public override ExitCode Execute()
        {
            // Parse the command line parameters
            string ScriptFileName        = ParseParamValue("Script", null);
            string TargetNames           = ParseParamValue("Target", null);
            string DocumentationFileName = ParseParamValue("Documentation", null);
            string SchemaFileName        = ParseParamValue("Schema", null);
            string ExportFileName        = ParseParamValue("Export", null);
            string PreprocessedFileName  = ParseParamValue("Preprocess", null);
            string SharedStorageDir      = ParseParamValue("SharedStorageDir", null);
            string SingleNodeName        = ParseParamValue("SingleNode", null);
            string TriggerName           = ParseParamValue("Trigger", null);

            string[] SkipTriggerNames          = ParseParamValue("SkipTrigger", "").Split(new char[] { '+', ';' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
            bool     bSkipTriggers             = ParseParam("SkipTriggers");
            string   TokenSignature            = ParseParamValue("TokenSignature", null);
            bool     bSkipTargetsWithoutTokens = ParseParam("SkipTargetsWithoutTokens");
            bool     bResume               = SingleNodeName != null || ParseParam("Resume");
            bool     bListOnly             = ParseParam("ListOnly");
            bool     bShowDiagnostics      = ParseParam("ShowDiagnostics");
            bool     bWriteToSharedStorage = ParseParam("WriteToSharedStorage") || CommandUtils.IsBuildMachine;
            bool     bPublicTasksOnly      = ParseParam("PublicTasksOnly");
            string   ReportName            = ParseParamValue("ReportName", null);

            GraphPrintOptions PrintOptions = GraphPrintOptions.ShowCommandLineOptions;

            if (ParseParam("ShowDeps"))
            {
                PrintOptions |= GraphPrintOptions.ShowDependencies;
            }
            if (ParseParam("ShowNotifications"))
            {
                PrintOptions |= GraphPrintOptions.ShowNotifications;
            }

            // Parse any specific nodes to clean
            List <string> CleanNodes = new List <string>();

            foreach (string NodeList in ParseParamValues("CleanNode"))
            {
                foreach (string NodeName in NodeList.Split('+', ';'))
                {
                    CleanNodes.Add(NodeName);
                }
            }

            // Set up the standard properties which build scripts might need
            Dictionary <string, string> DefaultProperties = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);

            DefaultProperties["Branch"]                 = P4Enabled ? P4Env.Branch : "Unknown";
            DefaultProperties["EscapedBranch"]          = P4Enabled ? CommandUtils.EscapePath(P4Env.Branch) : "Unknown";
            DefaultProperties["Change"]                 = P4Enabled ? P4Env.Changelist.ToString() : "0";
            DefaultProperties["CodeChange"]             = P4Enabled ? P4Env.CodeChangelist.ToString() : "0";
            DefaultProperties["RootDir"]                = CommandUtils.RootDirectory.FullName;
            DefaultProperties["IsBuildMachine"]         = IsBuildMachine ? "true" : "false";
            DefaultProperties["HostPlatform"]           = HostPlatform.Current.HostEditorPlatform.ToString();
            DefaultProperties["RestrictedFolderNames"]  = String.Join(";", RestrictedFolders.Names);
            DefaultProperties["RestrictedFolderFilter"] = String.Join(";", RestrictedFolders.Names.Select(x => String.Format(".../{0}/...", x)));

            // Attempt to read existing Build Version information
            BuildVersion Version;

            if (BuildVersion.TryRead(BuildVersion.GetDefaultFileName(), out Version))
            {
                DefaultProperties["EngineMajorVersion"]     = Version.MajorVersion.ToString();
                DefaultProperties["EngineMinorVersion"]     = Version.MinorVersion.ToString();
                DefaultProperties["EnginePatchVersion"]     = Version.PatchVersion.ToString();
                DefaultProperties["EngineCompatibleChange"] = Version.CompatibleChangelist.ToString();
            }

            // Add any additional custom arguments from the command line (of the form -Set:X=Y)
            Dictionary <string, string> Arguments = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);

            foreach (string Param in Params)
            {
                const string Prefix = "set:";
                if (Param.StartsWith(Prefix, StringComparison.InvariantCultureIgnoreCase))
                {
                    int EqualsIdx = Param.IndexOf('=');
                    if (EqualsIdx >= 0)
                    {
                        Arguments[Param.Substring(Prefix.Length, EqualsIdx - Prefix.Length)] = Param.Substring(EqualsIdx + 1);
                    }
                    else
                    {
                        LogWarning("Missing value for '{0}'", Param.Substring(Prefix.Length));
                    }
                }
            }

            // Find all the tasks from the loaded assemblies
            Dictionary <string, ScriptTask> NameToTask = new Dictionary <string, ScriptTask>();

            if (!FindAvailableTasks(NameToTask, bPublicTasksOnly))
            {
                return(ExitCode.Error_Unknown);
            }

            // Generate documentation
            if (DocumentationFileName != null)
            {
                GenerateDocumentation(NameToTask, new FileReference(DocumentationFileName));
                return(ExitCode.Success);
            }

            // Create a schema for the given tasks
            ScriptSchema Schema = new ScriptSchema(NameToTask);

            if (SchemaFileName != null)
            {
                FileReference FullSchemaFileName = new FileReference(SchemaFileName);
                LogInformation("Writing schema to {0}...", FullSchemaFileName.FullName);
                Schema.Export(FullSchemaFileName);
                if (ScriptFileName == null)
                {
                    return(ExitCode.Success);
                }
            }

            // Check there was a script specified
            if (ScriptFileName == null)
            {
                LogError("Missing -Script= parameter for BuildGraph");
                return(ExitCode.Error_Unknown);
            }

            // Read the script from disk
            Graph Graph;

            if (!ScriptReader.TryRead(new FileReference(ScriptFileName), Arguments, DefaultProperties, Schema, out Graph))
            {
                return(ExitCode.Error_Unknown);
            }

            // Create the temp storage handler
            DirectoryReference RootDir = new DirectoryReference(CommandUtils.CmdEnv.LocalRoot);
            TempStorage        Storage = new TempStorage(RootDir, DirectoryReference.Combine(RootDir, "Engine", "Saved", "BuildGraph"), (SharedStorageDir == null)? null : new DirectoryReference(SharedStorageDir), bWriteToSharedStorage);

            if (!bResume)
            {
                Storage.CleanLocal();
            }
            foreach (string CleanNode in CleanNodes)
            {
                Storage.CleanLocalNode(CleanNode);
            }

            // Convert the supplied target references into nodes
            HashSet <Node> TargetNodes = new HashSet <Node>();

            if (TargetNames == null)
            {
                if (!bListOnly)
                {
                    LogError("Missing -Target= parameter for BuildGraph");
                    return(ExitCode.Error_Unknown);
                }
                TargetNodes.UnionWith(Graph.Agents.SelectMany(x => x.Nodes));
            }
            else
            {
                foreach (string TargetName in TargetNames.Split(new char[] { '+', ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()))
                {
                    Node[] Nodes;
                    if (!Graph.TryResolveReference(TargetName, out Nodes))
                    {
                        LogError("Target '{0}' is not in graph", TargetName);
                        return(ExitCode.Error_Unknown);
                    }
                    TargetNodes.UnionWith(Nodes);
                }
            }

            // Try to acquire tokens for all the target nodes we want to build
            if (TokenSignature != null)
            {
                // Find all the lock files
                HashSet <FileReference> RequiredTokens = new HashSet <FileReference>(TargetNodes.SelectMany(x => x.RequiredTokens));

                // List out all the required tokens
                if (SingleNodeName == null)
                {
                    CommandUtils.LogInformation("Required tokens:");
                    foreach (Node Node in TargetNodes)
                    {
                        foreach (FileReference RequiredToken in Node.RequiredTokens)
                        {
                            CommandUtils.LogInformation("  '{0}' requires {1}", Node, RequiredToken);
                        }
                    }
                }

                // Try to create all the lock files
                List <FileReference> CreatedTokens = new List <FileReference>();
                if (!bListOnly)
                {
                    CreatedTokens.AddRange(RequiredTokens.Where(x => WriteTokenFile(x, TokenSignature)));
                }

                // Find all the tokens that we don't have
                Dictionary <FileReference, string> MissingTokens = new Dictionary <FileReference, string>();
                foreach (FileReference RequiredToken in RequiredTokens)
                {
                    string CurrentOwner = ReadTokenFile(RequiredToken);
                    if (CurrentOwner != null && CurrentOwner != TokenSignature)
                    {
                        MissingTokens.Add(RequiredToken, CurrentOwner);
                    }
                }

                // If we want to skip all the nodes with missing locks, adjust the target nodes to account for it
                if (MissingTokens.Count > 0)
                {
                    if (bSkipTargetsWithoutTokens)
                    {
                        // Find all the nodes we're going to skip
                        HashSet <Node> SkipNodes = new HashSet <Node>();
                        foreach (IGrouping <string, FileReference> MissingTokensForBuild in MissingTokens.GroupBy(x => x.Value, x => x.Key))
                        {
                            LogInformation("Skipping the following nodes due to {0}:", MissingTokensForBuild.Key);
                            foreach (FileReference MissingToken in MissingTokensForBuild)
                            {
                                foreach (Node SkipNode in TargetNodes.Where(x => x.RequiredTokens.Contains(MissingToken) && SkipNodes.Add(x)))
                                {
                                    LogInformation("    {0}", SkipNode);
                                }
                            }
                        }

                        // Write a list of everything left over
                        if (SkipNodes.Count > 0)
                        {
                            TargetNodes.ExceptWith(SkipNodes);
                            LogInformation("Remaining target nodes:");
                            foreach (Node TargetNode in TargetNodes)
                            {
                                LogInformation("    {0}", TargetNode);
                            }
                            if (TargetNodes.Count == 0)
                            {
                                LogInformation("    None.");
                            }
                        }
                    }
                    else
                    {
                        foreach (KeyValuePair <FileReference, string> Pair in MissingTokens)
                        {
                            List <Node> SkipNodes = TargetNodes.Where(x => x.RequiredTokens.Contains(Pair.Key)).ToList();
                            LogError("Cannot run {0} due to previous build: {1}", String.Join(", ", SkipNodes), Pair.Value);
                        }
                        foreach (FileReference CreatedToken in CreatedTokens)
                        {
                            FileReference.Delete(CreatedToken);
                        }
                        return(ExitCode.Error_Unknown);
                    }
                }
            }

            // Cull the graph to include only those nodes
            Graph.Select(TargetNodes);

            // Collapse any triggers in the graph which are marked to be skipped
            HashSet <ManualTrigger> SkipTriggers = new HashSet <ManualTrigger>();

            if (bSkipTriggers)
            {
                SkipTriggers.UnionWith(Graph.NameToTrigger.Values);
            }
            else
            {
                foreach (string SkipTriggerName in SkipTriggerNames)
                {
                    ManualTrigger SkipTrigger;
                    if (!Graph.NameToTrigger.TryGetValue(TriggerName, out SkipTrigger))
                    {
                        LogError("Couldn't find trigger '{0}'", TriggerName);
                        return(ExitCode.Error_Unknown);
                    }
                    SkipTriggers.Add(SkipTrigger);
                }
            }
            Graph.SkipTriggers(SkipTriggers);

            // If a report for the whole build was requested, insert it into the graph
            if (ReportName != null)
            {
                Report NewReport = new Report(ReportName);
                NewReport.Nodes.UnionWith(Graph.Agents.SelectMany(x => x.Nodes));
                Graph.NameToReport.Add(ReportName, NewReport);
            }

            // Write out the preprocessed script
            if (PreprocessedFileName != null)
            {
                FileReference PreprocessedFileLocation = new FileReference(PreprocessedFileName);
                LogInformation("Writing {0}...", PreprocessedFileLocation);
                Graph.Write(PreprocessedFileLocation, (SchemaFileName != null)? new FileReference(SchemaFileName) : null);
                return(ExitCode.Success);
            }

            // Find the triggers which we are explicitly running.
            ManualTrigger Trigger = null;

            if (TriggerName != null && !Graph.NameToTrigger.TryGetValue(TriggerName, out Trigger))
            {
                LogError("Couldn't find trigger '{0}'", TriggerName);
                return(ExitCode.Error_Unknown);
            }

            // If we're just building a single node, find it
            Node SingleNode = null;

            if (SingleNodeName != null && !Graph.NameToNode.TryGetValue(SingleNodeName, out SingleNode))
            {
                LogError("Node '{0}' is not in the trimmed graph", SingleNodeName);
                return(ExitCode.Error_Unknown);
            }

            // If we just want to show the contents of the graph, do so and exit.
            if (bListOnly)
            {
                HashSet <Node> CompletedNodes = FindCompletedNodes(Graph, Storage);
                Graph.Print(CompletedNodes, PrintOptions);
            }

            // Print out all the diagnostic messages which still apply, unless we're running a step as part of a build system or just listing the contents of the file.
            if (SingleNode == null && (!bListOnly || bShowDiagnostics))
            {
                IEnumerable <GraphDiagnostic> Diagnostics = Graph.Diagnostics.Where(x => x.EnclosingTrigger == Trigger);
                foreach (GraphDiagnostic Diagnostic in Diagnostics)
                {
                    if (Diagnostic.EventType == LogEventType.Console)
                    {
                        CommandUtils.LogInformation(Diagnostic.Message);
                    }
                    else if (Diagnostic.EventType == LogEventType.Warning)
                    {
                        CommandUtils.LogWarning(Diagnostic.Message);
                    }
                    else
                    {
                        CommandUtils.LogError(Diagnostic.Message);
                    }
                }
                if (Diagnostics.Any(x => x.EventType == LogEventType.Error))
                {
                    return(ExitCode.Error_Unknown);
                }
            }

            // Export the graph to a file
            if (ExportFileName != null)
            {
                HashSet <Node> CompletedNodes = FindCompletedNodes(Graph, Storage);
                Graph.Print(CompletedNodes, PrintOptions);
                Graph.Export(new FileReference(ExportFileName), Trigger, CompletedNodes);
                return(ExitCode.Success);
            }

            // Execute the command
            if (!bListOnly)
            {
                if (SingleNode != null)
                {
                    if (!BuildNode(new JobContext(this), Graph, SingleNode, Storage, bWithBanner: true))
                    {
                        return(ExitCode.Error_Unknown);
                    }
                }
                else
                {
                    if (!BuildAllNodes(new JobContext(this), Graph, Storage))
                    {
                        return(ExitCode.Error_Unknown);
                    }
                }
            }
            return(ExitCode.Success);
        }
Exemple #32
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public virtual InternalModelBuilder Apply(InternalModelBuilder modelBuilder)
        {
            foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
            {
                var unmappedProperty = entityType.GetProperties().FirstOrDefault(
                    p => (!ConfigurationSource.Convention.Overrides(p.GetConfigurationSource()) || !p.IsShadowProperty()) &&
                    !IsMappedPrimitiveProperty(p));

                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);

                clrProperties.UnionWith(
                    entityType.GetRuntimeProperties().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.Builder.IsIgnored(p, ConfigurationSource.Convention));

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

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

                    if (modelBuilder.IsIgnored(
                            modelBuilder.Metadata.GetDisplayName(propertyType),
                            ConfigurationSource.Convention) ||
                        (targetSequenceType != null &&
                         modelBuilder.IsIgnored(
                             modelBuilder.Metadata.GetDisplayName(targetSequenceType),
                             ConfigurationSource.Convention)))
                    {
                        continue;
                    }

                    var targetType = FindCandidateNavigationPropertyType(actualProperty);

                    var isTargetWeakOrOwned
                        = targetType != null &&
                          (modelBuilder.Metadata.HasEntityTypeWithDefiningNavigation(targetType) ||
                           modelBuilder.Metadata.ShouldBeOwnedType(targetType));

                    if (targetType?.IsValidEntityType() == true &&
                        (isTargetWeakOrOwned ||
                         modelBuilder.Metadata.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.FindDeclaredNavigation(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 (modelBuilder.Metadata.ShouldBeOwnedType(entityType.ClrType) &&
                                modelBuilder.Metadata.ShouldBeOwnedType(targetType))
                            {
                                throw new InvalidOperationException(
                                          CoreStrings.AmbiguousOwnedNavigation(entityType.DisplayName(), 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()));
                    }
                }
            }

            return(modelBuilder);
        }
Exemple #33
0
        public static void Main(string[] args)
        {
            string min = null;
            string max = null;

            foreach (var arg in args)
            {
                if (arg.StartsWith("/min:"))
                {
                    min = arg.Replace("/min:", string.Empty);
                }
                else if (arg.StartsWith("/max:"))
                {
                    max = arg.Replace("/max:", string.Empty);
                }
            }

            Version.TryParse(min, out Version minVersion);
            Version.TryParse(max, out Version maxVersion);

            if (minVersion == null || maxVersion == null)
            {
                Console.WriteLine("The differences generator needs to be run as follows:");
                Console.WriteLine("DifferencesGen /min:4.0.0.0 /max:5.0.0.0");

                return;
            }

            string folderPath = @"C:\Program Files (x86)\Windows Kits\10\References";

            string universalApiFile = "Windows.Foundation.UniversalApiContract.winmd";

            string universalApiDifferencesCompressedFile = "Differences-{0}.gz";

            AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (sender, eventArgs) => Assembly.ReflectionOnlyLoad(eventArgs.Name);
            WindowsRuntimeMetadata.ReflectionOnlyNamespaceResolve += (sender, eventArgs) =>
            {
                string path =
                    WindowsRuntimeMetadata.ResolveNamespace(eventArgs.NamespaceName, Enumerable.Empty <string>())
                    .FirstOrDefault();
                if (path == null)
                {
                    return;
                }

                eventArgs.ResolvedAssemblies.Add(Assembly.ReflectionOnlyLoadFrom(path));
            };

            DirectoryInfo directoryInfo = new DirectoryInfo(folderPath);

            FileInfo[] files = directoryInfo.GetFiles(universalApiFile, SearchOption.AllDirectories);

            List <Tuple <Version, Assembly> > assemblyList = new List <Tuple <Version, Assembly> >();

            if (files.Length > 0)
            {
                foreach (var file in files)
                {
                    var assembly = Assembly.ReflectionOnlyLoadFrom(file.FullName);

                    var nameParts = assembly.FullName.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);

                    var versionParts = nameParts[1].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);

                    var version = Version.Parse(versionParts[1]);

                    if (version >= minVersion && version <= maxVersion)
                    {
                        assemblyList.Add(new Tuple <Version, Assembly>(version, assembly));
                    }
                }
            }

            if (assemblyList.Count >= 2)
            {
                var orderedList = assemblyList.OrderBy(t => t.Item1).ToList();

                for (int i = 1; i < orderedList.Count; i++)
                {
                    var previousVersionAssembly = orderedList[i - 1].Item2;
                    var newerVersionAssembly    = orderedList[i].Item2;

                    var version = orderedList[i].Item1;

                    var previousVersionTypes = ProcessAssembly(previousVersionAssembly);
                    var newerVersionTypes    = ProcessAssembly(newerVersionAssembly);

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

                    foreach (var type in newerVersionTypes)
                    {
                        if (!previousVersionTypes.ContainsKey(type.Key))
                        {
                            addedTypes.Add(type.Key, null);

                            if (enumTypes.Contains(type.Key))
                            {
                                System.Diagnostics.Debug.WriteLine($"New enum {type.Key}");
                            }

                            continue;
                        }

                        HashSet <string> previousVersionTypeMembers = new HashSet <string>(previousVersionTypes[type.Key]);
                        HashSet <string> newerVersionTypeMembers    = new HashSet <string>(type.Value);

                        newerVersionTypeMembers.ExceptWith(previousVersionTypeMembers);

                        if (newerVersionTypeMembers.Count == 0)
                        {
                            continue;
                        }

                        if (enumTypes.Contains(type.Key))
                        {
                            System.Diagnostics.Debug.WriteLine($"Enum {type.Key} has new members: {string.Join(",", newerVersionTypeMembers)}");
                        }

                        foreach (var member in newerVersionTypeMembers)
                        {
                            if (typeEvents.Contains($"{type.Key}-{member}"))
                            {
                                System.Diagnostics.Debug.WriteLine($"Type {type.Key} has new event: {member}");
                            }
                        }

                        addedTypes.Add(type.Key, newerVersionTypeMembers.ToList());
                    }

                    StringBuilder stringBuilder = new StringBuilder();

                    using (var compressedFS = File.Create(Path.Combine(AssemblyDirectory, string.Format(universalApiDifferencesCompressedFile, version.ToString()))))
                    {
                        using (var compressionFS = new GZipStream(compressedFS, CompressionMode.Compress))
                        {
                            using (var writer = new StreamWriter(compressionFS))
                            {
                                foreach (var addedType in addedTypes)
                                {
                                    stringBuilder.Clear();

                                    stringBuilder.Append(addedType.Key);

                                    if (addedType.Value != null && addedType.Value.Count > 0)
                                    {
                                        stringBuilder.Append(':');
                                        stringBuilder.Append(string.Join(",", addedType.Value));
                                    }

                                    writer.WriteLine(stringBuilder.ToString());
                                }
                            }
                        }
                    }

                    stringBuilder.Length = 0;
                }
            }
        }
Exemple #34
0
        /* WARNING: Because of the sheer amount of combinations and loops we're dealing with, there is a LOT
         * of caching (both here and within Helpers), HashSets (for duplicate checks), and stopwatch timing.
         * Everything needs be optimized to the Nth degree to reduce as much overhead as possible.
         */

        public void InjectSurgeryRecipes(List <RecipeDef> surgeryList, List <ThingDef> pawnList)
        {
            Base XP = Base.Instance;

            Stopwatch stopwatch = Stopwatch.StartNew();

            /* Many mods like to use different def names for basic body parts.  This makes it harder to add the
             * surgery recipe to the alien.  We'll need to add in the similar body part to the
             * appliedOnFixedBodyParts list first.
             *
             * First, look through the list of common surgery recipes to infer the part type.  In other words, if
             * there's a surgery called "Install bionic arm" then that part is an arm that can accept other kinds of
             * arms.  Then, also look for body part matches by looking at the body part labels directly (basically
             * duck typing).
             *
             * These's all go into the part mapper for later injection.
             */
            var partToPartMapper = new Dictionary <string, HashSet <BodyPartDef> > {
            };

            // There are only a few pawn bio-types, so compile all of the pawn surgery lists outside of the
            // main surgery double-loop.
            if (Base.IsDebug)
            {
                stopwatch.Start();
            }

            var pawnSurgeriesByBioType = new Dictionary <string, HashSet <RecipeDef> > {
            };

            foreach (ThingDef pawn in pawnList.Where(p => p.recipes != null))
            {
                string pawnBioType = Helpers.GetPawnBioType(pawn);
                pawnSurgeriesByBioType.SetOrAddNestedRange(pawnBioType, pawn.recipes);
            }

            if (Base.IsDebug)
            {
                stopwatch.Stop();
                XP.ModLogger.Message(
                    "    PawnSurgeriesByBioType cache: took {0:F4}s; {1:N0}/{2:N0} keys/recipes",
                    stopwatch.ElapsedMilliseconds / 1000f,
                    pawnSurgeriesByBioType.Keys.Count(), pawnSurgeriesByBioType.Values.Sum(h => h.Count())
                    );
                stopwatch.Reset();
            }

            // This list is used a few times.  Best to compose it outside the loops.  Distinct is important
            // because there's a lot of dupes.
            if (Base.IsDebug)
            {
                stopwatch.Start();
            }

            List <BodyPartRecord> raceBodyParts =
                pawnList.
                Select(p => p.race.body).Distinct().
                SelectMany(bd => bd.AllParts).Distinct().
                ToList()
            ;

            if (Base.IsDebug)
            {
                stopwatch.Stop();
                XP.ModLogger.Message(
                    "    RaceBodyParts cache: took {0:F4}s; {1:N0} BPRs",
                    stopwatch.ElapsedMilliseconds / 1000f,
                    raceBodyParts.Count()
                    );
                stopwatch.Reset();
            }

            // Both of these are useful in surgery->pawn body part matches
            if (Base.IsDebug)
            {
                stopwatch.Start();
            }

            var doesPawnHaveSurgery  = new HashSet <string> {
            };
            var doesPawnHaveBodyPart = new HashSet <string> {
            };

            foreach (ThingDef pawn in pawnList)
            {
                if (pawn.recipes != null)
                {
                    doesPawnHaveSurgery.AddRange(
                        pawn.recipes.Select(
                            s => pawn.defName + "|" + s.label.ToLower()
                            )
                        );
                }
                doesPawnHaveBodyPart.AddRange(
                    pawn.race.body.AllParts.Distinct().Select(
                        bpr => pawn.defName + "|" + bpr.def.defName
                        )
                    );
            }

            if (Base.IsDebug)
            {
                stopwatch.Stop();
                XP.ModLogger.Message(
                    "    DoesPawnHaveSurgery + BodyPart caches: took {0:F4}s; {1:N0} + {2:N0} strings",
                    stopwatch.ElapsedMilliseconds / 1000f,
                    doesPawnHaveSurgery.Count(), doesPawnHaveBodyPart.Count()
                    );
                stopwatch.Reset();
            }

            /* Start with a hard-coded list, just in case any of these don't match.  This is especially helpful for
             * animals, since they don't always have obvious humanlike analogues.  This also works as a part group
             * separator to ensure parts don't get mixed into the wrong groups.
             */
            var staticPartGroups = new Dictionary <string, string[]> {
                { "Arm", new[] { "arm", "flipper" } },
                { "Shoulder", new[] { "shoulder" } },
                { "Hand", new[] { "hand", "claw", "grasper", "pincer" } },
                { "Finger", new[] { "finger", "thumb", "pinky" } },
                { "Leg", new[] { "leg" } },
                { "Foot", new[] { "foot", "hoof", "paw" } },
                { "Toe", new[] { "toe" } },
                { "Eye", new[] { "eye", "sight", "seeing", "visual" } },
                { "Ear", new[] { "ear", "antenna", "hear", "hearing", "sound" } },
                { "Nose", new[] { "nose", "nostril", "smell", "smelling" } },
                { "Jaw", new[] { "jaw", "beak", "mouth", "maw", "teeth" } },
                { "Brain", new[] { "brain" } },
                { "Torso", new[] { "torso", "thorax", "body", "shell" } },
                { "Ribcage", new[] { "ribcage" } },
                { "Heart", new[] { "heart", "reactor" } },
                { "Lung", new[] { "lung" } },
                { "Kidney", new[] { "kidney" } },
                { "Liver", new[] { "liver" } },
                { "Stomach", new[] { "stomach" } },
                { "Spine", new[] { "spine" } },
                { "Neck", new[] { "neck", "pronotum" } },
                // Wing should really be the base name, but there is no vanilla Wing part (even for birds!)
                { "Elytra", new[] { "elytra", "wing" } },
            };

            /* It's futile to try to separate the hand/foot connection, as animals have "hands" which also
             * sometimes double as feet.  We can try to clean this up later in CleanupHandFootSurgeryRecipes.
             *
             * We're still going to keep the bio-boundary below to keep out leg->hand connections.  That's still a
             * bit off.  And mechs, of course.
             */
            staticPartGroups["Hand"].AddRangeToArray(staticPartGroups["Foot"]);
            staticPartGroups["Foot"] = staticPartGroups["Hand"];

            // Initialize part mapper with the vanilla part
            foreach (string vanillaPartName in staticPartGroups.Keys)
            {
                partToPartMapper.Add(
                    vanillaPartName,
                    new HashSet <BodyPartDef> {
                    DefDatabase <BodyPartDef> .GetNamed(vanillaPartName)
                }
                    );
            }

            // Static part loop
            if (Base.IsDebug)
            {
                stopwatch.Start();
            }
            foreach (BodyPartRecord raceBodyPart in raceBodyParts)
            {
                // Try really hard to only match one vanilla part group
                foreach (partMatchType matchType in Enum.GetValues(typeof(partMatchType)))
                {
                    var partGroupMatched = new Dictionary <string, bool> {
                    };
                    foreach (string vanillaPartName in staticPartGroups.Keys)
                    {
                        partGroupMatched.Add(
                            vanillaPartName,
                            staticPartGroups[vanillaPartName].Any(fuzzyPartName =>
                                                                  matchType == partMatchType.BodyPartRecord ? Helpers.DoesBodyPartMatch(raceBodyPart, fuzzyPartName) :
                                                                  matchType == partMatchType.BodyPartDef    ? Helpers.DoesBodyPartMatch(raceBodyPart.def, fuzzyPartName) :
                                                                  matchType == partMatchType.DefName        ? Helpers.DoesBodyPartMatch(raceBodyPart.def.defName, fuzzyPartName) :
                                                                  matchType == partMatchType.LabelShort     ? Helpers.DoesBodyPartMatch(raceBodyPart.LabelShort, fuzzyPartName) :
                                                                  matchType == partMatchType.Label          ? Helpers.DoesBodyPartMatch(raceBodyPart.Label, fuzzyPartName) :
                                                                  false // ??? Forgot to add a partMatchType?
                                                                  )
                            );
                    }

                    // Only stop to add if there's a conclusive singular part matched
                    int partGroupMatches = staticPartGroups.Keys.Sum(k => partGroupMatched[k] ? 1 : 0);
                    if (partGroupMatches == 1)
                    {
                        string      vanillaPartName = partGroupMatched.Keys.First(k => partGroupMatched[k]);
                        BodyPartDef racePartDef     = raceBodyPart.def;

                        // Add to both sides
                        partToPartMapper[vanillaPartName].Add(racePartDef);
                        partToPartMapper.SetOrAddNested(
                            racePartDef.defName,
                            partToPartMapper[vanillaPartName].First(bpd => bpd.defName == vanillaPartName)
                            );
                        break;
                    }
                    else if (partGroupMatches == 0)
                    {
                        // It's never going to match on other loops, so just stop here
                        break;
                    }
                }
            }
            if (Base.IsDebug)
            {
                stopwatch.Stop();
                XP.ModLogger.Message(
                    "    Static part loop: took {0:F4}s; {1:N0}/{2:N0} PartToPartMapper keys/BPDs",
                    stopwatch.ElapsedMilliseconds / 1000f,
                    partToPartMapper.Keys.Count(), partToPartMapper.Values.Sum(h => h.Count())
                    );
                stopwatch.Reset();
            }

            // Part-to-part mapping
            // (This is actually fewer combinations than all of the duplicates within
            // surgeryList -> appliedOnFixedBodyParts.)
            if (Base.IsDebug)
            {
                stopwatch.Start();
            }
            for (int i = 0; i < raceBodyParts.Count(); i++)
            {
                BodyPartRecord firstBodyPart = raceBodyParts[i];
                string         fbpDefName    = firstBodyPart.def.defName;
                partToPartMapper.NewIfNoKey(fbpDefName);

                // Looks for matching (or near-matching) body part labels
                for (int j = i + 1; j < raceBodyParts.Count(); j++)    // don't repeat previous checks
                {
                    BodyPartRecord secondBodyPart = raceBodyParts[j];
                    string         sbpDefName     = secondBodyPart.def.defName;

                    if (firstBodyPart.def != secondBodyPart.def && Helpers.DoesBodyPartMatch(firstBodyPart, secondBodyPart))
                    {
                        partToPartMapper[fbpDefName].Add(secondBodyPart.def);
                        partToPartMapper.SetOrAddNested(sbpDefName, firstBodyPart.def);
                    }
                }
            }
            if (Base.IsDebug)
            {
                stopwatch.Stop();
                XP.ModLogger.Message(
                    "    Part-to-part mapping: took {0:F4}s; {1:N0}/{2:N0} PartToPartMapper keys/BPDs",
                    stopwatch.ElapsedMilliseconds / 1000f,
                    partToPartMapper.Keys.Count(), partToPartMapper.Values.Sum(h => h.Count())
                    );
                stopwatch.Reset();
            }

            // Surgery-to-part mapping
            if (Base.IsDebug)
            {
                stopwatch.Start();
            }

            foreach (RecipeDef surgery in surgeryList.Where(s => s.targetsBodyPart))
            {
                string surgeryBioType    = Helpers.GetSurgeryBioType(surgery);
                string surgeryLabelLower = surgery.label.ToLower();

                if (!pawnSurgeriesByBioType.ContainsKey(surgeryBioType))
                {
                    continue;
                }

                // Compose this list outside of the surgeryBodyPart loop
                HashSet <BodyPartDef> pawnSurgeryBodyParts =
                    // We can't cross the animal/humanlike boundary with these checks because animal surgery recipes tend to be a lot
                    // looser with limbs (ie: power claws on animal legs)
                    pawnSurgeriesByBioType[surgeryBioType].
                    Where(s => s.targetsBodyPart && s != surgery && s.defName != surgery.defName && s.label.ToLower() == surgeryLabelLower).
                    SelectMany(s => s.appliedOnFixedBodyParts).Distinct().
                    ToHashSet()
                ;
                if (pawnSurgeryBodyParts.Count == 0)
                {
                    continue;
                }

                /* If this list is crossing a bunch of our static part group boundaries, we should skip it.
                 * RoM's Druid Regrowth recipe is one such example that tends to pollute the whole bunch.
                 */
                int partGroupMatches = staticPartGroups.Keys.Sum(k =>
                                                                 partToPartMapper[k].Overlaps(pawnSurgeryBodyParts) || partToPartMapper[k].Overlaps(surgery.appliedOnFixedBodyParts) ? 1 : 0
                                                                 );
                if (partGroupMatches >= 2)
                {
                    continue;
                }

                // Look for matching surgery labels, and map them to similar body parts
                bool warnedAboutLargeSet = false;
                foreach (BodyPartDef surgeryBodyPart in surgery.appliedOnFixedBodyParts)
                {
                    string sbpDefName = surgeryBodyPart.defName;
                    partToPartMapper.NewIfNoKey(sbpDefName);

                    // Useful to warn when it's about to add a bunch of parts into a recipe at one time
                    HashSet <BodyPartDef> diff = pawnSurgeryBodyParts.Except(partToPartMapper[sbpDefName]).ToHashSet();
                    if (diff.Count() > 10 && !warnedAboutLargeSet)
                    {
                        XP.ModLogger.Warning(
                            "Mapping a large set of body parts from \"{0}\":\nSurgery parts: {1}\nCurrent mapper parts: {2} ==> {3}\nNew mapper parts: {4}",
                            surgery.LabelCap,
                            string.Join(", ", surgery.appliedOnFixedBodyParts.Select(bpd => bpd.defName)),
                            sbpDefName, string.Join(", ", partToPartMapper[sbpDefName].Select(bpd => bpd.defName)),
                            string.Join(", ", diff.Select(bpd => bpd.defName))
                            );
                        warnedAboutLargeSet = true;
                    }

                    partToPartMapper[sbpDefName].AddRange(
                        pawnSurgeryBodyParts.Where(bp => bp != surgeryBodyPart && bp.defName != sbpDefName)
                        );
                }
            }
            if (Base.IsDebug)
            {
                stopwatch.Stop();
                XP.ModLogger.Message(
                    "    Surgery-to-part mapping: took {0:F4}s; {1:N0}/{2:N0} PartToPartMapper keys/BPDs",
                    stopwatch.ElapsedMilliseconds / 1000f,
                    partToPartMapper.Keys.Count(), partToPartMapper.Values.Sum(h => h.Count())
                    );
                stopwatch.Reset();
            }

            // Clear out empty lists
            if (Base.IsDebug)
            {
                stopwatch.Start();
            }

            foreach (string part in partToPartMapper.Keys.ToArray())
            {
                if (partToPartMapper[part].Count < 1)
                {
                    partToPartMapper.Remove(part);
                }
            }

            if (Base.IsDebug)
            {
                stopwatch.Stop();
                XP.ModLogger.Message(
                    "    Empty list cleanup: took {0:F4}s; {1:N0}/{2:N0} PartToPartMapper keys/BPDs",
                    stopwatch.ElapsedMilliseconds / 1000f,
                    partToPartMapper.Keys.Count(), partToPartMapper.Values.Sum(h => h.Count())
                    );
                stopwatch.Reset();
            }

            // With the parts mapped, add new body parts to existing recipes
            if (Base.IsDebug)
            {
                stopwatch.Start();
            }

            int newPartsAdded = 0;

            foreach (RecipeDef surgery in surgeryList.Where(s => s.targetsBodyPart))
            {
                var newPartSet = new HashSet <BodyPartDef> {
                };
                foreach (BodyPartDef surgeryBodyPart in surgery.appliedOnFixedBodyParts)
                {
                    if (partToPartMapper.ContainsKey(surgeryBodyPart.defName))
                    {
                        newPartSet.AddRange(partToPartMapper[surgeryBodyPart.defName]);
                    }
                }

                List <BodyPartDef> AOFBP = surgery.appliedOnFixedBodyParts;
                if (newPartSet.Count() >= 1 && !newPartSet.IsSubsetOf(AOFBP))
                {
                    newPartSet.ExceptWith(AOFBP);
                    AOFBP.AddRange(newPartSet);
                    newPartsAdded += newPartSet.Count();
                }
            }

            if (Base.IsDebug)
            {
                stopwatch.Stop();
                XP.ModLogger.Message(
                    "    Add new body parts to surgeries: took {0:F4}s; {1:N0} additions",
                    stopwatch.ElapsedMilliseconds / 1000f,
                    newPartsAdded
                    );
                stopwatch.Reset();
            }

            // Apply relevant missing surgery options to all pawn Defs
            if (Base.IsDebug)
            {
                stopwatch.Start();
            }

            int newSurgeriesAdded = 0;

            foreach (RecipeDef surgery in surgeryList)
            {
                string surgeryLabelLower = surgery.label.ToLower();

                foreach (ThingDef pawnDef in pawnList.Where(p =>
                                                            // If it already exists, don't add it
                                                            !doesPawnHaveSurgery.Contains(p.defName + "|" + surgeryLabelLower)
                                                            ))
                {
                    bool shouldAddSurgery = false;

                    // If it's an administer recipe, add it
                    if (!surgery.targetsBodyPart)
                    {
                        shouldAddSurgery = true;
                    }

                    // If it targets a body part, but nothing specific, add it
                    else if (surgery.targetsBodyPart && surgery.appliedOnFixedBodyParts.Count() == 0 && surgery.appliedOnFixedBodyPartGroups.Count() == 0)
                    {
                        shouldAddSurgery = true;
                    }

                    // XXX: Despite my best efforts, this step is still mapping hand/foot surgeries together...

                    // If it targets any body parts that exist within the pawn, add it
                    else if (surgery.targetsBodyPart && surgery.appliedOnFixedBodyParts.Count() >= 1 && surgery.appliedOnFixedBodyParts.Any(sbp =>
                                                                                                                                            doesPawnHaveBodyPart.Contains(pawnDef.defName + "|" + sbp.defName)
                                                                                                                                            ))
                    {
                        shouldAddSurgery = true;
                    }

                    if (shouldAddSurgery)
                    {
                        newSurgeriesAdded++;
                        if (pawnDef.recipes == null)
                        {
                            pawnDef.recipes = new List <RecipeDef> {
                                surgery
                            }
                        }
                        ; else
                        {
                            pawnDef.recipes.Add(surgery);
                        }
                        if (surgery.recipeUsers == null)
                        {
                            surgery.recipeUsers = new List <ThingDef>  {
                                pawnDef
                            }
                        }
                        ; else
                        {
                            surgery.recipeUsers.Add(pawnDef);
                        }
                    }
                }
            }
            if (Base.IsDebug)
            {
                stopwatch.Stop();
                XP.ModLogger.Message(
                    "    Add new surgeries to pawns: took {0:F4}s; {1:N0} additions",
                    stopwatch.ElapsedMilliseconds / 1000f,
                    newSurgeriesAdded
                    );
                stopwatch.Reset();
            }
        }
    public DeploymentContext(
        FileReference RawProjectPathOrName,
        DirectoryReference InLocalRoot,
        DirectoryReference BaseStageDirectory,
        DirectoryReference BaseArchiveDirectory,
        Platform InSourcePlatform,
        Platform InTargetPlatform,
        List <UnrealTargetConfiguration> InTargetConfigurations,
        IEnumerable <StageTarget> InStageTargets,
        List <String> InStageExecutables,
        bool InServer,
        bool InCooked,
        bool InStageCrashReporter,
        bool InStage,
        bool InCookOnTheFly,
        bool InArchive,
        bool InProgram,
        bool IsClientInsteadOfNoEditor,
        bool InForceChunkManifests,
        bool InSeparateDebugStageDirectory
        )
    {
        bStageCrashReporter       = InStageCrashReporter;
        RawProjectPath            = RawProjectPathOrName;
        DedicatedServer           = InServer;
        LocalRoot                 = InLocalRoot;
        CookSourcePlatform        = InSourcePlatform;
        StageTargetPlatform       = InTargetPlatform;
        StageTargetConfigurations = new List <UnrealTargetConfiguration>(InTargetConfigurations);
        StageTargets              = new List <StageTarget>(InStageTargets);
        StageExecutables          = InStageExecutables;
        IsCodeBasedProject        = ProjectUtils.IsCodeBasedUProjectFile(RawProjectPath, StageTargetConfigurations);
        ShortProjectName          = ProjectUtils.GetShortProjectName(RawProjectPath);
        Stage   = InStage;
        Archive = InArchive;

        if (CookSourcePlatform != null && InCooked)
        {
            CookPlatform = CookSourcePlatform.GetCookPlatform(DedicatedServer, IsClientInsteadOfNoEditor);
        }
        else if (CookSourcePlatform != null && InProgram)
        {
            CookPlatform = CookSourcePlatform.GetCookPlatform(false, false);
        }
        else
        {
            CookPlatform = "";
        }

        if (StageTargetPlatform != null && InCooked)
        {
            FinalCookPlatform = StageTargetPlatform.GetCookPlatform(DedicatedServer, IsClientInsteadOfNoEditor);
        }
        else if (StageTargetPlatform != null && InProgram)
        {
            FinalCookPlatform = StageTargetPlatform.GetCookPlatform(false, false);
        }
        else
        {
            FinalCookPlatform = "";
        }

        PlatformDir = StageTargetPlatform.PlatformType.ToString();

        if (BaseStageDirectory != null)
        {
            StageDirectory      = DirectoryReference.Combine(BaseStageDirectory, FinalCookPlatform);
            DebugStageDirectory = InSeparateDebugStageDirectory? DirectoryReference.Combine(BaseStageDirectory, FinalCookPlatform + "Debug") : StageDirectory;
        }

        if (BaseArchiveDirectory != null)
        {
            ArchiveDirectory = DirectoryReference.Combine(BaseArchiveDirectory, FinalCookPlatform);
        }

        if (!FileReference.Exists(RawProjectPath))
        {
            throw new AutomationException("Can't find uproject file {0}.", RawProjectPathOrName);
        }

        EngineRoot  = DirectoryReference.Combine(LocalRoot, "Engine");
        ProjectRoot = RawProjectPath.Directory;

        RelativeProjectRootForStage = new StagedDirectoryReference(ShortProjectName);

        ProjectArgForCommandLines = CommandUtils.MakePathSafeToUseWithCommandLine(RawProjectPath.FullName);
        CookSourceRuntimeRootDir  = RuntimeRootDir = LocalRoot;
        RuntimeProjectRootDir     = ProjectRoot;

        if (Stage)
        {
            CommandUtils.CreateDirectory(StageDirectory.FullName);

            RuntimeRootDir            = StageDirectory;
            CookSourceRuntimeRootDir  = DirectoryReference.Combine(BaseStageDirectory, CookPlatform);
            RuntimeProjectRootDir     = DirectoryReference.Combine(StageDirectory, RelativeProjectRootForStage.Name);
            ProjectArgForCommandLines = CommandUtils.MakePathSafeToUseWithCommandLine(UProjectCommandLineArgInternalRoot + RelativeProjectRootForStage.Name + "/" + ShortProjectName + ".uproject");
        }
        if (Archive)
        {
            CommandUtils.CreateDirectory(ArchiveDirectory.FullName);
        }
        ProjectArgForCommandLines = ProjectArgForCommandLines.Replace("\\", "/");
        ProjectBinariesFolder     = DirectoryReference.Combine(ProjectUtils.GetClientProjectBinariesRootPath(RawProjectPath, TargetType.Game, IsCodeBasedProject), PlatformDir);

        // Build a list of restricted folder names. This will comprise all other restricted platforms, plus standard restricted folder names such as NoRedist, NotForLicensees, etc...
        RestrictedFolderNames.UnionWith(PlatformExports.GetPlatformFolderNames());
        foreach (UnrealTargetPlatform StagePlatform in StageTargetPlatform.GetStagePlatforms())
        {
            RestrictedFolderNames.ExceptWith(PlatformExports.GetIncludedFolderNames(StagePlatform));
        }
        RestrictedFolderNames.UnionWith(RestrictedFolder.GetNames());
        RestrictedFolderNames.Remove(StageTargetPlatform.IniPlatformType.ToString());

        // Read the game config files
        ConfigHierarchy GameConfig = ConfigCache.ReadHierarchy(ConfigHierarchyType.Game, ProjectRoot, InTargetPlatform.PlatformType);

        // Read the list of directories to remap when staging
        List <string> RemapDirectoriesList;

        if (GameConfig.GetArray("Staging", "RemapDirectories", out RemapDirectoriesList))
        {
            foreach (string RemapDirectory in RemapDirectoriesList)
            {
                Dictionary <string, string> Properties;
                if (!ConfigHierarchy.TryParse(RemapDirectory, out Properties))
                {
                    throw new AutomationException("Unable to parse '{0}'", RemapDirectory);
                }

                string FromDir;
                if (!Properties.TryGetValue("From", out FromDir))
                {
                    throw new AutomationException("Missing 'From' property in '{0}'", RemapDirectory);
                }

                string ToDir;
                if (!Properties.TryGetValue("To", out ToDir))
                {
                    throw new AutomationException("Missing 'To' property in '{0}'", RemapDirectory);
                }

                RemapDirectories.Add(Tuple.Create(new StagedDirectoryReference(FromDir), new StagedDirectoryReference(ToDir)));
            }
        }

        // Read the list of directories to whitelist from restricted folder warnings
        List <string> WhitelistDirectoriesList;

        if (GameConfig.GetArray("Staging", "WhitelistDirectories", out WhitelistDirectoriesList))
        {
            foreach (string WhitelistDirectory in WhitelistDirectoriesList)
            {
                WhitelistDirectories.Add(new StagedDirectoryReference(WhitelistDirectory));
            }
        }

        List <string> BlacklistLocTargetsList;

        if (GameConfig.GetArray("Staging", "BlacklistLocalizationTargets", out BlacklistLocTargetsList))
        {
            foreach (string BlacklistLocTarget in BlacklistLocTargetsList)
            {
                BlacklistLocalizationTargets.Add(BlacklistLocTarget);
            }
        }

        // Read the list of files which are whitelisted to be staged
        ReadConfigFileList(GameConfig, "Staging", "WhitelistConfigFiles", WhitelistConfigFiles);
        ReadConfigFileList(GameConfig, "Staging", "BlacklistConfigFiles", BlacklistConfigFiles);

        // Grab the game ini data
        ConfigHierarchy GameIni = ConfigCache.ReadHierarchy(ConfigHierarchyType.Game, ProjectRoot, InTargetPlatform.PlatformType);
        String          IniPath = "/Script/UnrealEd.ProjectPackagingSettings";

        // Read the config blacklists
        GameIni.GetArray(IniPath, "IniKeyBlacklist", out IniKeyBlacklist);
        GameIni.GetArray(IniPath, "IniSectionBlacklist", out IniSectionBlacklist);

        // If we were configured to use manifests across the whole project, then this platform should use manifests.
        // Otherwise, read whether we are generating chunks from the ProjectPackagingSettings ini.
        if (InForceChunkManifests)
        {
            PlatformUsesChunkManifests = true;
        }
        else
        {
            bool bSetting = false;
            if (GameIni.GetBool(IniPath, "bGenerateChunks", out bSetting))
            {
                PlatformUsesChunkManifests = bSetting;
            }
        }
    }
Exemple #36
0
        private void Diff(int index1, int index2)
        {
            var man1 = _manifestForms[index1].Manifest;
            var man2 = _manifestForms[index2].Manifest;

            var added = new HashSet <AssetInfo>(man2.Assets, SimpleAssetInfoComparer.Instance);

            added.ExceptWith(man1.Assets);

            var removed = new HashSet <AssetInfo>(man1.Assets, SimpleAssetInfoComparer.Instance);

            removed.ExceptWith(man2.Assets);

            var fullDiff = new List <(AssetInfo Info, DiffState State)>();

            foreach (var item in added)
            {
                fullDiff.Add((item, DiffState.Added));
            }

            foreach (var item in removed)
            {
                fullDiff.Add((item, DiffState.Removed));
            }

            fullDiff.Sort(CompareInfoAndStateTuple);
            _diffs = fullDiff.ToArray();

            lvDiff.BeginUpdate();

            lvDiff.Items.Clear();

            var listViewItems = new List <ListViewItem>();

            foreach (var(assetInfo, state) in fullDiff)
            {
                var lvi = new ListViewItem();
                lvi.SubItems.Add(assetInfo.ResourceName);
                lvi.SubItems.Add(assetInfo.RemoteName);
                lvi.SubItems.Add(assetInfo.ContentHash);
                lvi.SubItems.Add(assetInfo.Size.ToString());

                switch (state)
                {
                case DiffState.Added:
                    lvi.BackColor = Color.PaleGreen;
                    lvi.Text      = "+";
                    break;

                case DiffState.Removed:
                    lvi.BackColor = Color.LightPink;
                    lvi.Text      = "-";
                    break;

                case DiffState.Same:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(state), state, null);
                }

                listViewItems.Add(lvi);
            }

            lvDiff.Items.AddRange(listViewItems.ToArray());

            lvDiff.EndUpdate();
        }
Exemple #37
0
        private static async Task InitGlobalConfigAndLanguage()
        {
            string globalConfigFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);

            GlobalConfig = await GlobalConfig.Load(globalConfigFile).ConfigureAwait(false);

            if (GlobalConfig == null)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorGlobalConfigNotLoaded, globalConfigFile));
                await Task.Delay(5 * 1000).ConfigureAwait(false);
                await Exit(1).ConfigureAwait(false);

                return;
            }

            if (Debugging.IsUserDebugging)
            {
                ASF.ArchiLogger.LogGenericDebug(SharedInfo.GlobalConfigFileName + ": " + JsonConvert.SerializeObject(GlobalConfig, Formatting.Indented));
            }

            if (!string.IsNullOrEmpty(GlobalConfig.CurrentCulture))
            {
                try {
                    // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
                    CultureInfo culture = CultureInfo.CreateSpecificCulture(GlobalConfig.CurrentCulture);
                    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
                } catch (Exception) {
                    ASF.ArchiLogger.LogGenericError(Strings.ErrorInvalidCurrentCulture);
                }
            }

            if (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Equals("en"))
            {
                return;
            }

            ResourceSet defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true);

            if (defaultResourceSet == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(defaultResourceSet));
                return;
            }

            HashSet <DictionaryEntry> defaultStringObjects = defaultResourceSet.Cast <DictionaryEntry>().ToHashSet();

            if (defaultStringObjects.Count == 0)
            {
                ASF.ArchiLogger.LogNullError(nameof(defaultStringObjects));
                return;
            }

            ResourceSet currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

            if (currentResourceSet == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(currentResourceSet));
                return;
            }

            HashSet <DictionaryEntry> currentStringObjects = currentResourceSet.Cast <DictionaryEntry>().ToHashSet();

            if (currentStringObjects.Count >= defaultStringObjects.Count)
            {
                // Either we have 100% finished translation, or we're missing it entirely and using en-US
                HashSet <DictionaryEntry> testStringObjects = currentStringObjects.ToHashSet();
                testStringObjects.ExceptWith(defaultStringObjects);

                // If we got 0 as final result, this is the missing language
                // Otherwise it's just a small amount of strings that happen to be the same
                if (testStringObjects.Count == 0)
                {
                    currentStringObjects = testStringObjects;
                }
            }

            if (currentStringObjects.Count < defaultStringObjects.Count)
            {
                float translationCompleteness = currentStringObjects.Count / (float)defaultStringObjects.Count;
                ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentUICulture.Name, translationCompleteness.ToString("P1")));
            }
        }
 public void ExceptWith(IEnumerable <T> other)
 {
     lock (locker){
         hashSet.ExceptWith(other);
     }
 }
Exemple #39
0
 public void ExceptWith(IEnumerable <T> other)
 {
     _set.ExceptWith(other);
 }
Exemple #40
0
        private Dictionary <string, Dictionary <PatternRule, List <PatternMiningCoordinates> > > FindClusterCentroids(
            Dictionary <string, int> domainCounts,
            Dictionary <string, Dictionary <PatternRule, int> > ruleCoordOccsForDomains,
            Dictionary <string, Dictionary <PatternRule, Dictionary <Coord, int> > > domainsToRulesToCoordinateCounts,
            double clusterThresholdKm,
            int minItemsPerCluster,
            double minSupportRatioPerCluster)
        {
            var domainsToRulesToCentroids = new Dictionary <string, Dictionary <PatternRule, List <PatternMiningCoordinates> > >();

            var totalDomains       = domainsToRulesToCoordinateCounts.Count;
            var currentDomainCount = 0;

            foreach (var domainsToRulesToCoordinateCountsEntry in domainsToRulesToCoordinateCounts)
            {
                currentDomainCount++;
                var domain = domainsToRulesToCoordinateCountsEntry.Key;
                var rulesToCoordinateCounts = domainsToRulesToCoordinateCountsEntry.Value;

                var ruleCoordOccsForDomain = ruleCoordOccsForDomains[domain];

                var totalRulesForDomain = rulesToCoordinateCounts.Count();

                Dictionary <PatternRule, List <PatternMiningCoordinates> > rulesToCentroids = null;

                var currentRuleCount = 0;

                foreach (var rulesToCoordinateCountsEntry in rulesToCoordinateCounts)
                {
                    currentRuleCount++;
                    var rule = rulesToCoordinateCountsEntry.Key;
                    List <PatternMiningCoordinates> centroidsForRule = null;

                    Console.WriteLine($"{currentDomainCount}/{totalDomains} - {currentRuleCount}/{totalRulesForDomain} - Finding clusters for domain {domain} and rule {rule}");

                    var coordinateToCounts        = rulesToCoordinateCountsEntry.Value;
                    var originalCoordinatesOccSum = ruleCoordOccsForDomain[rule];

                    var coordinatesWithOcc = new HashSet <CoordWithOcc>(coordinateToCounts.Select(x => new CoordWithOcc(x.Key, x.Value)));

                    var clustering = new QTClustering <CoordWithOcc>(
                        distanceHelper: new CoordWithOccDistanceHelper(),
                        clusterDiameter: clusterThresholdKm,
                        itemsSet: coordinatesWithOcc);

                    Cluster <CoordWithOcc> cluster = null;

                    do
                    {
                        cluster = clustering.NextCluster();

                        if (cluster == null)
                        {
                            break;
                        }

                        var clusterMembersSum = cluster.Members.Sum(c => c.Occurrences);

                        if (clusterMembersSum < minItemsPerCluster)
                        {
                            break;
                        }

                        var supportRatio = clusterMembersSum / ((1.0d) * originalCoordinatesOccSum);

                        if (supportRatio < minSupportRatioPerCluster)
                        {
                            break;
                        }

                        if (rulesToCentroids == null)
                        {
                            rulesToCentroids = this.RetrieveRulesToCentroidsList(domainsToRulesToCentroids, domain);
                        }

                        if (centroidsForRule == null)
                        {
                            centroidsForRule = this.RetrieveCentroidsList(rulesToCentroids, rule);
                        }

                        var centroidCoordinates = new PatternMiningCoordinates()
                        {
                            Latitude   = cluster.Centroid.Coord.Latitude,
                            Longitude  = cluster.Centroid.Coord.Longitude,
                            Confidence = supportRatio
                        };

                        centroidsForRule.Add(centroidCoordinates);

                        Console.WriteLine($"                                                Found centroid: {centroidCoordinates}");

                        coordinatesWithOcc.ExceptWith(cluster.Members);

                        var maxRemainingSupportRatio = coordinatesWithOcc.Sum(c => c.Occurrences) / ((1.0d) * originalCoordinatesOccSum);

                        if (maxRemainingSupportRatio < minSupportRatioPerCluster)
                        {
                            break;
                        }
                    }while (cluster != null);
                }
            }

            return(domainsToRulesToCentroids);
        }
Exemple #41
0
 public void Remove(IEnumerable <IComparable> myComparables)
 {
     Value.ExceptWith(myComparables);
 }
Exemple #42
0
        /// <summary>
        /// Sugiyama step 1: Cycle Removal
        /// This method implements an enhanced Greedy Cycle Removal heuristic
        /// proposed by Eades et al, 1993.
        /// http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.47.7745
        /// </summary>
        public void RemoveCycles()
        {
            HashSet <Node> RemainingNodes = new HashSet <Node>(Nodes);
            HashSet <Edge> AcyclicEdges   = new HashSet <Edge>();

            while (RemainingNodes.Count > 0)
            {
                // Remove all sink nodes
                HashSet <Node> selected = new HashSet <Node>(RemainingNodes.Where(
                                                                 n => n.RightEdges.Count(x => x.Active) == 0));
                foreach (Node n in selected)
                {
                    foreach (Edge e in n.LeftEdges.Where(x => x.Active))
                    {
                        AcyclicEdges.Add(e);
                        e.Active = false;
                    }
                }

                // Remove all isolated nodes
                RemainingNodes.ExceptWith(selected);

                // Remove all source nodes
                selected = new HashSet <Node>(RemainingNodes.Where(
                                                  n => n.LeftEdges.Count(x => x.Active) == 0));
                foreach (Node n in selected)
                {
                    foreach (Edge e in n.RightEdges.Where(x => x.Active))
                    {
                        AcyclicEdges.Add(e);
                        e.Active = false;
                    }
                }

                // Remove all isolated nodes
                RemainingNodes.ExceptWith(selected);

                // Remove one node with the largest number of outgoing edges
                if (RemainingNodes.Count > 0)
                {
                    int max = RemainingNodes.Max(x => x.RightEdges.Count(y => y.Active)
                                                 - x.LeftEdges.Count(y => y.Active));
                    Node n = RemainingNodes.First(x => x.RightEdges.Count(y => y.Active)
                                                  - x.LeftEdges.Count(y => y.Active) == max);

                    AcyclicEdges.UnionWith(n.RightEdges.Where(x => x.Active));

                    foreach (Edge e in n.RightEdges)
                    {
                        e.Active = false;
                    }

                    foreach (Edge e in n.LeftEdges)
                    {
                        e.Active = false;
                    }

                    RemainingNodes.Remove(n);
                }
            }

            Edges = AcyclicEdges;

            foreach (Edge e in Edges)
            {
                e.Active = true;
            }
        }
Exemple #43
0
        public void ExtractNativeLinkInfo()
        {
            // ignore framework assemblies, they won't have any LinkWith attributes
            if (IsFrameworkAssembly == true)
            {
                return;
            }

            var assembly = AssemblyDefinition;

            if (!assembly.HasCustomAttributes)
            {
                return;
            }

            string resourceBundlePath = Path.ChangeExtension(FullPath, ".resources");
            string manifestPath       = Path.Combine(resourceBundlePath, "manifest");

            if (File.Exists(manifestPath))
            {
                foreach (NativeReferenceMetadata metadata in ReadManifest(manifestPath))
                {
                    LogNativeReference(metadata);
                    ProcessNativeReferenceOptions(metadata);

                    if (metadata.LibraryName.EndsWith(".framework", StringComparison.OrdinalIgnoreCase))
                    {
                        AssertiOSVersionSupportsUserFrameworks(metadata.LibraryName);
                        Frameworks.Add(metadata.LibraryName);
#if MMP // HACK - MMP currently doesn't respect Frameworks on non-App - https://github.com/xamarin/xamarin-macios/issues/5203
                        App.Frameworks.Add(metadata.LibraryName);
#endif
                    }
                    else
                    {
#if MMP // HACK - MMP currently doesn't respect LinkWith - https://github.com/xamarin/xamarin-macios/issues/5203
                        Driver.native_references.Add(metadata.LibraryName);
#endif
                        LinkWith.Add(metadata.LibraryName);
                    }
                }
            }

            ProcessLinkWithAttributes(assembly);

            // Make sure there are no duplicates between frameworks and weak frameworks.
            // Keep the weak ones.
            if (Frameworks != null && WeakFrameworks != null)
            {
                Frameworks.ExceptWith(WeakFrameworks);
            }

            if (NeedsGccExceptionHandling)
            {
                if (LinkerFlags == null)
                {
                    LinkerFlags = new List <string> ();
                }
                LinkerFlags.Add("-lgcc_eh");
            }
        }
Exemple #44
0
        /// <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.GetSkipNavigations().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.IsInterface ||
                             targetSequenceType?.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()));
                    }
                }
            }
        }
Exemple #45
0
        private TagWithValues[] GetRegionTagValuesWithoutRecursion(string text, int[] regionIds)
        {
            var textTags = GetTags(text);
            var tags     = LoadTagWithValues(textTags);
            var newTags  = new List <TagWithValues>();

            foreach (var tag in tags)
            {
                var regions      = new HashSet <int>(regionIds);
                var regionsUsed  = new HashSet <int>();
                var newTagValues = new List <TagValue>();

                foreach (var tagValue in tag.Values)
                {
                    // if we've found values for all regions then stop searching
                    if (regions.Count == regionsUsed.Count)
                    {
                        break;
                    }
                    var commonRegionIds = tagValue.RegionsId.Intersect(regions).ToArray();
                    if (commonRegionIds.Any())
                    {
                        regionsUsed.UnionWith(commonRegionIds);
                        newTagValues.Add(new TagValue()
                        {
                            RegionsId = commonRegionIds,
                            Value     = tagValue.Value
                        });
                    }
                }

                if (regions.Count != regionsUsed.Count)
                {
                    regions.ExceptWith(regionsUsed);

                    if (regions.Any()) // if we have product regions that is not used the we'll check their parents
                    {
                        foreach (var region in regions)
                        {
                            var parents = _regionService.GetParentsIds(region);
                            foreach (var parent in parents)
                            {
                                // if parent region has already been used for tag
                                if (regionsUsed.Contains(parent))
                                {
                                    var newTagValue = newTagValues.FirstOrDefault(n => n.RegionsId.Contains(parent));
                                    if (newTagValue == null)
                                    {
                                        continue;
                                    }
                                    // append region to found parent tag value
                                    newTagValue.RegionsId = newTagValue.RegionsId.Append(region).ToArray();
                                    break;
                                }
                                else
                                {
                                    // if parent has not used tag value
                                    var commonTagValue = tag.Values.FirstOrDefault(n => n.RegionsId.Contains(parent));
                                    if (commonTagValue == null)
                                    {
                                        continue;
                                    }
                                    // append found parent value with region itself
                                    newTagValues.Add(new TagValue()
                                    {
                                        RegionsId = new[] { region },
                                        Value     = commonTagValue.Value
                                    });
                                    break;
                                }
                            }
                        }
                    }
                }

                var resultValues = (
                    from v in newTagValues
                    group v.RegionsId by v.Value
                    into g
                    select new TagValue()
                {
                    Value = g.Key, RegionsId = g.SelectMany(n => n).ToArray()
                }).ToArray();


                newTags.Add(new TagWithValues()
                {
                    Title  = tag.Title,
                    Values = resultValues.ToArray()
                }
                            );
            }


            return(newTags.ToArray());
        }
Exemple #46
0
        public override void isSatiesfied <T>(Modest.Teaching.TransitionSystem <T> transition_system, LinkedList <T> states, out HashSet <T> sat, ref Pre_Compute_Factory <T> factory)
        {
            if (factory.prop_sats.ContainsKey(this))
            {
                factory.prop_sats.TryGetValue(this, out sat);
                return;
            }


            //Console.WriteLine("Always start");
            HashSet <T> v;                                                                        //Sat(operand)

            operand.isSatiesfied <T>(transition_system, states, out v, ref factory);
            HashSet <T> e = new HashSet <T>();                                                    //S\V

            foreach (var entry in states)
            {
                e.Add(entry);
            }

            e.ExceptWith(v);

            Queue <T> e_queue = new Queue <T>();

            foreach (var entry in e)
            {
                e_queue.Enqueue(entry);
            }

            Dictionary <T, int> state_c = new Dictionary <T, int>();



            // Initialize c[s] for every state in Sat(operand)
            foreach (var entry in v)
            {
                var         temp = entry;
                HashSet <T> post = factory.getPostSet(ref temp);

                state_c.Add(temp, post.Count);
            }

            int e_queue_size = e_queue.Count;

            while (e_queue_size > 0)
            {
                var         s_prime     = e_queue.Dequeue();
                HashSet <T> pre_s_prime = factory.getPreSet(ref s_prime);

                foreach (var s in pre_s_prime)
                {
                    if (v.Contains(s))
                    {
                        int current_c;
                        state_c.TryGetValue(s, out current_c);
                        state_c.Remove(s);

                        current_c--;

                        state_c.Add(s, current_c);

                        if (current_c == 0)
                        {
                            v.Remove(s);
                            e_queue.Enqueue(s);
                        }
                    }
                }

                e_queue_size = e_queue.Count;
            }

            factory.prop_sats.Add(this, v);

            sat = v;

            //Console.WriteLine("Always stop");
        }
 ///<inheritdoc/>
 public void ExceptWith(IEnumerable <TKey> other)
 {
     lock (_syncLock) _hashSet.ExceptWith(other);
 }
Exemple #48
0
        public void ExtractNativeLinkInfo()
        {
            // ignore framework assemblies, they won't have any LinkWith attributes
            if (IsFrameworkAssembly == true)
            {
                return;
            }

            var assembly = AssemblyDefinition;

            if (!assembly.HasCustomAttributes)
            {
                return;
            }

            string resourceBundlePath = Path.ChangeExtension(FullPath, ".resources");

            if (!Directory.Exists(resourceBundlePath))
            {
                var zipPath = resourceBundlePath + ".zip";
                if (File.Exists(zipPath))
                {
                    var path = Path.Combine(App.Cache.Location, Path.GetFileName(resourceBundlePath));
                    if (Driver.RunCommand("/usr/bin/unzip", "-u", "-o", "-d", path, zipPath) != 0)
                    {
                        throw ErrorHelper.CreateError(1306, Errors.MX1306 /* Could not decompress the file '{0}'. Please review the build log for more information from the native 'unzip' command. */, zipPath);
                    }
                    resourceBundlePath = path;
                }
            }
            string manifestPath = Path.Combine(resourceBundlePath, "manifest");

            if (File.Exists(manifestPath))
            {
                foreach (NativeReferenceMetadata metadata in ReadManifest(manifestPath))
                {
                    LogNativeReference(metadata);
                    ProcessNativeReferenceOptions(metadata);

                    switch (Path.GetExtension(metadata.LibraryName).ToLowerInvariant())
                    {
                    case ".framework":
                        AssertiOSVersionSupportsUserFrameworks(metadata.LibraryName);
                        Frameworks.Add(metadata.LibraryName);
#if MMP // HACK - MMP currently doesn't respect Frameworks on non-App - https://github.com/xamarin/xamarin-macios/issues/5203
                        App.Frameworks.Add(metadata.LibraryName);
#endif
                        break;

                    case ".xcframework":
                        // this is resolved, at msbuild time, into a framework
                        // but we must ignore it here (can't be the `default` case)
                        break;

                    default:
#if MMP // HACK - MMP currently doesn't respect LinkWith - https://github.com/xamarin/xamarin-macios/issues/5203
                        Driver.native_references.Add(metadata.LibraryName);
#endif
                        LinkWith.Add(metadata.LibraryName);
                        break;
                    }
                }
            }

            ProcessLinkWithAttributes(assembly);

            // Make sure there are no duplicates between frameworks and weak frameworks.
            // Keep the weak ones.
            if (Frameworks != null && WeakFrameworks != null)
            {
                Frameworks.ExceptWith(WeakFrameworks);
            }

            if (NeedsGccExceptionHandling)
            {
                if (LinkerFlags == null)
                {
                    LinkerFlags = new List <string> ();
                }
                LinkerFlags.Add("-lgcc_eh");
            }
        }
Exemple #49
0
        /// <summary>
        /// Assumes leftRoot is an existing folder. rightRoot may not exist if operating in speculative mode.
        /// </summary>
        public static FolderDiffResults DiffFolders(
            string leftRoot,
            string rightRoot,
            string pattern,
            bool recursive       = true,
            bool compareContents = true)
        {
            HashSet <string> leftRelativePaths = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            HashSet <string> leftOnlyFolders   = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            using (Log.MeasureTime("Scanning source directory"))
            {
                GetRelativePathsOfAllFiles(leftRoot, pattern, recursive, leftRelativePaths, leftOnlyFolders);
            }

            HashSet <string> rightRelativePaths = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            HashSet <string> rightOnlyFolders   = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            if (Directory.Exists(rightRoot))
            {
                using (Log.MeasureTime("Scanning destination directory"))
                {
                    GetRelativePathsOfAllFiles(rightRoot, pattern, recursive, rightRelativePaths, rightOnlyFolders);
                }
            }

            var leftOnlyFiles  = new List <string>();
            var identicalFiles = new List <string>();
            var changedFiles   = new List <string>();
            var rightOnlyFiles = new HashSet <string>(rightRelativePaths, StringComparer.OrdinalIgnoreCase);

            var commonFolders = leftOnlyFolders.Intersect(rightOnlyFolders, StringComparer.OrdinalIgnoreCase).ToArray();

            leftOnlyFolders.ExceptWith(commonFolders);
            rightOnlyFolders.ExceptWith(commonFolders);

            int current = 0;
            int total   = leftRelativePaths.Count;

            using (Log.MeasureTime("Comparing"))
            {
                Parallel.ForEach(
                    leftRelativePaths,
                    new ParallelOptions {
                    MaxDegreeOfParallelism = Environment.ProcessorCount * 2
                },
                    left =>
                {
                    var leftFullPath  = leftRoot + left;
                    var rightFullPath = rightRoot + left;

                    bool rightContains = rightRelativePaths.Contains(left);
                    if (rightContains)
                    {
                        bool areSame = !compareContents || Files.AreContentsIdentical(leftFullPath, rightFullPath);
                        if (areSame)
                        {
                            lock (identicalFiles)
                            {
                                identicalFiles.Add(left);
                            }
                        }
                        else
                        {
                            lock (changedFiles)
                            {
                                changedFiles.Add(left);
                            }
                        }
                    }
                    else
                    {
                        lock (leftOnlyFiles)
                        {
                            leftOnlyFiles.Add(left);
                        }
                    }

                    lock (rightOnlyFiles)
                    {
                        rightOnlyFiles.Remove(left);
                    }

                    Interlocked.Increment(ref current);
                });
            }

            using (Log.MeasureTime("Sorting"))
            {
                leftOnlyFiles.Sort();
                identicalFiles.Sort();
                changedFiles.Sort();

                return(new FolderDiffResults(
                           leftOnlyFiles,
                           identicalFiles,
                           changedFiles,
                           rightOnlyFiles.OrderBy(s => s).ToArray(),
                           leftOnlyFolders.OrderBy(s => s).ToArray(),
                           rightOnlyFolders.OrderBy(s => s).ToArray()));
            }
        }
Exemple #50
0
        public void ExtractNativeLinkInfo()
        {
            // ignore framework assemblies, they won't have any LinkWith attributes
            if (IsFrameworkAssembly == true)
            {
                return;
            }

            var assembly = AssemblyDefinition;

            if (!assembly.HasCustomAttributes)
            {
                return;
            }

            string resourceBundlePath = Path.ChangeExtension(FullPath, ".resources");
            string manifestPath       = Path.Combine(resourceBundlePath, "manifest");

            if (File.Exists(manifestPath))
            {
                foreach (NativeReferenceMetadata metadata in ReadManifest(manifestPath))
                {
                    LogNativeReference(metadata);
                    ProcessNativeReferenceOptions(metadata);

                    switch (Path.GetExtension(metadata.LibraryName).ToLowerInvariant())
                    {
                    case ".framework":
                        AssertiOSVersionSupportsUserFrameworks(metadata.LibraryName);
                        Frameworks.Add(metadata.LibraryName);
#if MMP // HACK - MMP currently doesn't respect Frameworks on non-App - https://github.com/xamarin/xamarin-macios/issues/5203
                        App.Frameworks.Add(metadata.LibraryName);
#endif
                        break;

                    case ".xcframework":
                        // this is resolved, at msbuild time, into a framework
                        // but we must ignore it here (can't be the `default` case)
                        break;

                    default:
#if MMP // HACK - MMP currently doesn't respect LinkWith - https://github.com/xamarin/xamarin-macios/issues/5203
                        Driver.native_references.Add(metadata.LibraryName);
#endif
                        LinkWith.Add(metadata.LibraryName);
                        break;
                    }
                }
            }

            ProcessLinkWithAttributes(assembly);

            // Make sure there are no duplicates between frameworks and weak frameworks.
            // Keep the weak ones.
            if (Frameworks != null && WeakFrameworks != null)
            {
                Frameworks.ExceptWith(WeakFrameworks);
            }

            if (NeedsGccExceptionHandling)
            {
                if (LinkerFlags == null)
                {
                    LinkerFlags = new List <string> ();
                }
                LinkerFlags.Add("-lgcc_eh");
            }
        }
Exemple #51
0
        private static void ProcessProjectDescriptor(XElement projectDescriptor, string baseDirectory)
        {
            Console.WriteLine("Processing project files in '{0}':", baseDirectory);
            var filesets = LoadFileSets(projectDescriptor, baseDirectory);

            Console.WriteLine("File sets:");
            foreach (var fs in filesets)
            {
                Console.WriteLine("  {0}: {1} files", fs.Key, fs.Value.Count);
            }

            foreach (var project in projectDescriptor.Elements("Project"))
            {
                string file            = (string)project.Attribute("File");
                string projectFileName = Path.Combine(baseDirectory, file);
                var    projectContents = XElement.Load(projectFileName);

                Console.WriteLine("Updating file: {0}", file);
                string contentBefore = projectContents.ToString();

                foreach (var itemGroup in project.Elements("ItemGroup"))
                {
                    string itemGroupName = (string)itemGroup.Attribute("Name");
                    var    keepOldAttr   = itemGroup.Attribute("KeepOldFiles");
                    bool   keepOldFiles  = keepOldAttr != null && bool.Parse(keepOldAttr.Value);
                    var    contents      = new HashSet <string>();
                    foreach (var fileSetElement in itemGroup.Elements("FileSet"))
                    {
                        string include = (string)fileSetElement.Attribute("Include");
                        string exclude = (string)fileSetElement.Attribute("Exclude");

                        if (include != null)
                        {
                            var fileset = GetFileset(filesets, include);
                            contents.UnionWith(fileset);
                        }

                        if (exclude != null)
                        {
                            var fileset = GetFileset(filesets, exclude);
                            contents.ExceptWith(fileset);
                        }
                    }

                    Console.WriteLine("  <{0}/>: {1} items", itemGroupName, contents.Count);

                    var fullItemGroup     = MSBuildNamespace + "ItemGroup";
                    var fullItemGroupName = MSBuildNamespace + itemGroupName;
                    var projectItemGroup  = projectContents.Elements(fullItemGroup).FirstOrDefault(c => c.Elements(fullItemGroupName).Any());
                    var groupIsEmpty      = false;

                    if (projectItemGroup != null)
                    {
                        //remove old elemens
                        if (!keepOldFiles)
                        {
                            projectItemGroup.Elements().Remove();
                            groupIsEmpty = true;
                        }
                    }
                    else
                    {
                        //create new group
                        projectItemGroup = new XElement(fullItemGroup);
                        projectContents.Add(projectItemGroup);
                        groupIsEmpty = true;
                    }
                    var xElementComparer = new XElementIncludeAttrComparer();
                    //add files
                    foreach (var filename in contents.OrderBy(c => c))
                    {
                        var item = new XElement(fullItemGroupName, new XAttribute("Include", filename));

                        if (!groupIsEmpty)
                        {
                            //ignore if already there

                            if (projectItemGroup.Elements().Contains(item, xElementComparer))
                            {
                                break;
                            }
                        }

                        foreach (var customize in projectDescriptor.Elements(MSBuildNamespace + "Customize"))
                        {
                            string fileSet   = (string)customize.Attribute("FileSet");
                            var    fsContent = filesets[fileSet];
                            if (fsContent.Contains(filename))
                            {
                                foreach (var e in customize.Elements())
                                {
                                    var cust = XElement.Parse(e.ToString());
                                    cust.Attribute(XNamespace.None + "xmlns").Remove();
                                    item.Add(cust);
                                }
                            }
                        }

                        projectItemGroup.Add(item);
                    }
                }

                string contentAfter = projectContents.ToString();
                if (contentBefore != contentAfter)
                {
                    Console.WriteLine("  Project updated. Saving.");
                    projectContents.Save(projectFileName);
                }
                else
                {
                    Console.WriteLine("  Project file is up-to-date.");
                }
            }
        }
Exemple #52
0
        internal void CoreUpdate()
        {
            if (m_IsUpdated)
            {
                return;
            }

            m_IsUpdated = true;

            // dominance

            for (int i = 0; i < m_Items.Count; ++i)
            {
                for (int j = i + 1; j < m_Items.Count; ++j)
                {
                    ObjectiveItem <T> left  = m_Items[i];
                    ObjectiveItem <T> right = m_Items[j];

                    int d = ObjectiveItem <T> .Dominance(left, right);

                    if (d > 0)
                    {
                        left.m_BetterThan.Add(right);
                        right.m_WorseThan.Add(left);
                    }
                    else if (d < 0)
                    {
                        right.m_BetterThan.Add(left);
                        left.m_WorseThan.Add(right);
                    }
                }
            }

            // frontiers
            HashSet <ObjectiveItem <T> > agenda = new HashSet <ObjectiveItem <T> >(m_Items);
            HashSet <ObjectiveItem <T> > skips  = new HashSet <ObjectiveItem <T> >();

            int level = 0;

            while (agenda.Any())
            {
                level += 1;

                List <ObjectiveItem <T> > exclude = new List <ObjectiveItem <T> >(m_Items.Count);

                foreach (var item in agenda)
                {
                    if (item.WorseThan.All(x => skips.Contains(x)))
                    {
                        exclude.Add(item);

                        item.m_FrontierLevel = level;
                    }
                }

                m_Frontiers.Add(level, exclude);

                agenda.ExceptWith(exclude);
                skips.UnionWith(exclude);
            }
        }
Exemple #53
0
        /// <summary>
        /// Strips shader variants from the underwater shader based on what features are enabled on the ocean material.
        /// </summary>
        public void ProcessUnderwaterShader(Shader shader, IList <ShaderCompilerData> data)
        {
            // This should not happen. There should always be at least one variant.
            if (data.Count == 0)
            {
                return;
            }

#if CREST_DEBUG
            var shaderVariantCount         = data.Count;
            var shaderVarientStrippedCount = 0;
#endif

            // Collect all shader keywords.
            var unusedShaderKeywords = new HashSet <ShaderKeyword>();
            for (int i = 0; i < data.Count; i++)
            {
                // Each ShaderCompilerData is a variant which is a combination of keywords. Since each list will be
                // different, simply getting a list of all keywords is not possible. This also appears to be the only
                // way to get a list of keywords without trying to extract them from shader property names. Lastly,
                // shader_feature will be returned only if they are enabled.
                unusedShaderKeywords.UnionWith(data[i].shaderKeywordSet.GetShaderKeywords());
            }

            // Get used shader keywords so we can exclude them.
            var usedShaderKeywords = new List <ShaderKeyword>();
            foreach (var shaderKeyword in unusedShaderKeywords)
            {
                // Do not handle built-in shader keywords.
                if (ShaderKeyword.GetKeywordType(shader, shaderKeyword) != ShaderKeywordType.UserDefined)
                {
                    usedShaderKeywords.Add(shaderKeyword);
                    continue;
                }

                // GetKeywordName will work for both global and local keywords.
                var shaderKeywordName = ShaderKeyword.GetKeywordName(shader, shaderKeyword);

                // These keywords will not be on ocean material.
                if (shaderKeywordName.Contains("_MENISCUS") || shaderKeywordName.Contains("_FULL_SCREEN_EFFECT"))
                {
                    usedShaderKeywords.Add(shaderKeyword);
                    continue;
                }

                // TODO: Strip this once post-processing is more unified.
                if (shaderKeywordName.Contains("_DEBUG_VIEW_OCEAN_MASK"))
                {
                    usedShaderKeywords.Add(shaderKeyword);
                    continue;
                }

                foreach (var oceanMaterial in _oceanMaterials)
                {
                    if (oceanMaterial.IsKeywordEnabled(shaderKeywordName))
                    {
                        usedShaderKeywords.Add(shaderKeyword);
                        break;
                    }
                }
            }

            // Exclude used keywords to obtain list of unused keywords.
            unusedShaderKeywords.ExceptWith(usedShaderKeywords);

            for (int index = 0; index < data.Count; index++)
            {
                foreach (var unusedShaderKeyword in unusedShaderKeywords)
                {
                    // IsEnabled means this variant uses this keyword and we can strip it.
                    if (data[index].shaderKeywordSet.IsEnabled(unusedShaderKeyword))
                    {
                        data.RemoveAt(index--);
#if CREST_DEBUG
                        shaderVarientStrippedCount++;
#endif
                        break;
                    }
                }
            }

#if CREST_DEBUG
            this.shaderVarientStrippedCount += shaderVarientStrippedCount;
            Debug.Log($"Crest: {shaderVarientStrippedCount} shader variants stripped of {shaderVariantCount} from {shader.name}.");
#endif
        }
Exemple #54
0
        public override IBidirectionalGraph <Cluster <T>, ClusterEdge <T> > GenerateClusters(IList <ClusterOrderEntry <T> > clusterOrder)
        {
            double mib            = 0.0;
            var    clusterIndices = new Dictionary <Cluster <T>, Tuple <int, int> >();
            var    curClusters    = new HashSet <Cluster <T> >();
            var    unclassifed    = new HashSet <T>(clusterOrder.Select(oe => oe.DataObject));
            var    sdaSet         = new List <SteepArea>();
            var    tree           = new BidirectionalGraph <Cluster <T>, ClusterEdge <T> >(false);
            var    scan           = new SteepScanPosition(clusterOrder);

            while (scan.HasNext)
            {
                int curPos = scan.Index;
                mib = Math.Max(mib, scan.Current.Reachability);
                if (scan.Successor != null)
                {
                    if (scan.SteepDown(_ixi))
                    {
                        UpdateFilterSdaSet(mib, sdaSet);
                        double startVal   = scan.Current.Reachability;
                        int    startSteep = scan.Index;
                        int    endSteep   = Math.Min(scan.Index + 1, clusterOrder.Count);
                        while (scan.HasNext)
                        {
                            scan.Next();
                            if (!scan.SteepDown(1.0))
                            {
                                break;
                            }
                            if (scan.SteepDown(_ixi))
                            {
                                endSteep = Math.Min(scan.Index + 1, clusterOrder.Count);
                            }
                            else if (scan.Index - endSteep > Optics.MinPoints)
                            {
                                break;
                            }
                        }
                        mib = clusterOrder[endSteep].Reachability;
                        var sda = new SteepArea(startSteep, endSteep, startVal);
                        sdaSet.Add(sda);
                        continue;
                    }
                    if (scan.SteepUp(_ixi))
                    {
                        UpdateFilterSdaSet(mib, sdaSet);
                        int startSteep = scan.Index;
                        int endSteep   = scan.Index + 1;
                        mib = scan.Current.Reachability;
                        double succ = scan.Successor.Reachability;
                        if (!double.IsPositiveInfinity(succ))
                        {
                            while (scan.HasNext)
                            {
                                scan.Next();
                                if (!scan.SteepUp(1.0))
                                {
                                    break;
                                }

                                if (scan.SteepUp(_ixi))
                                {
                                    endSteep = Math.Min(scan.Index + 1, clusterOrder.Count - 1);
                                    mib      = scan.Current.Reachability;
                                    succ     = scan.Successor.Reachability;
                                }
                                else if (scan.Index - endSteep > Optics.MinPoints)
                                {
                                    break;
                                }
                            }
                        }
                        var sua = new SteepArea(startSteep, endSteep, succ);
                        foreach (SteepArea sda in ((IEnumerable <SteepArea>)sdaSet).Reverse())
                        {
                            if (mib * _ixi < sda.Mib)
                            {
                                continue;
                            }

                            int cstart = sda.StartIndex;
                            int cend   = sua.EndIndex;
                            if (sda.Maximum * _ixi >= sua.Maximum)
                            {
                                while (cstart < sda.EndIndex)
                                {
                                    if (clusterOrder[cstart + 1].Reachability > sua.Maximum)
                                    {
                                        cstart++;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                            else if (sua.Maximum * _ixi >= sda.Maximum)
                            {
                                while (cend > sua.StartIndex)
                                {
                                    if (clusterOrder[cend - 1].Reachability > sda.Maximum)
                                    {
                                        cend--;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }

                            if (cend - cstart + 1 < Optics.MinPoints)
                            {
                                continue;
                            }

                            var cluster = new Cluster <T>(clusterOrder.Skip(cstart).Take(cend - cstart + 1).Select(oe => oe.DataObject).Intersect(unclassifed));
                            tree.AddVertex(cluster);
                            unclassifed.ExceptWith(cluster.DataObjects);

                            var toRemove = new HashSet <Cluster <T> >();
                            foreach (Cluster <T> curCluster in curClusters)
                            {
                                Tuple <int, int> indices = clusterIndices[curCluster];
                                if (cstart <= indices.Item1 && indices.Item2 <= cend)
                                {
                                    tree.AddEdge(new ClusterEdge <T>(cluster, curCluster));
                                    toRemove.Add(curCluster);
                                }
                            }
                            curClusters.ExceptWith(toRemove);
                            curClusters.Add(cluster);
                            clusterIndices[cluster] = Tuple.Create(cstart, cend);
                        }
                    }
                }

                if (curPos == scan.Index)
                {
                    scan.Next();
                }
            }

            if (unclassifed.Count > 0)
            {
                Cluster <T> allCluster = double.IsPositiveInfinity(clusterOrder.Last().Reachability)
                                        ? new Cluster <T>(unclassifed, true) : new Cluster <T>(unclassifed);
                tree.AddVertex(allCluster);
                foreach (Cluster <T> curCluster in curClusters)
                {
                    tree.AddEdge(new ClusterEdge <T>(allCluster, curCluster));
                }
            }

            return(tree);
        }
Exemple #55
0
        /// <summary>
        /// Applies a hill climbing algorithm to the given solution by trying to swap single nodes
        /// in and out until no swap improves it and returns the resulting solutions.
        /// </summary>
        /// <param name="original">The solution to improve. (not null)</param>
        /// <returns>The potentially improved solution.</returns>
        public HashSet <ushort> Improve(IEnumerable <ushort> original)
        {
            if (original == null)
            {
                throw new ArgumentNullException("original");
            }

            _current    = new HashSet <ushort>(original);
            _notCurrent = new HashSet <ushort>(_allNodes);
            _notCurrent.ExceptWith(_current);
            _curFitness  = _fitnessFunc(new HashSet <ushort>(_current));
            _improvement = true;

            while (_improvement)
            {
                _improvement = false;

                Parallel.ForEach(_current, (curNode, state) =>
                {
                    // If node is fixed or not in the search space it can't be removed.
                    if (_fixedNodes.Contains(curNode) || !_searchSpaceNodes.Contains(curNode))
                    {
                        return;
                    }

                    var newCur = new HashSet <ushort>(_current);
                    var newNot = new HashSet <ushort>(_notCurrent);

                    // Continue if node can't be removed.
                    if (CountNeighborsIn(curNode, newCur) > 1)
                    {
                        return;
                    }

                    // Remove current node
                    newCur.Remove(curNode);
                    var newFitness = _fitnessFunc(new HashSet <ushort>(newCur));
                    if (newFitness <= _curFitness)
                    {
                        // Swap current node with each of _notCurrent
                        foreach (var notNode in newNot)
                        {
                            // Break if someone else already found a better set.
                            if (state.IsStopped)
                            {
                                break;
                            }
                            // Continue if node can't be added.
                            if (CountNeighborsIn(notNode, newCur) == 0)
                            {
                                continue;
                            }

                            newCur.Add(notNode);
                            newFitness = _fitnessFunc(new HashSet <ushort>(newCur));
                            if (newFitness > _curFitness)
                            {
                                newNot.Remove(notNode);
                                break;
                            }
                            newCur.Remove(notNode);
                        }
                    }

                    if (newFitness <= _curFitness || state.IsStopped)
                    {
                        return;
                    }
                    lock (_improvementLock)
                    {
                        if (newFitness <= _curFitness || state.IsStopped)
                        {
                            return;
                        }
                        Debug.WriteLine("Improved from " + _curFitness + " to " + newFitness);
                        _current = newCur;
                        newNot.Add(curNode);
                        _notCurrent  = newNot;
                        _curFitness  = newFitness;
                        _improvement = true;
                        state.Stop();
                    }
                });
            }

            return(_current);
        }
        /// <summary>
        /// Find the consensus nucleotide for a set of nucleotides.
        /// </summary>
        /// <param name="symbols">Set of sequence items.</param>
        /// <returns>Consensus nucleotide.</returns>
        public override byte GetConsensusSymbol(HashSet <byte> symbols)
        {
            if (symbols == null)
            {
                throw new ArgumentNullException("symbols");
            }

            if (symbols.Count == 0)
            {
                throw new ArgumentException(Properties.Resource.SymbolCountZero);
            }

            HashSet <byte> symbolsInUpperCase = new HashSet <byte>();

            // Validate that all are valid DNA symbols
            HashSet <byte> validValues = GetValidSymbols();

            foreach (byte symbol in symbols)
            {
                if (!validValues.Contains(symbol))
                {
                    throw new ArgumentException(string.Format(
                                                    CultureInfo.CurrentCulture, Properties.Resource.INVALID_SYMBOL, (char)symbol, Name));
                }

                byte upperCaseSymbol = symbol;
                if (symbol >= 97 && symbol <= 122)
                {
                    upperCaseSymbol = (byte)(symbol - 32);
                }

                symbolsInUpperCase.Add(upperCaseSymbol);
            }

            // Remove all gap symbols
            HashSet <byte> gapItems = null;

            this.TryGetGapSymbols(out gapItems);

            byte defaultGap = 0;

            this.TryGetDefaultGapSymbol(out defaultGap);

            symbolsInUpperCase.ExceptWith(gapItems);

            if (symbolsInUpperCase.Count == 0)
            {
                // All are gap characters, return default 'Gap'
                return(defaultGap);
            }
            else if (symbolsInUpperCase.Count == 1)
            {
                return(symbolsInUpperCase.First());
            }
            else
            {
                HashSet <byte> baseSet = new HashSet <byte>();
                HashSet <byte> ambiguousSymbols;

                foreach (byte n in symbolsInUpperCase)
                {
                    ambiguousSymbols = null;
                    if (TryGetBasicSymbols(n, out ambiguousSymbols))
                    {
                        baseSet.UnionWith(ambiguousSymbols);
                    }
                    else
                    {
                        // If not found in ambiguous map, it has to be base / unambiguous character
                        baseSet.Add(n);
                    }
                }

                byte returnValue;
                TryGetAmbiguousSymbol(baseSet, out returnValue);

                return(returnValue);
            }
        }
Exemple #57
0
 private void RemoveWordFormingOverrides(IEnumerable <string> chars)
 {
     m_wordFormingOverrides.ExceptWith(chars.Select(c => char.ConvertToUtf32(c, 0)));
 }
Exemple #58
0
        List <ILNode> ConvertToAst(List <ByteCode> body, HashSet <ExceptionHandler> ehs)
        {
            List <ILNode> ast = new List <ILNode>();

            while (ehs.Any())
            {
                ILTryCatchBlock tryCatchBlock = new ILTryCatchBlock();

                // Find the first and widest scope
                int tryStart = ehs.Min(eh => eh.TryStart.Offset);
                int tryEnd   = ehs.Where(eh => eh.TryStart.Offset == tryStart).Max(eh => eh.TryEnd.Offset);
                var handlers = ehs.Where(eh => eh.TryStart.Offset == tryStart && eh.TryEnd.Offset == tryEnd).ToList();

                // Remember that any part of the body migt have been removed due to unreachability

                // Cut all instructions up to the try block
                {
                    int tryStartIdx = 0;
                    while (tryStartIdx < body.Count && body[tryStartIdx].Offset < tryStart)
                    {
                        tryStartIdx++;
                    }
                    ast.AddRange(ConvertToAst(body.CutRange(0, tryStartIdx)));
                }

                // Cut the try block
                {
                    HashSet <ExceptionHandler> nestedEHs = new HashSet <ExceptionHandler>(ehs.Where(eh => (tryStart <= eh.TryStart.Offset && eh.TryEnd.Offset < tryEnd) || (tryStart < eh.TryStart.Offset && eh.TryEnd.Offset <= tryEnd)));
                    ehs.ExceptWith(nestedEHs);
                    int tryEndIdx = 0;
                    while (tryEndIdx < body.Count && body[tryEndIdx].Offset < tryEnd)
                    {
                        tryEndIdx++;
                    }
                    tryCatchBlock.TryBlock = new ILBlock(ConvertToAst(body.CutRange(0, tryEndIdx), nestedEHs));
                }

                // Cut all handlers
                tryCatchBlock.CatchBlocks = new List <ILTryCatchBlock.CatchBlock>();
                foreach (ExceptionHandler eh in handlers)
                {
                    int handlerEndOffset = eh.HandlerEnd == null ? methodDef.Body.CodeSize : eh.HandlerEnd.Offset;
                    int startIdx         = 0;
                    while (startIdx < body.Count && body[startIdx].Offset < eh.HandlerStart.Offset)
                    {
                        startIdx++;
                    }
                    int endIdx = 0;
                    while (endIdx < body.Count && body[endIdx].Offset < handlerEndOffset)
                    {
                        endIdx++;
                    }
                    HashSet <ExceptionHandler> nestedEHs = new HashSet <ExceptionHandler>(ehs.Where(e => (eh.HandlerStart.Offset <= e.TryStart.Offset && e.TryEnd.Offset < handlerEndOffset) || (eh.HandlerStart.Offset < e.TryStart.Offset && e.TryEnd.Offset <= handlerEndOffset)));
                    ehs.ExceptWith(nestedEHs);
                    List <ILNode> handlerAst = ConvertToAst(body.CutRange(startIdx, endIdx - startIdx), nestedEHs);
                    if (eh.HandlerType == ExceptionHandlerType.Catch)
                    {
                        ILTryCatchBlock.CatchBlock catchBlock = new ILTryCatchBlock.CatchBlock()
                        {
                            ExceptionType = eh.CatchType,
                            Body          = handlerAst
                        };
                        // Handle the automatically pushed exception on the stack
                        ByteCode ldexception = ldexceptions[eh];
                        if (ldexception.StoreTo == null || ldexception.StoreTo.Count == 0)
                        {
                            // Exception is not used
                            catchBlock.ExceptionVariable = null;
                        }
                        else if (ldexception.StoreTo.Count == 1)
                        {
                            ILExpression first = catchBlock.Body[0] as ILExpression;
                            if (first != null &&
                                first.Code == ILCode.Pop &&
                                first.Arguments[0].Code == ILCode.Ldloc &&
                                first.Arguments[0].Operand == ldexception.StoreTo[0])
                            {
                                // The exception is just poped - optimize it all away;
                                if (context.Settings.AlwaysGenerateExceptionVariableForCatchBlocks)
                                {
                                    catchBlock.ExceptionVariable = new ILVariable()
                                    {
                                        Name = "ex_" + eh.HandlerStart.Offset.ToString("X2"), IsGenerated = true
                                    }
                                }
                                ;
                                else
                                {
                                    catchBlock.ExceptionVariable = null;
                                }
                                catchBlock.Body.RemoveAt(0);
                            }
                            else
                            {
                                catchBlock.ExceptionVariable = ldexception.StoreTo[0];
                            }
                        }
                        else
                        {
                            ILVariable exTemp = new ILVariable()
                            {
                                Name = "ex_" + eh.HandlerStart.Offset.ToString("X2"), IsGenerated = true
                            };
                            catchBlock.ExceptionVariable = exTemp;
                            foreach (ILVariable storeTo in ldexception.StoreTo)
                            {
                                catchBlock.Body.Insert(0, new ILExpression(ILCode.Stloc, storeTo, new ILExpression(ILCode.Ldloc, exTemp)));
                            }
                        }
                        tryCatchBlock.CatchBlocks.Add(catchBlock);
                    }
                    else if (eh.HandlerType == ExceptionHandlerType.Finally)
                    {
                        tryCatchBlock.FinallyBlock = new ILBlock(handlerAst);
                    }
                    else if (eh.HandlerType == ExceptionHandlerType.Fault)
                    {
                        tryCatchBlock.FaultBlock = new ILBlock(handlerAst);
                    }
                    else
                    {
                        // TODO: ExceptionHandlerType.Filter
                    }
                }

                ehs.ExceptWith(handlers);

                ast.Add(tryCatchBlock);
            }

            // Add whatever is left
            ast.AddRange(ConvertToAst(body));

            return(ast);
        }
        /// Process a message recieved from a client
        protected override void OnMessage(MessageEventArgs e)
        {
            // We only care about text messages, for now.
            if (e.Type != Opcode.Text)
            {
                return;
            }
            dataRates.RecieveDataFromClient(e.RawData.Length);

            // deserialize the message as JSON
            var json = SimpleJson.SimpleJson.DeserializeObject(e.Data) as SimpleJson.JsonObject;

            lock (dataLock)
            {
                // Do any tasks requested here
                foreach (var entry in json)
                {
                    // Try converting the item to a list - this is the most common expected.
                    // If we got a string, then add it to the list to allow "one-shot" submission
                    string[] listContents = new string[] { };
                    if (entry.Value is SimpleJson.JsonArray)
                    {
                        listContents = (entry.Value as SimpleJson.JsonArray).OfType <string>().Select(x => x.Trim()).ToArray();
                    }
                    else if (entry.Value is string)
                    {
                        listContents = new[] { entry.Value as string };
                    }

                    // Process the possible API entries
                    if (entry.Key == "+")
                    {
                        PluginLogger.print(string.Format("Client {0} added {1}", ID, string.Join(",", listContents)));
                        subscriptions.UnionWith(listContents);
                    }
                    else if (entry.Key == "-")
                    {
                        PluginLogger.print(string.Format("Client {0} removed {1}", ID, string.Join(",", listContents)));
                        subscriptions.ExceptWith(listContents);
                    }
                    else if (entry.Key == "run")
                    {
                        PluginLogger.print(string.Format("Client {0} running {1}", ID, string.Join(",", listContents)));
                        oneShotRuns.UnionWith(listContents);
                    }
                    else if (entry.Key == "rate")
                    {
                        streamRate = Convert.ToInt32(entry.Value);
                        PluginLogger.print(string.Format("Client {0} setting rate {1}", ID, streamRate));
                    }
                    else if (entry.Key == "binary")
                    {
                        binarySubscriptions = listContents;
                        PluginLogger.print(string.Format("Client {0} requests binary packets {1}", ID, string.Join(", ", listContents)));
                    }
                    else
                    {
                        PluginLogger.print(String.Format("Client {0} send unrecognised key {1}", ID, entry.Key));
                    }
                }
            } // Lock
        }     // OnMessage
Exemple #60
0
        /// <summary>
        /// Export the build graph to a Json file, for parallel execution by the build system
        /// </summary>
        /// <param name="File">Output file to write</param>
        /// <param name="Trigger">The trigger whose nodes to run. Null for the default nodes.</param>
        /// <param name="CompletedNodes">Set of nodes which have been completed</param>
        public void Export(FileReference File, ManualTrigger Trigger, HashSet <Node> CompletedNodes)
        {
            // Find all the nodes which we're actually going to execute. We'll use this to filter the graph.
            HashSet <Node> NodesToExecute = new HashSet <Node>();

            foreach (Node Node in Agents.SelectMany(x => x.Nodes))
            {
                if (!CompletedNodes.Contains(Node) && Node.IsBehind(Trigger))
                {
                    NodesToExecute.Add(Node);
                }
            }

            // Open the output file
            using (JsonWriter JsonWriter = new JsonWriter(File.FullName))
            {
                JsonWriter.WriteObjectStart();

                // Write all the agents
                JsonWriter.WriteArrayStart("Groups");
                foreach (Agent Agent in Agents)
                {
                    Node[] Nodes = Agent.Nodes.Where(x => NodesToExecute.Contains(x) && x.ControllingTrigger == Trigger).ToArray();
                    if (Nodes.Length > 0)
                    {
                        JsonWriter.WriteObjectStart();
                        JsonWriter.WriteValue("Name", Agent.Name);
                        JsonWriter.WriteArrayStart("Agent Types");
                        foreach (string AgentType in Agent.PossibleTypes)
                        {
                            JsonWriter.WriteValue(AgentType);
                        }
                        JsonWriter.WriteArrayEnd();
                        JsonWriter.WriteArrayStart("Nodes");
                        foreach (Node Node in Nodes)
                        {
                            JsonWriter.WriteObjectStart();
                            JsonWriter.WriteValue("Name", Node.Name);
                            JsonWriter.WriteValue("DependsOn", String.Join(";", Node.GetDirectOrderDependencies().Where(x => NodesToExecute.Contains(x) && x.ControllingTrigger == Trigger)));
                            JsonWriter.WriteObjectStart("Notify");
                            JsonWriter.WriteValue("Default", String.Join(";", Node.NotifyUsers));
                            JsonWriter.WriteValue("Submitters", String.Join(";", Node.NotifySubmitters));
                            JsonWriter.WriteValue("Warnings", Node.bNotifyOnWarnings);
                            JsonWriter.WriteObjectEnd();
                            JsonWriter.WriteObjectEnd();
                        }
                        JsonWriter.WriteArrayEnd();
                        JsonWriter.WriteObjectEnd();
                    }
                }
                JsonWriter.WriteArrayEnd();

                // Write all the badges
                JsonWriter.WriteArrayStart("Badges");
                foreach (Badge Badge in Badges)
                {
                    Node[] Dependencies = Badge.Nodes.Where(x => NodesToExecute.Contains(x) && x.ControllingTrigger == Trigger).ToArray();
                    if (Dependencies.Length > 0)
                    {
                        // Reduce that list to the smallest subset of direct dependencies
                        HashSet <Node> DirectDependencies = new HashSet <Node>(Dependencies);
                        foreach (Node Dependency in Dependencies)
                        {
                            DirectDependencies.ExceptWith(Dependency.OrderDependencies);
                        }

                        JsonWriter.WriteObjectStart();
                        JsonWriter.WriteValue("Name", Badge.Name);
                        if (!String.IsNullOrEmpty(Badge.Project))
                        {
                            JsonWriter.WriteValue("Project", Badge.Project);
                        }
                        if (Badge.Change != 0)
                        {
                            JsonWriter.WriteValue("Change", Badge.Change);
                        }
                        JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
                        JsonWriter.WriteValue("DirectDependencies", String.Join(";", DirectDependencies.Select(x => x.Name)));
                        JsonWriter.WriteObjectEnd();
                    }
                }
                JsonWriter.WriteArrayEnd();

                // Write all the triggers and reports.
                JsonWriter.WriteArrayStart("Reports");
                foreach (Report Report in NameToReport.Values)
                {
                    Node[] Dependencies = Report.Nodes.Where(x => NodesToExecute.Contains(x) && x.ControllingTrigger == Trigger).ToArray();
                    if (Dependencies.Length > 0)
                    {
                        // Reduce that list to the smallest subset of direct dependencies
                        HashSet <Node> DirectDependencies = new HashSet <Node>(Dependencies);
                        foreach (Node Dependency in Dependencies)
                        {
                            DirectDependencies.ExceptWith(Dependency.OrderDependencies);
                        }

                        JsonWriter.WriteObjectStart();
                        JsonWriter.WriteValue("Name", Report.Name);
                        JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
                        JsonWriter.WriteValue("DirectDependencies", String.Join(";", DirectDependencies.Select(x => x.Name)));
                        JsonWriter.WriteValue("Notify", String.Join(";", Report.NotifyUsers));
                        JsonWriter.WriteValue("IsTrigger", false);
                        JsonWriter.WriteObjectEnd();
                    }
                }
                foreach (ManualTrigger DownstreamTrigger in NameToTrigger.Values)
                {
                    if (DownstreamTrigger.Parent == Trigger)
                    {
                        // Find all the nodes that this trigger is dependent on
                        HashSet <Node> Dependencies = new HashSet <Node>();
                        foreach (Node NodeToExecute in NodesToExecute)
                        {
                            if (NodeToExecute.IsBehind(DownstreamTrigger))
                            {
                                Dependencies.UnionWith(NodeToExecute.OrderDependencies.Where(x => x.ControllingTrigger == Trigger));
                            }
                        }

                        // Reduce that list to the smallest subset of direct dependencies
                        HashSet <Node> DirectDependencies = new HashSet <Node>(Dependencies);
                        foreach (Node Dependency in Dependencies)
                        {
                            DirectDependencies.ExceptWith(Dependency.OrderDependencies);
                        }

                        // Write out the object
                        JsonWriter.WriteObjectStart();
                        JsonWriter.WriteValue("Name", DownstreamTrigger.Name);
                        JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
                        JsonWriter.WriteValue("DirectDependencies", String.Join(";", Dependencies.Where(x => DirectDependencies.Contains(x)).Select(x => x.Name)));
                        JsonWriter.WriteValue("Notify", String.Join(";", DownstreamTrigger.NotifyUsers));
                        JsonWriter.WriteValue("IsTrigger", true);
                        JsonWriter.WriteObjectEnd();
                    }
                }
                JsonWriter.WriteArrayEnd();

                JsonWriter.WriteObjectEnd();
            }
        }