コード例 #1
0
 /// <summary>
 ///     Takes this task and executes the given action, note that this method is not threadsafe!
 /// </summary>
 /// <param name="act"></param>
 public void Take(Action act)
 {
     if (!IsAvailable)
     {
         throw new InvalidOperationException("Can't take a HaltedTask that is already taken! Check IsAvailable first!! (This method is not safe thread!)");
     }
     rst.Set(act);
 }
コード例 #2
0
ファイル: WelderHUD.cs プロジェクト: Cheetah97/LaserWelders
        public void ComplainMissing(Dictionary <IMySlimBlock, Dictionary <string, int> > MissingPerBlock)
        {
            if (MissingPerBlock.Count == 0)
            {
                //SessionCore.DebugWrite(Tool.CustomName, $"ComplainMissing() early exit - 0 missing components", WriteOnlyIfDebug: true);
                return;
            }

            //if (SessionCore.Debug)
            //    SessionCore.DebugWrite(Tool.CustomName, $"ComplainMissing(): {MissingPerBlock.Count} blocks, {MissingPerBlock.Values.Sum(x => x.Values.Sum())} total components missing", WriteOnlyIfDebug: true);

            if (MyAPIGateway.Multiplayer.IsServer)
            {
                StringBuilder Text   = WriteMissing(MissingPerBlock);
                var           Player = MyAPIGateway.Session.Player;
                if (Player == null || Player.IdentityId != Tool.OwnerId)
                {
                    MissingText.Set(Text.ToString());
                    //SessionCore.DebugWrite(Tool.CustomName, $"ComplainMissing() exit - local player == null or ID mismatch", WriteOnlyIfDebug: true);
                }
                else if (Player.IdentityId == Tool.OwnerId)
                {
                    ComplainMissingLocal(Text.ToString());
                }
            }
            else
            {
                //SessionCore.DebugWrite(Tool.CustomName, $"ComplainMissing() exit - not a server", WriteOnlyIfDebug: true);
            }
        }
コード例 #3
0
ファイル: LaserDrill.cs プロジェクト: Cheetah97/LaserWelders
 public void Load()
 {
     try
     {
         if (MyAPIGateway.Multiplayer.MultiplayerActive && !MyAPIGateway.Multiplayer.IsServer)
         {
             SyncHarvestEfficiency.Ask();
             return;
         }
         string Storage = "";
         //if (Tool.Storage.ContainsKey(SessionCore.StorageGuid))
         if (Drill.Storage?.TryGetValue(SessionCore.StorageGuid, out Storage) == true)
         {
             try
             {
                 Persistent persistent = MyAPIGateway.Utilities.SerializeFromBinary <Persistent>(Convert.FromBase64String(Storage));
                 SyncHarvestEfficiency.Set(persistent.HarvestMultiplier);
             }
             catch (Exception Scrap)
             {
                 SessionCore.LogError($"{Drill.CustomName}.Load()", Scrap);
             }
         }
         else
         {
             SessionCore.DebugWrite($"{Drill.CustomName}.Load()", "Storage access failed.");
         }
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError($"{Drill.CustomName}.Load().AccessStorage", Scrap);
     }
 }
コード例 #4
0
        public Syncer <OUT> StartMining(CancellationTokenSource src)
        {
            var m = new Syncer <OUT>();

            var  _funcs = Factory.CreateMiners(src?.Token ?? CancellationToken.None).ToArray();
            long c      = _funcs.Length;

            foreach (var func in _funcs)
            {
                Task.Factory.StartNew(() => {
                    var res = default(OUT);
                    try {
                        src?.Token.ThrowIfCancellationRequested();
                        res = func();
/*#if DEBUG*/
                    } catch (Exception e) {
                        Console.WriteLine(e);

/*#else
 *                      } catch {
 #endif*/
                    } finally {
                        Interlocked.Decrement(ref c);
                        if (!m.IsSet && (src?.IsCancellationRequested == true || Interlocked.Read(ref c) == 0))
                        {
                            m.Set(default(OUT));
                            src?.Cancel();
                        }
                    }
                    lock (m.Sync)
                        if (!m.IsSet && !(res != null && res.Equals(default(OUT))))
                        {
                            m.Set(res);
                            src?.Cancel();
                        }
                }, src?.Token ?? CancellationToken.None);
            }
            return(m);
        }