Exemplo n.º 1
0
 private Task <TResult> GetAsynchronousResponse <TResult>(AsyncResults taskCompletionSource, CancellationToken cancellationToken)
 {
     return(TaskFactoryHelper <TResult> .StartNew(
                () =>
     {
         object obj;
         while (!(taskCompletionSource.TryTake(out obj, (int)TimeSpan.FromMinutes(2).TotalMilliseconds, cancellationToken)))
         {
             if (obj is TResult)
             {
                 return (TResult)obj;
             }
         }
         throw new AbandonedMutexException("We did not receive of reply from the server after 2 minutes for transaction " + taskCompletionSource.Id);
     }, BackgroundTaskScheduler.OnBackground(), cancellationToken));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Provides a synchronous wait version of a server request and callback.
        /// If the caller thread is UI thread, it executes asynchronously.
        /// If the caller thread is not UI thread, it blocks the caller thread.
        /// </summary>
        /// <typeparam name="T">The type expected via callback.</typeparam>
        /// <typeparam name="TResponse"></typeparam>
        /// <typeparam name="TRequest"></typeparam>
        /// <param name="request"></param>
        /// <param name="svcGatewayMethod"></param>
        /// <param name="timeout">The time to wait before giving up on the service response.</param>
        /// <returns></returns>
        /// <remarks>Note that this does not currently support progress reporting. If the service provides progress
        /// reports this will need to be amended.</remarks>
        protected TResponse ServerRequest <TResponse, TRequest>(TRequest request, SvcGatewayDelegate <TRequest, TResponse> svcGatewayMethod, TimeSpan timeout)
            where TResponse : ServiceResponse
            where TRequest : ICommonRequest
        {
            AsyncResults asyncResults = AddToResponseQueue(request.RequestID);

            TimeSpan defaultTimeout = TimeSpan.FromMinutes(2);

            if (defaultTimeout < timeout)
            {
                timeout = defaultTimeout;
            }
            if (UIThreadSingleton.IsCreated && UIThreadSingleton.IsCallFromUIThread)
            {
                Task <TResponse> callCompleted = TaskFactoryHelper <TResponse> .StartNew(
                    () => ExecServerRequest(request, svcGatewayMethod, timeout, asyncResults), BackgroundTaskScheduler.OnBackground());

                while (!callCompleted.IsFinishedRunning())
                {
                    Application.DoEvents();
                }

                if (callCompleted.Status != TaskStatus.RanToCompletion)
                {
                    if (callCompleted.Exception != null)
                    {
                        AggregateException aggregateException = callCompleted.Exception.Flatten();
                        if (aggregateException.InnerException != null)
                        {
                            throw aggregateException.InnerException;
                        }
                    }
                }
                return(callCompleted.Result);
            }
            else
            {
                return(ExecServerRequest(request, svcGatewayMethod, timeout, asyncResults));
            }
        }
Exemplo n.º 3
0
        public void Validate()
        {
            var t = TaskFactoryHelper.UiTaskFactory.StartNew(() =>
            {
                for (int x = 0; x < TilesWide; x++)
                {
                    OnProgressChanged(this,
                                      new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "Validating World..."));

                    for (int y = 0; y < TilesHigh; y++)
                    {
                        Tile curTile = Tiles[x, y];

                        if (curTile.Type == (int)TileType.IceByRod)
                        {
                            curTile.IsActive = false;
                        }

                        ValSpecial(x, y);
                    }
                }
            });

            foreach (Chest chest in Chests.ToArray())
            {
                bool removed = false;
                for (int x = chest.X; x < chest.X + 1; x++)
                {
                    for (int y = chest.Y; y < chest.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsChest(Tiles[x, y].Type))
                        {
                            Chests.Remove(chest);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }

            foreach (Sign sign in Signs.ToArray())
            {
                if (sign.Text == null)
                {
                    Signs.Remove(sign);
                    continue;
                }

                bool removed = false;
                for (int x = sign.X; x < sign.X + 1; x++)
                {
                    for (int y = sign.Y; y < sign.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsSign(Tiles[x, y].Type))
                        {
                            Signs.Remove(sign);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }


            foreach (TileEntity tileEntity in TileEntities.ToArray())
            {
                int x      = tileEntity.PosX;
                int y      = tileEntity.PosY;
                var anchor = GetAnchor(x, y);
                if (!Tiles[anchor.X, anchor.Y].IsActive || !Tile.IsTileEntity(Tiles[anchor.X, anchor.Y].Type))
                {
                    TaskFactoryHelper.ExecuteUiTask(() => TileEntities.Remove(tileEntity));
                }
            }

            OnProgressChanged(this,
                              new ProgressChangedEventArgs(0, "Validating Complete..."));

            if (Chests.Count > World.MaxChests)
            {
                throw new ArgumentOutOfRangeException($"Chest Count is {Chests.Count} which is greater than {World.MaxChests}.");
            }
            if (Signs.Count > World.MaxSigns)
            {
                throw new ArgumentOutOfRangeException($"Sign Count is {Signs.Count} which is greater than {World.MaxSigns}.");
            }
        }
Exemplo n.º 4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            ErrorLogging.Initialize();
            ErrorLogging.Log($"Starting TEdit {ErrorLogging.Version}");
            ErrorLogging.Log($"OS: {Environment.OSVersion}");

            Assembly asm = Assembly.GetExecutingAssembly();

            Version = FileVersionInfo.GetVersionInfo(asm.Location);

            try
            {
                int directxMajorVersion = DependencyChecker.GetDirectxMajorVersion();
                if (directxMajorVersion < 11)
                {
                    ErrorLogging.Log($"DirectX {directxMajorVersion} unsupported. DirectX 11 or higher is required.");
                }
            }
            catch (Exception ex)
            {
                ErrorLogging.Log("Failed to verify DirectX Version. TEdit may not run properly.");
                ErrorLogging.LogException(ex);
            }

            try
            {
                DependencyChecker.CheckPaths();
            }
            catch (Exception ex)
            {
                ErrorLogging.Log("Failed to verify Terraria Paths. TEdit may not run properly.");
                ErrorLogging.LogException(ex);
            }


            try
            {
                if (!DependencyChecker.VerifyTerraria())
                {
                    ErrorLogging.Log("Unable to locate Terraria. No texture data will be available.");
                }
                else
                {
                    ErrorLogging.Log($"Terraria v{DependencyChecker.GetTerrariaVersion() ?? "not found"}");
                    ErrorLogging.Log($"Terraria Data Path: {DependencyChecker.PathToContent}");
                }
            }
            catch (Exception ex)
            {
                ErrorLogging.Log("Failed to verify Terraria Paths. No texture data will be available.");
                ErrorLogging.LogException(ex);
            }


            if (e.Args != null && e.Args.Count() > 0)
            {
                ErrorLogging.Log($"Command Line Open: {e.Args[0]}");
                Properties["OpenFile"] = e.Args[0];
            }

            if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null &&
                AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null &&
                AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0)
            {
                string fname = "No filename given";
                try
                {
                    fname = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];

                    // It comes in as a URI; this helps to convert it to a path.
                    var uri = new Uri(fname);
                    fname = uri.LocalPath;

                    Properties["OpenFile"] = fname;
                }
                catch (Exception ex)
                {
                    // For some reason, this couldn't be read as a URI.
                    // Do what you must...
                    ErrorLogging.LogException(ex);
                }
            }

            DispatcherHelper.Initialize();
            TaskFactoryHelper.Initialize();
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            base.OnStartup(e);
        }
Exemplo n.º 5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            ErrorLogging.Initialize();
            ErrorLogging.Log(string.Format("TEdit版本 {0} (CN: {1})", ErrorLogging.Version, CnVersion.ToString(3)));
            ErrorLogging.Log(string.Format("OS: {0}", Environment.OSVersion));

            Assembly asm = Assembly.GetExecutingAssembly();

            Version = FileVersionInfo.GetVersionInfo(asm.Location);

            try
            {
                int directxMajorVersion = DependencyChecker.GetDirectxMajorVersion();
                if (directxMajorVersion < 11)
                {
                    ErrorLogging.Log(string.Format("DirectX {0} 过旧. 需要 DirectX 11 及更高版本.", directxMajorVersion));
                }
            }
            catch (Exception ex)
            {
                ErrorLogging.Log("无法验证DirectX版本. TEdit 可能无法正确运行.");
                ErrorLogging.LogException(ex);
            }

            try
            {
                DependencyChecker.CheckPaths();
            }
            catch (Exception ex)
            {
                ErrorLogging.Log("寻找 Terraria 材质路径失败. TEdit 可能无法正确运行.");
                ErrorLogging.LogException(ex);
            }


            try
            {
                if (!DependencyChecker.VerifyTerraria())
                {
                    ErrorLogging.Log("寻找 Terraria 目录失败. 没有可用的材质.");
                }
                else
                {
                    ErrorLogging.Log(string.Format("Terraria v{0}", DependencyChecker.GetTerrariaVersion() ?? "not found"));
                    ErrorLogging.Log(string.Format("Terraria Data Path: {0}", DependencyChecker.PathToContent));
                } // 日志文件里的内容, 暂时跳过汉化
            }
            catch (Exception ex)
            {
                ErrorLogging.Log("Failed to verify Terraria Paths. No texture data will be available.");
                ErrorLogging.LogException(ex);
            }


            if (e.Args != null && e.Args.Count() > 0)
            {
                ErrorLogging.Log(string.Format("Command Line Open: {0}", e.Args[0]));
                this.Properties["OpenFile"] = e.Args[0];
            }

            if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null &&
                AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null &&
                AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0)
            {
                string fname = "No filename given";
                try
                {
                    fname = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];

                    // It comes in as a URI; this helps to convert it to a path.
                    var uri = new Uri(fname);
                    fname = uri.LocalPath;

                    this.Properties["OpenFile"] = fname;
                }
                catch (Exception ex)
                {
                    // For some reason, this couldn't be read as a URI.
                    // Do what you must...
                    ErrorLogging.LogException(ex);
                }
            }

            DispatcherHelper.Initialize();
            TaskFactoryHelper.Initialize();
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            base.OnStartup(e);
        }
Exemplo n.º 6
0
        protected override void OnStartup(StartupEventArgs e)
        {
            ErrorLogging.Initialize();
            ErrorLogging.Log(string.Format("Starting TEdit {0}", ErrorLogging.Version));
            ErrorLogging.Log(string.Format("OS: {0}", Environment.OSVersion));

            Assembly asm = Assembly.GetExecutingAssembly();

            Version = FileVersionInfo.GetVersionInfo(asm.Location);

            if (!DependencyChecker.VerifyDotNet())
            {
                MessageBox.Show("Please install .Net 4.0", "Missing .Net", MessageBoxButton.OK, MessageBoxImage.Stop);
                ErrorLogging.LogException(new ApplicationException("MISSING .NET"));
                Shutdown();
            }
            else
            {
                ErrorLogging.Log(".Net >= 4.0");
            }

            if (!DependencyChecker.VerifyXna())
            {
                MessageBox.Show("Please install XNA Framework 4.0", "Missing XNA", MessageBoxButton.OK, MessageBoxImage.Stop);
                ErrorLogging.LogException(new ApplicationException("MISSING XNA"));
                Shutdown();
            }
            else
            {
                ErrorLogging.Log("XNA 4.0");
            }

            if (!DependencyChecker.VerifyTerraria())
            {
                ErrorLogging.Log("Unable to locate Terraria. No texture data will be available.");
            }
            else
            {
                ErrorLogging.Log(string.Format("Terraria Data Path: {0}", DependencyChecker.PathToContent));
            }

            if (e.Args != null && e.Args.Count() > 0)
            {
                ErrorLogging.Log(string.Format("Command Line Open: {0}", e.Args[0]));
                this.Properties["OpenFile"] = e.Args[0];
            }

            if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null &&
                AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null &&
                AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0)
            {
                string fname = "No filename given";
                try
                {
                    fname = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];

                    // It comes in as a URI; this helps to convert it to a path.
                    var uri = new Uri(fname);
                    fname = uri.LocalPath;

                    this.Properties["OpenFile"] = fname;
                }
                catch (Exception ex)
                {
                    // For some reason, this couldn't be read as a URI.
                    // Do what you must...
                    ErrorLogging.LogException(ex);
                }
            }

            DispatcherHelper.Initialize();
            TaskFactoryHelper.Initialize();
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            base.OnStartup(e);
        }