예제 #1
0
        public MainForm()
        {
            InitializeComponent();

            _callback = new MapCallback(statusStrip1, progressBar1, lblProgressMessage);

            _form = this;

            Init();
        }
예제 #2
0
        /// <summary>
        /// Calls a defined callback function on each element of an array, and returns an array that contains the results.
        /// </summary>
        /// <param name="callbackfn">A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.</param>
        /// <returns></returns>
        public JSDynamicArray Map(MapCallback callbackfn)
        {
            JSDynamicArray newArray = new JSDynamicArray();

            for (int index = 0; index < this.Length; index++)
            {
                newArray.Push(callbackfn(this[index], index, this));
            }

            return(newArray);
        }
예제 #3
0
        public static void Map <T>(this IEnumerable <T> collection, MapCallback <T> callback)
        {
            var enumerator = collection.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    var current = enumerator.Current;
                    var result  = callback.Invoke(current);
                    if (result.HasFlag(MapResult.Failure | MapResult.Halt))
                    {
                        break;
                    }
                }
            }
            finally
            {
                enumerator?.Dispose();
            }
        }
예제 #4
0
        public void GetMap(string mapName, MapCallback callback, Action <Exception> errorCallback)
        {
            var metadataPath  = GetMetadataPath(mapName);
            var minimapFile   = GetMinimapPath(mapName);
            var metalMapFile  = GetMetalmapPath(mapName);
            var heightMapFile = GetHeightmapPath(mapName);

            if (File.Exists(metadataPath))
            {
                // map found
                Map map = null;
                try
                {
                    map = GetMapMetadata(mapName);
                }
                catch (Exception e)
                {
                    Trace.WriteLine("Unable to deserialize map " + mapName + " from disk: " + e);
                }
                if (map != null)
                {
                    var minimapBytes   = File.Exists(minimapFile) ? File.ReadAllBytes(minimapFile) : null;
                    var heightMapBytes = File.Exists(heightMapFile) ? File.ReadAllBytes(heightMapFile) : null;
                    var metalMapBytes  = File.Exists(metalMapFile) ? File.ReadAllBytes(metalMapFile) : null;
                    callback(map, minimapBytes, heightMapBytes, metalMapBytes);
                    return;
                }
            }

            try
            {
                lock (mapRequestsLock)
                {
                    List <MapRequestCallBacks> list;
                    if (currentMapRequests.TryGetValue(mapName, out list))
                    {
                        list.Add(new MapRequestCallBacks(callback, errorCallback));
                        return;
                    }
                    else
                    {
                        currentMapRequests[mapName] = new List <MapRequestCallBacks>()
                        {
                            new MapRequestCallBacks(callback, errorCallback)
                        }
                    };
                }

                byte[] minimap   = null;
                byte[] metalmap  = null;
                byte[] heightmap = null;
                byte[] metadata  = null;

                lock (webClientForMap)
                {
                    var serverResourceUrlBase = GlobalConst.ResourceBaseUrl;
                    minimap = webClientForMap.DownloadData(String.Format("{0}/{1}.minimap.jpg", serverResourceUrlBase, mapName.EscapePath()));

                    metalmap = webClientForMap.DownloadData(String.Format("{0}/{1}.metalmap.jpg", serverResourceUrlBase, mapName.EscapePath()));

                    heightmap = webClientForMap.DownloadData(String.Format("{0}/{1}.heightmap.jpg", serverResourceUrlBase, mapName.EscapePath()));

                    metadata = webClientForMap.DownloadData(String.Format("{0}/{1}.metadata.xml.gz", serverResourceUrlBase, mapName.EscapePath()));
                }

                var map = GetMapMetadata(metadata);

                File.WriteAllBytes(minimapFile, minimap);
                File.WriteAllBytes(heightMapFile, heightmap);
                File.WriteAllBytes(metalMapFile, metalmap);
                File.WriteAllBytes(metadataPath, metadata);

                lock (mapRequestsLock)
                {
                    List <MapRequestCallBacks> rl;
                    currentMapRequests.TryGetValue(mapName, out rl);
                    if (rl != null)
                    {
                        foreach (var request in rl)
                        {
                            request.SuccessCallback(map, minimap, heightmap, metalmap);
                        }
                    }
                    currentMapRequests.Remove(mapName);
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine("Unable to deserialize map " + mapName + " from the server: " + e);

                try
                {
                    lock (mapRequestsLock)
                    {
                        List <MapRequestCallBacks> rl;
                        currentMapRequests.TryGetValue(mapName, out rl);
                        if (rl != null)
                        {
                            foreach (var request in rl)
                            {
                                request.ErrorCallback(e);
                            }
                        }
                        currentMapRequests.Remove(mapName);
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Error processing map download error {0}: {1}", mapName, ex);
                }
            }
        }
예제 #5
0
 public MapRequestCallBacks(MapCallback successCallback, Action <Exception> errorCallback)
 {
     SuccessCallback = successCallback;
     ErrorCallback   = errorCallback;
 }
예제 #6
0
 public void GetMapAsync(string mapName, MapCallback callback, Action <Exception> errorCallback)
 {
     Utils.StartAsync(() => GetMap(mapName, callback, errorCallback));
 }
예제 #7
0
        /**注册地图加载完成时--回调处理**/

        public void AddMapCallback(MapCallback mapLoadCallBack)
        {
            _callback = mapLoadCallBack;
        }
        public void GetMap(string mapName, MapCallback callback, Action<Exception> errorCallback)
        {
            var metadataPath = GetMetadataPath(mapName);
            var minimapFile = GetMinimapPath(mapName);
            var metalMapFile = GetMetalmapPath(mapName);
            var heightMapFile = GetHeightmapPath(mapName);

            if (File.Exists(metadataPath))
            {
                // map found
                Map map = null;
                try
                {
                    map = GetMapMetadata(mapName);
                }
                catch (Exception e)
                {
                    Trace.WriteLine("Unable to deserialize map " + mapName + " from disk: " + e);
                }
                if (map != null)
                {
                    var minimapBytes = File.Exists(minimapFile) ? File.ReadAllBytes(minimapFile) : null;
                    var heightMapBytes = File.Exists(heightMapFile) ? File.ReadAllBytes(heightMapFile) : null;
                    var metalMapBytes = File.Exists(metalMapFile) ? File.ReadAllBytes(metalMapFile) : null;
                    callback(map, minimapBytes, heightMapBytes, metalMapBytes);
                    return;
                }
            }

            try
            {
                lock (mapRequestsLock)
                {
                    List<MapRequestCallBacks> list;
                    if (currentMapRequests.TryGetValue(mapName, out list))
                    {
                        list.Add(new MapRequestCallBacks(callback, errorCallback));
                        return;
                    }
                    else currentMapRequests[mapName] = new List<MapRequestCallBacks>() { new MapRequestCallBacks(callback, errorCallback) };
                }

                byte[] minimap = null;
                byte[] metalmap = null;
                byte[] heightmap = null;
                byte[] metadata = null;

                lock (webClientForMap)
                {
                    var serverResourceUrlBase = GlobalConst.ResourceBaseUrl;
                    minimap = webClientForMap.DownloadData(String.Format("{0}/{1}.minimap.jpg", serverResourceUrlBase, mapName.EscapePath()));

                    metalmap = webClientForMap.DownloadData(String.Format("{0}/{1}.metalmap.jpg", serverResourceUrlBase, mapName.EscapePath()));

                    heightmap = webClientForMap.DownloadData(String.Format("{0}/{1}.heightmap.jpg", serverResourceUrlBase, mapName.EscapePath()));

                    metadata = webClientForMap.DownloadData(String.Format("{0}/{1}.metadata.xml.gz", serverResourceUrlBase, mapName.EscapePath()));
                }

                var map = GetMapMetadata(metadata);

                File.WriteAllBytes(minimapFile, minimap);
                File.WriteAllBytes(heightMapFile, heightmap);
                File.WriteAllBytes(metalMapFile, metalmap);
                File.WriteAllBytes(metadataPath, metadata);

                lock (mapRequestsLock)
                {
                    List<MapRequestCallBacks> rl;
                    currentMapRequests.TryGetValue(mapName, out rl);
                    if (rl != null) foreach (var request in rl) request.SuccessCallback(map, minimap, heightmap, metalmap);
                    currentMapRequests.Remove(mapName);
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine("Unable to deserialize map " + mapName + " from the server: " + e);

                try
                {
                    lock (mapRequestsLock)
                    {
                        List<MapRequestCallBacks> rl;
                        currentMapRequests.TryGetValue(mapName, out rl);
                        if (rl != null) foreach (var request in rl) request.ErrorCallback(e);
                        currentMapRequests.Remove(mapName);
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Error processing map download error {0}: {1}", mapName, ex);
                }
            }
        }
 public MapRequestCallBacks(MapCallback successCallback, Action<Exception> errorCallback)
 {
     SuccessCallback = successCallback;
     ErrorCallback = errorCallback;
 }
예제 #10
0
 public void GetMapAsync(string mapName, MapCallback callback, Action<Exception> errorCallback)
 {
     Utils.StartAsync(() => GetMap(mapName, callback, errorCallback));
 }
예제 #11
0
        private void MapSharer_OnMapUploadFailed(Map map)
        {
            if (lbChatBox.InvokeRequired)
            {
                MapCallback d = new MapCallback(MapSharer_OnMapUploadFailed);
                this.BeginInvoke(d, map);
                return;
            }

            AddNotice("Uploading map " + map.Name + " to the CnCNet map database failed.");
            AddNotice("You need to change the map or some players won't be able to participate in this match.");

            hostUploadedMaps.Add(map.SHA1);

            string msgToSend = "NOTICE " + ChannelName + " " + CTCPChar1 + CTCPChar2 + "MAPFAIL " + map.SHA1 + CTCPChar2;
            CnCNetData.ConnectionBridge.SendMessage(msgToSend);
        }
예제 #12
0
        private void MapSharer_OnMapUploadComplete(Map map)
        {
            if (lbChatBox.InvokeRequired)
            {
                MapCallback d = new MapCallback(MapSharer_OnMapUploadComplete);
                this.BeginInvoke(d, map);
                return;
            }

            hostUploadedMaps.Add(map.SHA1);

            AddNotice("Uploading map " + map.Name + " to the CnCNet map database complete.");

            string msgToSend = "NOTICE " + ChannelName + " " + CTCPChar1 + CTCPChar2 + "MAPOK " + map.SHA1 + CTCPChar2;
            CnCNetData.ConnectionBridge.SendMessage(msgToSend);
        }